Upstream version 6.35.131.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / XWalkResourceClient.java
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.
4
5 package org.xwalk.core;
6
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;
12
13 /**
14  * This class notifies the embedder resource events/callbacks.
15  */
16 public class XWalkResourceClient {
17     /** Success */
18     public static final int ERROR_OK = 0;
19     /** Generic error */
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;
41     /** Malformed URL */
42     public static final int ERROR_BAD_URL = -12;
43     /** Generic file error */
44     public static final int ERROR_FILE = -13;
45     /** File not found */
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;
49
50     /**
51      * Constructor.
52      * @param view the owner XWalkView instance.
53      */
54     public XWalkResourceClient(XWalkView view) {
55         // Keep the above parameter for future use.
56     }
57
58     /**
59      * Notify the client that the XWalkView will load the resource specified
60      * by the given url.
61      * @param view the owner XWalkView instance.
62      * @param url the url for the resource to be loaded.
63      */
64     public void onLoadStarted(XWalkView view, String url) {
65     }
66
67     /**
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.
72      */
73     public void onLoadFinished(XWalkView view, String url) {
74     }
75
76     /**
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.
80      */
81     public void onProgressChanged(XWalkView view, int progressInPercent) {
82     }
83
84     /**
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
90      * data.
91      * @param view The {@link org.xwalk.core.XWalkView} that is requesting the
92      *             resource.
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
96      *         resource itself.
97      */
98     public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
99         return null;
100     }
101
102     /**
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.
108      */
109     public void onReceivedLoadError(XWalkView view, int errorCode, String description,
110             String failingUrl) {
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() {
116                     @Override
117                     public void onClick(DialogInterface dialog, int which) {
118                         dialog.dismiss();
119                     }
120                 });
121         AlertDialog dialog = dialogBuilder.create();
122         dialog.show();
123     }
124 }