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.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 XWalkResourceClient {
18 public static final int ERROR_OK = 0;
20 public static final int ERROR_UNKNOWN = -1;
21 /** Server or proxy hostname lookup failed */
22 public static final int ERROR_HOST_LOOKUP = -2;
23 /** Unsupported authentication scheme (not basic or digest) */
24 public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
25 /** User authentication failed on server */
26 public static final int ERROR_AUTHENTICATION = -4;
27 /** User authentication failed on proxy */
28 public static final int ERROR_PROXY_AUTHENTICATION = -5;
29 /** Failed to connect to the server */
30 public static final int ERROR_CONNECT = -6;
31 /** Failed to read or write to the server */
32 public static final int ERROR_IO = -7;
33 /** Connection timed out */
34 public static final int ERROR_TIMEOUT = -8;
35 /** Too many redirects */
36 public static final int ERROR_REDIRECT_LOOP = -9;
37 /** Unsupported URI scheme */
38 public static final int ERROR_UNSUPPORTED_SCHEME = -10;
39 /** Failed to perform SSL handshake */
40 public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
42 public static final int ERROR_BAD_URL = -12;
43 /** Generic file error */
44 public static final int ERROR_FILE = -13;
46 public static final int ERROR_FILE_NOT_FOUND = -14;
47 /** Too many requests during this load */
48 public static final int ERROR_TOO_MANY_REQUESTS = -15;
52 * @param view the owner XWalkView instance.
54 public XWalkResourceClient(XWalkView view) {
55 // Keep the above parameter for future use.
59 * Notify the client that the XWalkView will load the resource specified
61 * @param view the owner XWalkView instance.
62 * @param url the url for the resource to be loaded.
64 public void onLoadStarted(XWalkView view, String url) {
68 * Notify the client that the XWalkView completes to load the resource
69 * specified by the given url.
70 * @param view the owner XWalkView instance.
71 * @param url the url for the resource done for loading.
73 public void onLoadFinished(XWalkView view, String url) {
77 * Notify the client the progress info of loading a specific url.
78 * @param view the owner XWalkView instance.
79 * @param progressInPercent the loading process in percent.
81 public void onProgressChanged(XWalkView view, int progressInPercent) {
85 * Notify the client of a resource request and allow the client to return
86 * the data. If the return value is null, the XWalkView
87 * will continue to load the resource as usual. Otherwise, the return
88 * response and data will be used. NOTE: This method is called by the
89 * network thread so clients should exercise caution when accessing private
91 * @param view The {@link org.xwalk.core.XWalkView} that is requesting the
93 * @param url The raw url of the resource.
94 * @return A {@link android.webkit.WebResourceResponse} containing the
95 * response information or null if the XWalkView should load the
98 public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
103 * Report an error to the client.
104 * @param view the owner XWalkView instance.
105 * @param errorCode the error id.
106 * @param description A String describing the error.
107 * @param failingUrl The url that failed to load.
109 public void onReceivedLoadError(XWalkView view, int errorCode, String description,
111 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(view.getContext());
112 dialogBuilder.setTitle(android.R.string.dialog_alert_title)
113 .setMessage(description)
114 .setCancelable(false)
115 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
117 public void onClick(DialogInterface dialog, int which) {
121 AlertDialog dialog = dialogBuilder.create();