blob: 70a49fb45e2cbabed608f1351f83bf8f619057f4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
Ignacio Solla451e3382014-11-10 10:35:54 +000019import android.annotation.SystemApi;
Selim Gurun48f6c452014-07-18 16:23:46 -070020import android.content.Intent;
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040021import android.content.pm.ActivityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.graphics.Bitmap;
Leon Scroggins70ca3c22009-10-02 15:58:55 -040023import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.os.Message;
Andrei Popescu6fa29582009-06-19 14:54:09 +010025import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
27public class WebChromeClient {
28
29 /**
30 * Tell the host application the current progress of loading a page.
31 * @param view The WebView that initiated the callback.
32 * @param newProgress Current page loading progress, represented by
33 * an integer between 0 and 100.
34 */
35 public void onProgressChanged(WebView view, int newProgress) {}
36
37 /**
38 * Notify the host application of a change in the document title.
39 * @param view The WebView that initiated the callback.
40 * @param title A String containing the new title of the document.
41 */
42 public void onReceivedTitle(WebView view, String title) {}
43
44 /**
45 * Notify the host application of a new favicon for the current page.
46 * @param view The WebView that initiated the callback.
47 * @param icon A Bitmap containing the favicon for the current page.
48 */
49 public void onReceivedIcon(WebView view, Bitmap icon) {}
50
51 /**
Patrick Scott2ba12622009-08-04 13:20:05 -040052 * Notify the host application of the url for an apple-touch-icon.
53 * @param view The WebView that initiated the callback.
54 * @param url The icon url.
Patrick Scottd58ccff2009-09-18 16:29:00 -040055 * @param precomposed True if the url is for a precomposed touch icon.
Patrick Scott2ba12622009-08-04 13:20:05 -040056 */
Patrick Scottd58ccff2009-09-18 16:29:00 -040057 public void onReceivedTouchIconUrl(WebView view, String url,
58 boolean precomposed) {}
Patrick Scott2ba12622009-08-04 13:20:05 -040059
60 /**
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010061 * A callback interface used by the host application to notify
62 * the current page that its custom view has been dismissed.
Andrei Popescu6fa29582009-06-19 14:54:09 +010063 */
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010064 public interface CustomViewCallback {
65 /**
66 * Invoked when the host application dismisses the
67 * custom view.
68 */
69 public void onCustomViewHidden();
70 }
71
72 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +000073 * Notify the host application that the current page has entered full
74 * screen mode. The host application must show the custom View which
75 * contains the web contents — video or other HTML content —
76 * in full screen mode. Also see "Full screen support" documentation on
Kristian Monsen0e0b2da2013-04-10 13:43:43 -070077 * {@link WebView}.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010078 * @param view is the View object to be shown.
Ignacio Solla7a4e18f2014-12-29 12:21:52 +000079 * @param callback invoke this callback to request the page to exit
80 * full screen mode.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010081 */
82 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010083
84 /**
85 * Notify the host application that the current page would
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040086 * like to show a custom View in a particular orientation.
87 * @param view is the View object to be shown.
88 * @param requestedOrientation An orientation constant as used in
89 * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
90 * @param callback is the callback to be invoked if and when the view
91 * is dismissed.
Kristian Monsen0e0b2da2013-04-10 13:43:43 -070092 * @deprecated This method supports the obsolete plugin mechanism,
93 * and will not be invoked in future
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040094 */
Kristian Monsen0e0b2da2013-04-10 13:43:43 -070095 @Deprecated
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040096 public void onShowCustomView(View view, int requestedOrientation,
97 CustomViewCallback callback) {};
Jonathan Dixon3a5cf382013-07-27 15:37:31 -070098
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040099 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000100 * Notify the host application that the current page has exited full
101 * screen mode. The host application must hide the custom View, ie. the
102 * View passed to {@link #onShowCustomView} when the content entered fullscreen.
103 * Also see "Full screen support" documentation on {@link WebView}.
Andrei Popescu6fa29582009-06-19 14:54:09 +0100104 */
105 public void onHideCustomView() {}
106
107 /**
Steve Block89e00a92011-08-03 15:24:43 +0100108 * Request the host application to create a new window. If the host
109 * application chooses to honor this request, it should return true from
110 * this method, create a new WebView to host the window, insert it into the
111 * View system and send the supplied resultMsg message to its target with
112 * the new WebView as an argument. If the host application chooses not to
113 * honor the request, it should return false from this method. The default
114 * implementation of this method does nothing and hence returns false.
115 * @param view The WebView from which the request for a new window
116 * originated.
117 * @param isDialog True if the new window should be a dialog, rather than
118 * a full-size window.
119 * @param isUserGesture True if the request was initiated by a user gesture,
120 * such as the user clicking a link.
121 * @param resultMsg The message to send when once a new WebView has been
122 * created. resultMsg.obj is a
Steve Blockb22a69f2011-10-17 11:55:37 +0100123 * {@link WebView.WebViewTransport} object. This should be
124 * used to transport the new WebView, by calling
125 * {@link WebView.WebViewTransport#setWebView(WebView)
126 * WebView.WebViewTransport.setWebView(WebView)}.
Steve Block89e00a92011-08-03 15:24:43 +0100127 * @return This method should return true if the host application will
128 * create a new window, in which case resultMsg should be sent to
129 * its target. Otherwise, this method should return false. Returning
130 * false from this method but also sending resultMsg will result in
131 * undefined behavior.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 */
Steve Block89e00a92011-08-03 15:24:43 +0100133 public boolean onCreateWindow(WebView view, boolean isDialog,
134 boolean isUserGesture, Message resultMsg) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 return false;
136 }
137
138 /**
139 * Request display and focus for this WebView. This may happen due to
140 * another WebView opening a link in this WebView and requesting that this
141 * WebView be displayed.
142 * @param view The WebView that needs to be focused.
143 */
144 public void onRequestFocus(WebView view) {}
145
146 /**
147 * Notify the host application to close the given WebView and remove it
148 * from the view system if necessary. At this point, WebCore has stopped
149 * any loading in this window and has removed any cross-scripting ability
150 * in javascript.
151 * @param window The WebView that needs to be closed.
152 */
153 public void onCloseWindow(WebView window) {}
154
155 /**
156 * Tell the client to display a javascript alert dialog. If the client
157 * returns true, WebView will assume that the client will handle the
158 * dialog. If the client returns false, it will continue execution.
159 * @param view The WebView that initiated the callback.
160 * @param url The url of the page requesting the dialog.
161 * @param message Message to be displayed in the window.
162 * @param result A JsResult to confirm that the user hit enter.
163 * @return boolean Whether the client will handle the alert dialog.
164 */
165 public boolean onJsAlert(WebView view, String url, String message,
166 JsResult result) {
167 return false;
168 }
169
170 /**
171 * Tell the client to display a confirm dialog to the user. If the client
172 * returns true, WebView will assume that the client will handle the
173 * confirm dialog and call the appropriate JsResult method. If the
174 * client returns false, a default value of false will be returned to
175 * javascript. The default behavior is to return false.
176 * @param view The WebView that initiated the callback.
177 * @param url The url of the page requesting the dialog.
178 * @param message Message to be displayed in the window.
179 * @param result A JsResult used to send the user's response to
180 * javascript.
181 * @return boolean Whether the client will handle the confirm dialog.
182 */
183 public boolean onJsConfirm(WebView view, String url, String message,
184 JsResult result) {
185 return false;
186 }
187
188 /**
189 * Tell the client to display a prompt dialog to the user. If the client
190 * returns true, WebView will assume that the client will handle the
191 * prompt dialog and call the appropriate JsPromptResult method. If the
192 * client returns false, a default value of false will be returned to to
193 * javascript. The default behavior is to return false.
194 * @param view The WebView that initiated the callback.
195 * @param url The url of the page requesting the dialog.
196 * @param message Message to be displayed in the window.
197 * @param defaultValue The default value displayed in the prompt dialog.
198 * @param result A JsPromptResult used to send the user's reponse to
199 * javascript.
200 * @return boolean Whether the client will handle the prompt dialog.
201 */
202 public boolean onJsPrompt(WebView view, String url, String message,
203 String defaultValue, JsPromptResult result) {
204 return false;
205 }
206
207 /**
208 * Tell the client to display a dialog to confirm navigation away from the
209 * current page. This is the result of the onbeforeunload javascript event.
210 * If the client returns true, WebView will assume that the client will
211 * handle the confirm dialog and call the appropriate JsResult method. If
212 * the client returns false, a default value of true will be returned to
213 * javascript to accept navigation away from the current page. The default
214 * behavior is to return false. Setting the JsResult to true will navigate
215 * away from the current page, false will cancel the navigation.
216 * @param view The WebView that initiated the callback.
217 * @param url The url of the page requesting the dialog.
218 * @param message Message to be displayed in the window.
219 * @param result A JsResult used to send the user's response to
220 * javascript.
221 * @return boolean Whether the client will handle the confirm dialog.
222 */
223 public boolean onJsBeforeUnload(WebView view, String url, String message,
224 JsResult result) {
225 return false;
226 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100227
228 /**
Steve Block285ddfc2012-03-28 12:46:02 +0100229 * Tell the client that the quota has been exceeded for the Web SQL Database
230 * API for a particular origin and request a new quota. The client must
231 * respond by invoking the
232 * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
233 * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
234 * minimum value that can be set for the new quota is the current quota. The
235 * default implementation responds with the current quota, so the quota will
236 * not be increased.
237 * @param url The URL of the page that triggered the notification
238 * @param databaseIdentifier The identifier of the database where the quota
239 * was exceeded.
240 * @param quota The quota for the origin, in bytes
241 * @param estimatedDatabaseSize The estimated size of the offending
242 * database, in bytes
243 * @param totalQuota The total quota for all origins, in bytes
244 * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
245 * must be used to inform the WebView of the new quota.
Jonathan Dixon5545d082013-08-31 22:43:11 -0700246 * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
247 * Management API.
Ben Murdoch7df19852009-04-22 13:07:58 +0100248 */
Jonathan Dixon5545d082013-08-31 22:43:11 -0700249 @Deprecated
Ben Murdoch7df19852009-04-22 13:07:58 +0100250 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Steve Block285ddfc2012-03-28 12:46:02 +0100251 long quota, long estimatedDatabaseSize, long totalQuota,
252 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100253 // This default implementation passes the current quota back to WebCore.
254 // WebCore will interpret this that new quota was declined.
Steve Block285ddfc2012-03-28 12:46:02 +0100255 quotaUpdater.updateQuota(quota);
Ben Murdoch7df19852009-04-22 13:07:58 +0100256 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700257
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100258 /**
Selim Gurunc86bec92012-06-28 16:47:19 -0700259 * Notify the host application that the Application Cache has reached the
260 * maximum size. The client must respond by invoking the
Steve Block285ddfc2012-03-28 12:46:02 +0100261 * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
262 * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
263 * minimum value that can be set for the new quota is the current quota. The
264 * default implementation responds with the current quota, so the quota will
265 * not be increased.
266 * @param requiredStorage The amount of storage required by the Application
267 * Cache operation that triggered this notification,
268 * in bytes.
Selim Gurunc86bec92012-06-28 16:47:19 -0700269 * @param quota the current maximum Application Cache size, in bytes
Steve Block285ddfc2012-03-28 12:46:02 +0100270 * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
271 * must be used to inform the WebView of the new quota.
Jonathan Dixon5545d082013-08-31 22:43:11 -0700272 * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
273 * Management API.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100274 */
Jonathan Dixon5545d082013-08-31 22:43:11 -0700275 @Deprecated
Steve Block285ddfc2012-03-28 12:46:02 +0100276 public void onReachedMaxAppCacheSize(long requiredStorage, long quota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100277 WebStorage.QuotaUpdater quotaUpdater) {
Steve Block285ddfc2012-03-28 12:46:02 +0100278 quotaUpdater.updateQuota(quota);
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100279 }
280
Guang Zhu81e41432009-05-08 16:09:55 -0700281 /**
Steve Block7351adf2011-11-30 15:52:32 +0000282 * Notify the host application that web content from the specified origin
283 * is attempting to use the Geolocation API, but no permission state is
284 * currently set for that origin. The host application should invoke the
285 * specified callback with the desired permission state. See
286 * {@link GeolocationPermissions} for details.
Tim Volodineb0e97982016-04-27 14:14:09 +0100287 *
288 * <p>Note that for applications targeting Android N and later SDKs
289 * (API level > {@link android.os.Build.VERSION_CODES#M})
290 * this method is only called for requests originating from secure
291 * origins such as https. On non-secure origins geolocation requests
292 * are automatically denied.</p>
293 *
Steve Block7351adf2011-11-30 15:52:32 +0000294 * @param origin The origin of the web content attempting to use the
295 * Geolocation API.
296 * @param callback The callback to use to set the permission state for the
297 * origin.
Steve Block4faee092009-07-28 18:20:50 +0100298 */
299 public void onGeolocationPermissionsShowPrompt(String origin,
Tim Volodine0bb7d2e2015-07-23 17:16:16 +0000300 GeolocationPermissions.Callback callback) {}
Steve Block4faee092009-07-28 18:20:50 +0100301
302 /**
Steve Block7351adf2011-11-30 15:52:32 +0000303 * Notify the host application that a request for Geolocation permissions,
304 * made with a previous call to
305 * {@link #onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt()}
306 * has been canceled. Any related UI should therefore be hidden.
Steve Block4faee092009-07-28 18:20:50 +0100307 */
308 public void onGeolocationPermissionsHidePrompt() {}
309
310 /**
Tao Bai4c22b542014-04-15 18:04:49 +0000311 * Notify the host application that web content is requesting permission to
312 * access the specified resources and the permission currently isn't granted
Tao Bai2871feb2014-07-16 13:54:15 -0700313 * or denied. The host application must invoke {@link PermissionRequest#grant(String[])}
Tao Bai4c22b542014-04-15 18:04:49 +0000314 * or {@link PermissionRequest#deny()}.
315 *
316 * If this method isn't overridden, the permission is denied.
317 *
318 * @param request the PermissionRequest from current web content.
Tao Bai4c22b542014-04-15 18:04:49 +0000319 */
320 public void onPermissionRequest(PermissionRequest request) {
321 request.deny();
322 }
323
324 /**
325 * Notify the host application that the given permission request
326 * has been canceled. Any related UI should therefore be hidden.
327 *
Tao Baifa1fd2c2014-04-30 13:31:34 -0700328 * @param request the PermissionRequest that needs be canceled.
Tao Bai4c22b542014-04-15 18:04:49 +0000329 */
330 public void onPermissionRequestCanceled(PermissionRequest request) {}
331
332 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700333 * Tell the client that a JavaScript execution timeout has occured. And the
334 * client may decide whether or not to interrupt the execution. If the
335 * client returns true, the JavaScript will be interrupted. If the client
336 * returns false, the execution will continue. Note that in the case of
337 * continuing execution, the timeout counter will be reset, and the callback
338 * will continue to occur if the script does not finish at the next check
339 * point.
340 * @return boolean Whether the JavaScript execution should be interrupted.
Ben Murdoch1bd37b12012-05-28 12:42:39 +0100341 * @deprecated This method is no longer supported and will not be invoked.
Guang Zhu81e41432009-05-08 16:09:55 -0700342 */
Ben Murdoch1bd37b12012-05-28 12:42:39 +0100343 // This method was only called when using the JSC javascript engine. V8 became
344 // the default JS engine with Froyo and support for building with JSC was
345 // removed in b/5495373. V8 does not have a mechanism for making a callback such
346 // as this.
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700347 @Deprecated
Guang Zhu81e41432009-05-08 16:09:55 -0700348 public boolean onJsTimeout() {
349 return true;
350 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100351
352 /**
Ben Murdoch7caaeec2009-11-19 18:14:53 +0000353 * Report a JavaScript error message to the host application. The ChromeClient
354 * should override this to process the log message as they see fit.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100355 * @param message The error message to report.
356 * @param lineNumber The line number of the error.
357 * @param sourceID The name of the source file that caused the error.
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000358 * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
359 * instead.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100360 */
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000361 @Deprecated
362 public void onConsoleMessage(String message, int lineNumber, String sourceID) { }
363
364 /**
365 * Report a JavaScript console message to the host application. The ChromeClient
366 * should override this to process the log message as they see fit.
367 * @param consoleMessage Object containing details of the console message.
368 * @return true if the message is handled by the client.
369 */
370 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
371 // Call the old version of this function for backwards compatability.
372 onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
373 consoleMessage.sourceId());
374 return false;
375 }
Andrei Popescubf385d72009-09-18 18:59:52 +0100376
377 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000378 * When not playing, video elements are represented by a 'poster' image. The
379 * image to use can be specified by the poster attribute of the video tag in
380 * HTML. If the attribute is absent, then a default poster will be used. This
381 * method allows the ChromeClient to provide that default image.
Andrei Popescubf385d72009-09-18 18:59:52 +0100382 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000383 * @return Bitmap The image to use as a default poster, or null if no such image is
384 * available.
Andrei Popescubf385d72009-09-18 18:59:52 +0100385 */
386 public Bitmap getDefaultVideoPoster() {
387 return null;
388 }
389
390 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000391 * Obtains a View to be displayed while buffering of full screen video is taking
392 * place. The host application can override this method to provide a View
393 * containing a spinner or similar.
Andrei Popescubf385d72009-09-18 18:59:52 +0100394 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000395 * @return View The View to be displayed whilst the video is loading.
Andrei Popescubf385d72009-09-18 18:59:52 +0100396 */
397 public View getVideoLoadingProgressView() {
398 return null;
399 }
Leon Clarke194e3452009-09-28 11:42:12 +0100400
401 /** Obtains a list of all visited history items, used for link coloring
Leon Clarke194e3452009-09-28 11:42:12 +0100402 */
403 public void getVisitedHistory(ValueCallback<String[]> callback) {
404 }
405
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400406 /**
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700407 * Tell the client to show a file chooser.
408 *
409 * This is called to handle HTML forms with 'file' input type, in response to the
410 * user pressing the "Select File" button.
411 * To cancel the request, call <code>filePathCallback.onReceiveValue(null)</code> and
412 * return true.
413 *
414 * @param webView The WebView instance that is initiating the request.
415 * @param filePathCallback Invoke this callback to supply the list of paths to files to upload,
416 * or NULL to cancel. Must only be called if the
417 * <code>showFileChooser</code> implementations returns true.
418 * @param fileChooserParams Describes the mode of file chooser to be opened, and options to be
419 * used with it.
420 * @return true if filePathCallback will be invoked, false to use default handling.
421 *
422 * @see FileChooserParams
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700423 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700424 public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700425 FileChooserParams fileChooserParams) {
426 return false;
427 }
428
429 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700430 * Parameters used in the {@link #onShowFileChooser} method.
431 */
432 public static abstract class FileChooserParams {
433 /** Open single file. Requires that the file exists before allowing the user to pick it. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700434 public static final int MODE_OPEN = 0;
Selim Gurun48f6c452014-07-18 16:23:46 -0700435 /** Like Open but allows multiple files to be selected. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700436 public static final int MODE_OPEN_MULTIPLE = 1;
Selim Gurun48f6c452014-07-18 16:23:46 -0700437 /** Like Open but allows a folder to be selected. The implementation should enumerate
Selim Gurun17d1adb2014-08-27 11:22:26 -0700438 all files selected by this operation.
439 This feature is not supported at the moment.
440 @hide */
441 public static final int MODE_OPEN_FOLDER = 2;
Selim Gurun48f6c452014-07-18 16:23:46 -0700442 /** Allows picking a nonexistent file and saving it. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700443 public static final int MODE_SAVE = 3;
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700444
445 /**
Tao Baie8df27a2014-09-02 14:09:49 -0700446 * Parse the result returned by the file picker activity. This method should be used with
447 * {@link #createIntent}. Refer to {@link #createIntent} for how to use it.
448 *
449 * @param resultCode the integer result code returned by the file picker activity.
450 * @param data the intent returned by the file picker activity.
451 * @return the Uris of selected file(s) or null if the resultCode indicates
452 * activity canceled or any other error.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700453 */
Tao Baie8df27a2014-09-02 14:09:49 -0700454 public static Uri[] parseResult(int resultCode, Intent data) {
455 return WebViewFactory.getProvider().getStatics().parseFileChooserResult(resultCode, data);
456 }
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700457
458 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700459 * Returns file chooser mode.
460 */
461 public abstract int getMode();
462
463 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -0700464 * Returns an array of acceptable MIME types. The returned MIME type
465 * could be partial such as audio/*. The array will be empty if no
Selim Gurun48f6c452014-07-18 16:23:46 -0700466 * acceptable types are specified.
467 */
468 public abstract String[] getAcceptTypes();
469
470 /**
471 * Returns preference for a live media captured value (e.g. Camera, Microphone).
472 * True indicates capture is enabled, false disabled.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700473 *
Selim Gurun48f6c452014-07-18 16:23:46 -0700474 * Use <code>getAcceptTypes</code> to determine suitable capture devices.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700475 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700476 public abstract boolean isCaptureEnabled();
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700477
478 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700479 * Returns the title to use for this file selector, or null. If null a default
480 * title should be used.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700481 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700482 public abstract CharSequence getTitle();
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700483
484 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -0700485 * The file name of a default selection if specified, or null.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700486 */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700487 public abstract String getFilenameHint();
Tao Baie8df27a2014-09-02 14:09:49 -0700488
489 /**
490 * Creates an intent that would start a file picker for file selection.
491 * The Intent supports choosing files from simple file sources available
492 * on the device. Some advanced sources (for example, live media capture)
493 * may not be supported and applications wishing to support these sources
494 * or more advanced file operations should build their own Intent.
495 *
496 * <pre>
497 * How to use:
498 * 1. Build an intent using {@link #createIntent}
499 * 2. Fire the intent using {@link android.app.Activity#startActivityForResult}.
500 * 3. Check for ActivityNotFoundException and take a user friendly action if thrown.
501 * 4. Listen the result using {@link android.app.Activity#onActivityResult}
502 * 5. Parse the result using {@link #parseResult} only if media capture was not requested.
503 * 6. Send the result using filePathCallback of {@link WebChromeClient#onShowFileChooser}
504 * </pre>
505 *
506 * @return an Intent that supports basic file chooser sources.
507 */
508 public abstract Intent createIntent();
509 }
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700510
511 /**
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400512 * Tell the client to open a file chooser.
513 * @param uploadFile A ValueCallback to set the URI of the file to upload.
Ben Murdoch4ae32f52010-05-18 14:30:39 +0100514 * onReceiveValue must be called to wake up the thread.a
515 * @param acceptType The value of the 'accept' attribute of the input tag
516 * associated with this file picker.
Ben Murdochbe716922012-01-11 10:55:10 +0000517 * @param capture The value of the 'capture' attribute of the input tag
518 * associated with this file picker.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700519 *
520 * @deprecated Use {@link #showFileChooser} instead.
521 * @hide This method was not published in any SDK version.
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400522 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000523 @SystemApi
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700524 @Deprecated
Ben Murdochbe716922012-01-11 10:55:10 +0000525 public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400526 uploadFile.onReceiveValue(null);
527 }
Cary Clark924af702010-06-04 16:37:43 -0400528
529 /**
Ben Murdoch57914382010-11-16 11:50:39 +0000530 * Tell the client that the page being viewed has an autofillable
531 * form and the user would like to set a profile up.
532 * @param msg A Message to send once the user has successfully
533 * set up a profile and to inform the WebTextView it should
534 * now autofill using that new profile.
535 * @hide
536 */
537 public void setupAutoFill(Message msg) { }
538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539}