Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / XWalkWebChromeClient.java
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 org.xwalk.core;
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 import android.webkit.WebStorage;
25 import android.webkit.ConsoleMessage;
26 import android.webkit.ValueCallback;
27
28 public class XWalkWebChromeClient {
29
30     /**
31      * Tell the host application the current progress of loading a page.
32      * @param view The XWalkView that initiated the callback.
33      * @param newProgress Current page loading progress, represented by
34      *                    an integer between 0 and 100.
35      */
36     public void onProgressChanged(XWalkView view, int newProgress) {}
37
38     /**
39      * Notify the host application of a change in the document title.
40      * @param view The XWalkView that initiated the callback.
41      * @param title A String containing the new title of the document.
42      */
43     public void onReceivedTitle(XWalkView view, String title) {}
44
45     /**
46      * Notify the host application of a new favicon for the current page.
47      * @param view The XWalkView that initiated the callback.
48      * @param icon A Bitmap containing the favicon for the current page.
49      */
50     public void onReceivedIcon(XWalkView view, Bitmap icon) {}
51
52     /**
53      * Notify the host application of the url for an apple-touch-icon.
54      * @param view The XWalkView that initiated the callback.
55      * @param url The icon url.
56      * @param precomposed True if the url is for a precomposed touch icon.
57      */
58     public void onReceivedTouchIconUrl(XWalkView view, String url,
59             boolean precomposed) {}
60
61     /**
62      * A callback interface used by the host application to notify
63      * the current page that its custom view has been dismissed.
64      */
65     public interface CustomViewCallback {
66         /**
67          * Invoked when the host application dismisses the
68          * custom view.
69          */
70         public void onCustomViewHidden();
71     }
72
73     /**
74      * Notify the host application that the current page would
75      * like to show a custom View.
76      * @param view is the View object to be shown.
77      * @param callback is the callback to be invoked if and when the view
78      * is dismissed.
79      */
80     public void onShowCustomView(View view, CustomViewCallback callback) {};
81
82     /**
83      * Notify the host application that the current page would
84      * like to show a custom View in a particular orientation.
85      * @param view is the View object to be shown.
86      * @param requestedOrientation An orientation constant as used in
87      * {@link ActivityInfo#screenOrientation ActivityInfo.screenOrientation}.
88      * @param callback is the callback to be invoked if and when the view
89      * is dismissed.
90      */
91     public void onShowCustomView(View view, int requestedOrientation,
92             CustomViewCallback callback) {};
93
94     /**
95      * Notify the host application that the current page would
96      * like to hide its custom view.
97      */
98     public void onHideCustomView() {}
99
100     /**
101      * Request the host application to create a new window. If the host
102      * application chooses to honor this request, it should return true from
103      * this method, create a new XWalkView to host the window, insert it into the
104      * View system and send the supplied resultMsg message to its target with
105      * the new XWalkView as an argument. If the host application chooses not to
106      * honor the request, it should return false from this method. The default
107      * implementation of this method does nothing and hence returns false.
108      * @param view The XWalkView from which the request for a new window
109      *             originated.
110      * @param isDialog True if the new window should be a dialog, rather than
111      *                 a full-size window.
112      * @param isUserGesture True if the request was initiated by a user gesture,
113      *                      such as the user clicking a link.
114      * @param resultMsg The message to send when once a new XWalkView has been
115      *                  created. resultMsg.obj is a
116      *                  {@link XWalkView.XWalkViewTransport} object. This should be
117      *                  used to transport the new XWalkView, by calling
118      *                  {@link XWalkView.XWalkViewTransport#setXWalkView(XWalkView)
119      *                  XWalkView.XWalkViewTransport.setXWalkView(XWalkView)}.
120      * @return This method should return true if the host application will
121      *         create a new window, in which case resultMsg should be sent to
122      *         its target. Otherwise, this method should return false. Returning
123      *         false from this method but also sending resultMsg will result in
124      *         undefined behavior.
125      */
126     public boolean onCreateWindow(XWalkView view, boolean isDialog,
127             boolean isUserGesture, Message resultMsg) {
128         return false;
129     }
130
131     /**
132      * Request display and focus for this XWalkView. This may happen due to
133      * another XWalkView opening a link in this XWalkView and requesting that this
134      * XWalkView be displayed.
135      * @param view The XWalkView that needs to be focused.
136      */
137     public void onRequestFocus(XWalkView view) {}
138
139     /**
140      * Notify the host application to close the given XWalkView and remove it
141      * from the view system if necessary. At this point, WebCore has stopped
142      * any loading in this window and has removed any cross-scripting ability
143      * in javascript.
144      * @param window The XWalkView that needs to be closed.
145      */
146     public void onCloseWindow(XWalkView window) {}
147
148     /**
149      * Tell the client to display a javascript alert dialog.  If the client
150      * returns true, XWalkView will assume that the client will handle the
151      * dialog.  If the client returns false, it will continue execution.
152      * @param view The XWalkView that initiated the callback.
153      * @param url The url of the page requesting the dialog.
154      * @param message Message to be displayed in the window.
155      * @param result A JsResult to confirm that the user hit enter.
156      * @return boolean Whether the client will handle the alert dialog.
157      */
158     public boolean onJsAlert(XWalkView view, String url, String message,
159             JsResult result) {
160         return false;
161     }
162
163     /**
164      * Tell the client to display a confirm dialog to the user. If the client
165      * returns true, XWalkView will assume that the client will handle the
166      * confirm dialog and call the appropriate JsResult method. If the
167      * client returns false, a default value of false will be returned to
168      * javascript. The default behavior is to return false.
169      * @param view The XWalkView that initiated the callback.
170      * @param url The url of the page requesting the dialog.
171      * @param message Message to be displayed in the window.
172      * @param result A JsResult used to send the user's response to
173      *               javascript.
174      * @return boolean Whether the client will handle the confirm dialog.
175      */
176     public boolean onJsConfirm(XWalkView view, String url, String message,
177             JsResult result) {
178         return false;
179     }
180
181     /**
182      * Tell the client to display a prompt dialog to the user. If the client
183      * returns true, XWalkView will assume that the client will handle the
184      * prompt dialog and call the appropriate JsPromptResult method. If the
185      * client returns false, a default value of false will be returned to to
186      * javascript. The default behavior is to return false.
187      * @param view The XWalkView 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 defaultValue The default value displayed in the prompt dialog.
191      * @param result A JsPromptResult used to send the user's reponse to
192      *               javascript.
193      * @return boolean Whether the client will handle the prompt dialog.
194      */
195     public boolean onJsPrompt(XWalkView view, String url, String message,
196             String defaultValue, JsPromptResult result) {
197         return false;
198     }
199
200     /**
201      * Tell the client to display a dialog to confirm navigation away from the
202      * current page. This is the result of the onbeforeunload javascript event.
203      * If the client returns true, XWalkView will assume that the client will
204      * handle the confirm dialog and call the appropriate JsResult method. If
205      * the client returns false, a default value of true will be returned to
206      * javascript to accept navigation away from the current page. The default
207      * behavior is to return false. Setting the JsResult to true will navigate
208      * away from the current page, false will cancel the navigation.
209      * @param view The XWalkView that initiated the callback.
210      * @param url The url of the page requesting the dialog.
211      * @param message Message to be displayed in the window.
212      * @param result A JsResult used to send the user's response to
213      *               javascript.
214      * @return boolean Whether the client will handle the confirm dialog.
215      */
216     public boolean onJsBeforeUnload(XWalkView view, String url, String message,
217             JsResult result) {
218         return false;
219     }
220
221    /**
222     * Tell the client that the quota has been exceeded for the Web SQL Database
223     * API for a particular origin and request a new quota. The client must
224     * respond by invoking the
225     * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
226     * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
227     * minimum value that can be set for the new quota is the current quota. The
228     * default implementation responds with the current quota, so the quota will
229     * not be increased.
230     * @param url The URL of the page that triggered the notification
231     * @param databaseIdentifier The identifier of the database where the quota
232     *                           was exceeded.
233     * @param quota The quota for the origin, in bytes
234     * @param estimatedDatabaseSize The estimated size of the offending
235     *                              database, in bytes
236     * @param totalQuota The total quota for all origins, in bytes
237     * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
238     *                     must be used to inform the XWalkView of the new quota.
239     */
240     // Note that the callback must always be executed at some point to ensure
241     // that the sleeping WebCore thread is woken up.
242     // Since the parameter type WebStorage.QuotaUpdater and this API are
243     // deprecated in Android 4.4, while this parameter type and this API
244     // are still used before Android 4.4, no other API and parameter are
245     // to replace them, suppress the compiling warnings for Android 4.4
246     // due to deprecation.
247     @SuppressWarnings("deprecation")
248     public void onExceededDatabaseQuota(String url, String databaseIdentifier,
249             long quota, long estimatedDatabaseSize, long totalQuota,
250             WebStorage.QuotaUpdater quotaUpdater) {
251         // This default implementation passes the current quota back to WebCore.
252         // WebCore will interpret this that new quota was declined.
253         quotaUpdater.updateQuota(quota);
254     }
255
256    /**
257     * Tell the client that the quota has been reached for the Application Cache
258     * API and request a new quota. The client must respond by invoking the
259     * {@link WebStorage.QuotaUpdater#updateQuota(long) updateQuota(long)}
260     * method of the supplied {@link WebStorage.QuotaUpdater} instance. The
261     * minimum value that can be set for the new quota is the current quota. The
262     * default implementation responds with the current quota, so the quota will
263     * not be increased.
264     * @param requiredStorage The amount of storage required by the Application
265     *                        Cache operation that triggered this notification,
266     *                        in bytes.
267     * @param quota The quota, in bytes
268     * @param quotaUpdater An instance of {@link WebStorage.QuotaUpdater} which
269     *                     must be used to inform the XWalkView of the new quota.
270     */
271     // Note that the callback must always be executed at some point to ensure
272     // that the sleeping WebCore thread is woken up.
273     // Since the parameter type WebStorage.QuotaUpdater and this API are
274     // deprecated in Android 4.4, while this parameter type and this API
275     // are still used before Android 4.4, no other API and parameter are
276     // to replace them, suppress the compiling warnings for Android 4.4
277     // due to deprecation.
278     @SuppressWarnings("deprecation")
279     public void onReachedMaxAppCacheSize(long requiredStorage, long quota,
280             WebStorage.QuotaUpdater quotaUpdater) {
281         quotaUpdater.updateQuota(quota);
282     }
283
284     /**
285      * Notify the host application that web content from the specified origin
286      * is attempting to use the Geolocation API, but no permission state is
287      * currently set for that origin. The host application should invoke the
288      * specified callback with the desired permission state. See
289      * {@link GeolocationPermissions} for details.
290      * @param origin The origin of the web content attempting to use the
291      *               Geolocation API.
292      * @param callback The callback to use to set the permission state for the
293      *                 origin.
294      */
295     public void onGeolocationPermissionsShowPrompt(String origin,
296             XWalkGeolocationPermissions.Callback callback) {}
297
298     /**
299      * Notify the host application that a request for Geolocation permissions,
300      * made with a previous call to
301      * {@link #onGeolocationPermissionsShowPrompt(String,GeolocationPermissions.Callback) onGeolocationPermissionsShowPrompt()}
302      * has been canceled. Any related UI should therefore be hidden.
303      */
304     public void onGeolocationPermissionsHidePrompt() {}
305
306     /**
307      * Tell the client that a JavaScript execution timeout has occured. And the
308      * client may decide whether or not to interrupt the execution. If the
309      * client returns true, the JavaScript will be interrupted. If the client
310      * returns false, the execution will continue. Note that in the case of
311      * continuing execution, the timeout counter will be reset, and the callback
312      * will continue to occur if the script does not finish at the next check
313      * point.
314      * @return boolean Whether the JavaScript execution should be interrupted.
315      */
316     public boolean onJsTimeout() {
317         return true;
318     }
319
320     /**
321      * Tell the client to toggle fullscreen mode.
322      * @param enterFullscreen Whether enter or cancel fullscreen.
323      */
324     public void onToggleFullscreen(boolean enterFullscreen) {}
325
326     /**
327      * Query the fullscreen status of the client.
328      * @return boolean Whether the client is fullscreen.
329      */
330     public boolean isFullscreen() {
331         return false;
332     }
333
334     /**
335      * Report a JavaScript error message to the host application. The ChromeClient
336      * should override this to process the log message as they see fit.
337      * @param message The error message to report.
338      * @param lineNumber The line number of the error.
339      * @param sourceID The name of the source file that caused the error.
340      * @deprecated Use {@link #onConsoleMessage(ConsoleMessage) onConsoleMessage(ConsoleMessage)}
341      *      instead.
342      */
343     @Deprecated
344     public void onConsoleMessage(String message, int lineNumber, String sourceID) { }
345
346     /**
347      * Report a JavaScript console message to the host application. The ChromeClient
348      * should override this to process the log message as they see fit.
349      * @param consoleMessage Object containing details of the console message.
350      * @return true if the message is handled by the client.
351      */
352     public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
353         // Call the old version of this function for backwards compatability.
354         onConsoleMessage(consoleMessage.message(), consoleMessage.lineNumber(),
355                 consoleMessage.sourceId());
356         return false;
357     }
358
359     /**
360      * When not playing, video elements are represented by a 'poster' image. The
361      * image to use can be specified by the poster attribute of the video tag in
362      * HTML. If the attribute is absent, then a default poster will be used. This
363      * method allows the ChromeClient to provide that default image.
364      *
365      * @return Bitmap The image to use as a default poster, or null if no such image is
366      * available.
367      */
368     public Bitmap getDefaultVideoPoster() {
369         return null;
370     }
371
372     /**
373      * When the user starts to playback a video element, it may take time for enough
374      * data to be buffered before the first frames can be rendered. While this buffering
375      * is taking place, the ChromeClient can use this function to provide a View to be
376      * displayed. For example, the ChromeClient could show a spinner animation.
377      *
378      * @return View The View to be displayed whilst the video is loading.
379      */
380     public View getVideoLoadingProgressView() {
381         return null;
382     }
383
384     /** Obtains a list of all visited history items, used for link coloring
385      */
386     public void getVisitedHistory(ValueCallback<String[]> callback) {
387     }
388
389     /**
390      * Tell the client to open a file chooser.
391      * @param uploadFile A ValueCallback to set the URI of the file to upload.
392      *      onReceiveValue must be called to wake up the thread.a
393      * @param acceptType The value of the 'accept' attribute of the input tag
394      *         associated with this file picker.
395      * @param capture The value of the 'capture' attribute of the input tag
396      *         associated with this file picker.
397      * @hide
398      */
399     public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
400         uploadFile.onReceiveValue(null);
401     }
402
403     /**
404      * Tell the client that the page being viewed is web app capable,
405      * i.e. has specified the fullscreen-web-app-capable meta tag.
406      * @hide
407      */
408     public void setInstallableWebApp() { }
409
410     /**
411      * Tell the client that the page being viewed has an autofillable
412      * form and the user would like to set a profile up.
413      * @param msg A Message to send once the user has successfully
414      *      set up a profile and to inform the WebTextView it should
415      *      now autofill using that new profile.
416      * @hide
417      */
418     public void setupAutoFill(Message msg) { }
419
420 }