• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.webkit;
18 
19 import android.content.pm.ActivityInfo;
20 import android.graphics.Bitmap;
21 import android.net.Uri;
22 import android.os.Message;
23 import android.view.View;
24 
25 public 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      */
onProgressChanged(WebView view, int newProgress)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      */
onReceivedTitle(WebView view, String title)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      */
onReceivedIcon(WebView view, Bitmap icon)47     public void onReceivedIcon(WebView view, Bitmap icon) {}
48 
49     /**
50      * 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.
53      * @param precomposed True if the url is for a precomposed touch icon.
54      */
onReceivedTouchIconUrl(WebView view, String url, boolean precomposed)55     public void onReceivedTouchIconUrl(WebView view, String url,
56             boolean precomposed) {}
57 
58     /**
59      * A callback interface used by the host application to notify
60      * the current page that its custom view has been dismissed.
61      */
62     public interface CustomViewCallback {
63         /**
64          * Invoked when the host application dismisses the
65          * custom view.
66          */
onCustomViewHidden()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.
76      */
onShowCustomView(View view, CustomViewCallback callback)77     public void onShowCustomView(View view, CustomViewCallback callback) {};
78 
79     /**
80      * Notify the host application that the current page would
81      * 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      */
onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback)88     public void onShowCustomView(View view, int requestedOrientation,
89             CustomViewCallback callback) {};
90 
91     /**
92      * Notify the host application that the current page would
93      * like to hide its custom view.
94      */
onHideCustomView()95     public void onHideCustomView() {}
96 
97     /**
98      * 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      */
onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg)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      */
onRequestFocus(WebView view)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      */
onCloseWindow(WebView window)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      */
onJsAlert(WebView view, String url, String message, JsResult result)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      */
onJsConfirm(WebView view, String url, String message, JsResult result)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      */
onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result)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      */
onJsBeforeUnload(WebView view, String url, String message, JsResult result)207     public boolean onJsBeforeUnload(WebView view, String url, String message,
208             JsResult result) {
209         return false;
210     }
211 
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.
218     * @param estimatedSize The estimated size of the database.
219     * @param totalUsedQuota is the sum of all origins' quota.
220     * @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     */
onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)224     public void onExceededDatabaseQuota(String url, String databaseIdentifier,
225         long currentQuota, long estimatedSize, long totalUsedQuota,
226         WebStorage.QuotaUpdater quotaUpdater) {
227         // 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     }
231 
232    /**
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.
240     */
onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)241     public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
242             WebStorage.QuotaUpdater quotaUpdater) {
243         quotaUpdater.updateQuota(0);
244     }
245 
246     /**
247      * Instructs the client to show a prompt to ask the user to set the
248      * Geolocation permission state for the specified origin.
249      */
onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)250     public void onGeolocationPermissionsShowPrompt(String origin,
251             GeolocationPermissions.Callback callback) {}
252 
253     /**
254      * Instructs the client to hide the Geolocation permissions prompt.
255      */
onGeolocationPermissionsHidePrompt()256     public void onGeolocationPermissionsHidePrompt() {}
257 
258     /**
259      * 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.
267      */
onJsTimeout()268     public boolean onJsTimeout() {
269         return true;
270     }
271 
272     /**
273      * Report a JavaScript error message to the host application. The ChromeClient
274      * should override this to process the log message as they see fit.
275      * @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.
278      * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
279      *      instead.
280      */
281     @Deprecated
onConsoleMessage(String message, int lineNumber, String sourceID)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      */
onConsoleMessage(ConsoleMessage consoleMessage)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     }
296 
297     /**
298      * 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.
302      *
303      * @return Bitmap The image to use as a default poster, or null if no such image is
304      * available.
305      */
getDefaultVideoPoster()306     public Bitmap getDefaultVideoPoster() {
307         return null;
308     }
309 
310     /**
311      * 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.
315      *
316      * @return View The View to be displayed whilst the video is loading.
317      */
getVideoLoadingProgressView()318     public View getVideoLoadingProgressView() {
319         return null;
320     }
321 
322     /** Obtains a list of all visited history items, used for link coloring
323      */
getVisitedHistory(ValueCallback<String[]> callback)324     public void getVisitedHistory(ValueCallback<String[]> callback) {
325     }
326 
327     /**
328      * Tell the client to open a file chooser.
329      * @param uploadFile A ValueCallback to set the URI of the file to upload.
330      *      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.
333      * @hide
334      */
openFileChooser(ValueCallback<Uri> uploadFile, String acceptType)335     public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) {
336         uploadFile.onReceiveValue(null);
337     }
338 
339     /**
340      * 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      */
setInstallableWebApp()344     public void setInstallableWebApp() { }
345 
346     /**
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      */
setupAutoFill(Message msg)354     public void setupAutoFill(Message msg) { }
355 
356 }
357