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