2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.xwalk.core;
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;
25 public class XWalkClient {
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.
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.
40 public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
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.
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
56 public void onPageStarted(XWalkView view, String url, Bitmap favicon) {
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}.
65 * @param view The XWalkView that is initiating the callback.
66 * @param url The url of the page.
68 public void onPageFinished(XWalkView view, String url) {
72 * Notify the host application that a web page is closed by calling
75 public void onCloseWindow(XWalkView view) {
79 * Notify the host application that the XWalkView will load the resource
80 * specified by the given url.
82 * @param view The XWalkView that is initiating the callback.
83 * @param url The url of the resource the XWalkView will load.
85 public void onLoadResource(XWalkView view, String url) {
89 * Notify the host application that the renderer of XWalkView is hung.
91 * @param view The XWalkView on which the render is hung.
93 public void onRendererUnresponsive(XWalkView view) {
97 * Notify the host application that the renderer of XWalkView is no longer hung.
99 * @param view The XWalkView which becomes responsive now.
101 public void onRendererResponsive(XWalkView view) {
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
112 * @param view The {@link android.webkit.XWalkView} that is requesting the
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
119 public WebResourceResponse shouldInterceptRequest(XWalkView view,
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
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.
137 public void onTooManyRedirects(XWalkView view, Message cancelMsg,
138 Message continueMsg) {
139 cancelMsg.sendToTarget();
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.
151 public void onReceivedError(XWalkView view, int errorCode,
152 String description, String failingUrl) {
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
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
164 public void onFormResubmission(XWalkView view, Message dontResend,
166 dontResend.sendToTarget();
170 * Notify the host application to update its visited links database.
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.
176 public void doUpdateVisitedHistory(XWalkView view, String url,
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
187 * @param view The XWalkView that is initiating the callback.
188 * @param handler An SslErrorHandler object that will handle the user's
190 * @param error The SSL error object.
192 public void onReceivedSslError(XWalkView view, SslErrorHandler handler,
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().
203 public void onProceededAfterSslError(XWalkView view, SslError error) {
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.
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.
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) {
229 * Notify the host application to handle an authentication request. The
230 * default behavior is to cancel the request.
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
238 public void onReceivedHttpAuthRequest(XWalkView view,
239 XWalkHttpAuthHandler handler, String host, String realm) {
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.
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
255 public boolean shouldOverrideKeyEvent(XWalkView view, KeyEvent event) {
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.
266 * @param view The XWalkView that is initiating the callback.
267 * @param event The key event.
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);
278 * Notify the host application that the scale applied to the XWalkView has
281 * @param view he XWalkView that is initiating the callback.
282 * @param oldScale The old scale factor
283 * @param newScale The new scale factor
285 public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
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.
298 public void onReceivedLoginRequest(XWalkView view, String realm,
299 String account, String args) {