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; |
| 21 | |
| 22 | public class WebChromeClient { |
| 23 | |
| 24 | /** |
| 25 | * Tell the host application the current progress of loading a page. |
| 26 | * @param view The WebView that initiated the callback. |
| 27 | * @param newProgress Current page loading progress, represented by |
| 28 | * an integer between 0 and 100. |
| 29 | */ |
| 30 | public void onProgressChanged(WebView view, int newProgress) {} |
| 31 | |
| 32 | /** |
| 33 | * Notify the host application of a change in the document title. |
| 34 | * @param view The WebView that initiated the callback. |
| 35 | * @param title A String containing the new title of the document. |
| 36 | */ |
| 37 | public void onReceivedTitle(WebView view, String title) {} |
| 38 | |
| 39 | /** |
| 40 | * Notify the host application of a new favicon for the current page. |
| 41 | * @param view The WebView that initiated the callback. |
| 42 | * @param icon A Bitmap containing the favicon for the current page. |
| 43 | */ |
| 44 | public void onReceivedIcon(WebView view, Bitmap icon) {} |
| 45 | |
| 46 | /** |
| 47 | * Request the host application to create a new Webview. The host |
| 48 | * application should handle placement of the new WebView in the view |
| 49 | * system. The default behavior returns null. |
| 50 | * @param view The WebView that initiated the callback. |
| 51 | * @param dialog True if the new window is meant to be a small dialog |
| 52 | * window. |
| 53 | * @param userGesture True if the request was initiated by a user gesture |
| 54 | * such as clicking a link. |
| 55 | * @param resultMsg The message to send when done creating a new WebView. |
| 56 | * Set the new WebView through resultMsg.obj which is |
| 57 | * WebView.WebViewTransport() and then call |
| 58 | * resultMsg.sendToTarget(); |
| 59 | * @return Similar to javscript dialogs, this method should return true if |
| 60 | * the client is going to handle creating a new WebView. Note that |
| 61 | * the WebView will halt processing if this method returns true so |
| 62 | * make sure to call resultMsg.sendToTarget(). It is undefined |
| 63 | * behavior to call resultMsg.sendToTarget() after returning false |
| 64 | * from this method. |
| 65 | */ |
| 66 | public boolean onCreateWindow(WebView view, boolean dialog, |
| 67 | boolean userGesture, Message resultMsg) { |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Request display and focus for this WebView. This may happen due to |
| 73 | * another WebView opening a link in this WebView and requesting that this |
| 74 | * WebView be displayed. |
| 75 | * @param view The WebView that needs to be focused. |
| 76 | */ |
| 77 | public void onRequestFocus(WebView view) {} |
| 78 | |
| 79 | /** |
| 80 | * Notify the host application to close the given WebView and remove it |
| 81 | * from the view system if necessary. At this point, WebCore has stopped |
| 82 | * any loading in this window and has removed any cross-scripting ability |
| 83 | * in javascript. |
| 84 | * @param window The WebView that needs to be closed. |
| 85 | */ |
| 86 | public void onCloseWindow(WebView window) {} |
| 87 | |
| 88 | /** |
| 89 | * Tell the client to display a javascript alert dialog. If the client |
| 90 | * returns true, WebView will assume that the client will handle the |
| 91 | * dialog. If the client returns false, it will continue execution. |
| 92 | * @param view The WebView that initiated the callback. |
| 93 | * @param url The url of the page requesting the dialog. |
| 94 | * @param message Message to be displayed in the window. |
| 95 | * @param result A JsResult to confirm that the user hit enter. |
| 96 | * @return boolean Whether the client will handle the alert dialog. |
| 97 | */ |
| 98 | public boolean onJsAlert(WebView view, String url, String message, |
| 99 | JsResult result) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Tell the client to display a confirm dialog to the user. If the client |
| 105 | * returns true, WebView will assume that the client will handle the |
| 106 | * confirm dialog and call the appropriate JsResult method. If the |
| 107 | * client returns false, a default value of false will be returned to |
| 108 | * javascript. The default behavior is to return false. |
| 109 | * @param view The WebView that initiated the callback. |
| 110 | * @param url The url of the page requesting the dialog. |
| 111 | * @param message Message to be displayed in the window. |
| 112 | * @param result A JsResult used to send the user's response to |
| 113 | * javascript. |
| 114 | * @return boolean Whether the client will handle the confirm dialog. |
| 115 | */ |
| 116 | public boolean onJsConfirm(WebView view, String url, String message, |
| 117 | JsResult result) { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Tell the client to display a prompt dialog to the user. If the client |
| 123 | * returns true, WebView will assume that the client will handle the |
| 124 | * prompt dialog and call the appropriate JsPromptResult method. If the |
| 125 | * client returns false, a default value of false will be returned to to |
| 126 | * javascript. The default behavior is to return false. |
| 127 | * @param view The WebView that initiated the callback. |
| 128 | * @param url The url of the page requesting the dialog. |
| 129 | * @param message Message to be displayed in the window. |
| 130 | * @param defaultValue The default value displayed in the prompt dialog. |
| 131 | * @param result A JsPromptResult used to send the user's reponse to |
| 132 | * javascript. |
| 133 | * @return boolean Whether the client will handle the prompt dialog. |
| 134 | */ |
| 135 | public boolean onJsPrompt(WebView view, String url, String message, |
| 136 | String defaultValue, JsPromptResult result) { |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Tell the client to display a dialog to confirm navigation away from the |
| 142 | * current page. This is the result of the onbeforeunload javascript event. |
| 143 | * If the client returns true, WebView will assume that the client will |
| 144 | * handle the confirm dialog and call the appropriate JsResult method. If |
| 145 | * the client returns false, a default value of true will be returned to |
| 146 | * javascript to accept navigation away from the current page. The default |
| 147 | * behavior is to return false. Setting the JsResult to true will navigate |
| 148 | * away from the current page, false will cancel the navigation. |
| 149 | * @param view The WebView that initiated the callback. |
| 150 | * @param url The url of the page requesting the dialog. |
| 151 | * @param message Message to be displayed in the window. |
| 152 | * @param result A JsResult used to send the user's response to |
| 153 | * javascript. |
| 154 | * @return boolean Whether the client will handle the confirm dialog. |
| 155 | */ |
| 156 | public boolean onJsBeforeUnload(WebView view, String url, String message, |
| 157 | JsResult result) { |
| 158 | return false; |
| 159 | } |
Ben Murdoch | 7df1985 | 2009-04-22 13:07:58 +0100 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * Tell the client that the database quota for the origin has been exceeded. |
| 163 | * @param url The URL that triggered the notification |
| 164 | * @param databaseIdentifier The identifier of the database that caused the |
| 165 | * quota overflow. |
| 166 | * @param currentQuota The current quota for the origin. |
| 167 | * @param quotaUpdater A callback to inform the WebCore thread that a new |
| 168 | * quota is available. This callback must always be executed at some |
| 169 | * point to ensure that the sleeping WebCore thread is woken up. |
| 170 | */ |
| 171 | public void onExceededDatabaseQuota(String url, String databaseIdentifier, |
| 172 | long currentQuota, WebStorage.QuotaUpdater quotaUpdater) { |
| 173 | // This default implementation passes the current quota back to WebCore. |
| 174 | // WebCore will interpret this that new quota was declined. |
| 175 | quotaUpdater.updateQuota(currentQuota); |
| 176 | } |
Guang Zhu | 10e4d20 | 2009-05-11 18:09:51 -0700 | [diff] [blame^] | 177 | |
Guang Zhu | 81e4143 | 2009-05-08 16:09:55 -0700 | [diff] [blame] | 178 | /** |
| 179 | * Tell the client that a JavaScript execution timeout has occured. And the |
| 180 | * client may decide whether or not to interrupt the execution. If the |
| 181 | * client returns true, the JavaScript will be interrupted. If the client |
| 182 | * returns false, the execution will continue. Note that in the case of |
| 183 | * continuing execution, the timeout counter will be reset, and the callback |
| 184 | * will continue to occur if the script does not finish at the next check |
| 185 | * point. |
| 186 | * @return boolean Whether the JavaScript execution should be interrupted. |
| 187 | * @hide pending API Council approval |
| 188 | */ |
| 189 | public boolean onJsTimeout() { |
| 190 | return true; |
| 191 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | } |