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