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.net.Uri; 21 import android.os.Message; 22 import android.view.View; 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 /** 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. 52 * @param precomposed True if the url is for a precomposed touch icon. 53 */ 54 public void onReceivedTouchIconUrl(WebView view, String url, 55 boolean precomposed) {} 56 57 /** 58 * A callback interface used by the host application to notify 59 * the current page that its custom view has been dismissed. 60 */ 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 public void onShowCustomView(View view, CustomViewCallback callback) {}; 77 78 /** 79 * Notify the host application that the current page would 80 * like to hide its custom view. 81 */ 82 public void onHideCustomView() {} 83 84 /** 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 } 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. 205 * @param estimatedSize The estimated size of the database. 206 * @param totalUsedQuota is the sum of all origins' quota. 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, 212 long currentQuota, long estimatedSize, long totalUsedQuota, 213 WebStorage.QuotaUpdater quotaUpdater) { 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 } 218 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. 227 */ 228 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, 229 WebStorage.QuotaUpdater quotaUpdater) { 230 quotaUpdater.updateQuota(0); 231 } 232 233 /** 234 * Instructs the client to show a prompt to ask the user to set the 235 * Geolocation permission state for the specified origin. 236 */ 237 public void onGeolocationPermissionsShowPrompt(String origin, 238 GeolocationPermissions.Callback callback) {} 239 240 /** 241 * Instructs the client to hide the Geolocation permissions prompt. 242 */ 243 public void onGeolocationPermissionsHidePrompt() {} 244 245 /** 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. 254 */ 255 public boolean onJsTimeout() { 256 return true; 257 } 258 259 /** 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. 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. 265 * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)} 266 * instead. 267 */ 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 } 283 284 /** 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. 289 * 290 * @return Bitmap The image to use as a default poster, or null if no such image is 291 * available. 292 */ 293 public Bitmap getDefaultVideoPoster() { 294 return null; 295 } 296 297 /** 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. 302 * 303 * @return View The View to be displayed whilst the video is loading. 304 */ 305 public View getVideoLoadingProgressView() { 306 return null; 307 } 308 309 /** Obtains a list of all visited history items, used for link coloring 310 */ 311 public void getVisitedHistory(ValueCallback<String[]> callback) { 312 } 313 314 /** 315 * Tell the client to open a file chooser. 316 * @param uploadFile A ValueCallback to set the URI of the file to upload. 317 * onReceiveValue must be called to wake up the thread. 318 * @hide 319 */ 320 public void openFileChooser(ValueCallback<Uri> uploadFile) { 321 uploadFile.onReceiveValue(null); 322 } 323 } 324