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