The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.webkit; |
| 18 | |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 19 | import android.annotation.Nullable; |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 22 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 24 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.os.Message; |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 26 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | |
| 28 | public 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 Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 53 | * 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 Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 56 | * @param precomposed {@code true} if the url is for a precomposed touch icon. |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 57 | */ |
Patrick Scott | d58ccff | 2009-09-18 16:29:00 -0400 | [diff] [blame] | 58 | public void onReceivedTouchIconUrl(WebView view, String url, |
| 59 | boolean precomposed) {} |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 60 | |
| 61 | /** |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 62 | * A callback interface used by the host application to notify |
| 63 | * the current page that its custom view has been dismissed. |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 64 | */ |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 65 | public interface CustomViewCallback { |
| 66 | /** |
| 67 | * Invoked when the host application dismisses the |
| 68 | * custom view. |
| 69 | */ |
| 70 | public void onCustomViewHidden(); |
| 71 | } |
| 72 | |
| 73 | /** |
Ignacio Solla | 7a4e18f | 2014-12-29 12:21:52 +0000 | [diff] [blame] | 74 | * 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 Monsen | 0e0b2da | 2013-04-10 13:43:43 -0700 | [diff] [blame] | 78 | * {@link WebView}. |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 79 | * @param view is the View object to be shown. |
Ignacio Solla | 7a4e18f | 2014-12-29 12:21:52 +0000 | [diff] [blame] | 80 | * @param callback invoke this callback to request the page to exit |
| 81 | * full screen mode. |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 82 | */ |
| 83 | public void onShowCustomView(View view, CustomViewCallback callback) {}; |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Notify the host application that the current page would |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 87 | * 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 Monsen | 0e0b2da | 2013-04-10 13:43:43 -0700 | [diff] [blame] | 93 | * @deprecated This method supports the obsolete plugin mechanism, |
| 94 | * and will not be invoked in future |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 95 | */ |
Kristian Monsen | 0e0b2da | 2013-04-10 13:43:43 -0700 | [diff] [blame] | 96 | @Deprecated |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 97 | public void onShowCustomView(View view, int requestedOrientation, |
| 98 | CustomViewCallback callback) {}; |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 99 | |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame] | 100 | /** |
Ignacio Solla | 7a4e18f | 2014-12-29 12:21:52 +0000 | [diff] [blame] | 101 | * 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 Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 105 | */ |
| 106 | public void onHideCustomView() {} |
| 107 | |
| 108 | /** |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 109 | * Request the host application to create a new window. If the host |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 110 | * application chooses to honor this request, it should return {@code true} from |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 111 | * 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 Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 114 | * 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}. |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 116 | * @param view The WebView from which the request for a new window |
| 117 | * originated. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 118 | * @param isDialog {@code true} if the new window should be a dialog, rather than |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 119 | * a full-size window. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 120 | * @param isUserGesture {@code true} if the request was initiated by a user gesture, |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 121 | * such as the user clicking a link. |
| 122 | * @param resultMsg The message to send when once a new WebView has been |
| 123 | * created. resultMsg.obj is a |
Steve Block | b22a69f | 2011-10-17 11:55:37 +0100 | [diff] [blame] | 124 | * {@link WebView.WebViewTransport} object. This should be |
| 125 | * used to transport the new WebView, by calling |
| 126 | * {@link WebView.WebViewTransport#setWebView(WebView) |
| 127 | * WebView.WebViewTransport.setWebView(WebView)}. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 128 | * @return This method should return {@code true} if the host application will |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 129 | * create a new window, in which case resultMsg should be sent to |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 130 | * its target. Otherwise, this method should return {@code false}. Returning |
| 131 | * {@code false} from this method but also sending resultMsg will result in |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 132 | * undefined behavior. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | */ |
Steve Block | 89e00a9 | 2011-08-03 15:24:43 +0100 | [diff] [blame] | 134 | public boolean onCreateWindow(WebView view, boolean isDialog, |
| 135 | boolean isUserGesture, Message resultMsg) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Request display and focus for this WebView. This may happen due to |
| 141 | * another WebView opening a link in this WebView and requesting that this |
| 142 | * WebView be displayed. |
| 143 | * @param view The WebView that needs to be focused. |
| 144 | */ |
| 145 | public void onRequestFocus(WebView view) {} |
| 146 | |
| 147 | /** |
| 148 | * Notify the host application to close the given WebView and remove it |
| 149 | * from the view system if necessary. At this point, WebCore has stopped |
| 150 | * any loading in this window and has removed any cross-scripting ability |
| 151 | * in javascript. |
| 152 | * @param window The WebView that needs to be closed. |
| 153 | */ |
| 154 | public void onCloseWindow(WebView window) {} |
| 155 | |
| 156 | /** |
| 157 | * Tell the client to display a javascript alert dialog. If the client |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 158 | * returns {@code true}, WebView will assume that the client will handle the |
| 159 | * dialog. If the client returns {@code false}, it will continue execution. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | * @param view The WebView that initiated the callback. |
| 161 | * @param url The url of the page requesting the dialog. |
| 162 | * @param message Message to be displayed in the window. |
| 163 | * @param result A JsResult to confirm that the user hit enter. |
| 164 | * @return boolean Whether the client will handle the alert dialog. |
| 165 | */ |
| 166 | public boolean onJsAlert(WebView view, String url, String message, |
| 167 | JsResult result) { |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Tell the client to display a confirm dialog to the user. If the client |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 173 | * returns {@code true}, WebView will assume that the client will handle the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | * confirm dialog and call the appropriate JsResult method. If the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 175 | * client returns false, a default value of {@code false} will be returned to |
| 176 | * javascript. The default behavior is to return {@code false}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | * @param view The WebView that initiated the callback. |
| 178 | * @param url The url of the page requesting the dialog. |
| 179 | * @param message Message to be displayed in the window. |
| 180 | * @param result A JsResult used to send the user's response to |
| 181 | * javascript. |
| 182 | * @return boolean Whether the client will handle the confirm dialog. |
| 183 | */ |
| 184 | public boolean onJsConfirm(WebView view, String url, String message, |
| 185 | JsResult result) { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Tell the client to display a prompt dialog to the user. If the client |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 191 | * returns {@code true}, WebView will assume that the client will handle the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | * prompt dialog and call the appropriate JsPromptResult method. If the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 193 | * client returns false, a default value of {@code false} will be returned to to |
| 194 | * javascript. The default behavior is to return {@code false}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | * @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 defaultValue The default value displayed in the prompt dialog. |
| 199 | * @param result A JsPromptResult used to send the user's reponse to |
| 200 | * javascript. |
| 201 | * @return boolean Whether the client will handle the prompt dialog. |
| 202 | */ |
| 203 | public boolean onJsPrompt(WebView view, String url, String message, |
| 204 | String defaultValue, JsPromptResult result) { |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Tell the client to display a dialog to confirm navigation away from the |
| 210 | * current page. This is the result of the onbeforeunload javascript event. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 211 | * If the client returns {@code true}, WebView will assume that the client will |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | * handle the confirm dialog and call the appropriate JsResult method. If |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 213 | * the client returns {@code false}, a default value of {@code true} will be returned to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | * javascript to accept navigation away from the current page. The default |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 215 | * behavior is to return {@code false}. Setting the JsResult to {@code true} will navigate |
| 216 | * away from the current page, {@code false} will cancel the navigation. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | * @param view The WebView that initiated the callback. |
| 218 | * @param url The url of the page requesting the dialog. |
| 219 | * @param message Message to be displayed in the window. |
| 220 | * @param result A JsResult used to send the user's response to |
| 221 | * javascript. |
| 222 | * @return boolean Whether the client will handle the confirm dialog. |
| 223 | */ |
| 224 | public boolean onJsBeforeUnload(WebView view, String url, String message, |
| 225 | JsResult result) { |
| 226 | return false; |
| 227 | } |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 228 | |
| 229 | /** |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 230 | * Tell the client that the quota has been exceeded for the Web SQL Database |
| 231 | * API for a particular origin and request a new quota. The client must |
| 232 | * respond by invoking the |
| 233 | * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)} |
| 234 | * method of the supplied {@link WebStorage.QuotaUpdater} instance. The |
| 235 | * minimum value that can be set for the new quota is the current quota. The |
| 236 | * default implementation responds with the current quota, so the quota will |
| 237 | * not be increased. |
| 238 | * @param url The URL of the page that triggered the notification |
| 239 | * @param databaseIdentifier The identifier of the database where the quota |
| 240 | * was exceeded. |
| 241 | * @param quota The quota for the origin, in bytes |
| 242 | * @param estimatedDatabaseSize The estimated size of the offending |
| 243 | * database, in bytes |
| 244 | * @param totalQuota The total quota for all origins, in bytes |
| 245 | * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which |
| 246 | * must be used to inform the WebView of the new quota. |
Jonathan Dixon | 5545d08 | 2013-08-31 22:43:11 -0700 | [diff] [blame] | 247 | * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota |
| 248 | * Management API. |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 249 | */ |
Jonathan Dixon | 5545d08 | 2013-08-31 22:43:11 -0700 | [diff] [blame] | 250 | @Deprecated |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 251 | public void onExceededDatabaseQuota(String url, String databaseIdentifier, |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 252 | long quota, long estimatedDatabaseSize, long totalQuota, |
| 253 | WebStorage.QuotaUpdater quotaUpdater) { |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 254 | // This default implementation passes the current quota back to WebCore. |
| 255 | // WebCore will interpret this that new quota was declined. |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 256 | quotaUpdater.updateQuota(quota); |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 257 | } |
Guang Zhu | 10e4d20 | 2009-05-11 18:09:51 -0700 | [diff] [blame] | 258 | |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 259 | /** |
Selim Gurun | c86bec9 | 2012-06-28 16:47:19 -0700 | [diff] [blame] | 260 | * Notify the host application that the Application Cache has reached the |
| 261 | * maximum size. The client must respond by invoking the |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 262 | * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)} |
| 263 | * method of the supplied {@link WebStorage.QuotaUpdater} instance. The |
| 264 | * minimum value that can be set for the new quota is the current quota. The |
| 265 | * default implementation responds with the current quota, so the quota will |
| 266 | * not be increased. |
| 267 | * @param requiredStorage The amount of storage required by the Application |
| 268 | * Cache operation that triggered this notification, |
| 269 | * in bytes. |
Selim Gurun | c86bec9 | 2012-06-28 16:47:19 -0700 | [diff] [blame] | 270 | * @param quota the current maximum Application Cache size, in bytes |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 271 | * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which |
| 272 | * must be used to inform the WebView of the new quota. |
Jonathan Dixon | 5545d08 | 2013-08-31 22:43:11 -0700 | [diff] [blame] | 273 | * @deprecated This method is no longer called; WebView now uses the HTML5 / JavaScript Quota |
| 274 | * Management API. |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 275 | */ |
Jonathan Dixon | 5545d08 | 2013-08-31 22:43:11 -0700 | [diff] [blame] | 276 | @Deprecated |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 277 | public void onReachedMaxAppCacheSize(long requiredStorage, long quota, |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 278 | WebStorage.QuotaUpdater quotaUpdater) { |
Steve Block | 285ddfc | 2012-03-28 12:46:02 +0100 | [diff] [blame] | 279 | quotaUpdater.updateQuota(quota); |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 282 | /** |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 283 | * Notify the host application that web content from the specified origin |
| 284 | * is attempting to use the Geolocation API, but no permission state is |
| 285 | * currently set for that origin. The host application should invoke the |
| 286 | * specified callback with the desired permission state. See |
| 287 | * {@link GeolocationPermissions} for details. |
Tim Volodine | b0e9798 | 2016-04-27 14:14:09 +0100 | [diff] [blame] | 288 | * |
| 289 | * <p>Note that for applications targeting Android N and later SDKs |
| 290 | * (API level > {@link android.os.Build.VERSION_CODES#M}) |
| 291 | * this method is only called for requests originating from secure |
| 292 | * origins such as https. On non-secure origins geolocation requests |
| 293 | * are automatically denied.</p> |
| 294 | * |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 295 | * @param origin The origin of the web content attempting to use the |
| 296 | * Geolocation API. |
| 297 | * @param callback The callback to use to set the permission state for the |
| 298 | * origin. |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 299 | */ |
| 300 | public void onGeolocationPermissionsShowPrompt(String origin, |
Tim Volodine | 0bb7d2e | 2015-07-23 17:16:16 +0000 | [diff] [blame] | 301 | GeolocationPermissions.Callback callback) {} |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 302 | |
| 303 | /** |
Steve Block | 7351adf | 2011-11-30 15:52:32 +0000 | [diff] [blame] | 304 | * Notify the host application that a request for Geolocation permissions, |
| 305 | * made with a previous call to |
| 306 | * {@link #onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt()} |
| 307 | * has been canceled. Any related UI should therefore be hidden. |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 308 | */ |
| 309 | public void onGeolocationPermissionsHidePrompt() {} |
| 310 | |
| 311 | /** |
Tao Bai | 4c22b54 | 2014-04-15 18:04:49 +0000 | [diff] [blame] | 312 | * Notify the host application that web content is requesting permission to |
| 313 | * access the specified resources and the permission currently isn't granted |
Tao Bai | 2871feb | 2014-07-16 13:54:15 -0700 | [diff] [blame] | 314 | * or denied. The host application must invoke {@link PermissionRequest#grant(String[])} |
Tao Bai | 4c22b54 | 2014-04-15 18:04:49 +0000 | [diff] [blame] | 315 | * or {@link PermissionRequest#deny()}. |
| 316 | * |
| 317 | * If this method isn't overridden, the permission is denied. |
| 318 | * |
| 319 | * @param request the PermissionRequest from current web content. |
Tao Bai | 4c22b54 | 2014-04-15 18:04:49 +0000 | [diff] [blame] | 320 | */ |
| 321 | public void onPermissionRequest(PermissionRequest request) { |
| 322 | request.deny(); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Notify the host application that the given permission request |
| 327 | * has been canceled. Any related UI should therefore be hidden. |
| 328 | * |
Tao Bai | fa1fd2c | 2014-04-30 13:31:34 -0700 | [diff] [blame] | 329 | * @param request the PermissionRequest that needs be canceled. |
Tao Bai | 4c22b54 | 2014-04-15 18:04:49 +0000 | [diff] [blame] | 330 | */ |
| 331 | public void onPermissionRequestCanceled(PermissionRequest request) {} |
| 332 | |
| 333 | /** |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 334 | * Tell the client that a JavaScript execution timeout has occured. And the |
| 335 | * client may decide whether or not to interrupt the execution. If the |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 336 | * client returns {@code true}, the JavaScript will be interrupted. If the client |
| 337 | * returns {@code false}, the execution will continue. Note that in the case of |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 338 | * continuing execution, the timeout counter will be reset, and the callback |
| 339 | * will continue to occur if the script does not finish at the next check |
| 340 | * point. |
| 341 | * @return boolean Whether the JavaScript execution should be interrupted. |
Ben Murdoch | 1bd37b1 | 2012-05-28 12:42:39 +0100 | [diff] [blame] | 342 | * @deprecated This method is no longer supported and will not be invoked. |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 343 | */ |
Ben Murdoch | 1bd37b1 | 2012-05-28 12:42:39 +0100 | [diff] [blame] | 344 | // This method was only called when using the JSC javascript engine. V8 became |
| 345 | // the default JS engine with Froyo and support for building with JSC was |
| 346 | // removed in b/5495373. V8 does not have a mechanism for making a callback such |
| 347 | // as this. |
Aurimas Liutikas | 514c5ef | 2016-05-24 15:22:55 -0700 | [diff] [blame] | 348 | @Deprecated |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 349 | public boolean onJsTimeout() { |
| 350 | return true; |
| 351 | } |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 352 | |
| 353 | /** |
Ben Murdoch | 7caaeec | 2009-11-19 18:14:53 +0000 | [diff] [blame] | 354 | * Report a JavaScript error message to the host application. The ChromeClient |
| 355 | * should override this to process the log message as they see fit. |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 356 | * @param message The error message to report. |
| 357 | * @param lineNumber The line number of the error. |
| 358 | * @param sourceID The name of the source file that caused the error. |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 359 | * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)} |
| 360 | * instead. |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 361 | */ |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 362 | @Deprecated |
| 363 | public void onConsoleMessage(String message, int lineNumber, String sourceID) { } |
| 364 | |
| 365 | /** |
| 366 | * Report a JavaScript console message to the host application. The ChromeClient |
| 367 | * should override this to process the log message as they see fit. |
| 368 | * @param consoleMessage Object containing details of the console message. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 369 | * @return {@code true} if the message is handled by the client. |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 370 | */ |
| 371 | public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
| 372 | // Call the old version of this function for backwards compatability. |
| 373 | onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(), |
| 374 | consoleMessage.sourceId()); |
| 375 | return false; |
| 376 | } |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 377 | |
| 378 | /** |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 379 | * When not playing, video elements are represented by a 'poster' image. The |
| 380 | * image to use can be specified by the poster attribute of the video tag in |
| 381 | * HTML. If the attribute is absent, then a default poster will be used. This |
| 382 | * method allows the ChromeClient to provide that default image. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 383 | * |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 384 | * @return Bitmap The image to use as a default poster, or {@code null} if no such image is |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 385 | * available. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 386 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 387 | @Nullable |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 388 | public Bitmap getDefaultVideoPoster() { |
| 389 | return null; |
| 390 | } |
| 391 | |
| 392 | /** |
Ignacio Solla | 7a4e18f | 2014-12-29 12:21:52 +0000 | [diff] [blame] | 393 | * Obtains a View to be displayed while buffering of full screen video is taking |
| 394 | * place. The host application can override this method to provide a View |
| 395 | * containing a spinner or similar. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 396 | * |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 397 | * @return View The View to be displayed whilst the video is loading. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 398 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 399 | @Nullable |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 400 | public View getVideoLoadingProgressView() { |
| 401 | return null; |
| 402 | } |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 403 | |
| 404 | /** Obtains a list of all visited history items, used for link coloring |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 405 | */ |
| 406 | public void getVisitedHistory(ValueCallback<String[]> callback) { |
| 407 | } |
| 408 | |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 409 | /** |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 410 | * Tell the client to show a file chooser. |
| 411 | * |
| 412 | * This is called to handle HTML forms with 'file' input type, in response to the |
| 413 | * user pressing the "Select File" button. |
| 414 | * To cancel the request, call <code>filePathCallback.onReceiveValue(null)</code> and |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 415 | * return {@code true}. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 416 | * |
| 417 | * @param webView The WebView instance that is initiating the request. |
| 418 | * @param filePathCallback Invoke this callback to supply the list of paths to files to upload, |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 419 | * or {@code null} to cancel. Must only be called if the |
| 420 | * {@link #onShowFileChooser} implementation returns {@code true}. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 421 | * @param fileChooserParams Describes the mode of file chooser to be opened, and options to be |
| 422 | * used with it. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 423 | * @return {@code true} if filePathCallback will be invoked, {@code false} to use default |
| 424 | * handling. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 425 | * |
| 426 | * @see FileChooserParams |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 427 | */ |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 428 | public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 429 | FileChooserParams fileChooserParams) { |
| 430 | return false; |
| 431 | } |
| 432 | |
| 433 | /** |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 434 | * Parameters used in the {@link #onShowFileChooser} method. |
| 435 | */ |
| 436 | public static abstract class FileChooserParams { |
| 437 | /** Open single file. Requires that the file exists before allowing the user to pick it. */ |
Selim Gurun | 17d1adb | 2014-08-27 11:22:26 -0700 | [diff] [blame] | 438 | public static final int MODE_OPEN = 0; |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 439 | /** Like Open but allows multiple files to be selected. */ |
Selim Gurun | 17d1adb | 2014-08-27 11:22:26 -0700 | [diff] [blame] | 440 | public static final int MODE_OPEN_MULTIPLE = 1; |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 441 | /** Like Open but allows a folder to be selected. The implementation should enumerate |
Selim Gurun | 17d1adb | 2014-08-27 11:22:26 -0700 | [diff] [blame] | 442 | all files selected by this operation. |
| 443 | This feature is not supported at the moment. |
| 444 | @hide */ |
| 445 | public static final int MODE_OPEN_FOLDER = 2; |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 446 | /** Allows picking a nonexistent file and saving it. */ |
Selim Gurun | 17d1adb | 2014-08-27 11:22:26 -0700 | [diff] [blame] | 447 | public static final int MODE_SAVE = 3; |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 448 | |
| 449 | /** |
Tao Bai | e8df27a | 2014-09-02 14:09:49 -0700 | [diff] [blame] | 450 | * Parse the result returned by the file picker activity. This method should be used with |
| 451 | * {@link #createIntent}. Refer to {@link #createIntent} for how to use it. |
| 452 | * |
| 453 | * @param resultCode the integer result code returned by the file picker activity. |
| 454 | * @param data the intent returned by the file picker activity. |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 455 | * @return the Uris of selected file(s) or {@code null} if the resultCode indicates |
Tao Bai | e8df27a | 2014-09-02 14:09:49 -0700 | [diff] [blame] | 456 | * activity canceled or any other error. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 457 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 458 | @Nullable |
Tao Bai | e8df27a | 2014-09-02 14:09:49 -0700 | [diff] [blame] | 459 | public static Uri[] parseResult(int resultCode, Intent data) { |
| 460 | return WebViewFactory.getProvider().getStatics().parseFileChooserResult(resultCode, data); |
| 461 | } |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 462 | |
| 463 | /** |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 464 | * Returns file chooser mode. |
| 465 | */ |
| 466 | public abstract int getMode(); |
| 467 | |
| 468 | /** |
Selim Gurun | 17d1adb | 2014-08-27 11:22:26 -0700 | [diff] [blame] | 469 | * Returns an array of acceptable MIME types. The returned MIME type |
| 470 | * could be partial such as audio/*. The array will be empty if no |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 471 | * acceptable types are specified. |
| 472 | */ |
| 473 | public abstract String[] getAcceptTypes(); |
| 474 | |
| 475 | /** |
| 476 | * Returns preference for a live media captured value (e.g. Camera, Microphone). |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 477 | * True indicates capture is enabled, {@code false} disabled. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 478 | * |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 479 | * Use <code>getAcceptTypes</code> to determine suitable capture devices. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 480 | */ |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 481 | public abstract boolean isCaptureEnabled(); |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 482 | |
| 483 | /** |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 484 | * Returns the title to use for this file selector. If {@code null} a default title should |
| 485 | * be used. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 486 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 487 | @Nullable |
Selim Gurun | 48f6c45 | 2014-07-18 16:23:46 -0700 | [diff] [blame] | 488 | public abstract CharSequence getTitle(); |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 489 | |
| 490 | /** |
Nate Fischer | 0a6140d | 2017-09-05 12:37:49 -0700 | [diff] [blame] | 491 | * The file name of a default selection if specified, or {@code null}. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 492 | */ |
Nate Fischer | 3442c74 | 2017-09-08 17:02:00 -0700 | [diff] [blame^] | 493 | @Nullable |
Selim Gurun | 17d1adb | 2014-08-27 11:22:26 -0700 | [diff] [blame] | 494 | public abstract String getFilenameHint(); |
Tao Bai | e8df27a | 2014-09-02 14:09:49 -0700 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * Creates an intent that would start a file picker for file selection. |
| 498 | * The Intent supports choosing files from simple file sources available |
| 499 | * on the device. Some advanced sources (for example, live media capture) |
| 500 | * may not be supported and applications wishing to support these sources |
| 501 | * or more advanced file operations should build their own Intent. |
| 502 | * |
| 503 | * <pre> |
| 504 | * How to use: |
| 505 | * 1. Build an intent using {@link #createIntent} |
| 506 | * 2. Fire the intent using {@link android.app.Activity#startActivityForResult}. |
| 507 | * 3. Check for ActivityNotFoundException and take a user friendly action if thrown. |
| 508 | * 4. Listen the result using {@link android.app.Activity#onActivityResult} |
| 509 | * 5. Parse the result using {@link #parseResult} only if media capture was not requested. |
| 510 | * 6. Send the result using filePathCallback of {@link WebChromeClient#onShowFileChooser} |
| 511 | * </pre> |
| 512 | * |
| 513 | * @return an Intent that supports basic file chooser sources. |
| 514 | */ |
| 515 | public abstract Intent createIntent(); |
| 516 | } |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 517 | |
| 518 | /** |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 519 | * Tell the client to open a file chooser. |
| 520 | * @param uploadFile A ValueCallback to set the URI of the file to upload. |
Ben Murdoch | 4ae32f5 | 2010-05-18 14:30:39 +0100 | [diff] [blame] | 521 | * onReceiveValue must be called to wake up the thread.a |
| 522 | * @param acceptType The value of the 'accept' attribute of the input tag |
| 523 | * associated with this file picker. |
Ben Murdoch | be71692 | 2012-01-11 10:55:10 +0000 | [diff] [blame] | 524 | * @param capture The value of the 'capture' attribute of the input tag |
| 525 | * associated with this file picker. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 526 | * |
Nate Fischer | c4f8f89 | 2017-08-30 15:39:32 -0700 | [diff] [blame] | 527 | * @deprecated Use {@link #onShowFileChooser} instead. |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 528 | * @hide This method was not published in any SDK version. |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 529 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 530 | @SystemApi |
Jonathan Dixon | 3a5cf38 | 2013-07-27 15:37:31 -0700 | [diff] [blame] | 531 | @Deprecated |
Ben Murdoch | be71692 | 2012-01-11 10:55:10 +0000 | [diff] [blame] | 532 | public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) { |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 533 | uploadFile.onReceiveValue(null); |
| 534 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | } |