blob: ae4f7c2105fa5382dded96a1163e71dfb68ada6b [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;
Leon Scroggins70ca3c22009-10-02 15:58:55 -040020import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.os.Message;
Andrei Popescu6fa29582009-06-19 14:54:09 +010022import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24public class WebChromeClient {
25
26 /**
27 * Tell the host application the current progress of loading a page.
28 * @param view The WebView that initiated the callback.
29 * @param newProgress Current page loading progress, represented by
30 * an integer between 0 and 100.
31 */
32 public void onProgressChanged(WebView view, int newProgress) {}
33
34 /**
35 * Notify the host application of a change in the document title.
36 * @param view The WebView that initiated the callback.
37 * @param title A String containing the new title of the document.
38 */
39 public void onReceivedTitle(WebView view, String title) {}
40
41 /**
42 * Notify the host application of a new favicon for the current page.
43 * @param view The WebView that initiated the callback.
44 * @param icon A Bitmap containing the favicon for the current page.
45 */
46 public void onReceivedIcon(WebView view, Bitmap icon) {}
47
48 /**
Patrick Scott2ba12622009-08-04 13:20:05 -040049 * Notify the host application of the url for an apple-touch-icon.
50 * @param view The WebView that initiated the callback.
51 * @param url The icon url.
Patrick Scottd58ccff2009-09-18 16:29:00 -040052 * @param precomposed True if the url is for a precomposed touch icon.
Patrick Scott2ba12622009-08-04 13:20:05 -040053 * @hide pending council approval
54 */
Patrick Scottd58ccff2009-09-18 16:29:00 -040055 public void onReceivedTouchIconUrl(WebView view, String url,
56 boolean precomposed) {}
Patrick Scott2ba12622009-08-04 13:20:05 -040057
58 /**
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010059 * A callback interface used by the host application to notify
60 * the current page that its custom view has been dismissed.
Andrei Popescu6fa29582009-06-19 14:54:09 +010061 *
62 * @hide pending council approval
63 */
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010064 public interface CustomViewCallback {
65 /**
66 * Invoked when the host application dismisses the
67 * custom view.
68 */
69 public void onCustomViewHidden();
70 }
71
72 /**
73 * Notify the host application that the current page would
74 * like to show a custom View.
75 * @param view is the View object to be shown.
76 * @param callback is the callback to be invoked if and when the view
77 * is dismissed.
78 *
79 * @hide pending council approval
80 */
81 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010082
83 /**
84 * Notify the host application that the current page would
85 * like to hide its custom view.
86 *
87 * @hide pending council approval
88 */
89 public void onHideCustomView() {}
90
91 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 * Request the host application to create a new Webview. The host
93 * application should handle placement of the new WebView in the view
94 * system. The default behavior returns null.
95 * @param view The WebView that initiated the callback.
96 * @param dialog True if the new window is meant to be a small dialog
97 * window.
98 * @param userGesture True if the request was initiated by a user gesture
99 * such as clicking a link.
100 * @param resultMsg The message to send when done creating a new WebView.
101 * Set the new WebView through resultMsg.obj which is
102 * WebView.WebViewTransport() and then call
103 * resultMsg.sendToTarget();
104 * @return Similar to javscript dialogs, this method should return true if
105 * the client is going to handle creating a new WebView. Note that
106 * the WebView will halt processing if this method returns true so
107 * make sure to call resultMsg.sendToTarget(). It is undefined
108 * behavior to call resultMsg.sendToTarget() after returning false
109 * from this method.
110 */
111 public boolean onCreateWindow(WebView view, boolean dialog,
112 boolean userGesture, Message resultMsg) {
113 return false;
114 }
115
116 /**
117 * Request display and focus for this WebView. This may happen due to
118 * another WebView opening a link in this WebView and requesting that this
119 * WebView be displayed.
120 * @param view The WebView that needs to be focused.
121 */
122 public void onRequestFocus(WebView view) {}
123
124 /**
125 * Notify the host application to close the given WebView and remove it
126 * from the view system if necessary. At this point, WebCore has stopped
127 * any loading in this window and has removed any cross-scripting ability
128 * in javascript.
129 * @param window The WebView that needs to be closed.
130 */
131 public void onCloseWindow(WebView window) {}
132
133 /**
134 * Tell the client to display a javascript alert dialog. If the client
135 * returns true, WebView will assume that the client will handle the
136 * dialog. If the client returns false, it will continue execution.
137 * @param view The WebView that initiated the callback.
138 * @param url The url of the page requesting the dialog.
139 * @param message Message to be displayed in the window.
140 * @param result A JsResult to confirm that the user hit enter.
141 * @return boolean Whether the client will handle the alert dialog.
142 */
143 public boolean onJsAlert(WebView view, String url, String message,
144 JsResult result) {
145 return false;
146 }
147
148 /**
149 * Tell the client to display a confirm dialog to the user. If the client
150 * returns true, WebView will assume that the client will handle the
151 * confirm dialog and call the appropriate JsResult method. If the
152 * client returns false, a default value of false will be returned to
153 * javascript. The default behavior is to return false.
154 * @param view The WebView that initiated the callback.
155 * @param url The url of the page requesting the dialog.
156 * @param message Message to be displayed in the window.
157 * @param result A JsResult used to send the user's response to
158 * javascript.
159 * @return boolean Whether the client will handle the confirm dialog.
160 */
161 public boolean onJsConfirm(WebView view, String url, String message,
162 JsResult result) {
163 return false;
164 }
165
166 /**
167 * Tell the client to display a prompt dialog to the user. If the client
168 * returns true, WebView will assume that the client will handle the
169 * prompt dialog and call the appropriate JsPromptResult method. If the
170 * client returns false, a default value of false will be returned to to
171 * javascript. The default behavior is to return false.
172 * @param view The WebView that initiated the callback.
173 * @param url The url of the page requesting the dialog.
174 * @param message Message to be displayed in the window.
175 * @param defaultValue The default value displayed in the prompt dialog.
176 * @param result A JsPromptResult used to send the user's reponse to
177 * javascript.
178 * @return boolean Whether the client will handle the prompt dialog.
179 */
180 public boolean onJsPrompt(WebView view, String url, String message,
181 String defaultValue, JsPromptResult result) {
182 return false;
183 }
184
185 /**
186 * Tell the client to display a dialog to confirm navigation away from the
187 * current page. This is the result of the onbeforeunload javascript event.
188 * If the client returns true, WebView will assume that the client will
189 * handle the confirm dialog and call the appropriate JsResult method. If
190 * the client returns false, a default value of true will be returned to
191 * javascript to accept navigation away from the current page. The default
192 * behavior is to return false. Setting the JsResult to true will navigate
193 * away from the current page, false will cancel the navigation.
194 * @param view The WebView that initiated the callback.
195 * @param url The url of the page requesting the dialog.
196 * @param message Message to be displayed in the window.
197 * @param result A JsResult used to send the user's response to
198 * javascript.
199 * @return boolean Whether the client will handle the confirm dialog.
200 */
201 public boolean onJsBeforeUnload(WebView view, String url, String message,
202 JsResult result) {
203 return false;
204 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100205
206 /**
207 * Tell the client that the database quota for the origin has been exceeded.
208 * @param url The URL that triggered the notification
209 * @param databaseIdentifier The identifier of the database that caused the
210 * quota overflow.
211 * @param currentQuota The current quota for the origin.
Ben Murdochd497d872009-08-25 19:32:54 +0100212 * @param estimatedSize The estimated size of the database.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100213 * @param totalUsedQuota is the sum of all origins' quota.
Ben Murdoch7df19852009-04-22 13:07:58 +0100214 * @param quotaUpdater A callback to inform the WebCore thread that a new
215 * quota is available. This callback must always be executed at some
216 * point to ensure that the sleeping WebCore thread is woken up.
217 */
218 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Ben Murdochd497d872009-08-25 19:32:54 +0100219 long currentQuota, long estimatedSize, long totalUsedQuota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100220 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100221 // This default implementation passes the current quota back to WebCore.
222 // WebCore will interpret this that new quota was declined.
223 quotaUpdater.updateQuota(currentQuota);
224 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700225
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100226 /**
227 * Tell the client that the Application Cache has exceeded its max size.
228 * @param spaceNeeded is the amount of disk space that would be needed
229 * in order for the last appcache operation to succeed.
230 * @param totalUsedQuota is the sum of all origins' quota.
231 * @param quotaUpdater A callback to inform the WebCore thread that a new
232 * app cache size is available. This callback must always be executed at
233 * some point to ensure that the sleeping WebCore thread is woken up.
234 * @hide pending API council approval.
235 */
236 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
237 WebStorage.QuotaUpdater quotaUpdater) {
238 quotaUpdater.updateQuota(0);
239 }
240
Guang Zhu81e41432009-05-08 16:09:55 -0700241 /**
Steve Block4faee092009-07-28 18:20:50 +0100242 * Instructs the client to show a prompt to ask the user to set the
243 * Geolocation permission state for the specified origin.
Steve Block4faee092009-07-28 18:20:50 +0100244 */
245 public void onGeolocationPermissionsShowPrompt(String origin,
246 GeolocationPermissions.Callback callback) {}
247
248 /**
249 * Instructs the client to hide the Geolocation permissions prompt.
Steve Block4faee092009-07-28 18:20:50 +0100250 */
251 public void onGeolocationPermissionsHidePrompt() {}
252
253 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700254 * Tell the client that a JavaScript execution timeout has occured. And the
255 * client may decide whether or not to interrupt the execution. If the
256 * client returns true, the JavaScript will be interrupted. If the client
257 * returns false, the execution will continue. Note that in the case of
258 * continuing execution, the timeout counter will be reset, and the callback
259 * will continue to occur if the script does not finish at the next check
260 * point.
261 * @return boolean Whether the JavaScript execution should be interrupted.
262 * @hide pending API Council approval
263 */
264 public boolean onJsTimeout() {
265 return true;
266 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100267
268 /**
269 * Add a JavaScript error message to the console. Clients should override
270 * this to process the log message as they see fit.
271 * @param message The error message to report.
272 * @param lineNumber The line number of the error.
273 * @param sourceID The name of the source file that caused the error.
274 * @hide pending API council.
275 */
Steve Block4faee092009-07-28 18:20:50 +0100276 public void addMessageToConsole(String message, int lineNumber, String sourceID) {}
Andrei Popescubf385d72009-09-18 18:59:52 +0100277
278 /**
279 * Ask the host application for an icon to represent a <video> element.
280 * This icon will be used if the Web page did not specify a poster attribute.
281 *
282 * @return Bitmap The icon or null if no such icon is available.
283 * @hide pending API Council approval
284 */
285 public Bitmap getDefaultVideoPoster() {
286 return null;
287 }
288
289 /**
290 * Ask the host application for a custom progress view to show while
291 * a <video> is loading.
292 *
293 * @return View The progress view.
294 * @hide pending API Council approval
295 */
296 public View getVideoLoadingProgressView() {
297 return null;
298 }
Leon Clarke194e3452009-09-28 11:42:12 +0100299
300 /** Obtains a list of all visited history items, used for link coloring
301 * @hide pending API Council approval
302 */
303 public void getVisitedHistory(ValueCallback<String[]> callback) {
304 }
305
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400306 /**
307 * Tell the client to open a file chooser.
308 * @param uploadFile A ValueCallback to set the URI of the file to upload.
309 * onReceiveValue must be called to wake up the thread.
310 * @hide
311 */
312 public void openFileChooser(ValueCallback<Uri> uploadFile) {
313 uploadFile.onReceiveValue(null);
314 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315}