WebChromeClient.java revision 59e2ad93bf37c7ded44c033d38fe7c972e2f4118
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
17package android.webkit;
18
19import android.graphics.Bitmap;
20import android.os.Message;
21import android.view.View;
22
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    /**
48     * A callback interface used by the host application to notify
49     * the current page that its custom view has been dismissed.
50     *
51     * @hide pending council approval
52     */
53    public interface CustomViewCallback {
54        /**
55         * Invoked when the host application dismisses the
56         * custom view.
57         */
58        public void onCustomViewHidden();
59    }
60
61    /**
62     * Notify the host application that the current page would
63     * like to show a custom View.
64     * @param view is the View object to be shown.
65     * @param callback is the callback to be invoked if and when the view
66     * is dismissed.
67     *
68     * @hide pending council approval
69     */
70    public void onShowCustomView(View view, CustomViewCallback callback) {};
71
72    /**
73     * Notify the host application that the current page would
74     * like to hide its custom view.
75     *
76     * @hide pending council approval
77     */
78    public void onHideCustomView() {}
79
80    /**
81     * Request the host application to create a new Webview. The host
82     * application should handle placement of the new WebView in the view
83     * system. The default behavior returns null.
84     * @param view The WebView that initiated the callback.
85     * @param dialog True if the new window is meant to be a small dialog
86     *               window.
87     * @param userGesture True if the request was initiated by a user gesture
88     *                    such as clicking a link.
89     * @param resultMsg The message to send when done creating a new WebView.
90     *                  Set the new WebView through resultMsg.obj which is
91     *                  WebView.WebViewTransport() and then call
92     *                  resultMsg.sendToTarget();
93     * @return Similar to javscript dialogs, this method should return true if
94     *         the client is going to handle creating a new WebView. Note that
95     *         the WebView will halt processing if this method returns true so
96     *         make sure to call resultMsg.sendToTarget(). It is undefined
97     *         behavior to call resultMsg.sendToTarget() after returning false
98     *         from this method.
99     */
100    public boolean onCreateWindow(WebView view, boolean dialog,
101            boolean userGesture, Message resultMsg) {
102        return false;
103    }
104
105    /**
106     * Request display and focus for this WebView. This may happen due to
107     * another WebView opening a link in this WebView and requesting that this
108     * WebView be displayed.
109     * @param view The WebView that needs to be focused.
110     */
111    public void onRequestFocus(WebView view) {}
112
113    /**
114     * Notify the host application to close the given WebView and remove it
115     * from the view system if necessary. At this point, WebCore has stopped
116     * any loading in this window and has removed any cross-scripting ability
117     * in javascript.
118     * @param window The WebView that needs to be closed.
119     */
120    public void onCloseWindow(WebView window) {}
121
122    /**
123     * Tell the client to display a javascript alert dialog.  If the client
124     * returns true, WebView will assume that the client will handle the
125     * dialog.  If the client returns false, it will continue execution.
126     * @param view The WebView that initiated the callback.
127     * @param url The url of the page requesting the dialog.
128     * @param message Message to be displayed in the window.
129     * @param result A JsResult to confirm that the user hit enter.
130     * @return boolean Whether the client will handle the alert dialog.
131     */
132    public boolean onJsAlert(WebView view, String url, String message,
133            JsResult result) {
134        return false;
135    }
136
137    /**
138     * Tell the client to display a confirm dialog to the user. If the client
139     * returns true, WebView will assume that the client will handle the
140     * confirm dialog and call the appropriate JsResult method. If the
141     * client returns false, a default value of false will be returned to
142     * javascript. The default behavior is to return false.
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 used to send the user's response to
147     *               javascript.
148     * @return boolean Whether the client will handle the confirm dialog.
149     */
150    public boolean onJsConfirm(WebView view, String url, String message,
151            JsResult result) {
152        return false;
153    }
154
155    /**
156     * Tell the client to display a prompt dialog to the user. If the client
157     * returns true, WebView will assume that the client will handle the
158     * prompt dialog and call the appropriate JsPromptResult method. If the
159     * client returns false, a default value of false will be returned to to
160     * javascript. The default behavior is to return false.
161     * @param view The WebView that initiated the callback.
162     * @param url The url of the page requesting the dialog.
163     * @param message Message to be displayed in the window.
164     * @param defaultValue The default value displayed in the prompt dialog.
165     * @param result A JsPromptResult used to send the user's reponse to
166     *               javascript.
167     * @return boolean Whether the client will handle the prompt dialog.
168     */
169    public boolean onJsPrompt(WebView view, String url, String message,
170            String defaultValue, JsPromptResult result) {
171        return false;
172    }
173
174    /**
175     * Tell the client to display a dialog to confirm navigation away from the
176     * current page. This is the result of the onbeforeunload javascript event.
177     * If the client returns true, WebView will assume that the client will
178     * handle the confirm dialog and call the appropriate JsResult method. If
179     * the client returns false, a default value of true will be returned to
180     * javascript to accept navigation away from the current page. The default
181     * behavior is to return false. Setting the JsResult to true will navigate
182     * away from the current page, false will cancel the navigation.
183     * @param view The WebView that initiated the callback.
184     * @param url The url of the page requesting the dialog.
185     * @param message Message to be displayed in the window.
186     * @param result A JsResult used to send the user's response to
187     *               javascript.
188     * @return boolean Whether the client will handle the confirm dialog.
189     */
190    public boolean onJsBeforeUnload(WebView view, String url, String message,
191            JsResult result) {
192        return false;
193    }
194
195   /**
196    * Tell the client that the database quota for the origin has been exceeded.
197    * @param url The URL that triggered the notification
198    * @param databaseIdentifier The identifier of the database that caused the
199    *     quota overflow.
200    * @param currentQuota The current quota for the origin.
201    * @param totalUsedQuota is the sum of all origins' quota.
202    * @param quotaUpdater A callback to inform the WebCore thread that a new
203    *     quota is available. This callback must always be executed at some
204    *     point to ensure that the sleeping WebCore thread is woken up.
205    */
206    public void onExceededDatabaseQuota(String url, String databaseIdentifier,
207        long currentQuota, long totalUsedQuota,
208        WebStorage.QuotaUpdater quotaUpdater) {
209        // This default implementation passes the current quota back to WebCore.
210        // WebCore will interpret this that new quota was declined.
211        quotaUpdater.updateQuota(currentQuota);
212    }
213
214   /**
215    * Tell the client that the Application Cache has exceeded its max size.
216    * @param spaceNeeded is the amount of disk space that would be needed
217    * in order for the last appcache operation to succeed.
218    * @param totalUsedQuota is the sum of all origins' quota.
219    * @param quotaUpdater A callback to inform the WebCore thread that a new
220    * app cache size is available. This callback must always be executed at
221    * some point to ensure that the sleeping WebCore thread is woken up.
222    * @hide pending API council approval.
223    */
224    public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
225            WebStorage.QuotaUpdater quotaUpdater) {
226        quotaUpdater.updateQuota(0);
227    }
228
229    /**
230     * Tell the client that a JavaScript execution timeout has occured. And the
231     * client may decide whether or not to interrupt the execution. If the
232     * client returns true, the JavaScript will be interrupted. If the client
233     * returns false, the execution will continue. Note that in the case of
234     * continuing execution, the timeout counter will be reset, and the callback
235     * will continue to occur if the script does not finish at the next check
236     * point.
237     * @return boolean Whether the JavaScript execution should be interrupted.
238     * @hide pending API Council approval
239     */
240    public boolean onJsTimeout() {
241        return true;
242    }
243
244    /**
245     * Add a JavaScript error message to the console. Clients should override
246     * this to process the log message as they see fit.
247     * @param message The error message to report.
248     * @param lineNumber The line number of the error.
249     * @param sourceID The name of the source file that caused the error.
250     * @hide pending API council.
251     */
252    public void addMessageToConsole(String message, int lineNumber, String sourceID) {
253    }
254}
255