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 | /** |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame^] | 48 | * A callback interface used by the host application to notify |
| 49 | * the current page that its custom view has been dismissed. |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 50 | * |
| 51 | * @hide pending council approval |
| 52 | */ |
Andrei Popescu | 3c946a1a | 2009-07-03 08:20:53 +0100 | [diff] [blame^] | 53 | public interface CustomViewCallback { |
| 54 | /** |
| 55 | * Invoked when the host application dismisses the |
| 56 | * custom view. |
| 57 | */ |
| 58 | public void onCustomViewHidden(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Notify the host application that the current page would |
| 63 | * like to show a custom View. |
| 64 | * @param view is the View object to be shown. |
| 65 | * @param callback is the callback to be invoked if and when the view |
| 66 | * is dismissed. |
| 67 | * |
| 68 | * @hide pending council approval |
| 69 | */ |
| 70 | public void onShowCustomView(View view, CustomViewCallback callback) {}; |
Andrei Popescu | 6fa2958 | 2009-06-19 14:54:09 +0100 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Notify the host application that the current page would |
| 74 | * like to hide its custom view. |
| 75 | * |
| 76 | * @hide pending council approval |
| 77 | */ |
| 78 | public void onHideCustomView() {} |
| 79 | |
| 80 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | * Request the host application to create a new Webview. The host |
| 82 | * application should handle placement of the new WebView in the view |
| 83 | * system. The default behavior returns null. |
| 84 | * @param view The WebView that initiated the callback. |
| 85 | * @param dialog True if the new window is meant to be a small dialog |
| 86 | * window. |
| 87 | * @param userGesture True if the request was initiated by a user gesture |
| 88 | * such as clicking a link. |
| 89 | * @param resultMsg The message to send when done creating a new WebView. |
| 90 | * Set the new WebView through resultMsg.obj which is |
| 91 | * WebView.WebViewTransport() and then call |
| 92 | * resultMsg.sendToTarget(); |
| 93 | * @return Similar to javscript dialogs, this method should return true if |
| 94 | * the client is going to handle creating a new WebView. Note that |
| 95 | * the WebView will halt processing if this method returns true so |
| 96 | * make sure to call resultMsg.sendToTarget(). It is undefined |
| 97 | * behavior to call resultMsg.sendToTarget() after returning false |
| 98 | * from this method. |
| 99 | */ |
| 100 | public boolean onCreateWindow(WebView view, boolean dialog, |
| 101 | boolean userGesture, Message resultMsg) { |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Request display and focus for this WebView. This may happen due to |
| 107 | * another WebView opening a link in this WebView and requesting that this |
| 108 | * WebView be displayed. |
| 109 | * @param view The WebView that needs to be focused. |
| 110 | */ |
| 111 | public void onRequestFocus(WebView view) {} |
| 112 | |
| 113 | /** |
| 114 | * Notify the host application to close the given WebView and remove it |
| 115 | * from the view system if necessary. At this point, WebCore has stopped |
| 116 | * any loading in this window and has removed any cross-scripting ability |
| 117 | * in javascript. |
| 118 | * @param window The WebView that needs to be closed. |
| 119 | */ |
| 120 | public void onCloseWindow(WebView window) {} |
| 121 | |
| 122 | /** |
| 123 | * Tell the client to display a javascript alert dialog. If the client |
| 124 | * returns true, WebView will assume that the client will handle the |
| 125 | * dialog. If the client returns false, it will continue execution. |
| 126 | * @param view The WebView that initiated the callback. |
| 127 | * @param url The url of the page requesting the dialog. |
| 128 | * @param message Message to be displayed in the window. |
| 129 | * @param result A JsResult to confirm that the user hit enter. |
| 130 | * @return boolean Whether the client will handle the alert dialog. |
| 131 | */ |
| 132 | public boolean onJsAlert(WebView view, String url, String message, |
| 133 | JsResult result) { |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Tell the client to display a confirm dialog to the user. If the client |
| 139 | * returns true, WebView will assume that the client will handle the |
| 140 | * confirm dialog and call the appropriate JsResult method. If the |
| 141 | * client returns false, a default value of false will be returned to |
| 142 | * javascript. The default behavior is to return false. |
| 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 used to send the user's response to |
| 147 | * javascript. |
| 148 | * @return boolean Whether the client will handle the confirm dialog. |
| 149 | */ |
| 150 | public boolean onJsConfirm(WebView view, String url, String message, |
| 151 | JsResult result) { |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Tell the client to display a prompt dialog to the user. If the client |
| 157 | * returns true, WebView will assume that the client will handle the |
| 158 | * prompt dialog and call the appropriate JsPromptResult method. If the |
| 159 | * client returns false, a default value of false will be returned to to |
| 160 | * javascript. The default behavior is to return false. |
| 161 | * @param view The WebView that initiated the callback. |
| 162 | * @param url The url of the page requesting the dialog. |
| 163 | * @param message Message to be displayed in the window. |
| 164 | * @param defaultValue The default value displayed in the prompt dialog. |
| 165 | * @param result A JsPromptResult used to send the user's reponse to |
| 166 | * javascript. |
| 167 | * @return boolean Whether the client will handle the prompt dialog. |
| 168 | */ |
| 169 | public boolean onJsPrompt(WebView view, String url, String message, |
| 170 | String defaultValue, JsPromptResult result) { |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Tell the client to display a dialog to confirm navigation away from the |
| 176 | * current page. This is the result of the onbeforeunload javascript event. |
| 177 | * If the client returns true, WebView will assume that the client will |
| 178 | * handle the confirm dialog and call the appropriate JsResult method. If |
| 179 | * the client returns false, a default value of true will be returned to |
| 180 | * javascript to accept navigation away from the current page. The default |
| 181 | * behavior is to return false. Setting the JsResult to true will navigate |
| 182 | * away from the current page, false will cancel the navigation. |
| 183 | * @param view The WebView that initiated the callback. |
| 184 | * @param url The url of the page requesting the dialog. |
| 185 | * @param message Message to be displayed in the window. |
| 186 | * @param result A JsResult used to send the user's response to |
| 187 | * javascript. |
| 188 | * @return boolean Whether the client will handle the confirm dialog. |
| 189 | */ |
| 190 | public boolean onJsBeforeUnload(WebView view, String url, String message, |
| 191 | JsResult result) { |
| 192 | return false; |
| 193 | } |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Tell the client that the database quota for the origin has been exceeded. |
| 197 | * @param url The URL that triggered the notification |
| 198 | * @param databaseIdentifier The identifier of the database that caused the |
| 199 | * quota overflow. |
| 200 | * @param currentQuota The current quota for the origin. |
| 201 | * @param quotaUpdater A callback to inform the WebCore thread that a new |
| 202 | * quota is available. This callback must always be executed at some |
| 203 | * point to ensure that the sleeping WebCore thread is woken up. |
| 204 | */ |
| 205 | public void onExceededDatabaseQuota(String url, String databaseIdentifier, |
| 206 | long currentQuota, WebStorage.QuotaUpdater quotaUpdater) { |
| 207 | // This default implementation passes the current quota back to WebCore. |
| 208 | // WebCore will interpret this that new quota was declined. |
| 209 | quotaUpdater.updateQuota(currentQuota); |
| 210 | } |
Guang Zhu | 10e4d20 | 2009-05-11 18:09:51 -0700 | [diff] [blame] | 211 | |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 212 | /** |
| 213 | * Tell the client that a JavaScript execution timeout has occured. And the |
| 214 | * client may decide whether or not to interrupt the execution. If the |
| 215 | * client returns true, the JavaScript will be interrupted. If the client |
| 216 | * returns false, the execution will continue. Note that in the case of |
| 217 | * continuing execution, the timeout counter will be reset, and the callback |
| 218 | * will continue to occur if the script does not finish at the next check |
| 219 | * point. |
| 220 | * @return boolean Whether the JavaScript execution should be interrupted. |
| 221 | * @hide pending API Council approval |
| 222 | */ |
| 223 | public boolean onJsTimeout() { |
| 224 | return true; |
| 225 | } |
Ben Murdoch | 6262ae5 | 2009-04-17 13:21:53 +0100 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Add a JavaScript error message to the console. Clients should override |
| 229 | * this to process the log message as they see fit. |
| 230 | * @param message The error message to report. |
| 231 | * @param lineNumber The line number of the error. |
| 232 | * @param sourceID The name of the source file that caused the error. |
| 233 | * @hide pending API council. |
| 234 | */ |
| 235 | public void addMessageToConsole(String message, int lineNumber, String sourceID) { |
| 236 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |