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