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 public class XWalkResourceClientInternal {
21 public static final int ERROR_OK = 0;
26 public static final int ERROR_UNKNOWN = -1;
28 * Server or proxy hostname lookup failed
31 public static final int ERROR_HOST_LOOKUP = -2;
33 * Unsupported authentication scheme (not basic or digest)
36 public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
38 * User authentication failed on server
41 public static final int ERROR_AUTHENTICATION = -4;
43 * User authentication failed on proxy
46 public static final int ERROR_PROXY_AUTHENTICATION = -5;
48 * Failed to connect to the server
51 public static final int ERROR_CONNECT = -6;
53 * Failed to read or write to the server
56 public static final int ERROR_IO = -7;
58 * Connection timed out
61 public static final int ERROR_TIMEOUT = -8;
66 public static final int ERROR_REDIRECT_LOOP = -9;
68 * Unsupported URI scheme
71 public static final int ERROR_UNSUPPORTED_SCHEME = -10;
73 * Failed to perform SSL handshake
76 public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
81 public static final int ERROR_BAD_URL = -12;
86 public static final int ERROR_FILE = -13;
91 public static final int ERROR_FILE_NOT_FOUND = -14;
93 * Too many requests during this load
96 public static final int ERROR_TOO_MANY_REQUESTS = -15;
100 * @param view the owner XWalkViewInternal instance.
103 public XWalkResourceClientInternal(XWalkViewInternal view) {
104 // Keep the above parameter for future use.
108 * Notify the client that the XWalkViewInternal will load the resource specified
110 * @param view the owner XWalkViewInternal instance.
111 * @param url the url for the resource to be loaded.
114 public void onLoadStarted(XWalkViewInternal view, String url) {
118 * Notify the client that the XWalkViewInternal completes to load the resource
119 * specified by the given url.
120 * @param view the owner XWalkViewInternal instance.
121 * @param url the url for the resource done for loading.
124 public void onLoadFinished(XWalkViewInternal view, String url) {
128 * Notify the client the progress info of loading a specific url.
129 * @param view the owner XWalkViewInternal instance.
130 * @param progressInPercent the loading process in percent.
133 public void onProgressChanged(XWalkViewInternal view, int progressInPercent) {
137 * Notify the client of a resource request and allow the client to return
138 * the data. If the return value is null, the XWalkViewInternal
139 * will continue to load the resource as usual. Otherwise, the return
140 * response and data will be used. NOTE: This method is called by the
141 * network thread so clients should exercise caution when accessing private
143 * @param view The {@link org.xwalk.core.internal.XWalkViewInternal} that is requesting the
145 * @param url The raw url of the resource.
146 * @return A {@link android.webkit.WebResourceResponse} containing the
147 * response information or null if the XWalkViewInternal should load the
151 public WebResourceResponse shouldInterceptLoadRequest(XWalkViewInternal view, String url) {
156 * Report an error to the client.
157 * @param view the owner XWalkViewInternal instance.
158 * @param errorCode the error id.
159 * @param description A String describing the error.
160 * @param failingUrl The url that failed to load.
163 public void onReceivedLoadError(XWalkViewInternal view, int errorCode, String description,
165 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(view.getContext());
166 dialogBuilder.setTitle(android.R.string.dialog_alert_title)
167 .setMessage(description)
168 .setCancelable(false)
169 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
171 public void onClick(DialogInterface dialog, int which) {
175 AlertDialog dialog = dialogBuilder.create();
180 * Give the host application a chance to take over the control when a new
181 * url is about to be loaded in the current XWalkViewInternal. If XWalkClient is not
182 * provided, by default XWalkViewInternal will ask Activity Manager to choose the
183 * proper handler for the url. If XWalkClient is provided, return true
184 * means the host application handles the url, while return false means the
185 * current XWalkViewInternal handles the url.
187 * @param view The XWalkViewInternal that is initiating the callback.
188 * @param url The url to be loaded.
189 * @return True if the host application wants to leave the current XWalkViewInternal
190 * and handle the url itself, otherwise return false.
194 public boolean shouldOverrideUrlLoading(XWalkViewInternal view, String url) {