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