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 | |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame^] | 19 | import android.content.pm.ActivityInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.graphics.Bitmap; |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 21 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.os.Message; |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 23 | import android.view.View; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | public class WebChromeClient { |
| 26 | |
| 27 | /** |
| 28 | * Tell the host application the current progress of loading a page. |
| 29 | * @param view The WebView that initiated the callback. |
| 30 | * @param newProgress Current page loading progress, represented by |
| 31 | * an integer between 0 and 100. |
| 32 | */ |
| 33 | public void onProgressChanged(WebView view, int newProgress) {} |
| 34 | |
| 35 | /** |
| 36 | * Notify the host application of a change in the document title. |
| 37 | * @param view The WebView that initiated the callback. |
| 38 | * @param title A String containing the new title of the document. |
| 39 | */ |
| 40 | public void onReceivedTitle(WebView view, String title) {} |
| 41 | |
| 42 | /** |
| 43 | * Notify the host application of a new favicon for the current page. |
| 44 | * @param view The WebView that initiated the callback. |
| 45 | * @param icon A Bitmap containing the favicon for the current page. |
| 46 | */ |
| 47 | public void onReceivedIcon(WebView view, Bitmap icon) {} |
| 48 | |
| 49 | /** |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 50 | * Notify the host application of the url for an apple-touch-icon. |
| 51 | * @param view The WebView that initiated the callback. |
| 52 | * @param url The icon url. |
Patrick Scott | d58ccff | 2009-09-18 16:29:00 -0400 | [diff] [blame] | 53 | * @param precomposed True if the url is for a precomposed touch icon. |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 54 | */ |
Patrick Scott | d58ccff | 2009-09-18 16:29:00 -0400 | [diff] [blame] | 55 | public void onReceivedTouchIconUrl(WebView view, String url, |
| 56 | boolean precomposed) {} |
Patrick Scott | 2ba1262 | 2009-08-04 13:20:05 -0400 | [diff] [blame] | 57 | |
| 58 | /** |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 59 | * A callback interface used by the host application to notify |
| 60 | * the current page that its custom view has been dismissed. |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 61 | */ |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 62 | public interface CustomViewCallback { |
| 63 | /** |
| 64 | * Invoked when the host application dismisses the |
| 65 | * custom view. |
| 66 | */ |
| 67 | public void onCustomViewHidden(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Notify the host application that the current page would |
| 72 | * like to show a custom View. |
| 73 | * @param view is the View object to be shown. |
| 74 | * @param callback is the callback to be invoked if and when the view |
| 75 | * is dismissed. |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame] | 76 | */ |
| 77 | public void onShowCustomView(View view, CustomViewCallback callback) {}; |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Notify the host application that the current page would |
Derek Sollenberger | 7ab3d67 | 2011-06-01 14:45:05 -0400 | [diff] [blame^] | 81 | * like to show a custom View in a particular orientation. |
| 82 | * @param view is the View object to be shown. |
| 83 | * @param requestedOrientation An orientation constant as used in |
| 84 | * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}. |
| 85 | * @param callback is the callback to be invoked if and when the view |
| 86 | * is dismissed. |
| 87 | */ |
| 88 | public void onShowCustomView(View view, int requestedOrientation, |
| 89 | CustomViewCallback callback) {}; |
| 90 | |
| 91 | /** |
| 92 | * Notify the host application that the current page would |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 93 | * like to hide its custom view. |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 94 | */ |
| 95 | public void onHideCustomView() {} |
| 96 | |
| 97 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | * Request the host application to create a new Webview. The host |
| 99 | * application should handle placement of the new WebView in the view |
| 100 | * system. The default behavior returns null. |
| 101 | * @param view The WebView that initiated the callback. |
| 102 | * @param dialog True if the new window is meant to be a small dialog |
| 103 | * window. |
| 104 | * @param userGesture True if the request was initiated by a user gesture |
| 105 | * such as clicking a link. |
| 106 | * @param resultMsg The message to send when done creating a new WebView. |
| 107 | * Set the new WebView through resultMsg.obj which is |
| 108 | * WebView.WebViewTransport() and then call |
| 109 | * resultMsg.sendToTarget(); |
| 110 | * @return Similar to javscript dialogs, this method should return true if |
| 111 | * the client is going to handle creating a new WebView. Note that |
| 112 | * the WebView will halt processing if this method returns true so |
| 113 | * make sure to call resultMsg.sendToTarget(). It is undefined |
| 114 | * behavior to call resultMsg.sendToTarget() after returning false |
| 115 | * from this method. |
| 116 | */ |
| 117 | public boolean onCreateWindow(WebView view, boolean dialog, |
| 118 | boolean userGesture, Message resultMsg) { |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Request display and focus for this WebView. This may happen due to |
| 124 | * another WebView opening a link in this WebView and requesting that this |
| 125 | * WebView be displayed. |
| 126 | * @param view The WebView that needs to be focused. |
| 127 | */ |
| 128 | public void onRequestFocus(WebView view) {} |
| 129 | |
| 130 | /** |
| 131 | * Notify the host application to close the given WebView and remove it |
| 132 | * from the view system if necessary. At this point, WebCore has stopped |
| 133 | * any loading in this window and has removed any cross-scripting ability |
| 134 | * in javascript. |
| 135 | * @param window The WebView that needs to be closed. |
| 136 | */ |
| 137 | public void onCloseWindow(WebView window) {} |
| 138 | |
| 139 | /** |
| 140 | * Tell the client to display a javascript alert dialog. If the client |
| 141 | * returns true, WebView will assume that the client will handle the |
| 142 | * dialog. If the client returns false, it will continue execution. |
| 143 | * @param view The WebView that initiated the callback. |
| 144 | * @param url The url of the page requesting the dialog. |
| 145 | * @param message Message to be displayed in the window. |
| 146 | * @param result A JsResult to confirm that the user hit enter. |
| 147 | * @return boolean Whether the client will handle the alert dialog. |
| 148 | */ |
| 149 | public boolean onJsAlert(WebView view, String url, String message, |
| 150 | JsResult result) { |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Tell the client to display a confirm dialog to the user. If the client |
| 156 | * returns true, WebView will assume that the client will handle the |
| 157 | * confirm dialog and call the appropriate JsResult method. If the |
| 158 | * client returns false, a default value of false will be returned to |
| 159 | * javascript. The default behavior is to return false. |
| 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 used to send the user's response to |
| 164 | * javascript. |
| 165 | * @return boolean Whether the client will handle the confirm dialog. |
| 166 | */ |
| 167 | public boolean onJsConfirm(WebView view, String url, String message, |
| 168 | JsResult result) { |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Tell the client to display a prompt dialog to the user. If the client |
| 174 | * returns true, WebView will assume that the client will handle the |
| 175 | * prompt dialog and call the appropriate JsPromptResult method. If the |
| 176 | * client returns false, a default value of false will be returned to to |
| 177 | * javascript. The default behavior is to return false. |
| 178 | * @param view The WebView that initiated the callback. |
| 179 | * @param url The url of the page requesting the dialog. |
| 180 | * @param message Message to be displayed in the window. |
| 181 | * @param defaultValue The default value displayed in the prompt dialog. |
| 182 | * @param result A JsPromptResult used to send the user's reponse to |
| 183 | * javascript. |
| 184 | * @return boolean Whether the client will handle the prompt dialog. |
| 185 | */ |
| 186 | public boolean onJsPrompt(WebView view, String url, String message, |
| 187 | String defaultValue, JsPromptResult result) { |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Tell the client to display a dialog to confirm navigation away from the |
| 193 | * current page. This is the result of the onbeforeunload javascript event. |
| 194 | * If the client returns true, WebView will assume that the client will |
| 195 | * handle the confirm dialog and call the appropriate JsResult method. If |
| 196 | * the client returns false, a default value of true will be returned to |
| 197 | * javascript to accept navigation away from the current page. The default |
| 198 | * behavior is to return false. Setting the JsResult to true will navigate |
| 199 | * away from the current page, false will cancel the navigation. |
| 200 | * @param view The WebView that initiated the callback. |
| 201 | * @param url The url of the page requesting the dialog. |
| 202 | * @param message Message to be displayed in the window. |
| 203 | * @param result A JsResult used to send the user's response to |
| 204 | * javascript. |
| 205 | * @return boolean Whether the client will handle the confirm dialog. |
| 206 | */ |
| 207 | public boolean onJsBeforeUnload(WebView view, String url, String message, |
| 208 | JsResult result) { |
| 209 | return false; |
| 210 | } |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * Tell the client that the database quota for the origin has been exceeded. |
| 214 | * @param url The URL that triggered the notification |
| 215 | * @param databaseIdentifier The identifier of the database that caused the |
| 216 | * quota overflow. |
| 217 | * @param currentQuota The current quota for the origin. |
Ben Murdoch | d497d87 | 2009-08-25 19:32:54 +0100 | [diff] [blame] | 218 | * @param estimatedSize The estimated size of the database. |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 219 | * @param totalUsedQuota is the sum of all origins' quota. |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 220 | * @param quotaUpdater A callback to inform the WebCore thread that a new |
| 221 | * quota is available. This callback must always be executed at some |
| 222 | * point to ensure that the sleeping WebCore thread is woken up. |
| 223 | */ |
| 224 | public void onExceededDatabaseQuota(String url, String databaseIdentifier, |
Ben Murdoch | d497d87 | 2009-08-25 19:32:54 +0100 | [diff] [blame] | 225 | long currentQuota, long estimatedSize, long totalUsedQuota, |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 226 | WebStorage.QuotaUpdater quotaUpdater) { |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 227 | // This default implementation passes the current quota back to WebCore. |
| 228 | // WebCore will interpret this that new quota was declined. |
| 229 | quotaUpdater.updateQuota(currentQuota); |
| 230 | } |
Guang Zhu | 10e4d20 | 2009-05-11 18:09:51 -0700 | [diff] [blame] | 231 | |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 232 | /** |
| 233 | * Tell the client that the Application Cache has exceeded its max size. |
| 234 | * @param spaceNeeded is the amount of disk space that would be needed |
| 235 | * in order for the last appcache operation to succeed. |
| 236 | * @param totalUsedQuota is the sum of all origins' quota. |
| 237 | * @param quotaUpdater A callback to inform the WebCore thread that a new |
| 238 | * app cache size is available. This callback must always be executed at |
| 239 | * some point to ensure that the sleeping WebCore thread is woken up. |
Andrei Popescu | 59e2ad9 | 2009-07-28 13:38:06 +0100 | [diff] [blame] | 240 | */ |
| 241 | public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, |
| 242 | WebStorage.QuotaUpdater quotaUpdater) { |
| 243 | quotaUpdater.updateQuota(0); |
| 244 | } |
| 245 | |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 246 | /** |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 247 | * Instructs the client to show a prompt to ask the user to set the |
| 248 | * Geolocation permission state for the specified origin. |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 249 | */ |
| 250 | public void onGeolocationPermissionsShowPrompt(String origin, |
| 251 | GeolocationPermissions.Callback callback) {} |
| 252 | |
| 253 | /** |
| 254 | * Instructs the client to hide the Geolocation permissions prompt. |
Steve Block | 4faee09 | 2009-07-28 18:20:50 +0100 | [diff] [blame] | 255 | */ |
| 256 | public void onGeolocationPermissionsHidePrompt() {} |
| 257 | |
| 258 | /** |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 259 | * Tell the client that a JavaScript execution timeout has occured. And the |
| 260 | * client may decide whether or not to interrupt the execution. If the |
| 261 | * client returns true, the JavaScript will be interrupted. If the client |
| 262 | * returns false, the execution will continue. Note that in the case of |
| 263 | * continuing execution, the timeout counter will be reset, and the callback |
| 264 | * will continue to occur if the script does not finish at the next check |
| 265 | * point. |
| 266 | * @return boolean Whether the JavaScript execution should be interrupted. |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 267 | */ |
| 268 | public boolean onJsTimeout() { |
| 269 | return true; |
| 270 | } |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 271 | |
| 272 | /** |
Ben Murdoch | 7caaeec | 2009-11-19 18:14:53 +0000 | [diff] [blame] | 273 | * Report a JavaScript error message to the host application. The ChromeClient |
| 274 | * should override this to process the log message as they see fit. |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 275 | * @param message The error message to report. |
| 276 | * @param lineNumber The line number of the error. |
| 277 | * @param sourceID The name of the source file that caused the error. |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 278 | * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)} |
| 279 | * instead. |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 280 | */ |
Ben Murdoch | 3141e0a | 2010-01-28 15:06:32 +0000 | [diff] [blame] | 281 | @Deprecated |
| 282 | public void onConsoleMessage(String message, int lineNumber, String sourceID) { } |
| 283 | |
| 284 | /** |
| 285 | * Report a JavaScript console message to the host application. The ChromeClient |
| 286 | * should override this to process the log message as they see fit. |
| 287 | * @param consoleMessage Object containing details of the console message. |
| 288 | * @return true if the message is handled by the client. |
| 289 | */ |
| 290 | public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
| 291 | // Call the old version of this function for backwards compatability. |
| 292 | onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(), |
| 293 | consoleMessage.sourceId()); |
| 294 | return false; |
| 295 | } |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 296 | |
| 297 | /** |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 298 | * When not playing, video elements are represented by a 'poster' image. The |
| 299 | * image to use can be specified by the poster attribute of the video tag in |
| 300 | * HTML. If the attribute is absent, then a default poster will be used. This |
| 301 | * method allows the ChromeClient to provide that default image. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 302 | * |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 303 | * @return Bitmap The image to use as a default poster, or null if no such image is |
| 304 | * available. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 305 | */ |
| 306 | public Bitmap getDefaultVideoPoster() { |
| 307 | return null; |
| 308 | } |
| 309 | |
| 310 | /** |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 311 | * When the user starts to playback a video element, it may take time for enough |
| 312 | * data to be buffered before the first frames can be rendered. While this buffering |
| 313 | * is taking place, the ChromeClient can use this function to provide a View to be |
| 314 | * displayed. For example, the ChromeClient could show a spinner animation. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 315 | * |
Ben Murdoch | f0c443d | 2009-11-19 16:43:58 +0000 | [diff] [blame] | 316 | * @return View The View to be displayed whilst the video is loading. |
Andrei Popescu | bf385d7 | 2009-09-18 18:59:52 +0100 | [diff] [blame] | 317 | */ |
| 318 | public View getVideoLoadingProgressView() { |
| 319 | return null; |
| 320 | } |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 321 | |
| 322 | /** Obtains a list of all visited history items, used for link coloring |
Leon Clarke | 194e345 | 2009-09-28 11:42:12 +0100 | [diff] [blame] | 323 | */ |
| 324 | public void getVisitedHistory(ValueCallback<String[]> callback) { |
| 325 | } |
| 326 | |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 327 | /** |
| 328 | * Tell the client to open a file chooser. |
| 329 | * @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] | 330 | * onReceiveValue must be called to wake up the thread.a |
| 331 | * @param acceptType The value of the 'accept' attribute of the input tag |
| 332 | * associated with this file picker. |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 333 | * @hide |
| 334 | */ |
Ben Murdoch | 4ae32f5 | 2010-05-18 14:30:39 +0100 | [diff] [blame] | 335 | public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) { |
Leon Scroggins | 70ca3c2 | 2009-10-02 15:58:55 -0400 | [diff] [blame] | 336 | uploadFile.onReceiveValue(null); |
| 337 | } |
Cary Clark | 924af70 | 2010-06-04 16:37:43 -0400 | [diff] [blame] | 338 | |
| 339 | /** |
Ben Murdoch | 6312de2 | 2010-06-29 19:20:11 +0100 | [diff] [blame] | 340 | * Tell the client that the page being viewed is web app capable, |
| 341 | * i.e. has specified the fullscreen-web-app-capable meta tag. |
| 342 | * @hide |
| 343 | */ |
| 344 | public void setInstallableWebApp() { } |
| 345 | |
Ben Murdoch | 5791438 | 2010-11-16 11:50:39 +0000 | [diff] [blame] | 346 | /** |
| 347 | * Tell the client that the page being viewed has an autofillable |
| 348 | * form and the user would like to set a profile up. |
| 349 | * @param msg A Message to send once the user has successfully |
| 350 | * set up a profile and to inform the WebTextView it should |
| 351 | * now autofill using that new profile. |
| 352 | * @hide |
| 353 | */ |
| 354 | public void setupAutoFill(Message msg) { } |
| 355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | } |