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