Upstream version 5.34.97.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / XWalkClient.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.graphics.Bitmap;
20 import android.net.http.SslError;
21 import android.os.Message;
22 import android.view.KeyEvent;
23 import android.webkit.WebResourceResponse;
24
25 public class XWalkClient {
26
27     /**
28      * Give the host application a chance to take over the control when a new
29      * url is about to be loaded in the current XWalkView. If XWalkClient is not
30      * provided, by default XWalkView will ask Activity Manager to choose the
31      * proper handler for the url. If XWalkClient is provided, return true
32      * means the host application handles the url, while return false means the
33      * current XWalkView handles the url.
34      *
35      * @param view The XWalkView that is initiating the callback.
36      * @param url The url to be loaded.
37      * @return True if the host application wants to leave the current XWalkView
38      *         and handle the url itself, otherwise return false.
39      */
40     public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
41         return false;
42     }
43
44     /**
45      * Notify the host application that a page has started loading. This method
46      * is called once for each main frame load so a page with iframes or
47      * framesets will call onPageStarted one time for the main frame. This also
48      * means that onPageStarted will not be called when the contents of an
49      * embedded frame changes, i.e. clicking a link whose target is an iframe.
50      *
51      * @param view The XWalkView that is initiating the callback.
52      * @param url The url to be loaded.
53      * @param favicon The favicon for this page if it already exists in the
54      *            database.
55      */
56     public void onPageStarted(XWalkView view, String url, Bitmap favicon) {
57     }
58
59     /**
60      * Notify the host application that a page has finished loading. This method
61      * is called only for main frame. When onPageFinished() is called, the
62      * rendering picture may not be updated yet. To get the notification for the
63      * new Picture, use {@link XWalkView.PictureListener#onNewPicture}.
64      *
65      * @param view The XWalkView that is initiating the callback.
66      * @param url The url of the page.
67      */
68     public void onPageFinished(XWalkView view, String url) {
69     }
70
71     /**
72      * Notify the host application that a web page is closed by calling
73      * window.close().
74      */
75     public void onCloseWindow(XWalkView view) {
76     }
77
78     /**
79      * Notify the host application that the XWalkView will load the resource
80      * specified by the given url.
81      *
82      * @param view The XWalkView that is initiating the callback.
83      * @param url The url of the resource the XWalkView will load.
84      */
85     public void onLoadResource(XWalkView view, String url) {
86     }
87
88     /**
89      * Notify the host application that the renderer of XWalkView is hung.
90      *
91      * @param view The XWalkView on which the render is hung.
92      */
93     public void onRendererUnresponsive(XWalkView view) {
94     }
95
96     /**
97      * Notify the host application that the renderer of XWalkView is no longer hung.
98      *
99      * @param view The XWalkView which becomes responsive now.
100      */
101     public void onRendererResponsive(XWalkView view) {
102     }
103
104     /**
105      * Notify the host application of a resource request and allow the
106      * application to return the data.  If the return value is null, the XWalkView
107      * will continue to load the resource as usual.  Otherwise, the return
108      * response and data will be used.  NOTE: This method is called by the
109      * network thread so clients should exercise caution when accessing private
110      * data.
111      *
112      * @param view The {@link android.webkit.XWalkView} that is requesting the
113      *             resource.
114      * @param url The raw url of the resource.
115      * @return A {@link android.webkit.WebResourceResponse} containing the
116      *         response information or null if the XWalkView should load the
117      *         resource itself.
118      */
119     public WebResourceResponse shouldInterceptRequest(XWalkView view,
120             String url) {
121         return null;
122     }
123
124     /**
125      * Notify the host application that there have been an excessive number of
126      * HTTP redirects. As the host application if it would like to continue
127      * trying to load the resource. The default behavior is to send the cancel
128      * message.
129      *
130      * @param view The XWalkView that is initiating the callback.
131      * @param cancelMsg The message to send if the host wants to cancel
132      * @param continueMsg The message to send if the host wants to continue
133      * @deprecated This method is no longer called. When the XWalkView encounters
134      *             a redirect loop, it will cancel the load.
135      */
136     @Deprecated
137     public void onTooManyRedirects(XWalkView view, Message cancelMsg,
138             Message continueMsg) {
139         cancelMsg.sendToTarget();
140     }
141
142     /**
143      * Report an error to the host application. These errors are unrecoverable
144      * (i.e. the main resource is unavailable). The errorCode parameter
145      * corresponds to one of the ERROR_* constants.
146      * @param view The XWalkView that is initiating the callback.
147      * @param errorCode The error code corresponding to an ERROR_* value.
148      * @param description A String describing the error.
149      * @param failingUrl The url that failed to load.
150      */
151     public void onReceivedError(XWalkView view, int errorCode,
152             String description, String failingUrl) {
153     }
154
155     /**
156      * As the host application if the browser should resend data as the
157      * requested page was a result of a POST. The default is to not resend the
158      * data.
159      *
160      * @param view The XWalkView that is initiating the callback.
161      * @param dontResend The message to send if the browser should not resend
162      * @param resend The message to send if the browser should resend data
163      */
164     public void onFormResubmission(XWalkView view, Message dontResend,
165             Message resend) {
166         dontResend.sendToTarget();
167     }
168
169     /**
170      * Notify the host application to update its visited links database.
171      *
172      * @param view The XWalkView that is initiating the callback.
173      * @param url The url being visited.
174      * @param isReload True if this url is being reloaded.
175      */
176     public void doUpdateVisitedHistory(XWalkView view, String url,
177             boolean isReload) {
178     }
179
180     /**
181      * Notify the host application that an SSL error occurred while loading a
182      * resource. The host application must call either handler.cancel() or
183      * handler.proceed(). Note that the decision may be retained for use in
184      * response to future SSL errors. The default behavior is to cancel the
185      * load.
186      *
187      * @param view The XWalkView that is initiating the callback.
188      * @param handler An SslErrorHandler object that will handle the user's
189      *            response.
190      * @param error The SSL error object.
191      */
192     public void onReceivedSslError(XWalkView view, SslErrorHandler handler,
193             SslError error) {
194         handler.cancel();
195     }
196
197     /**
198      * Notify the host application that an SSL error occurred while loading a
199      * resource, but the XWalkView chose to proceed anyway based on a
200      * decision retained from a previous response to onReceivedSslError().
201      * @hide
202      */
203     public void onProceededAfterSslError(XWalkView view, SslError error) {
204     }
205
206     /**
207      * Notify the host application to handle a SSL client certificate
208      * request (display the request to the user and ask whether to
209      * proceed with a client certificate or not). The host application
210      * has to call either handler.cancel() or handler.proceed() as the
211      * connection is suspended and waiting for the response. The
212      * default behavior is to cancel, returning no client certificate.
213      *
214      * @param view The XWalkView that is initiating the callback.
215      * @param handler A ClientCertRequestHandler object that will
216      *            handle the user's response.
217      * @param host_and_port The host and port of the requesting server.
218      *
219      * @hide
220      */
221     // TODO: comment this method temporarily, will implemtent later when all
222     //       dependencies are resovled.
223     // public void onReceivedClientCertRequest(XWalkView view,
224     //         ClientCertRequestHandler handler, String host_and_port) {
225     //     handler.cancel();
226     // }
227
228     /**
229      * Notify the host application to handle an authentication request. The
230      * default behavior is to cancel the request.
231      *
232      * @param view The XWalkView that is initiating the callback.
233      * @param handler The XWalkHttpAuthHandler that will handle the user's response.
234      * @param host The host requiring authentication.
235      * @param realm A description to help store user credentials for future
236      *            visits.
237      */
238     public void onReceivedHttpAuthRequest(XWalkView view,
239             XWalkHttpAuthHandler handler, String host, String realm) {
240         handler.cancel();
241     }
242
243     /**
244      * Give the host application a chance to handle the key event synchronously.
245      * e.g. menu shortcut key events need to be filtered this way. If return
246      * true, XWalkView will not handle the key event. If return false, XWalkView
247      * will always handle the key event, so none of the super in the view chain
248      * will see the key event. The default behavior returns false.
249      *
250      * @param view The XWalkView that is initiating the callback.
251      * @param event The key event.
252      * @return True if the host application wants to handle the key event
253      *         itself, otherwise return false
254      */
255     public boolean shouldOverrideKeyEvent(XWalkView view, KeyEvent event) {
256         return false;
257     }
258
259     /**
260      * Notify the host application that a key was not handled by the XWalkView.
261      * Except system keys, XWalkView always consumes the keys in the normal flow
262      * or if shouldOverrideKeyEvent returns true. This is called asynchronously
263      * from where the key is dispatched. It gives the host application a chance
264      * to handle the unhandled key events.
265      *
266      * @param view The XWalkView that is initiating the callback.
267      * @param event The key event.
268      */
269     public void onUnhandledKeyEvent(XWalkView view, KeyEvent event) {
270         // TODO: Commment the below code for compile
271         // ViewRootImpl root = view.getViewRootImpl();
272         // if (root != null) {
273         //     root.dispatchUnhandledKey(event);
274         // }
275     }
276
277     /**
278      * Notify the host application that the scale applied to the XWalkView has
279      * changed.
280      *
281      * @param view he XWalkView that is initiating the callback.
282      * @param oldScale The old scale factor
283      * @param newScale The new scale factor
284      */
285     public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
286     }
287
288     /**
289      * Notify the host application that a request to automatically log in the
290      * user has been processed.
291      * @param view The XWalkView requesting the login.
292      * @param realm The account realm used to look up accounts.
293      * @param account An optional account. If not null, the account should be
294      *                checked against accounts on the device. If it is a valid
295      *                account, it should be used to log in the user.
296      * @param args Authenticator specific arguments used to log in the user.
297      */
298     public void onReceivedLoginRequest(XWalkView view, String realm,
299             String account, String args) {
300     }
301 }