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.app.AlertDialog;
8 import android.content.DialogInterface;
9 import android.webkit.WebResourceResponse;
11 import org.xwalk.core.internal.XWalkResourceClientInternal;
12 import org.xwalk.core.internal.XWalkViewInternal;
15 * This class notifies the embedder resource events/callbacks.
17 public class XWalkResourceClient extends XWalkResourceClientInternal {
22 public static final int ERROR_OK = 0;
27 public static final int ERROR_UNKNOWN = -1;
29 * Server or proxy hostname lookup failed
32 public static final int ERROR_HOST_LOOKUP = -2;
34 * Unsupported authentication scheme (not basic or digest)
37 public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
39 * User authentication failed on server
42 public static final int ERROR_AUTHENTICATION = -4;
44 * User authentication failed on proxy
47 public static final int ERROR_PROXY_AUTHENTICATION = -5;
49 * Failed to connect to the server
52 public static final int ERROR_CONNECT = -6;
54 * Failed to read or write to the server
57 public static final int ERROR_IO = -7;
59 * Connection timed out
62 public static final int ERROR_TIMEOUT = -8;
67 public static final int ERROR_REDIRECT_LOOP = -9;
69 * Unsupported URI scheme
72 public static final int ERROR_UNSUPPORTED_SCHEME = -10;
74 * Failed to perform SSL handshake
77 public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
82 public static final int ERROR_BAD_URL = -12;
87 public static final int ERROR_FILE = -13;
92 public static final int ERROR_FILE_NOT_FOUND = -14;
94 * Too many requests during this load
97 public static final int ERROR_TOO_MANY_REQUESTS = -15;
101 * @param view the owner XWalkView instance.
104 public XWalkResourceClient(XWalkView view) {
109 * Notify the client that the XWalkView will load the resource specified
111 * @param view the owner XWalkView instance.
112 * @param url the url for the resource to be loaded.
115 public void onLoadStarted(XWalkView view, String url) {
116 super.onLoadStarted(view, url);
123 public void onLoadStarted(XWalkViewInternal view, String url) {
124 if (view instanceof XWalkView) {
125 onLoadStarted((XWalkView) view, url);
127 super.onLoadStarted(view, url);
132 * Notify the client that the XWalkView completes to load the resource
133 * specified by the given url.
134 * @param view the owner XWalkView instance.
135 * @param url the url for the resource done for loading.
138 public void onLoadFinished(XWalkView view, String url) {
139 super.onLoadFinished(view, url);
146 public void onLoadFinished(XWalkViewInternal view, String url) {
147 if (view instanceof XWalkView) {
148 onLoadFinished((XWalkView) view, url);
150 super.onLoadFinished(view, url);
155 * Notify the client the progress info of loading a specific url.
156 * @param view the owner XWalkView instance.
157 * @param progressInPercent the loading process in percent.
160 public void onProgressChanged(XWalkView view, int progressInPercent) {
161 super.onProgressChanged(view, progressInPercent);
168 public void onProgressChanged(XWalkViewInternal view, int progressInPercent) {
169 if (view instanceof XWalkView) {
170 onProgressChanged((XWalkView) view, progressInPercent);
172 super.onProgressChanged(view, progressInPercent);
177 * Notify the client of a resource request and allow the client to return
178 * the data. If the return value is null, the XWalkView
179 * will continue to load the resource as usual. Otherwise, the return
180 * response and data will be used. NOTE: This method is called by the
181 * network thread so clients should exercise caution when accessing private
183 * @param view The {@link org.xwalk.core.XWalkView} that is requesting the
185 * @param url The raw url of the resource.
186 * @return A {@link android.webkit.WebResourceResponse} containing the
187 * response information or null if the XWalkView should load the
191 public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
192 return super.shouldInterceptLoadRequest(view, url);
199 public WebResourceResponse shouldInterceptLoadRequest(XWalkViewInternal view, String url) {
200 if (view instanceof XWalkView) {
201 return shouldInterceptLoadRequest((XWalkView) view, url);
204 return super.shouldInterceptLoadRequest(view, url);
208 * Report an error to the client.
209 * @param view the owner XWalkView instance.
210 * @param errorCode the error id.
211 * @param description A String describing the error.
212 * @param failingUrl The url that failed to load.
215 public void onReceivedLoadError(XWalkView view, int errorCode, String description,
217 super.onReceivedLoadError(view, errorCode, description, failingUrl);
224 public void onReceivedLoadError(XWalkViewInternal view, int errorCode, String description,
226 if (view instanceof XWalkView) {
227 onReceivedLoadError((XWalkView) view, errorCode, description, failingUrl);
229 super.onReceivedLoadError(view, errorCode, description, failingUrl);