Upstream version 9.37.193.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.webkit.WebResourceResponse;
8
9 import org.xwalk.core.internal.XWalkResourceClientInternal;
10 import org.xwalk.core.internal.XWalkViewInternal;
11
12 /**
13  * This class notifies the embedder resource events/callbacks.
14  */
15 public class XWalkResourceClient extends XWalkResourceClientInternal {
16     /**
17      * Success
18      * @since 1.0
19      */
20     public static final int ERROR_OK = 0;
21     /**
22      * Generic error
23      * @since 1.0
24      */
25     public static final int ERROR_UNKNOWN = -1;
26     /**
27      * Server or proxy hostname lookup failed
28      * @since 1.0
29      */
30     public static final int ERROR_HOST_LOOKUP = -2;
31     /**
32      * Unsupported authentication scheme (not basic or digest)
33      * @since 1.0
34      */
35     public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
36     /**
37      * User authentication failed on server
38      * @since 1.0
39      */
40     public static final int ERROR_AUTHENTICATION = -4;
41     /**
42      * User authentication failed on proxy
43      * @since 1.0
44      */
45     public static final int ERROR_PROXY_AUTHENTICATION = -5;
46     /**
47      * Failed to connect to the server
48      * @since 1.0
49      */
50     public static final int ERROR_CONNECT = -6;
51     /**
52      * Failed to read or write to the server
53      * @since 1.0
54      */
55     public static final int ERROR_IO = -7;
56     /**
57      * Connection timed out
58      * @since 1.0
59      */
60     public static final int ERROR_TIMEOUT = -8;
61     /**
62      * Too many redirects
63      * @since 1.0
64      */
65     public static final int ERROR_REDIRECT_LOOP = -9;
66     /**
67      * Unsupported URI scheme
68      * @since 1.0
69      */
70     public static final int ERROR_UNSUPPORTED_SCHEME = -10;
71     /**
72      * Failed to perform SSL handshake
73      * @since 1.0
74      */
75     public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
76     /**
77      * Malformed URL
78      * @since 1.0
79      */
80     public static final int ERROR_BAD_URL = -12;
81     /**
82      * Generic file error
83      * @since 1.0
84      */
85     public static final int ERROR_FILE = -13;
86     /**
87      * File not found
88      * @since 1.0
89      */
90     public static final int ERROR_FILE_NOT_FOUND = -14;
91     /**
92      * Too many requests during this load
93      * @since 1.0
94      */
95     public static final int ERROR_TOO_MANY_REQUESTS = -15;
96
97     /**
98      * Constructor.
99      * @param view the owner XWalkView instance.
100      * @since 1.0
101      */
102     public XWalkResourceClient(XWalkView view) {
103         super(view);
104     }
105
106     /**
107      * Notify the client that the XWalkView will load the resource specified
108      * by the given url.
109      * @param view the owner XWalkView instance.
110      * @param url the url for the resource to be loaded.
111      * @since 1.0
112      */
113     public void onLoadStarted(XWalkView view, String url) {
114         super.onLoadStarted(view, url);
115     }
116
117     /**
118      * @hide
119      */
120     @Override
121     public void onLoadStarted(XWalkViewInternal view, String url) {
122         if (view instanceof XWalkView) {
123             onLoadStarted((XWalkView) view, url);
124         } else {
125             super.onLoadStarted(view, url);
126         }
127     }
128
129     /**
130      * Notify the client that the XWalkView completes to load the resource
131      * specified by the given url.
132      * @param view the owner XWalkView instance.
133      * @param url the url for the resource done for loading.
134      * @since 1.0
135      */
136     public void onLoadFinished(XWalkView view, String url) {
137         super.onLoadFinished(view, url);
138     }
139
140     /**
141      * @hide
142      */
143     @Override
144     public void onLoadFinished(XWalkViewInternal view, String url) {
145         if (view instanceof XWalkView) {
146             onLoadFinished((XWalkView) view, url);
147         } else {
148             super.onLoadFinished(view, url);
149         }
150     }
151
152     /**
153      * Notify the client the progress info of loading a specific url.
154      * @param view the owner XWalkView instance.
155      * @param progressInPercent the loading process in percent.
156      * @since 1.0
157      */
158     public void onProgressChanged(XWalkView view, int progressInPercent) {
159         super.onProgressChanged(view, progressInPercent);
160     }
161
162     /**
163      * @hide
164      */
165     @Override
166     public void onProgressChanged(XWalkViewInternal view, int progressInPercent) {
167         if (view instanceof XWalkView) {
168             onProgressChanged((XWalkView) view, progressInPercent);
169         } else {
170             super.onProgressChanged(view, progressInPercent);
171         }
172     }
173
174     /**
175      * Notify the client of a resource request and allow the client to return
176      * the data.  If the return value is null, the XWalkView
177      * will continue to load the resource as usual.  Otherwise, the return
178      * response and data will be used.  NOTE: This method is called by the
179      * network thread so clients should exercise caution when accessing private
180      * data.
181      * @param view The {@link org.xwalk.core.XWalkView} that is requesting the
182      *             resource.
183      * @param url The raw url of the resource.
184      * @return A {@link android.webkit.WebResourceResponse} containing the
185      *         response information or null if the XWalkView should load the
186      *         resource itself.
187      * @since 1.0
188      */
189     public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
190         return super.shouldInterceptLoadRequest(view, url);
191     }
192
193     /**
194      * @hide
195      */
196     @Override
197     public WebResourceResponse shouldInterceptLoadRequest(XWalkViewInternal view, String url) {
198         if (view instanceof XWalkView) {
199             return shouldInterceptLoadRequest((XWalkView) view, url);
200         }
201
202         return super.shouldInterceptLoadRequest(view, url);
203     }
204
205     /**
206      * Report an error to the client.
207      * @param view the owner XWalkView instance.
208      * @param errorCode the error id.
209      * @param description A String describing the error.
210      * @param failingUrl The url that failed to load.
211      * @since 1.0
212      */
213     public void onReceivedLoadError(XWalkView view, int errorCode, String description,
214             String failingUrl) {
215         super.onReceivedLoadError(view, errorCode, description, failingUrl);
216     }
217
218     /**
219      * @hide
220      */
221     @Override
222     public void onReceivedLoadError(XWalkViewInternal view, int errorCode, String description,
223             String failingUrl) {
224         if (view instanceof XWalkView) {
225             onReceivedLoadError((XWalkView) view, errorCode, description, failingUrl);
226         } else {
227             super.onReceivedLoadError(view, errorCode, description, failingUrl);
228         }
229     }
230
231     /**
232      * Give the host application a chance to take over the control when a new
233      * url is about to be loaded in the current XWalkView. If XWalkClient is not
234      * provided, by default XWalkView will ask Activity Manager to choose the
235      * proper handler for the url. If XWalkClient is provided, return true
236      * means the host application handles the url, while return false means the
237      * current XWalkView handles the url.
238      *
239      * @param view The XWalkView that is initiating the callback.
240      * @param url The url to be loaded.
241      * @return True if the host application wants to leave the current XWalkView
242      *         and handle the url itself, otherwise return false.
243      *
244      * @since 2.1
245      */
246     public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
247         return super.shouldOverrideUrlLoading(view, url);
248     }
249
250     /**
251      * @hide
252      */
253     @Override
254     public boolean shouldOverrideUrlLoading(XWalkViewInternal view, String url) {
255         if (view instanceof XWalkView) {
256             return shouldOverrideUrlLoading((XWalkView) view, url);
257         }
258
259         return super.shouldOverrideUrlLoading(view, url);
260     }
261 }