blob: 95fe963d7891eaf99538a3ce1aea9cdff682644d [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
Nate Fischer3442c742017-09-08 17:02:00 -070019import android.annotation.Nullable;
Ignacio Solla451e3382014-11-10 10:35:54 +000020import android.annotation.SystemApi;
Selim Gurun48f6c452014-07-18 16:23:46 -070021import android.content.Intent;
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040022import android.content.pm.ActivityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.graphics.Bitmap;
Leon Scroggins70ca3c22009-10-02 15:58:55 -040024import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Message;
Andrei Popescu6fa29582009-06-19 14:54:09 +010026import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
28public class WebChromeClient {
29
30 /**
31 * Tell the host application the current progress of loading a page.
32 * @param view The WebView that initiated the callback.
33 * @param newProgress Current page loading progress, represented by
34 * an integer between 0 and 100.
35 */
36 public void onProgressChanged(WebView view, int newProgress) {}
37
38 /**
39 * Notify the host application of a change in the document title.
40 * @param view The WebView that initiated the callback.
41 * @param title A String containing the new title of the document.
42 */
43 public void onReceivedTitle(WebView view, String title) {}
44
45 /**
46 * Notify the host application of a new favicon for the current page.
47 * @param view The WebView that initiated the callback.
48 * @param icon A Bitmap containing the favicon for the current page.
49 */
50 public void onReceivedIcon(WebView view, Bitmap icon) {}
51
52 /**
Patrick Scott2ba12622009-08-04 13:20:05 -040053 * Notify the host application of the url for an apple-touch-icon.
54 * @param view The WebView that initiated the callback.
55 * @param url The icon url.
Nate Fischer0a6140d2017-09-05 12:37:49 -070056 * @param precomposed {@code true} if the url is for a precomposed touch icon.
Patrick Scott2ba12622009-08-04 13:20:05 -040057 */
Patrick Scottd58ccff2009-09-18 16:29:00 -040058 public void onReceivedTouchIconUrl(WebView view, String url,
59 boolean precomposed) {}
Patrick Scott2ba12622009-08-04 13:20:05 -040060
61 /**
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010062 * A callback interface used by the host application to notify
63 * the current page that its custom view has been dismissed.
Andrei Popescu6fa29582009-06-19 14:54:09 +010064 */
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010065 public interface CustomViewCallback {
66 /**
67 * Invoked when the host application dismisses the
68 * custom view.
69 */
70 public void onCustomViewHidden();
71 }
72
73 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +000074 * Notify the host application that the current page has entered full
75 * screen mode. The host application must show the custom View which
76 * contains the web contents — video or other HTML content —
77 * in full screen mode. Also see "Full screen support" documentation on
Kristian Monsen0e0b2da2013-04-10 13:43:43 -070078 * {@link WebView}.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010079 * @param view is the View object to be shown.
Ignacio Solla7a4e18f2014-12-29 12:21:52 +000080 * @param callback invoke this callback to request the page to exit
81 * full screen mode.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010082 */
83 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010084
85 /**
86 * Notify the host application that the current page would
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040087 * like to show a custom View in a particular orientation.
88 * @param view is the View object to be shown.
89 * @param requestedOrientation An orientation constant as used in
90 * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
91 * @param callback is the callback to be invoked if and when the view
92 * is dismissed.
Kristian Monsen0e0b2da2013-04-10 13:43:43 -070093 * @deprecated This method supports the obsolete plugin mechanism,
94 * and will not be invoked in future
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040095 */
Kristian Monsen0e0b2da2013-04-10 13:43:43 -070096 @Deprecated
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040097 public void onShowCustomView(View view, int requestedOrientation,
98 CustomViewCallback callback) {};
Jonathan Dixon3a5cf382013-07-27 15:37:31 -070099
Derek Sollenberger7ab3d672011-06-01 14:45:05 -0400100 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000101 * Notify the host application that the current page has exited full
102 * screen mode. The host application must hide the custom View, ie. the
103 * View passed to {@link #onShowCustomView} when the content entered fullscreen.
104 * Also see "Full screen support" documentation on {@link WebView}.
Andrei Popescu6fa29582009-06-19 14:54:09 +0100105 */
106 public void onHideCustomView() {}
107
108 /**
Steve Block89e00a92011-08-03 15:24:43 +0100109 * Request the host application to create a new window. If the host
Nate Fischer0a6140d2017-09-05 12:37:49 -0700110 * application chooses to honor this request, it should return {@code true} from
Steve Block89e00a92011-08-03 15:24:43 +0100111 * this method, create a new WebView to host the window, insert it into the
112 * View system and send the supplied resultMsg message to its target with
113 * the new WebView as an argument. If the host application chooses not to
Nate Fischer0a6140d2017-09-05 12:37:49 -0700114 * honor the request, it should return {@code false} from this method. The default
115 * implementation of this method does nothing and hence returns {@code false}.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400116 * <p>
117 * Applications should typically not allow windows to be created when the
118 * {@code isUserGesture} flag is false, as this may be an unwanted popup.
119 * <p>
120 * Applications should be careful how they display the new window: don't simply
121 * overlay it over the existing WebView as this may mislead the user about which
122 * site they are viewing. If your application displays the URL of the main page,
123 * make sure to also display the URL of the new window in a similar fashion. If
124 * your application does not display URLs, consider disallowing the creation of
125 * new windows entirely.
126 * <p class="note"><b>Note:</b> There is no trustworthy way to tell which page
127 * requested the new window: the request might originate from a third-party iframe
128 * inside the WebView.
129 *
Steve Block89e00a92011-08-03 15:24:43 +0100130 * @param view The WebView from which the request for a new window
131 * originated.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700132 * @param isDialog {@code true} if the new window should be a dialog, rather than
Steve Block89e00a92011-08-03 15:24:43 +0100133 * a full-size window.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700134 * @param isUserGesture {@code true} if the request was initiated by a user gesture,
Steve Block89e00a92011-08-03 15:24:43 +0100135 * such as the user clicking a link.
136 * @param resultMsg The message to send when once a new WebView has been
137 * created. resultMsg.obj is a
Steve Blockb22a69f2011-10-17 11:55:37 +0100138 * {@link WebView.WebViewTransport} object. This should be
139 * used to transport the new WebView, by calling
140 * {@link WebView.WebViewTransport#setWebView(WebView)
141 * WebView.WebViewTransport.setWebView(WebView)}.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700142 * @return This method should return {@code true} if the host application will
Steve Block89e00a92011-08-03 15:24:43 +0100143 * create a new window, in which case resultMsg should be sent to
Nate Fischer0a6140d2017-09-05 12:37:49 -0700144 * its target. Otherwise, this method should return {@code false}. Returning
145 * {@code false} from this method but also sending resultMsg will result in
Steve Block89e00a92011-08-03 15:24:43 +0100146 * undefined behavior.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 */
Steve Block89e00a92011-08-03 15:24:43 +0100148 public boolean onCreateWindow(WebView view, boolean isDialog,
149 boolean isUserGesture, Message resultMsg) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 return false;
151 }
152
153 /**
154 * Request display and focus for this WebView. This may happen due to
155 * another WebView opening a link in this WebView and requesting that this
156 * WebView be displayed.
157 * @param view The WebView that needs to be focused.
158 */
159 public void onRequestFocus(WebView view) {}
160
161 /**
162 * Notify the host application to close the given WebView and remove it
163 * from the view system if necessary. At this point, WebCore has stopped
164 * any loading in this window and has removed any cross-scripting ability
165 * in javascript.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400166 * <p>
167 * As with {@link #onCreateWindow}, the application should ensure that any
168 * URL or security indicator displayed is updated so that the user can tell
169 * that the page they were interacting with has been closed.
170 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 * @param window The WebView that needs to be closed.
172 */
173 public void onCloseWindow(WebView window) {}
174
175 /**
176 * Tell the client to display a javascript alert dialog. If the client
Nate Fischer0a6140d2017-09-05 12:37:49 -0700177 * returns {@code true}, WebView will assume that the client will handle the
178 * dialog. If the client returns {@code false}, it will continue execution.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800179 * @param view The WebView that initiated the callback.
180 * @param url The url of the page requesting the dialog.
181 * @param message Message to be displayed in the window.
182 * @param result A JsResult to confirm that the user hit enter.
183 * @return boolean Whether the client will handle the alert dialog.
184 */
185 public boolean onJsAlert(WebView view, String url, String message,
186 JsResult result) {
187 return false;
188 }
189
190 /**
191 * Tell the client to display a confirm dialog to the user. If the client
Nate Fischer0a6140d2017-09-05 12:37:49 -0700192 * returns {@code true}, WebView will assume that the client will handle the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 * confirm dialog and call the appropriate JsResult method. If the
Nate Fischer0a6140d2017-09-05 12:37:49 -0700194 * client returns false, a default value of {@code false} will be returned to
195 * javascript. The default behavior is to return {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 * @param view The WebView that initiated the callback.
197 * @param url The url of the page requesting the dialog.
198 * @param message Message to be displayed in the window.
199 * @param result A JsResult used to send the user's response to
200 * javascript.
201 * @return boolean Whether the client will handle the confirm dialog.
202 */
203 public boolean onJsConfirm(WebView view, String url, String message,
204 JsResult result) {
205 return false;
206 }
207
208 /**
209 * Tell the client to display a prompt dialog to the user. If the client
Nate Fischer0a6140d2017-09-05 12:37:49 -0700210 * returns {@code true}, WebView will assume that the client will handle the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 * prompt dialog and call the appropriate JsPromptResult method. If the
Nate Fischer0a6140d2017-09-05 12:37:49 -0700212 * client returns false, a default value of {@code false} will be returned to to
213 * javascript. The default behavior is to return {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 * @param view The WebView that initiated the callback.
215 * @param url The url of the page requesting the dialog.
216 * @param message Message to be displayed in the window.
217 * @param defaultValue The default value displayed in the prompt dialog.
218 * @param result A JsPromptResult used to send the user's reponse to
219 * javascript.
220 * @return boolean Whether the client will handle the prompt dialog.
221 */
222 public boolean onJsPrompt(WebView view, String url, String message,
223 String defaultValue, JsPromptResult result) {
224 return false;
225 }
226
227 /**
228 * Tell the client to display a dialog to confirm navigation away from the
229 * current page. This is the result of the onbeforeunload javascript event.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700230 * If the client returns {@code true}, WebView will assume that the client will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 * handle the confirm dialog and call the appropriate JsResult method. If
Nate Fischer0a6140d2017-09-05 12:37:49 -0700232 * the client returns {@code false}, a default value of {@code true} will be returned to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 * javascript to accept navigation away from the current page. The default
Nate Fischer0a6140d2017-09-05 12:37:49 -0700234 * behavior is to return {@code false}. Setting the JsResult to {@code true} will navigate
235 * away from the current page, {@code false} will cancel the navigation.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 * @param view The WebView that initiated the callback.
237 * @param url The url of the page requesting the dialog.
238 * @param message Message to be displayed in the window.
239 * @param result A JsResult used to send the user's response to
240 * javascript.
241 * @return boolean Whether the client will handle the confirm dialog.
242 */
243 public boolean onJsBeforeUnload(WebView view, String url, String message,
244 JsResult result) {
245 return false;
246 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100247
248 /**
Steve Block285ddfc2012-03-28 12:46:02 +0100249 * Tell the client that the quota has been exceeded for the Web SQL Database
250 * API for a particular origin and request a new quota. The client must
251 * respond by invoking the
252 * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
253 * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
254 * minimum value that can be set for the new quota is the current quota. The
255 * default implementation responds with the current quota, so the quota will
256 * not be increased.
257 * @param url The URL of the page that triggered the notification
258 * @param databaseIdentifier The identifier of the database where the quota
259 * was exceeded.
260 * @param quota The quota for the origin, in bytes
261 * @param estimatedDatabaseSize The estimated size of the offending
262 * database, in bytes
263 * @param totalQuota The total quota for all origins, in bytes
264 * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
265 * must be used to inform the WebView of the new quota.
Jonathan Dixon5545d082013-08-31 22:43:11 -0700266 * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
267 * Management API.
Ben Murdoch7df19852009-04-22 13:07:58 +0100268 */
Jonathan Dixon5545d082013-08-31 22:43:11 -0700269 @Deprecated
Ben Murdoch7df19852009-04-22 13:07:58 +0100270 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Steve Block285ddfc2012-03-28 12:46:02 +0100271 long quota, long estimatedDatabaseSize, long totalQuota,
272 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100273 // This default implementation passes the current quota back to WebCore.
274 // WebCore will interpret this that new quota was declined.
Steve Block285ddfc2012-03-28 12:46:02 +0100275 quotaUpdater.updateQuota(quota);
Ben Murdoch7df19852009-04-22 13:07:58 +0100276 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700277
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100278 /**
Selim Gurunc86bec92012-06-28 16:47:19 -0700279 * Notify the host application that the Application Cache has reached the
280 * maximum size. The client must respond by invoking the
Steve Block285ddfc2012-03-28 12:46:02 +0100281 * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
282 * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
283 * minimum value that can be set for the new quota is the current quota. The
284 * default implementation responds with the current quota, so the quota will
285 * not be increased.
286 * @param requiredStorage The amount of storage required by the Application
287 * Cache operation that triggered this notification,
288 * in bytes.
Selim Gurunc86bec92012-06-28 16:47:19 -0700289 * @param quota the current maximum Application Cache size, in bytes
Steve Block285ddfc2012-03-28 12:46:02 +0100290 * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
291 * must be used to inform the WebView of the new quota.
Jonathan Dixon5545d082013-08-31 22:43:11 -0700292 * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
293 * Management API.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100294 */
Jonathan Dixon5545d082013-08-31 22:43:11 -0700295 @Deprecated
Steve Block285ddfc2012-03-28 12:46:02 +0100296 public void onReachedMaxAppCacheSize(long requiredStorage, long quota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100297 WebStorage.QuotaUpdater quotaUpdater) {
Steve Block285ddfc2012-03-28 12:46:02 +0100298 quotaUpdater.updateQuota(quota);
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100299 }
300
Guang Zhu81e41432009-05-08 16:09:55 -0700301 /**
Steve Block7351adf2011-11-30 15:52:32 +0000302 * Notify the host application that web content from the specified origin
303 * is attempting to use the Geolocation API, but no permission state is
304 * currently set for that origin. The host application should invoke the
305 * specified callback with the desired permission state. See
306 * {@link GeolocationPermissions} for details.
Tim Volodineb0e97982016-04-27 14:14:09 +0100307 *
308 * <p>Note that for applications targeting Android N and later SDKs
309 * (API level > {@link android.os.Build.VERSION_CODES#M})
310 * this method is only called for requests originating from secure
311 * origins such as https. On non-secure origins geolocation requests
Nate Fischerf02f8462017-09-11 15:16:33 -0700312 * are automatically denied.
Tim Volodineb0e97982016-04-27 14:14:09 +0100313 *
Steve Block7351adf2011-11-30 15:52:32 +0000314 * @param origin The origin of the web content attempting to use the
315 * Geolocation API.
316 * @param callback The callback to use to set the permission state for the
317 * origin.
Steve Block4faee092009-07-28 18:20:50 +0100318 */
319 public void onGeolocationPermissionsShowPrompt(String origin,
Tim Volodine0bb7d2e2015-07-23 17:16:16 +0000320 GeolocationPermissions.Callback callback) {}
Steve Block4faee092009-07-28 18:20:50 +0100321
322 /**
Steve Block7351adf2011-11-30 15:52:32 +0000323 * Notify the host application that a request for Geolocation permissions,
324 * made with a previous call to
325 * {@link #onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt()}
326 * has been canceled. Any related UI should therefore be hidden.
Steve Block4faee092009-07-28 18:20:50 +0100327 */
328 public void onGeolocationPermissionsHidePrompt() {}
329
330 /**
Tao Bai4c22b542014-04-15 18:04:49 +0000331 * Notify the host application that web content is requesting permission to
332 * access the specified resources and the permission currently isn't granted
Tao Bai2871feb2014-07-16 13:54:15 -0700333 * or denied. The host application must invoke {@link PermissionRequest#grant(String[])}
Tao Bai4c22b542014-04-15 18:04:49 +0000334 * or {@link PermissionRequest#deny()}.
335 *
336 * If this method isn't overridden, the permission is denied.
337 *
338 * @param request the PermissionRequest from current web content.
Tao Bai4c22b542014-04-15 18:04:49 +0000339 */
340 public void onPermissionRequest(PermissionRequest request) {
341 request.deny();
342 }
343
344 /**
345 * Notify the host application that the given permission request
346 * has been canceled. Any related UI should therefore be hidden.
347 *
Tao Baifa1fd2c2014-04-30 13:31:34 -0700348 * @param request the PermissionRequest that needs be canceled.
Tao Bai4c22b542014-04-15 18:04:49 +0000349 */
350 public void onPermissionRequestCanceled(PermissionRequest request) {}
351
352 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700353 * Tell the client that a JavaScript execution timeout has occured. And the
354 * client may decide whether or not to interrupt the execution. If the
Nate Fischer0a6140d2017-09-05 12:37:49 -0700355 * client returns {@code true}, the JavaScript will be interrupted. If the client
356 * returns {@code false}, the execution will continue. Note that in the case of
Guang Zhu81e41432009-05-08 16:09:55 -0700357 * continuing execution, the timeout counter will be reset, and the callback
358 * will continue to occur if the script does not finish at the next check
359 * point.
360 * @return boolean Whether the JavaScript execution should be interrupted.
Ben Murdoch1bd37b12012-05-28 12:42:39 +0100361 * @deprecated This method is no longer supported and will not be invoked.
Guang Zhu81e41432009-05-08 16:09:55 -0700362 */
Ben Murdoch1bd37b12012-05-28 12:42:39 +0100363 // This method was only called when using the JSC javascript engine. V8 became
364 // the default JS engine with Froyo and support for building with JSC was
365 // removed in b/5495373. V8 does not have a mechanism for making a callback such
366 // as this.
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700367 @Deprecated
Guang Zhu81e41432009-05-08 16:09:55 -0700368 public boolean onJsTimeout() {
369 return true;
370 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100371
372 /**
Ben Murdoch7caaeec2009-11-19 18:14:53 +0000373 * Report a JavaScript error message to the host application. The ChromeClient
374 * should override this to process the log message as they see fit.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100375 * @param message The error message to report.
376 * @param lineNumber The line number of the error.
377 * @param sourceID The name of the source file that caused the error.
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000378 * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
379 * instead.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100380 */
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000381 @Deprecated
382 public void onConsoleMessage(String message, int lineNumber, String sourceID) { }
383
384 /**
385 * Report a JavaScript console message to the host application. The ChromeClient
386 * should override this to process the log message as they see fit.
387 * @param consoleMessage Object containing details of the console message.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700388 * @return {@code true} if the message is handled by the client.
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000389 */
390 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
391 // Call the old version of this function for backwards compatability.
392 onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
393 consoleMessage.sourceId());
394 return false;
395 }
Andrei Popescubf385d72009-09-18 18:59:52 +0100396
397 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000398 * When not playing, video elements are represented by a 'poster' image. The
399 * image to use can be specified by the poster attribute of the video tag in
400 * HTML. If the attribute is absent, then a default poster will be used. This
401 * method allows the ChromeClient to provide that default image.
Andrei Popescubf385d72009-09-18 18:59:52 +0100402 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700403 * @return Bitmap The image to use as a default poster, or {@code null} if no such image is
Ben Murdochf0c443d2009-11-19 16:43:58 +0000404 * available.
Andrei Popescubf385d72009-09-18 18:59:52 +0100405 */
Nate Fischer3442c742017-09-08 17:02:00 -0700406 @Nullable
Andrei Popescubf385d72009-09-18 18:59:52 +0100407 public Bitmap getDefaultVideoPoster() {
408 return null;
409 }
410
411 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000412 * Obtains a View to be displayed while buffering of full screen video is taking
413 * place. The host application can override this method to provide a View
414 * containing a spinner or similar.
Andrei Popescubf385d72009-09-18 18:59:52 +0100415 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000416 * @return View The View to be displayed whilst the video is loading.
Andrei Popescubf385d72009-09-18 18:59:52 +0100417 */
Nate Fischer3442c742017-09-08 17:02:00 -0700418 @Nullable
Andrei Popescubf385d72009-09-18 18:59:52 +0100419 public View getVideoLoadingProgressView() {
420 return null;
421 }
Leon Clarke194e3452009-09-28 11:42:12 +0100422
423 /** Obtains a list of all visited history items, used for link coloring
Leon Clarke194e3452009-09-28 11:42:12 +0100424 */
425 public void getVisitedHistory(ValueCallback<String[]> callback) {
426 }
427
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400428 /**
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700429 * Tell the client to show a file chooser.
430 *
431 * This is called to handle HTML forms with 'file' input type, in response to the
432 * user pressing the "Select File" button.
433 * To cancel the request, call <code>filePathCallback.onReceiveValue(null)</code> and
Nate Fischer0a6140d2017-09-05 12:37:49 -0700434 * return {@code true}.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700435 *
436 * @param webView The WebView instance that is initiating the request.
437 * @param filePathCallback Invoke this callback to supply the list of paths to files to upload,
Nate Fischer0a6140d2017-09-05 12:37:49 -0700438 * or {@code null} to cancel. Must only be called if the
439 * {@link #onShowFileChooser} implementation returns {@code true}.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700440 * @param fileChooserParams Describes the mode of file chooser to be opened, and options to be
441 * used with it.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700442 * @return {@code true} if filePathCallback will be invoked, {@code false} to use default
443 * handling.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700444 *
445 * @see FileChooserParams
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700446 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700447 public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700448 FileChooserParams fileChooserParams) {
449 return false;
450 }
451
452 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700453 * Parameters used in the {@link #onShowFileChooser} method.
454 */
455 public static abstract class FileChooserParams {
456 /** Open single file. Requires that the file exists before allowing the user to pick it. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700457 public static final int MODE_OPEN = 0;
Selim Gurun48f6c452014-07-18 16:23:46 -0700458 /** Like Open but allows multiple files to be selected. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700459 public static final int MODE_OPEN_MULTIPLE = 1;
Selim Gurun48f6c452014-07-18 16:23:46 -0700460 /** Like Open but allows a folder to be selected. The implementation should enumerate
Selim Gurun17d1adb2014-08-27 11:22:26 -0700461 all files selected by this operation.
462 This feature is not supported at the moment.
463 @hide */
464 public static final int MODE_OPEN_FOLDER = 2;
Selim Gurun48f6c452014-07-18 16:23:46 -0700465 /** Allows picking a nonexistent file and saving it. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700466 public static final int MODE_SAVE = 3;
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700467
468 /**
Tao Baie8df27a2014-09-02 14:09:49 -0700469 * Parse the result returned by the file picker activity. This method should be used with
470 * {@link #createIntent}. Refer to {@link #createIntent} for how to use it.
471 *
472 * @param resultCode the integer result code returned by the file picker activity.
473 * @param data the intent returned by the file picker activity.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700474 * @return the Uris of selected file(s) or {@code null} if the resultCode indicates
Tao Baie8df27a2014-09-02 14:09:49 -0700475 * activity canceled or any other error.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700476 */
Nate Fischer3442c742017-09-08 17:02:00 -0700477 @Nullable
Tao Baie8df27a2014-09-02 14:09:49 -0700478 public static Uri[] parseResult(int resultCode, Intent data) {
479 return WebViewFactory.getProvider().getStatics().parseFileChooserResult(resultCode, data);
480 }
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700481
482 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700483 * Returns file chooser mode.
484 */
485 public abstract int getMode();
486
487 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -0700488 * Returns an array of acceptable MIME types. The returned MIME type
489 * could be partial such as audio/*. The array will be empty if no
Selim Gurun48f6c452014-07-18 16:23:46 -0700490 * acceptable types are specified.
491 */
492 public abstract String[] getAcceptTypes();
493
494 /**
495 * Returns preference for a live media captured value (e.g. Camera, Microphone).
Nate Fischer0a6140d2017-09-05 12:37:49 -0700496 * True indicates capture is enabled, {@code false} disabled.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700497 *
Selim Gurun48f6c452014-07-18 16:23:46 -0700498 * Use <code>getAcceptTypes</code> to determine suitable capture devices.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700499 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700500 public abstract boolean isCaptureEnabled();
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700501
502 /**
Nate Fischer3442c742017-09-08 17:02:00 -0700503 * Returns the title to use for this file selector. If {@code null} a default title should
504 * be used.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700505 */
Nate Fischer3442c742017-09-08 17:02:00 -0700506 @Nullable
Selim Gurun48f6c452014-07-18 16:23:46 -0700507 public abstract CharSequence getTitle();
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700508
509 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -0700510 * The file name of a default selection if specified, or {@code null}.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700511 */
Nate Fischer3442c742017-09-08 17:02:00 -0700512 @Nullable
Selim Gurun17d1adb2014-08-27 11:22:26 -0700513 public abstract String getFilenameHint();
Tao Baie8df27a2014-09-02 14:09:49 -0700514
515 /**
516 * Creates an intent that would start a file picker for file selection.
517 * The Intent supports choosing files from simple file sources available
518 * on the device. Some advanced sources (for example, live media capture)
519 * may not be supported and applications wishing to support these sources
520 * or more advanced file operations should build their own Intent.
521 *
522 * <pre>
523 * How to use:
524 * 1. Build an intent using {@link #createIntent}
525 * 2. Fire the intent using {@link android.app.Activity#startActivityForResult}.
526 * 3. Check for ActivityNotFoundException and take a user friendly action if thrown.
527 * 4. Listen the result using {@link android.app.Activity#onActivityResult}
528 * 5. Parse the result using {@link #parseResult} only if media capture was not requested.
529 * 6. Send the result using filePathCallback of {@link WebChromeClient#onShowFileChooser}
530 * </pre>
531 *
532 * @return an Intent that supports basic file chooser sources.
533 */
534 public abstract Intent createIntent();
535 }
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700536
537 /**
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400538 * Tell the client to open a file chooser.
539 * @param uploadFile A ValueCallback to set the URI of the file to upload.
Ben Murdoch4ae32f52010-05-18 14:30:39 +0100540 * onReceiveValue must be called to wake up the thread.a
541 * @param acceptType The value of the 'accept' attribute of the input tag
542 * associated with this file picker.
Ben Murdochbe716922012-01-11 10:55:10 +0000543 * @param capture The value of the 'capture' attribute of the input tag
544 * associated with this file picker.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700545 *
Nate Fischerc4f8f892017-08-30 15:39:32 -0700546 * @deprecated Use {@link #onShowFileChooser} instead.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700547 * @hide This method was not published in any SDK version.
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400548 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000549 @SystemApi
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700550 @Deprecated
Ben Murdochbe716922012-01-11 10:55:10 +0000551 public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400552 uploadFile.onReceiveValue(null);
553 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554}