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.internal;
7 import android.app.AlertDialog;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.view.View;
11 import android.webkit.WebResourceResponse;
14 * This class notifies the embedder resource events/callbacks.
16 @XWalkAPI(createExternally = true)
17 public class XWalkResourceClientInternal {
23 public static final int ERROR_OK = 0;
29 public static final int ERROR_UNKNOWN = -1;
31 * Server or proxy hostname lookup failed
35 public static final int ERROR_HOST_LOOKUP = -2;
37 * Unsupported authentication scheme (not basic or digest)
41 public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
43 * User authentication failed on server
47 public static final int ERROR_AUTHENTICATION = -4;
49 * User authentication failed on proxy
53 public static final int ERROR_PROXY_AUTHENTICATION = -5;
55 * Failed to connect to the server
59 public static final int ERROR_CONNECT = -6;
61 * Failed to read or write to the server
65 public static final int ERROR_IO = -7;
67 * Connection timed out
71 public static final int ERROR_TIMEOUT = -8;
77 public static final int ERROR_REDIRECT_LOOP = -9;
79 * Unsupported URI scheme
83 public static final int ERROR_UNSUPPORTED_SCHEME = -10;
85 * Failed to perform SSL handshake
89 public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
95 public static final int ERROR_BAD_URL = -12;
101 public static final int ERROR_FILE = -13;
107 public static final int ERROR_FILE_NOT_FOUND = -14;
109 * Too many requests during this load
113 public static final int ERROR_TOO_MANY_REQUESTS = -15;
117 * @param view the owner XWalkViewInternal instance.
121 public XWalkResourceClientInternal(XWalkViewInternal view) {
122 // Keep the above parameter for future use.
126 * Notify the client that the XWalkViewInternal will load the resource specified
128 * @param view the owner XWalkViewInternal instance.
129 * @param url the url for the resource to be loaded.
133 public void onLoadStarted(XWalkViewInternal view, String url) {
137 * Notify the client that the XWalkViewInternal completes to load the resource
138 * specified by the given url.
139 * @param view the owner XWalkViewInternal instance.
140 * @param url the url for the resource done for loading.
144 public void onLoadFinished(XWalkViewInternal view, String url) {
148 * Notify the client the progress info of loading a specific url.
149 * @param view the owner XWalkViewInternal instance.
150 * @param progressInPercent the loading process in percent.
154 public void onProgressChanged(XWalkViewInternal view, int progressInPercent) {
158 * Notify the client of a resource request and allow the client to return
159 * the data. If the return value is null, the XWalkViewInternal
160 * will continue to load the resource as usual. Otherwise, the return
161 * response and data will be used. NOTE: This method is called by the
162 * network thread so clients should exercise caution when accessing private
164 * @param view The owner XWalkViewInternal instance that is requesting the
166 * @param url The raw url of the resource.
167 * @return A {@link android.webkit.WebResourceResponse} containing the
168 * response information or null if the XWalkViewInternal should load the
173 public WebResourceResponse shouldInterceptLoadRequest(XWalkViewInternal view, String url) {
178 * Report an error to the client.
179 * @param view the owner XWalkViewInternal instance.
180 * @param errorCode the error id.
181 * @param description A String describing the error.
182 * @param failingUrl The url that failed to load.
186 public void onReceivedLoadError(XWalkViewInternal view, int errorCode, String description,
188 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(view.getContext());
189 dialogBuilder.setTitle(android.R.string.dialog_alert_title)
190 .setMessage(description)
191 .setCancelable(false)
192 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
194 public void onClick(DialogInterface dialog, int which) {
198 AlertDialog dialog = dialogBuilder.create();
203 * Give the host application a chance to take over the control when a new
204 * url is about to be loaded in the current XWalkViewInternal. If XWalkClient is not
205 * provided, by default XWalkViewInternal will ask Activity Manager to choose the
206 * proper handler for the url. If XWalkClient is provided, return true
207 * means the host application handles the url, while return false means the
208 * current XWalkViewInternal handles the url.
210 * @param view The XWalkViewInternal that is initiating the callback.
211 * @param url The url to be loaded.
212 * @return True if the host application wants to leave the current XWalkViewInternal
213 * and handle the url itself, otherwise return false.
218 public boolean shouldOverrideUrlLoading(XWalkViewInternal view, String url) {