WebChromeClient.java revision b2359262b48bf33887c72be94b044cfdfd602858
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 17package android.webkit; 18 19import android.graphics.Bitmap; 20import android.os.Message; 21import android.view.View; 22 23public class WebChromeClient { 24 25 /** 26 * Tell the host application that the WebView has changed viewing modes. 27 * @param view The WebView that initiated the callback. 28 * @param newViewingMode One of the values described in WebView as possible 29 * values for the viewing mode 30 * @hide 31 */ 32 public void onChangeViewingMode(WebView view, int newViewingMode) {} 33 34 /** 35 * Tell the host application the current progress of loading a page. 36 * @param view The WebView that initiated the callback. 37 * @param newProgress Current page loading progress, represented by 38 * an integer between 0 and 100. 39 */ 40 public void onProgressChanged(WebView view, int newProgress) {} 41 42 /** 43 * Notify the host application of a change in the document title. 44 * @param view The WebView that initiated the callback. 45 * @param title A String containing the new title of the document. 46 */ 47 public void onReceivedTitle(WebView view, String title) {} 48 49 /** 50 * Notify the host application of a new favicon for the current page. 51 * @param view The WebView that initiated the callback. 52 * @param icon A Bitmap containing the favicon for the current page. 53 */ 54 public void onReceivedIcon(WebView view, Bitmap icon) {} 55 56 /** 57 * Notify the host application of the url for an apple-touch-icon. 58 * @param view The WebView that initiated the callback. 59 * @param url The icon url. 60 * @hide pending council approval 61 */ 62 public void onReceivedTouchIconUrl(WebView view, String url) {} 63 64 /** 65 * A callback interface used by the host application to notify 66 * the current page that its custom view has been dismissed. 67 * 68 * @hide pending council approval 69 */ 70 public interface CustomViewCallback { 71 /** 72 * Invoked when the host application dismisses the 73 * custom view. 74 */ 75 public void onCustomViewHidden(); 76 } 77 78 /** 79 * Notify the host application that the current page would 80 * like to show a custom View. 81 * @param view is the View object to be shown. 82 * @param callback is the callback to be invoked if and when the view 83 * is dismissed. 84 * 85 * @hide pending council approval 86 */ 87 public void onShowCustomView(View view, CustomViewCallback callback) {}; 88 89 /** 90 * Notify the host application that the current page would 91 * like to hide its custom view. 92 * 93 * @hide pending council approval 94 */ 95 public void onHideCustomView() {} 96 97 /** 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 } 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. 218 * @param totalUsedQuota is the sum of all origins' quota. 219 * @param quotaUpdater A callback to inform the WebCore thread that a new 220 * quota is available. This callback must always be executed at some 221 * point to ensure that the sleeping WebCore thread is woken up. 222 */ 223 public void onExceededDatabaseQuota(String url, String databaseIdentifier, 224 long currentQuota, long totalUsedQuota, 225 WebStorage.QuotaUpdater quotaUpdater) { 226 // This default implementation passes the current quota back to WebCore. 227 // WebCore will interpret this that new quota was declined. 228 quotaUpdater.updateQuota(currentQuota); 229 } 230 231 /** 232 * Tell the client that the Application Cache has exceeded its max size. 233 * @param spaceNeeded is the amount of disk space that would be needed 234 * in order for the last appcache operation to succeed. 235 * @param totalUsedQuota is the sum of all origins' quota. 236 * @param quotaUpdater A callback to inform the WebCore thread that a new 237 * app cache size is available. This callback must always be executed at 238 * some point to ensure that the sleeping WebCore thread is woken up. 239 * @hide pending API council approval. 240 */ 241 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, 242 WebStorage.QuotaUpdater quotaUpdater) { 243 quotaUpdater.updateQuota(0); 244 } 245 246 /** 247 * Instructs the client to show a prompt to ask the user to set the 248 * Geolocation permission state for the specified origin. 249 * @hide pending API council approval. 250 */ 251 public void onGeolocationPermissionsShowPrompt(String origin, 252 GeolocationPermissions.Callback callback) {} 253 254 /** 255 * Instructs the client to hide the Geolocation permissions prompt. 256 * @hide pending API council approval. 257 */ 258 public void onGeolocationPermissionsHidePrompt() {} 259 260 /** 261 * Tell the client that a JavaScript execution timeout has occured. And the 262 * client may decide whether or not to interrupt the execution. If the 263 * client returns true, the JavaScript will be interrupted. If the client 264 * returns false, the execution will continue. Note that in the case of 265 * continuing execution, the timeout counter will be reset, and the callback 266 * will continue to occur if the script does not finish at the next check 267 * point. 268 * @return boolean Whether the JavaScript execution should be interrupted. 269 * @hide pending API Council approval 270 */ 271 public boolean onJsTimeout() { 272 return true; 273 } 274 275 /** 276 * Add a JavaScript error message to the console. Clients should override 277 * this to process the log message as they see fit. 278 * @param message The error message to report. 279 * @param lineNumber The line number of the error. 280 * @param sourceID The name of the source file that caused the error. 281 * @hide pending API council. 282 */ 283 public void addMessageToConsole(String message, int lineNumber, String sourceID) {} 284} 285