blob: f8522edb7dcd22af7ad6ac7d022ff0839f201d67 [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 /**
Nate Fischeraaaa6602019-10-24 20:35:54 -070074 * Notify the host application that the current page has entered full screen mode. After this
75 * call, web content will no longer be rendered in the WebView, but will instead be rendered
76 * in {@code view}. The host application should add this View to a Window which is configured
77 * with {@link android.view.WindowManager.LayoutParams#FLAG_FULLSCREEN} flag in order to
78 * actually display this web content full screen.
79 *
80 * <p>The application may explicitly exit fullscreen mode by invoking {@code callback} (ex. when
81 * the user presses the back button). However, this is generally not necessary as the web page
82 * will often show its own UI to close out of fullscreen. Regardless of how the WebView exits
83 * fullscreen mode, WebView will invoke {@link #onHideCustomView()}, signaling for the
84 * application to remove the custom View.
85 *
86 * <p>If this method is not overridden, WebView will report to the web page it does not support
87 * fullscreen mode and will not honor the web page's request to run in fullscreen mode.
88 *
89 * <p class="note"><b>Note:</b> if overriding this method, the application must also override
90 * {@link #onHideCustomView()}.
91 *
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010092 * @param view is the View object to be shown.
Ignacio Solla7a4e18f2014-12-29 12:21:52 +000093 * @param callback invoke this callback to request the page to exit
94 * full screen mode.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010095 */
96 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010097
98 /**
99 * Notify the host application that the current page would
Derek Sollenberger7ab3d672011-06-01 14:45:05 -0400100 * like to show a custom View in a particular orientation.
101 * @param view is the View object to be shown.
102 * @param requestedOrientation An orientation constant as used in
103 * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
104 * @param callback is the callback to be invoked if and when the view
105 * is dismissed.
Kristian Monsen0e0b2da2013-04-10 13:43:43 -0700106 * @deprecated This method supports the obsolete plugin mechanism,
107 * and will not be invoked in future
Derek Sollenberger7ab3d672011-06-01 14:45:05 -0400108 */
Kristian Monsen0e0b2da2013-04-10 13:43:43 -0700109 @Deprecated
Derek Sollenberger7ab3d672011-06-01 14:45:05 -0400110 public void onShowCustomView(View view, int requestedOrientation,
111 CustomViewCallback callback) {};
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700112
Derek Sollenberger7ab3d672011-06-01 14:45:05 -0400113 /**
Nate Fischeraaaa6602019-10-24 20:35:54 -0700114 * Notify the host application that the current page has exited full screen mode. The host
115 * application must hide the custom View (the View which was previously passed to {@link
116 * #onShowCustomView(View, CustomViewCallback) onShowCustomView()}). After this call, web
117 * content will render in the original WebView again.
118 *
119 * <p class="note"><b>Note:</b> if overriding this method, the application must also override
120 * {@link #onShowCustomView(View, CustomViewCallback) onShowCustomView()}.
Andrei Popescu6fa29582009-06-19 14:54:09 +0100121 */
122 public void onHideCustomView() {}
123
124 /**
Steve Block89e00a92011-08-03 15:24:43 +0100125 * Request the host application to create a new window. If the host
Nate Fischer0a6140d2017-09-05 12:37:49 -0700126 * application chooses to honor this request, it should return {@code true} from
Steve Block89e00a92011-08-03 15:24:43 +0100127 * this method, create a new WebView to host the window, insert it into the
128 * View system and send the supplied resultMsg message to its target with
129 * the new WebView as an argument. If the host application chooses not to
Nate Fischer0a6140d2017-09-05 12:37:49 -0700130 * honor the request, it should return {@code false} from this method. The default
131 * implementation of this method does nothing and hence returns {@code false}.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400132 * <p>
133 * Applications should typically not allow windows to be created when the
134 * {@code isUserGesture} flag is false, as this may be an unwanted popup.
135 * <p>
136 * Applications should be careful how they display the new window: don't simply
137 * overlay it over the existing WebView as this may mislead the user about which
138 * site they are viewing. If your application displays the URL of the main page,
139 * make sure to also display the URL of the new window in a similar fashion. If
140 * your application does not display URLs, consider disallowing the creation of
141 * new windows entirely.
142 * <p class="note"><b>Note:</b> There is no trustworthy way to tell which page
143 * requested the new window: the request might originate from a third-party iframe
144 * inside the WebView.
145 *
Steve Block89e00a92011-08-03 15:24:43 +0100146 * @param view The WebView from which the request for a new window
147 * originated.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700148 * @param isDialog {@code true} if the new window should be a dialog, rather than
Steve Block89e00a92011-08-03 15:24:43 +0100149 * a full-size window.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700150 * @param isUserGesture {@code true} if the request was initiated by a user gesture,
Steve Block89e00a92011-08-03 15:24:43 +0100151 * such as the user clicking a link.
152 * @param resultMsg The message to send when once a new WebView has been
153 * created. resultMsg.obj is a
Steve Blockb22a69f2011-10-17 11:55:37 +0100154 * {@link WebView.WebViewTransport} object. This should be
155 * used to transport the new WebView, by calling
156 * {@link WebView.WebViewTransport#setWebView(WebView)
157 * WebView.WebViewTransport.setWebView(WebView)}.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700158 * @return This method should return {@code true} if the host application will
Steve Block89e00a92011-08-03 15:24:43 +0100159 * create a new window, in which case resultMsg should be sent to
Nate Fischer0a6140d2017-09-05 12:37:49 -0700160 * its target. Otherwise, this method should return {@code false}. Returning
161 * {@code false} from this method but also sending resultMsg will result in
Steve Block89e00a92011-08-03 15:24:43 +0100162 * undefined behavior.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800163 */
Steve Block89e00a92011-08-03 15:24:43 +0100164 public boolean onCreateWindow(WebView view, boolean isDialog,
165 boolean isUserGesture, Message resultMsg) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 return false;
167 }
168
169 /**
170 * Request display and focus for this WebView. This may happen due to
171 * another WebView opening a link in this WebView and requesting that this
172 * WebView be displayed.
173 * @param view The WebView that needs to be focused.
174 */
175 public void onRequestFocus(WebView view) {}
176
177 /**
178 * Notify the host application to close the given WebView and remove it
179 * from the view system if necessary. At this point, WebCore has stopped
180 * any loading in this window and has removed any cross-scripting ability
181 * in javascript.
Torne (Richard Coles)97bf0be2018-05-16 10:51:56 -0400182 * <p>
183 * As with {@link #onCreateWindow}, the application should ensure that any
184 * URL or security indicator displayed is updated so that the user can tell
185 * that the page they were interacting with has been closed.
186 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 * @param window The WebView that needs to be closed.
188 */
189 public void onCloseWindow(WebView window) {}
190
191 /**
192 * Tell the client to display a javascript alert dialog. If the client
Nate Fischer0a6140d2017-09-05 12:37:49 -0700193 * returns {@code true}, WebView will assume that the client will handle the
194 * dialog. If the client returns {@code false}, it will continue execution.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 * @param view The WebView that initiated the callback.
196 * @param url The url of the page requesting the dialog.
197 * @param message Message to be displayed in the window.
198 * @param result A JsResult to confirm that the user hit enter.
199 * @return boolean Whether the client will handle the alert dialog.
200 */
201 public boolean onJsAlert(WebView view, String url, String message,
202 JsResult result) {
203 return false;
204 }
205
206 /**
207 * Tell the client to display a confirm dialog to the user. If the client
Nate Fischer0a6140d2017-09-05 12:37:49 -0700208 * returns {@code true}, WebView will assume that the client will handle the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 * confirm dialog and call the appropriate JsResult method. If the
Nate Fischer0a6140d2017-09-05 12:37:49 -0700210 * client returns false, a default value of {@code false} will be returned to
211 * javascript. The default behavior is to return {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 * @param view The WebView that initiated the callback.
213 * @param url The url of the page requesting the dialog.
214 * @param message Message to be displayed in the window.
215 * @param result A JsResult used to send the user's response to
216 * javascript.
217 * @return boolean Whether the client will handle the confirm dialog.
218 */
219 public boolean onJsConfirm(WebView view, String url, String message,
220 JsResult result) {
221 return false;
222 }
223
224 /**
225 * Tell the client to display a prompt dialog to the user. If the client
Nate Fischer0a6140d2017-09-05 12:37:49 -0700226 * returns {@code true}, WebView will assume that the client will handle the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800227 * prompt dialog and call the appropriate JsPromptResult method. If the
Nate Fischer0a6140d2017-09-05 12:37:49 -0700228 * client returns false, a default value of {@code false} will be returned to to
229 * javascript. The default behavior is to return {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 * @param view The WebView that initiated the callback.
231 * @param url The url of the page requesting the dialog.
232 * @param message Message to be displayed in the window.
233 * @param defaultValue The default value displayed in the prompt dialog.
234 * @param result A JsPromptResult used to send the user's reponse to
235 * javascript.
236 * @return boolean Whether the client will handle the prompt dialog.
237 */
238 public boolean onJsPrompt(WebView view, String url, String message,
239 String defaultValue, JsPromptResult result) {
240 return false;
241 }
242
243 /**
244 * Tell the client to display a dialog to confirm navigation away from the
245 * current page. This is the result of the onbeforeunload javascript event.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700246 * If the client returns {@code true}, WebView will assume that the client will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 * handle the confirm dialog and call the appropriate JsResult method. If
Nate Fischer0a6140d2017-09-05 12:37:49 -0700248 * 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 -0800249 * javascript to accept navigation away from the current page. The default
Nate Fischer0a6140d2017-09-05 12:37:49 -0700250 * behavior is to return {@code false}. Setting the JsResult to {@code true} will navigate
251 * away from the current page, {@code false} will cancel the navigation.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 * @param view The WebView that initiated the callback.
253 * @param url The url of the page requesting the dialog.
254 * @param message Message to be displayed in the window.
255 * @param result A JsResult used to send the user's response to
256 * javascript.
257 * @return boolean Whether the client will handle the confirm dialog.
258 */
259 public boolean onJsBeforeUnload(WebView view, String url, String message,
260 JsResult result) {
261 return false;
262 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100263
264 /**
Steve Block285ddfc2012-03-28 12:46:02 +0100265 * Tell the client that the quota has been exceeded for the Web SQL Database
266 * API for a particular origin and request a new quota. The client must
267 * respond by invoking the
268 * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
269 * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
270 * minimum value that can be set for the new quota is the current quota. The
271 * default implementation responds with the current quota, so the quota will
272 * not be increased.
273 * @param url The URL of the page that triggered the notification
274 * @param databaseIdentifier The identifier of the database where the quota
275 * was exceeded.
276 * @param quota The quota for the origin, in bytes
277 * @param estimatedDatabaseSize The estimated size of the offending
278 * database, in bytes
279 * @param totalQuota The total quota for all origins, in bytes
280 * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
281 * must be used to inform the WebView of the new quota.
Jonathan Dixon5545d082013-08-31 22:43:11 -0700282 * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
283 * Management API.
Ben Murdoch7df19852009-04-22 13:07:58 +0100284 */
Jonathan Dixon5545d082013-08-31 22:43:11 -0700285 @Deprecated
Ben Murdoch7df19852009-04-22 13:07:58 +0100286 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Steve Block285ddfc2012-03-28 12:46:02 +0100287 long quota, long estimatedDatabaseSize, long totalQuota,
288 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100289 // This default implementation passes the current quota back to WebCore.
290 // WebCore will interpret this that new quota was declined.
Steve Block285ddfc2012-03-28 12:46:02 +0100291 quotaUpdater.updateQuota(quota);
Ben Murdoch7df19852009-04-22 13:07:58 +0100292 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700293
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100294 /**
Selim Gurunc86bec92012-06-28 16:47:19 -0700295 * Notify the host application that the Application Cache has reached the
296 * maximum size. The client must respond by invoking the
Steve Block285ddfc2012-03-28 12:46:02 +0100297 * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
298 * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
299 * minimum value that can be set for the new quota is the current quota. The
300 * default implementation responds with the current quota, so the quota will
301 * not be increased.
302 * @param requiredStorage The amount of storage required by the Application
303 * Cache operation that triggered this notification,
304 * in bytes.
Selim Gurunc86bec92012-06-28 16:47:19 -0700305 * @param quota the current maximum Application Cache size, in bytes
Steve Block285ddfc2012-03-28 12:46:02 +0100306 * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
307 * must be used to inform the WebView of the new quota.
Jonathan Dixon5545d082013-08-31 22:43:11 -0700308 * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota
309 * Management API.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100310 */
Jonathan Dixon5545d082013-08-31 22:43:11 -0700311 @Deprecated
Steve Block285ddfc2012-03-28 12:46:02 +0100312 public void onReachedMaxAppCacheSize(long requiredStorage, long quota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100313 WebStorage.QuotaUpdater quotaUpdater) {
Steve Block285ddfc2012-03-28 12:46:02 +0100314 quotaUpdater.updateQuota(quota);
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100315 }
316
Guang Zhu81e41432009-05-08 16:09:55 -0700317 /**
Steve Block7351adf2011-11-30 15:52:32 +0000318 * Notify the host application that web content from the specified origin
319 * is attempting to use the Geolocation API, but no permission state is
320 * currently set for that origin. The host application should invoke the
321 * specified callback with the desired permission state. See
322 * {@link GeolocationPermissions} for details.
Tim Volodineb0e97982016-04-27 14:14:09 +0100323 *
324 * <p>Note that for applications targeting Android N and later SDKs
325 * (API level > {@link android.os.Build.VERSION_CODES#M})
326 * this method is only called for requests originating from secure
327 * origins such as https. On non-secure origins geolocation requests
Nate Fischerf02f8462017-09-11 15:16:33 -0700328 * are automatically denied.
Tim Volodineb0e97982016-04-27 14:14:09 +0100329 *
Steve Block7351adf2011-11-30 15:52:32 +0000330 * @param origin The origin of the web content attempting to use the
331 * Geolocation API.
332 * @param callback The callback to use to set the permission state for the
333 * origin.
Steve Block4faee092009-07-28 18:20:50 +0100334 */
335 public void onGeolocationPermissionsShowPrompt(String origin,
Tim Volodine0bb7d2e2015-07-23 17:16:16 +0000336 GeolocationPermissions.Callback callback) {}
Steve Block4faee092009-07-28 18:20:50 +0100337
338 /**
Steve Block7351adf2011-11-30 15:52:32 +0000339 * Notify the host application that a request for Geolocation permissions,
340 * made with a previous call to
341 * {@link #onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt()}
342 * has been canceled. Any related UI should therefore be hidden.
Steve Block4faee092009-07-28 18:20:50 +0100343 */
344 public void onGeolocationPermissionsHidePrompt() {}
345
346 /**
Tao Bai4c22b542014-04-15 18:04:49 +0000347 * Notify the host application that web content is requesting permission to
348 * access the specified resources and the permission currently isn't granted
Tao Bai2871feb2014-07-16 13:54:15 -0700349 * or denied. The host application must invoke {@link PermissionRequest#grant(String[])}
Tao Bai4c22b542014-04-15 18:04:49 +0000350 * or {@link PermissionRequest#deny()}.
351 *
352 * If this method isn't overridden, the permission is denied.
353 *
354 * @param request the PermissionRequest from current web content.
Tao Bai4c22b542014-04-15 18:04:49 +0000355 */
356 public void onPermissionRequest(PermissionRequest request) {
357 request.deny();
358 }
359
360 /**
361 * Notify the host application that the given permission request
362 * has been canceled. Any related UI should therefore be hidden.
363 *
Tao Baifa1fd2c2014-04-30 13:31:34 -0700364 * @param request the PermissionRequest that needs be canceled.
Tao Bai4c22b542014-04-15 18:04:49 +0000365 */
366 public void onPermissionRequestCanceled(PermissionRequest request) {}
367
368 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700369 * Tell the client that a JavaScript execution timeout has occured. And the
370 * client may decide whether or not to interrupt the execution. If the
Nate Fischer0a6140d2017-09-05 12:37:49 -0700371 * client returns {@code true}, the JavaScript will be interrupted. If the client
372 * returns {@code false}, the execution will continue. Note that in the case of
Guang Zhu81e41432009-05-08 16:09:55 -0700373 * continuing execution, the timeout counter will be reset, and the callback
374 * will continue to occur if the script does not finish at the next check
375 * point.
376 * @return boolean Whether the JavaScript execution should be interrupted.
Ben Murdoch1bd37b12012-05-28 12:42:39 +0100377 * @deprecated This method is no longer supported and will not be invoked.
Guang Zhu81e41432009-05-08 16:09:55 -0700378 */
Ben Murdoch1bd37b12012-05-28 12:42:39 +0100379 // This method was only called when using the JSC javascript engine. V8 became
380 // the default JS engine with Froyo and support for building with JSC was
381 // removed in b/5495373. V8 does not have a mechanism for making a callback such
382 // as this.
Aurimas Liutikas514c5ef2016-05-24 15:22:55 -0700383 @Deprecated
Guang Zhu81e41432009-05-08 16:09:55 -0700384 public boolean onJsTimeout() {
385 return true;
386 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100387
388 /**
Ben Murdoch7caaeec2009-11-19 18:14:53 +0000389 * Report a JavaScript error message to the host application. The ChromeClient
390 * should override this to process the log message as they see fit.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100391 * @param message The error message to report.
392 * @param lineNumber The line number of the error.
393 * @param sourceID The name of the source file that caused the error.
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000394 * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
395 * instead.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100396 */
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000397 @Deprecated
398 public void onConsoleMessage(String message, int lineNumber, String sourceID) { }
399
400 /**
401 * Report a JavaScript console message to the host application. The ChromeClient
402 * should override this to process the log message as they see fit.
403 * @param consoleMessage Object containing details of the console message.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700404 * @return {@code true} if the message is handled by the client.
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000405 */
406 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
407 // Call the old version of this function for backwards compatability.
408 onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
409 consoleMessage.sourceId());
410 return false;
411 }
Andrei Popescubf385d72009-09-18 18:59:52 +0100412
413 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000414 * When not playing, video elements are represented by a 'poster' image. The
415 * image to use can be specified by the poster attribute of the video tag in
416 * HTML. If the attribute is absent, then a default poster will be used. This
417 * method allows the ChromeClient to provide that default image.
Andrei Popescubf385d72009-09-18 18:59:52 +0100418 *
Nate Fischer0a6140d2017-09-05 12:37:49 -0700419 * @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 +0000420 * available.
Andrei Popescubf385d72009-09-18 18:59:52 +0100421 */
Nate Fischer3442c742017-09-08 17:02:00 -0700422 @Nullable
Andrei Popescubf385d72009-09-18 18:59:52 +0100423 public Bitmap getDefaultVideoPoster() {
424 return null;
425 }
426
427 /**
Ignacio Solla7a4e18f2014-12-29 12:21:52 +0000428 * Obtains a View to be displayed while buffering of full screen video is taking
429 * place. The host application can override this method to provide a View
430 * containing a spinner or similar.
Andrei Popescubf385d72009-09-18 18:59:52 +0100431 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000432 * @return View The View to be displayed whilst the video is loading.
Andrei Popescubf385d72009-09-18 18:59:52 +0100433 */
Nate Fischer3442c742017-09-08 17:02:00 -0700434 @Nullable
Andrei Popescubf385d72009-09-18 18:59:52 +0100435 public View getVideoLoadingProgressView() {
436 return null;
437 }
Leon Clarke194e3452009-09-28 11:42:12 +0100438
439 /** Obtains a list of all visited history items, used for link coloring
Leon Clarke194e3452009-09-28 11:42:12 +0100440 */
441 public void getVisitedHistory(ValueCallback<String[]> callback) {
442 }
443
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400444 /**
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700445 * Tell the client to show a file chooser.
446 *
447 * This is called to handle HTML forms with 'file' input type, in response to the
448 * user pressing the "Select File" button.
449 * To cancel the request, call <code>filePathCallback.onReceiveValue(null)</code> and
Nate Fischer0a6140d2017-09-05 12:37:49 -0700450 * return {@code true}.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700451 *
452 * @param webView The WebView instance that is initiating the request.
453 * @param filePathCallback Invoke this callback to supply the list of paths to files to upload,
Nate Fischer0a6140d2017-09-05 12:37:49 -0700454 * or {@code null} to cancel. Must only be called if the
455 * {@link #onShowFileChooser} implementation returns {@code true}.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700456 * @param fileChooserParams Describes the mode of file chooser to be opened, and options to be
457 * used with it.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700458 * @return {@code true} if filePathCallback will be invoked, {@code false} to use default
459 * handling.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700460 *
461 * @see FileChooserParams
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700462 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700463 public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700464 FileChooserParams fileChooserParams) {
465 return false;
466 }
467
468 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700469 * Parameters used in the {@link #onShowFileChooser} method.
470 */
471 public static abstract class FileChooserParams {
472 /** Open single file. Requires that the file exists before allowing the user to pick it. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700473 public static final int MODE_OPEN = 0;
Selim Gurun48f6c452014-07-18 16:23:46 -0700474 /** Like Open but allows multiple files to be selected. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700475 public static final int MODE_OPEN_MULTIPLE = 1;
Selim Gurun48f6c452014-07-18 16:23:46 -0700476 /** Like Open but allows a folder to be selected. The implementation should enumerate
Selim Gurun17d1adb2014-08-27 11:22:26 -0700477 all files selected by this operation.
478 This feature is not supported at the moment.
479 @hide */
480 public static final int MODE_OPEN_FOLDER = 2;
Selim Gurun48f6c452014-07-18 16:23:46 -0700481 /** Allows picking a nonexistent file and saving it. */
Selim Gurun17d1adb2014-08-27 11:22:26 -0700482 public static final int MODE_SAVE = 3;
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700483
484 /**
Tao Baie8df27a2014-09-02 14:09:49 -0700485 * Parse the result returned by the file picker activity. This method should be used with
486 * {@link #createIntent}. Refer to {@link #createIntent} for how to use it.
487 *
488 * @param resultCode the integer result code returned by the file picker activity.
489 * @param data the intent returned by the file picker activity.
Nate Fischer0a6140d2017-09-05 12:37:49 -0700490 * @return the Uris of selected file(s) or {@code null} if the resultCode indicates
Tao Baie8df27a2014-09-02 14:09:49 -0700491 * activity canceled or any other error.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700492 */
Nate Fischer3442c742017-09-08 17:02:00 -0700493 @Nullable
Tao Baie8df27a2014-09-02 14:09:49 -0700494 public static Uri[] parseResult(int resultCode, Intent data) {
495 return WebViewFactory.getProvider().getStatics().parseFileChooserResult(resultCode, data);
496 }
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700497
498 /**
Selim Gurun48f6c452014-07-18 16:23:46 -0700499 * Returns file chooser mode.
500 */
501 public abstract int getMode();
502
503 /**
Selim Gurun17d1adb2014-08-27 11:22:26 -0700504 * Returns an array of acceptable MIME types. The returned MIME type
505 * could be partial such as audio/*. The array will be empty if no
Selim Gurun48f6c452014-07-18 16:23:46 -0700506 * acceptable types are specified.
507 */
508 public abstract String[] getAcceptTypes();
509
510 /**
511 * Returns preference for a live media captured value (e.g. Camera, Microphone).
Nate Fischer0a6140d2017-09-05 12:37:49 -0700512 * True indicates capture is enabled, {@code false} disabled.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700513 *
Selim Gurun48f6c452014-07-18 16:23:46 -0700514 * Use <code>getAcceptTypes</code> to determine suitable capture devices.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700515 */
Selim Gurun48f6c452014-07-18 16:23:46 -0700516 public abstract boolean isCaptureEnabled();
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700517
518 /**
Nate Fischer3442c742017-09-08 17:02:00 -0700519 * Returns the title to use for this file selector. If {@code null} a default title should
520 * be used.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700521 */
Nate Fischer3442c742017-09-08 17:02:00 -0700522 @Nullable
Selim Gurun48f6c452014-07-18 16:23:46 -0700523 public abstract CharSequence getTitle();
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700524
525 /**
Nate Fischer0a6140d2017-09-05 12:37:49 -0700526 * The file name of a default selection if specified, or {@code null}.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700527 */
Nate Fischer3442c742017-09-08 17:02:00 -0700528 @Nullable
Selim Gurun17d1adb2014-08-27 11:22:26 -0700529 public abstract String getFilenameHint();
Tao Baie8df27a2014-09-02 14:09:49 -0700530
531 /**
532 * Creates an intent that would start a file picker for file selection.
533 * The Intent supports choosing files from simple file sources available
534 * on the device. Some advanced sources (for example, live media capture)
535 * may not be supported and applications wishing to support these sources
536 * or more advanced file operations should build their own Intent.
537 *
Nate Fischer06fd0602019-08-12 20:44:51 -0700538 * <p>How to use:
539 * <ol>
540 * <li>Build an intent using {@link #createIntent}</li>
541 * <li>Fire the intent using {@link android.app.Activity#startActivityForResult}.</li>
542 * <li>Check for ActivityNotFoundException and take a user friendly action if thrown.</li>
543 * <li>Listen the result using {@link android.app.Activity#onActivityResult}</li>
544 * <li>Parse the result using {@link #parseResult} only if media capture was not
545 * requested.</li>
546 * <li>Send the result using filePathCallback of {@link
547 * WebChromeClient#onShowFileChooser}</li>
548 * </ol>
Tao Baie8df27a2014-09-02 14:09:49 -0700549 *
550 * @return an Intent that supports basic file chooser sources.
551 */
552 public abstract Intent createIntent();
553 }
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700554
555 /**
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400556 * Tell the client to open a file chooser.
557 * @param uploadFile A ValueCallback to set the URI of the file to upload.
Ben Murdoch4ae32f52010-05-18 14:30:39 +0100558 * onReceiveValue must be called to wake up the thread.a
559 * @param acceptType The value of the 'accept' attribute of the input tag
560 * associated with this file picker.
Ben Murdochbe716922012-01-11 10:55:10 +0000561 * @param capture The value of the 'capture' attribute of the input tag
562 * associated with this file picker.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700563 *
Nate Fischerc4f8f892017-08-30 15:39:32 -0700564 * @deprecated Use {@link #onShowFileChooser} instead.
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700565 * @hide This method was not published in any SDK version.
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400566 */
Ignacio Solla451e3382014-11-10 10:35:54 +0000567 @SystemApi
Jonathan Dixon3a5cf382013-07-27 15:37:31 -0700568 @Deprecated
Ben Murdochbe716922012-01-11 10:55:10 +0000569 public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400570 uploadFile.onReceiveValue(null);
571 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572}