blob: 1ae1d85a19c570b49a06cec5b5d32ed01f8d09c7 [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 /**
Patrick Scott2ba12622009-08-04 13:20:05 -040048 * 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.
Patrick Scottd58ccff2009-09-18 16:29:00 -040051 * @param precomposed True if the url is for a precomposed touch icon.
Patrick Scott2ba12622009-08-04 13:20:05 -040052 * @hide pending council approval
53 */
Patrick Scottd58ccff2009-09-18 16:29:00 -040054 public void onReceivedTouchIconUrl(WebView view, String url,
55 boolean precomposed) {}
Patrick Scott2ba12622009-08-04 13:20:05 -040056
57 /**
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010058 * A callback interface used by the host application to notify
59 * the current page that its custom view has been dismissed.
Andrei Popescu6fa29582009-06-19 14:54:09 +010060 *
61 * @hide pending council approval
62 */
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010063 public interface CustomViewCallback {
64 /**
65 * Invoked when the host application dismisses the
66 * custom view.
67 */
68 public void onCustomViewHidden();
69 }
70
71 /**
72 * Notify the host application that the current page would
73 * like to show a custom View.
74 * @param view is the View object to be shown.
75 * @param callback is the callback to be invoked if and when the view
76 * is dismissed.
77 *
78 * @hide pending council approval
79 */
80 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010081
82 /**
83 * Notify the host application that the current page would
84 * like to hide its custom view.
85 *
86 * @hide pending council approval
87 */
88 public void onHideCustomView() {}
89
90 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 * Request the host application to create a new Webview. The host
92 * application should handle placement of the new WebView in the view
93 * system. The default behavior returns null.
94 * @param view The WebView that initiated the callback.
95 * @param dialog True if the new window is meant to be a small dialog
96 * window.
97 * @param userGesture True if the request was initiated by a user gesture
98 * such as clicking a link.
99 * @param resultMsg The message to send when done creating a new WebView.
100 * Set the new WebView through resultMsg.obj which is
101 * WebView.WebViewTransport() and then call
102 * resultMsg.sendToTarget();
103 * @return Similar to javscript dialogs, this method should return true if
104 * the client is going to handle creating a new WebView. Note that
105 * the WebView will halt processing if this method returns true so
106 * make sure to call resultMsg.sendToTarget(). It is undefined
107 * behavior to call resultMsg.sendToTarget() after returning false
108 * from this method.
109 */
110 public boolean onCreateWindow(WebView view, boolean dialog,
111 boolean userGesture, Message resultMsg) {
112 return false;
113 }
114
115 /**
116 * Request display and focus for this WebView. This may happen due to
117 * another WebView opening a link in this WebView and requesting that this
118 * WebView be displayed.
119 * @param view The WebView that needs to be focused.
120 */
121 public void onRequestFocus(WebView view) {}
122
123 /**
124 * Notify the host application to close the given WebView and remove it
125 * from the view system if necessary. At this point, WebCore has stopped
126 * any loading in this window and has removed any cross-scripting ability
127 * in javascript.
128 * @param window The WebView that needs to be closed.
129 */
130 public void onCloseWindow(WebView window) {}
131
132 /**
133 * Tell the client to display a javascript alert dialog. If the client
134 * returns true, WebView will assume that the client will handle the
135 * dialog. If the client returns false, it will continue execution.
136 * @param view The WebView that initiated the callback.
137 * @param url The url of the page requesting the dialog.
138 * @param message Message to be displayed in the window.
139 * @param result A JsResult to confirm that the user hit enter.
140 * @return boolean Whether the client will handle the alert dialog.
141 */
142 public boolean onJsAlert(WebView view, String url, String message,
143 JsResult result) {
144 return false;
145 }
146
147 /**
148 * Tell the client to display a confirm dialog to the user. If the client
149 * returns true, WebView will assume that the client will handle the
150 * confirm dialog and call the appropriate JsResult method. If the
151 * client returns false, a default value of false will be returned to
152 * javascript. The default behavior is to return false.
153 * @param view The WebView that initiated the callback.
154 * @param url The url of the page requesting the dialog.
155 * @param message Message to be displayed in the window.
156 * @param result A JsResult used to send the user's response to
157 * javascript.
158 * @return boolean Whether the client will handle the confirm dialog.
159 */
160 public boolean onJsConfirm(WebView view, String url, String message,
161 JsResult result) {
162 return false;
163 }
164
165 /**
166 * Tell the client to display a prompt dialog to the user. If the client
167 * returns true, WebView will assume that the client will handle the
168 * prompt dialog and call the appropriate JsPromptResult method. If the
169 * client returns false, a default value of false will be returned to to
170 * javascript. The default behavior is to return false.
171 * @param view The WebView that initiated the callback.
172 * @param url The url of the page requesting the dialog.
173 * @param message Message to be displayed in the window.
174 * @param defaultValue The default value displayed in the prompt dialog.
175 * @param result A JsPromptResult used to send the user's reponse to
176 * javascript.
177 * @return boolean Whether the client will handle the prompt dialog.
178 */
179 public boolean onJsPrompt(WebView view, String url, String message,
180 String defaultValue, JsPromptResult result) {
181 return false;
182 }
183
184 /**
185 * Tell the client to display a dialog to confirm navigation away from the
186 * current page. This is the result of the onbeforeunload javascript event.
187 * If the client returns true, WebView will assume that the client will
188 * handle the confirm dialog and call the appropriate JsResult method. If
189 * the client returns false, a default value of true will be returned to
190 * javascript to accept navigation away from the current page. The default
191 * behavior is to return false. Setting the JsResult to true will navigate
192 * away from the current page, false will cancel the navigation.
193 * @param view The WebView that initiated the callback.
194 * @param url The url of the page requesting the dialog.
195 * @param message Message to be displayed in the window.
196 * @param result A JsResult used to send the user's response to
197 * javascript.
198 * @return boolean Whether the client will handle the confirm dialog.
199 */
200 public boolean onJsBeforeUnload(WebView view, String url, String message,
201 JsResult result) {
202 return false;
203 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100204
205 /**
206 * Tell the client that the database quota for the origin has been exceeded.
207 * @param url The URL that triggered the notification
208 * @param databaseIdentifier The identifier of the database that caused the
209 * quota overflow.
210 * @param currentQuota The current quota for the origin.
Ben Murdochd497d872009-08-25 19:32:54 +0100211 * @param estimatedSize The estimated size of the database.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100212 * @param totalUsedQuota is the sum of all origins' quota.
Ben Murdoch7df19852009-04-22 13:07:58 +0100213 * @param quotaUpdater A callback to inform the WebCore thread that a new
214 * quota is available. This callback must always be executed at some
215 * point to ensure that the sleeping WebCore thread is woken up.
216 */
217 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Ben Murdochd497d872009-08-25 19:32:54 +0100218 long currentQuota, long estimatedSize, long totalUsedQuota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100219 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100220 // This default implementation passes the current quota back to WebCore.
221 // WebCore will interpret this that new quota was declined.
222 quotaUpdater.updateQuota(currentQuota);
223 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700224
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100225 /**
226 * Tell the client that the Application Cache has exceeded its max size.
227 * @param spaceNeeded is the amount of disk space that would be needed
228 * in order for the last appcache operation to succeed.
229 * @param totalUsedQuota is the sum of all origins' quota.
230 * @param quotaUpdater A callback to inform the WebCore thread that a new
231 * app cache size is available. This callback must always be executed at
232 * some point to ensure that the sleeping WebCore thread is woken up.
233 * @hide pending API council approval.
234 */
235 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
236 WebStorage.QuotaUpdater quotaUpdater) {
237 quotaUpdater.updateQuota(0);
238 }
239
Guang Zhu81e41432009-05-08 16:09:55 -0700240 /**
Steve Block4faee092009-07-28 18:20:50 +0100241 * Instructs the client to show a prompt to ask the user to set the
242 * Geolocation permission state for the specified origin.
243 * @hide pending API council approval.
244 */
245 public void onGeolocationPermissionsShowPrompt(String origin,
246 GeolocationPermissions.Callback callback) {}
247
248 /**
249 * Instructs the client to hide the Geolocation permissions prompt.
250 * @hide pending API council approval.
251 */
252 public void onGeolocationPermissionsHidePrompt() {}
253
254 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700255 * Tell the client that a JavaScript execution timeout has occured. And the
256 * client may decide whether or not to interrupt the execution. If the
257 * client returns true, the JavaScript will be interrupted. If the client
258 * returns false, the execution will continue. Note that in the case of
259 * continuing execution, the timeout counter will be reset, and the callback
260 * will continue to occur if the script does not finish at the next check
261 * point.
262 * @return boolean Whether the JavaScript execution should be interrupted.
263 * @hide pending API Council approval
264 */
265 public boolean onJsTimeout() {
266 return true;
267 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100268
269 /**
270 * Add a JavaScript error message to the console. Clients should override
271 * this to process the log message as they see fit.
272 * @param message The error message to report.
273 * @param lineNumber The line number of the error.
274 * @param sourceID The name of the source file that caused the error.
275 * @hide pending API council.
276 */
Steve Block4faee092009-07-28 18:20:50 +0100277 public void addMessageToConsole(String message, int lineNumber, String sourceID) {}
Andrei Popescubf385d72009-09-18 18:59:52 +0100278
279 /**
280 * Ask the host application for an icon to represent a <video> element.
281 * This icon will be used if the Web page did not specify a poster attribute.
282 *
283 * @return Bitmap The icon or null if no such icon is available.
284 * @hide pending API Council approval
285 */
286 public Bitmap getDefaultVideoPoster() {
287 return null;
288 }
289
290 /**
291 * Ask the host application for a custom progress view to show while
292 * a <video> is loading.
293 *
294 * @return View The progress view.
295 * @hide pending API Council approval
296 */
297 public View getVideoLoadingProgressView() {
298 return null;
299 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300}