1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.core;
7 import android.webkit.WebResourceResponse;
9 import org.xwalk.core.internal.XWalkResourceClientInternal;
10 import org.xwalk.core.internal.XWalkViewInternal;
13 * This class notifies the embedder resource events/callbacks.
15 public class XWalkResourceClient extends XWalkResourceClientInternal {
20 public static final int ERROR_OK = 0;
25 public static final int ERROR_UNKNOWN = -1;
27 * Server or proxy hostname lookup failed
30 public static final int ERROR_HOST_LOOKUP = -2;
32 * Unsupported authentication scheme (not basic or digest)
35 public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
37 * User authentication failed on server
40 public static final int ERROR_AUTHENTICATION = -4;
42 * User authentication failed on proxy
45 public static final int ERROR_PROXY_AUTHENTICATION = -5;
47 * Failed to connect to the server
50 public static final int ERROR_CONNECT = -6;
52 * Failed to read or write to the server
55 public static final int ERROR_IO = -7;
57 * Connection timed out
60 public static final int ERROR_TIMEOUT = -8;
65 public static final int ERROR_REDIRECT_LOOP = -9;
67 * Unsupported URI scheme
70 public static final int ERROR_UNSUPPORTED_SCHEME = -10;
72 * Failed to perform SSL handshake
75 public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
80 public static final int ERROR_BAD_URL = -12;
85 public static final int ERROR_FILE = -13;
90 public static final int ERROR_FILE_NOT_FOUND = -14;
92 * Too many requests during this load
95 public static final int ERROR_TOO_MANY_REQUESTS = -15;
99 * @param view the owner XWalkView instance.
102 public XWalkResourceClient(XWalkView view) {
107 * Notify the client that the XWalkView will load the resource specified
109 * @param view the owner XWalkView instance.
110 * @param url the url for the resource to be loaded.
113 public void onLoadStarted(XWalkView view, String url) {
114 super.onLoadStarted(view, url);
121 public void onLoadStarted(XWalkViewInternal view, String url) {
122 if (view instanceof XWalkView) {
123 onLoadStarted((XWalkView) view, url);
125 super.onLoadStarted(view, url);
130 * Notify the client that the XWalkView completes to load the resource
131 * specified by the given url.
132 * @param view the owner XWalkView instance.
133 * @param url the url for the resource done for loading.
136 public void onLoadFinished(XWalkView view, String url) {
137 super.onLoadFinished(view, url);
144 public void onLoadFinished(XWalkViewInternal view, String url) {
145 if (view instanceof XWalkView) {
146 onLoadFinished((XWalkView) view, url);
148 super.onLoadFinished(view, url);
153 * Notify the client the progress info of loading a specific url.
154 * @param view the owner XWalkView instance.
155 * @param progressInPercent the loading process in percent.
158 public void onProgressChanged(XWalkView view, int progressInPercent) {
159 super.onProgressChanged(view, progressInPercent);
166 public void onProgressChanged(XWalkViewInternal view, int progressInPercent) {
167 if (view instanceof XWalkView) {
168 onProgressChanged((XWalkView) view, progressInPercent);
170 super.onProgressChanged(view, progressInPercent);
175 * Notify the client of a resource request and allow the client to return
176 * the data. If the return value is null, the XWalkView
177 * will continue to load the resource as usual. Otherwise, the return
178 * response and data will be used. NOTE: This method is called by the
179 * network thread so clients should exercise caution when accessing private
181 * @param view The {@link org.xwalk.core.XWalkView} that is requesting the
183 * @param url The raw url of the resource.
184 * @return A {@link android.webkit.WebResourceResponse} containing the
185 * response information or null if the XWalkView should load the
189 public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
190 return super.shouldInterceptLoadRequest(view, url);
197 public WebResourceResponse shouldInterceptLoadRequest(XWalkViewInternal view, String url) {
198 if (view instanceof XWalkView) {
199 return shouldInterceptLoadRequest((XWalkView) view, url);
202 return super.shouldInterceptLoadRequest(view, url);
206 * Report an error to the client.
207 * @param view the owner XWalkView instance.
208 * @param errorCode the error id.
209 * @param description A String describing the error.
210 * @param failingUrl The url that failed to load.
213 public void onReceivedLoadError(XWalkView view, int errorCode, String description,
215 super.onReceivedLoadError(view, errorCode, description, failingUrl);
222 public void onReceivedLoadError(XWalkViewInternal view, int errorCode, String description,
224 if (view instanceof XWalkView) {
225 onReceivedLoadError((XWalkView) view, errorCode, description, failingUrl);
227 super.onReceivedLoadError(view, errorCode, description, failingUrl);
232 * Give the host application a chance to take over the control when a new
233 * url is about to be loaded in the current XWalkView. If XWalkClient is not
234 * provided, by default XWalkView will ask Activity Manager to choose the
235 * proper handler for the url. If XWalkClient is provided, return true
236 * means the host application handles the url, while return false means the
237 * current XWalkView handles the url.
239 * @param view The XWalkView that is initiating the callback.
240 * @param url The url to be loaded.
241 * @return True if the host application wants to leave the current XWalkView
242 * and handle the url itself, otherwise return false.
246 public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
247 return super.shouldOverrideUrlLoading(view, url);
254 public boolean shouldOverrideUrlLoading(XWalkViewInternal view, String url) {
255 if (view instanceof XWalkView) {
256 return shouldOverrideUrlLoading((XWalkView) view, url);
259 return super.shouldOverrideUrlLoading(view, url);