blob: ae40ded3590728bd1e332612ef5af0e48a15f21f [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
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040019import android.content.pm.ActivityInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.graphics.Bitmap;
Leon Scroggins70ca3c22009-10-02 15:58:55 -040021import android.net.Uri;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.Message;
Andrei Popescu6fa29582009-06-19 14:54:09 +010023import android.view.View;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25public class WebChromeClient {
26
27 /**
28 * Tell the host application the current progress of loading a page.
29 * @param view The WebView that initiated the callback.
30 * @param newProgress Current page loading progress, represented by
31 * an integer between 0 and 100.
32 */
33 public void onProgressChanged(WebView view, int newProgress) {}
34
35 /**
36 * Notify the host application of a change in the document title.
37 * @param view The WebView that initiated the callback.
38 * @param title A String containing the new title of the document.
39 */
40 public void onReceivedTitle(WebView view, String title) {}
41
42 /**
43 * Notify the host application of a new favicon for the current page.
44 * @param view The WebView that initiated the callback.
45 * @param icon A Bitmap containing the favicon for the current page.
46 */
47 public void onReceivedIcon(WebView view, Bitmap icon) {}
48
49 /**
Patrick Scott2ba12622009-08-04 13:20:05 -040050 * Notify the host application of the url for an apple-touch-icon.
51 * @param view The WebView that initiated the callback.
52 * @param url The icon url.
Patrick Scottd58ccff2009-09-18 16:29:00 -040053 * @param precomposed True if the url is for a precomposed touch icon.
Patrick Scott2ba12622009-08-04 13:20:05 -040054 */
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 */
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010062 public interface CustomViewCallback {
63 /**
64 * Invoked when the host application dismisses the
65 * custom view.
66 */
67 public void onCustomViewHidden();
68 }
69
70 /**
71 * Notify the host application that the current page would
72 * like to show a custom View.
73 * @param view is the View object to be shown.
74 * @param callback is the callback to be invoked if and when the view
75 * is dismissed.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010076 */
77 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010078
79 /**
80 * Notify the host application that the current page would
Derek Sollenberger7ab3d672011-06-01 14:45:05 -040081 * like to show a custom View in a particular orientation.
82 * @param view is the View object to be shown.
83 * @param requestedOrientation An orientation constant as used in
84 * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
85 * @param callback is the callback to be invoked if and when the view
86 * is dismissed.
87 */
88 public void onShowCustomView(View view, int requestedOrientation,
89 CustomViewCallback callback) {};
90
91 /**
92 * Notify the host application that the current page would
Andrei Popescu6fa29582009-06-19 14:54:09 +010093 * like to hide its custom view.
Andrei Popescu6fa29582009-06-19 14:54:09 +010094 */
95 public void onHideCustomView() {}
96
97 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 * Request the host application to create a new Webview. The host
99 * application should handle placement of the new WebView in the view
100 * system. The default behavior returns null.
101 * @param view The WebView that initiated the callback.
102 * @param dialog True if the new window is meant to be a small dialog
103 * window.
104 * @param userGesture True if the request was initiated by a user gesture
105 * such as clicking a link.
106 * @param resultMsg The message to send when done creating a new WebView.
107 * Set the new WebView through resultMsg.obj which is
108 * WebView.WebViewTransport() and then call
109 * resultMsg.sendToTarget();
110 * @return Similar to javscript dialogs, this method should return true if
111 * the client is going to handle creating a new WebView. Note that
112 * the WebView will halt processing if this method returns true so
113 * make sure to call resultMsg.sendToTarget(). It is undefined
114 * behavior to call resultMsg.sendToTarget() after returning false
115 * from this method.
116 */
117 public boolean onCreateWindow(WebView view, boolean dialog,
118 boolean userGesture, Message resultMsg) {
119 return false;
120 }
121
122 /**
123 * Request display and focus for this WebView. This may happen due to
124 * another WebView opening a link in this WebView and requesting that this
125 * WebView be displayed.
126 * @param view The WebView that needs to be focused.
127 */
128 public void onRequestFocus(WebView view) {}
129
130 /**
131 * Notify the host application to close the given WebView and remove it
132 * from the view system if necessary. At this point, WebCore has stopped
133 * any loading in this window and has removed any cross-scripting ability
134 * in javascript.
135 * @param window The WebView that needs to be closed.
136 */
137 public void onCloseWindow(WebView window) {}
138
139 /**
140 * Tell the client to display a javascript alert dialog. If the client
141 * returns true, WebView will assume that the client will handle the
142 * dialog. If the client returns false, it will continue execution.
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 to confirm that the user hit enter.
147 * @return boolean Whether the client will handle the alert dialog.
148 */
149 public boolean onJsAlert(WebView view, String url, String message,
150 JsResult result) {
151 return false;
152 }
153
154 /**
155 * Tell the client to display a confirm dialog to the user. If the client
156 * returns true, WebView will assume that the client will handle the
157 * confirm dialog and call the appropriate JsResult method. If the
158 * client returns false, a default value of false will be returned to
159 * javascript. The default behavior is to return false.
160 * @param view The WebView that initiated the callback.
161 * @param url The url of the page requesting the dialog.
162 * @param message Message to be displayed in the window.
163 * @param result A JsResult used to send the user's response to
164 * javascript.
165 * @return boolean Whether the client will handle the confirm dialog.
166 */
167 public boolean onJsConfirm(WebView view, String url, String message,
168 JsResult result) {
169 return false;
170 }
171
172 /**
173 * Tell the client to display a prompt dialog to the user. If the client
174 * returns true, WebView will assume that the client will handle the
175 * prompt dialog and call the appropriate JsPromptResult method. If the
176 * client returns false, a default value of false will be returned to to
177 * javascript. The default behavior is to return false.
178 * @param view The WebView that initiated the callback.
179 * @param url The url of the page requesting the dialog.
180 * @param message Message to be displayed in the window.
181 * @param defaultValue The default value displayed in the prompt dialog.
182 * @param result A JsPromptResult used to send the user's reponse to
183 * javascript.
184 * @return boolean Whether the client will handle the prompt dialog.
185 */
186 public boolean onJsPrompt(WebView view, String url, String message,
187 String defaultValue, JsPromptResult result) {
188 return false;
189 }
190
191 /**
192 * Tell the client to display a dialog to confirm navigation away from the
193 * current page. This is the result of the onbeforeunload javascript event.
194 * If the client returns true, WebView will assume that the client will
195 * handle the confirm dialog and call the appropriate JsResult method. If
196 * the client returns false, a default value of true will be returned to
197 * javascript to accept navigation away from the current page. The default
198 * behavior is to return false. Setting the JsResult to true will navigate
199 * away from the current page, false will cancel the navigation.
200 * @param view The WebView that initiated the callback.
201 * @param url The url of the page requesting the dialog.
202 * @param message Message to be displayed in the window.
203 * @param result A JsResult used to send the user's response to
204 * javascript.
205 * @return boolean Whether the client will handle the confirm dialog.
206 */
207 public boolean onJsBeforeUnload(WebView view, String url, String message,
208 JsResult result) {
209 return false;
210 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100211
212 /**
213 * Tell the client that the database quota for the origin has been exceeded.
214 * @param url The URL that triggered the notification
215 * @param databaseIdentifier The identifier of the database that caused the
216 * quota overflow.
217 * @param currentQuota The current quota for the origin.
Ben Murdochd497d872009-08-25 19:32:54 +0100218 * @param estimatedSize The estimated size of the database.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100219 * @param totalUsedQuota is the sum of all origins' quota.
Ben Murdoch7df19852009-04-22 13:07:58 +0100220 * @param quotaUpdater A callback to inform the WebCore thread that a new
221 * quota is available. This callback must always be executed at some
222 * point to ensure that the sleeping WebCore thread is woken up.
223 */
224 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Ben Murdochd497d872009-08-25 19:32:54 +0100225 long currentQuota, long estimatedSize, long totalUsedQuota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100226 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100227 // This default implementation passes the current quota back to WebCore.
228 // WebCore will interpret this that new quota was declined.
229 quotaUpdater.updateQuota(currentQuota);
230 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700231
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100232 /**
233 * Tell the client that the Application Cache has exceeded its max size.
234 * @param spaceNeeded is the amount of disk space that would be needed
235 * in order for the last appcache operation to succeed.
236 * @param totalUsedQuota is the sum of all origins' quota.
237 * @param quotaUpdater A callback to inform the WebCore thread that a new
238 * app cache size is available. This callback must always be executed at
239 * some point to ensure that the sleeping WebCore thread is woken up.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100240 */
241 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
242 WebStorage.QuotaUpdater quotaUpdater) {
243 quotaUpdater.updateQuota(0);
244 }
245
Guang Zhu81e41432009-05-08 16:09:55 -0700246 /**
Steve Block4faee092009-07-28 18:20:50 +0100247 * Instructs the client to show a prompt to ask the user to set the
248 * Geolocation permission state for the specified origin.
Steve Block4faee092009-07-28 18:20:50 +0100249 */
250 public void onGeolocationPermissionsShowPrompt(String origin,
251 GeolocationPermissions.Callback callback) {}
252
253 /**
254 * Instructs the client to hide the Geolocation permissions prompt.
Steve Block4faee092009-07-28 18:20:50 +0100255 */
256 public void onGeolocationPermissionsHidePrompt() {}
257
258 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700259 * Tell the client that a JavaScript execution timeout has occured. And the
260 * client may decide whether or not to interrupt the execution. If the
261 * client returns true, the JavaScript will be interrupted. If the client
262 * returns false, the execution will continue. Note that in the case of
263 * continuing execution, the timeout counter will be reset, and the callback
264 * will continue to occur if the script does not finish at the next check
265 * point.
266 * @return boolean Whether the JavaScript execution should be interrupted.
Guang Zhu81e41432009-05-08 16:09:55 -0700267 */
268 public boolean onJsTimeout() {
269 return true;
270 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100271
272 /**
Ben Murdoch7caaeec2009-11-19 18:14:53 +0000273 * Report a JavaScript error message to the host application. The ChromeClient
274 * should override this to process the log message as they see fit.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100275 * @param message The error message to report.
276 * @param lineNumber The line number of the error.
277 * @param sourceID The name of the source file that caused the error.
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000278 * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
279 * instead.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100280 */
Ben Murdoch3141e0a2010-01-28 15:06:32 +0000281 @Deprecated
282 public void onConsoleMessage(String message, int lineNumber, String sourceID) { }
283
284 /**
285 * Report a JavaScript console message to the host application. The ChromeClient
286 * should override this to process the log message as they see fit.
287 * @param consoleMessage Object containing details of the console message.
288 * @return true if the message is handled by the client.
289 */
290 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
291 // Call the old version of this function for backwards compatability.
292 onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
293 consoleMessage.sourceId());
294 return false;
295 }
Andrei Popescubf385d72009-09-18 18:59:52 +0100296
297 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000298 * When not playing, video elements are represented by a 'poster' image. The
299 * image to use can be specified by the poster attribute of the video tag in
300 * HTML. If the attribute is absent, then a default poster will be used. This
301 * method allows the ChromeClient to provide that default image.
Andrei Popescubf385d72009-09-18 18:59:52 +0100302 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000303 * @return Bitmap The image to use as a default poster, or null if no such image is
304 * available.
Andrei Popescubf385d72009-09-18 18:59:52 +0100305 */
306 public Bitmap getDefaultVideoPoster() {
307 return null;
308 }
309
310 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000311 * When the user starts to playback a video element, it may take time for enough
312 * data to be buffered before the first frames can be rendered. While this buffering
313 * is taking place, the ChromeClient can use this function to provide a View to be
314 * displayed. For example, the ChromeClient could show a spinner animation.
Andrei Popescubf385d72009-09-18 18:59:52 +0100315 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000316 * @return View The View to be displayed whilst the video is loading.
Andrei Popescubf385d72009-09-18 18:59:52 +0100317 */
318 public View getVideoLoadingProgressView() {
319 return null;
320 }
Leon Clarke194e3452009-09-28 11:42:12 +0100321
322 /** Obtains a list of all visited history items, used for link coloring
Leon Clarke194e3452009-09-28 11:42:12 +0100323 */
324 public void getVisitedHistory(ValueCallback<String[]> callback) {
325 }
326
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400327 /**
328 * Tell the client to open a file chooser.
329 * @param uploadFile A ValueCallback to set the URI of the file to upload.
Ben Murdoch4ae32f52010-05-18 14:30:39 +0100330 * onReceiveValue must be called to wake up the thread.a
331 * @param acceptType The value of the 'accept' attribute of the input tag
332 * associated with this file picker.
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400333 * @hide
334 */
Ben Murdoch4ae32f52010-05-18 14:30:39 +0100335 public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) {
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400336 uploadFile.onReceiveValue(null);
337 }
Cary Clark924af702010-06-04 16:37:43 -0400338
339 /**
Ben Murdoch6312de22010-06-29 19:20:11 +0100340 * Tell the client that the page being viewed is web app capable,
341 * i.e. has specified the fullscreen-web-app-capable meta tag.
342 * @hide
343 */
344 public void setInstallableWebApp() { }
345
Ben Murdoch57914382010-11-16 11:50:39 +0000346 /**
347 * Tell the client that the page being viewed has an autofillable
348 * form and the user would like to set a profile up.
349 * @param msg A Message to send once the user has successfully
350 * set up a profile and to inform the WebTextView it should
351 * now autofill using that new profile.
352 * @hide
353 */
354 public void setupAutoFill(Message msg) { }
355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356}