blob: dd494e1ed0b0b7d3e3ff110b4ac6097f3eecb71f [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 */
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 */
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010061 public interface CustomViewCallback {
62 /**
63 * Invoked when the host application dismisses the
64 * custom view.
65 */
66 public void onCustomViewHidden();
67 }
68
69 /**
70 * Notify the host application that the current page would
71 * like to show a custom View.
72 * @param view is the View object to be shown.
73 * @param callback is the callback to be invoked if and when the view
74 * is dismissed.
Andrei Popescu3c946a1a2009-07-03 08:20:53 +010075 */
76 public void onShowCustomView(View view, CustomViewCallback callback) {};
Andrei Popescu6fa29582009-06-19 14:54:09 +010077
78 /**
79 * Notify the host application that the current page would
80 * like to hide its custom view.
Andrei Popescu6fa29582009-06-19 14:54:09 +010081 */
82 public void onHideCustomView() {}
83
84 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 * Request the host application to create a new Webview. The host
86 * application should handle placement of the new WebView in the view
87 * system. The default behavior returns null.
88 * @param view The WebView that initiated the callback.
89 * @param dialog True if the new window is meant to be a small dialog
90 * window.
91 * @param userGesture True if the request was initiated by a user gesture
92 * such as clicking a link.
93 * @param resultMsg The message to send when done creating a new WebView.
94 * Set the new WebView through resultMsg.obj which is
95 * WebView.WebViewTransport() and then call
96 * resultMsg.sendToTarget();
97 * @return Similar to javscript dialogs, this method should return true if
98 * the client is going to handle creating a new WebView. Note that
99 * the WebView will halt processing if this method returns true so
100 * make sure to call resultMsg.sendToTarget(). It is undefined
101 * behavior to call resultMsg.sendToTarget() after returning false
102 * from this method.
103 */
104 public boolean onCreateWindow(WebView view, boolean dialog,
105 boolean userGesture, Message resultMsg) {
106 return false;
107 }
108
109 /**
110 * Request display and focus for this WebView. This may happen due to
111 * another WebView opening a link in this WebView and requesting that this
112 * WebView be displayed.
113 * @param view The WebView that needs to be focused.
114 */
115 public void onRequestFocus(WebView view) {}
116
117 /**
118 * Notify the host application to close the given WebView and remove it
119 * from the view system if necessary. At this point, WebCore has stopped
120 * any loading in this window and has removed any cross-scripting ability
121 * in javascript.
122 * @param window The WebView that needs to be closed.
123 */
124 public void onCloseWindow(WebView window) {}
125
126 /**
127 * Tell the client to display a javascript alert dialog. If the client
128 * returns true, WebView will assume that the client will handle the
129 * dialog. If the client returns false, it will continue execution.
130 * @param view The WebView that initiated the callback.
131 * @param url The url of the page requesting the dialog.
132 * @param message Message to be displayed in the window.
133 * @param result A JsResult to confirm that the user hit enter.
134 * @return boolean Whether the client will handle the alert dialog.
135 */
136 public boolean onJsAlert(WebView view, String url, String message,
137 JsResult result) {
138 return false;
139 }
140
141 /**
142 * Tell the client to display a confirm dialog to the user. If the client
143 * returns true, WebView will assume that the client will handle the
144 * confirm dialog and call the appropriate JsResult method. If the
145 * client returns false, a default value of false will be returned to
146 * javascript. The default behavior is to return false.
147 * @param view The WebView that initiated the callback.
148 * @param url The url of the page requesting the dialog.
149 * @param message Message to be displayed in the window.
150 * @param result A JsResult used to send the user's response to
151 * javascript.
152 * @return boolean Whether the client will handle the confirm dialog.
153 */
154 public boolean onJsConfirm(WebView view, String url, String message,
155 JsResult result) {
156 return false;
157 }
158
159 /**
160 * Tell the client to display a prompt dialog to the user. If the client
161 * returns true, WebView will assume that the client will handle the
162 * prompt dialog and call the appropriate JsPromptResult method. If the
163 * client returns false, a default value of false will be returned to to
164 * javascript. The default behavior is to return false.
165 * @param view The WebView that initiated the callback.
166 * @param url The url of the page requesting the dialog.
167 * @param message Message to be displayed in the window.
168 * @param defaultValue The default value displayed in the prompt dialog.
169 * @param result A JsPromptResult used to send the user's reponse to
170 * javascript.
171 * @return boolean Whether the client will handle the prompt dialog.
172 */
173 public boolean onJsPrompt(WebView view, String url, String message,
174 String defaultValue, JsPromptResult result) {
175 return false;
176 }
177
178 /**
179 * Tell the client to display a dialog to confirm navigation away from the
180 * current page. This is the result of the onbeforeunload javascript event.
181 * If the client returns true, WebView will assume that the client will
182 * handle the confirm dialog and call the appropriate JsResult method. If
183 * the client returns false, a default value of true will be returned to
184 * javascript to accept navigation away from the current page. The default
185 * behavior is to return false. Setting the JsResult to true will navigate
186 * away from the current page, false will cancel the navigation.
187 * @param view The WebView that initiated the callback.
188 * @param url The url of the page requesting the dialog.
189 * @param message Message to be displayed in the window.
190 * @param result A JsResult used to send the user's response to
191 * javascript.
192 * @return boolean Whether the client will handle the confirm dialog.
193 */
194 public boolean onJsBeforeUnload(WebView view, String url, String message,
195 JsResult result) {
196 return false;
197 }
Ben Murdoch7df19852009-04-22 13:07:58 +0100198
199 /**
200 * Tell the client that the database quota for the origin has been exceeded.
201 * @param url The URL that triggered the notification
202 * @param databaseIdentifier The identifier of the database that caused the
203 * quota overflow.
204 * @param currentQuota The current quota for the origin.
Ben Murdochd497d872009-08-25 19:32:54 +0100205 * @param estimatedSize The estimated size of the database.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100206 * @param totalUsedQuota is the sum of all origins' quota.
Ben Murdoch7df19852009-04-22 13:07:58 +0100207 * @param quotaUpdater A callback to inform the WebCore thread that a new
208 * quota is available. This callback must always be executed at some
209 * point to ensure that the sleeping WebCore thread is woken up.
210 */
211 public void onExceededDatabaseQuota(String url, String databaseIdentifier,
Ben Murdochd497d872009-08-25 19:32:54 +0100212 long currentQuota, long estimatedSize, long totalUsedQuota,
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100213 WebStorage.QuotaUpdater quotaUpdater) {
Ben Murdoch7df19852009-04-22 13:07:58 +0100214 // This default implementation passes the current quota back to WebCore.
215 // WebCore will interpret this that new quota was declined.
216 quotaUpdater.updateQuota(currentQuota);
217 }
Guang Zhu10e4d202009-05-11 18:09:51 -0700218
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100219 /**
220 * Tell the client that the Application Cache has exceeded its max size.
221 * @param spaceNeeded is the amount of disk space that would be needed
222 * in order for the last appcache operation to succeed.
223 * @param totalUsedQuota is the sum of all origins' quota.
224 * @param quotaUpdater A callback to inform the WebCore thread that a new
225 * app cache size is available. This callback must always be executed at
226 * some point to ensure that the sleeping WebCore thread is woken up.
Andrei Popescu59e2ad92009-07-28 13:38:06 +0100227 */
228 public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
229 WebStorage.QuotaUpdater quotaUpdater) {
230 quotaUpdater.updateQuota(0);
231 }
232
Guang Zhu81e41432009-05-08 16:09:55 -0700233 /**
Steve Block4faee092009-07-28 18:20:50 +0100234 * Instructs the client to show a prompt to ask the user to set the
235 * Geolocation permission state for the specified origin.
Steve Block4faee092009-07-28 18:20:50 +0100236 */
237 public void onGeolocationPermissionsShowPrompt(String origin,
238 GeolocationPermissions.Callback callback) {}
239
240 /**
241 * Instructs the client to hide the Geolocation permissions prompt.
Steve Block4faee092009-07-28 18:20:50 +0100242 */
243 public void onGeolocationPermissionsHidePrompt() {}
244
245 /**
Guang Zhu81e41432009-05-08 16:09:55 -0700246 * Tell the client that a JavaScript execution timeout has occured. And the
247 * client may decide whether or not to interrupt the execution. If the
248 * client returns true, the JavaScript will be interrupted. If the client
249 * returns false, the execution will continue. Note that in the case of
250 * continuing execution, the timeout counter will be reset, and the callback
251 * will continue to occur if the script does not finish at the next check
252 * point.
253 * @return boolean Whether the JavaScript execution should be interrupted.
Guang Zhu81e41432009-05-08 16:09:55 -0700254 */
255 public boolean onJsTimeout() {
256 return true;
257 }
Ben Murdoch6262ae52009-04-17 13:21:53 +0100258
259 /**
260 * Add a JavaScript error message to the console. Clients should override
261 * this to process the log message as they see fit.
262 * @param message The error message to report.
263 * @param lineNumber The line number of the error.
264 * @param sourceID The name of the source file that caused the error.
Ben Murdoch6262ae52009-04-17 13:21:53 +0100265 */
Steve Block4faee092009-07-28 18:20:50 +0100266 public void addMessageToConsole(String message, int lineNumber, String sourceID) {}
Andrei Popescubf385d72009-09-18 18:59:52 +0100267
268 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000269 * When not playing, video elements are represented by a 'poster' image. The
270 * image to use can be specified by the poster attribute of the video tag in
271 * HTML. If the attribute is absent, then a default poster will be used. This
272 * method allows the ChromeClient to provide that default image.
Andrei Popescubf385d72009-09-18 18:59:52 +0100273 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000274 * @return Bitmap The image to use as a default poster, or null if no such image is
275 * available.
Andrei Popescubf385d72009-09-18 18:59:52 +0100276 */
277 public Bitmap getDefaultVideoPoster() {
278 return null;
279 }
280
281 /**
Ben Murdochf0c443d2009-11-19 16:43:58 +0000282 * When the user starts to playback a video element, it may take time for enough
283 * data to be buffered before the first frames can be rendered. While this buffering
284 * is taking place, the ChromeClient can use this function to provide a View to be
285 * displayed. For example, the ChromeClient could show a spinner animation.
Andrei Popescubf385d72009-09-18 18:59:52 +0100286 *
Ben Murdochf0c443d2009-11-19 16:43:58 +0000287 * @return View The View to be displayed whilst the video is loading.
Andrei Popescubf385d72009-09-18 18:59:52 +0100288 */
289 public View getVideoLoadingProgressView() {
290 return null;
291 }
Leon Clarke194e3452009-09-28 11:42:12 +0100292
293 /** Obtains a list of all visited history items, used for link coloring
Leon Clarke194e3452009-09-28 11:42:12 +0100294 */
295 public void getVisitedHistory(ValueCallback<String[]> callback) {
296 }
297
Leon Scroggins70ca3c22009-10-02 15:58:55 -0400298 /**
299 * Tell the client to open a file chooser.
300 * @param uploadFile A ValueCallback to set the URI of the file to upload.
301 * onReceiveValue must be called to wake up the thread.
302 * @hide
303 */
304 public void openFileChooser(ValueCallback<Uri> uploadFile) {
305 uploadFile.onReceiveValue(null);
306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307}