forked from davisford/chromeview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChromeAwContentsClientProxy.java
370 lines (347 loc) · 11.2 KB
/
ChromeAwContentsClientProxy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
package us.costan.chrome.impl;
import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwHttpAuthHandler;
import org.chromium.android_webview.InterceptedRequestData;
import org.chromium.android_webview.JsPromptResultReceiver;
import org.chromium.android_webview.JsResultReceiver;
import us.costan.chrome.ChromeJsResult;
import us.costan.chrome.ChromeView;
import us.costan.chrome.ChromeViewClient;
import us.costan.chrome.ChromeWebClient;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Picture;
import android.net.http.SslError;
import android.os.Build;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.DownloadListener;
import android.webkit.ValueCallback;
import android.webkit.WebResourceResponse;
import android.webkit.GeolocationPermissions.Callback;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebView.FindListener;
/** Glue that passes calls from the Chromium view to a WebChromeClient. */
public class ChromeAwContentsClientProxy extends AwContentsClient {
// Inspired from
// chromium/src/android_webview/test/shell/src/org/chromium/android_webview/test/NullContentsClient:w
// chromium/src/android_webview/javatests/src/org/chromium/android_webview/tests/*ContentsClient
// http://developer.android.com/reference/android/webkit/WebChromeClient.html
/** The view whose clients are proxied by this instance. */
private final ChromeView view_;
/** ChromeView equivalent of WebViewClient. */
private ChromeViewClient viewClient_;
/** ChromeView equivalent of WebChromeClient. */
private ChromeWebClient webClient_;
/** Receives download notifications. */
private DownloadListener downloadListener_;
/** Receives find results notifications. */
private FindListener findListener_;
/** Resets the ChromeViewClient proxy target. */
public void setChromeViewClient(ChromeViewClient chromeViewClient) {
viewClient_ = chromeViewClient;
}
/** Resets the ChromeWebClient proxy target. */
public void setChromeWebClient(ChromeWebClient chromeWebClient) {
webClient_ = chromeWebClient;
}
/** Resets the DownloadListener proxy target. */
public void setDownloadListener(DownloadListener downloadListener) {
downloadListener_ = downloadListener;
}
/** Resets the FindListener proxy target. */
public void setFindListener(FindListener findListener) {
findListener_ = findListener;
}
/**
* Creates a new proxy.
*
* @param chromeView The view whose clients are proxied by this instance.
*/
public ChromeAwContentsClientProxy(ChromeView chromeView) {
view_ = chromeView;
viewClient_ = null;
webClient_ = null;
}
@Override
public void onHideCustomView() {
// TODO Auto-generated method stub
}
@Override
public Bitmap getDefaultVideoPoster() {
// TODO Auto-generated method stub
return null;
}
//// WebChromeClient inexact proxies.
@Override
protected void handleJsAlert(String url, String message,
JsResultReceiver receiver) {
if (webClient_ != null) {
ChromeJsResult result = new ChromeJsResult(
new ChromeJsResultReceiverProxy(receiver));
if (webClient_.onJsAlert(view_, url, message, result)) {
return; // Alert will be handled by the client.
}
}
receiver.cancel(); // Default alert handling.
}
@Override
protected void handleJsBeforeUnload(String url, String message,
JsResultReceiver receiver) {
if (webClient_ != null) {
ChromeJsResult result = new ChromeJsResult(
new ChromeJsResultReceiverProxy(receiver));
if (webClient_.onJsBeforeUnload(view_, url, message,
result)) {
return; // Alert will be handled by the client.
}
}
receiver.cancel(); // Default alert handling.
}
@Override
protected void handleJsConfirm(String url, String message,
JsResultReceiver receiver) {
if (webClient_ != null) {
ChromeJsResult result = new ChromeJsResult(
new ChromeJsResultReceiverProxy(receiver));
if (webClient_.onJsAlert(view_, url, message, result)) {
return; // Alert will be handled by the client.
}
}
receiver.cancel(); // Default alert handling.
}
@Override
protected void handleJsPrompt(String url, String message,
String defaultValue, JsPromptResultReceiver receiver) {
if (webClient_ != null) {
ChromeJsResult result = new ChromeJsResult(
new ChromeJsPromptResultProxy(receiver));
if (webClient_.onJsAlert(view_, url, message, result)) {
return; // Alert will be handled by the client.
}
}
receiver.cancel(); // Default alert handling.
}
//// WebChromeClient proxy methods.
@Override
public void onProgressChanged(int progress) {
if (webClient_ != null)
webClient_.onProgressChanged(view_, progress);
}
@Override
public void onReceivedIcon(Bitmap bitmap) {
if (webClient_ != null)
webClient_.onReceivedIcon(view_, bitmap);
}
@Override
public void onReceivedTouchIconUrl(String url, boolean precomposed) {
if (webClient_ != null)
webClient_.onReceivedTouchIconUrl(view_, url, precomposed);
}
@Override
public void onShowCustomView(View view, int requestedOrientation,
CustomViewCallback callback) {
if (webClient_ != null) {
webClient_.onShowCustomView(view_, requestedOrientation,
callback);
}
}
@Override
protected boolean onCreateWindow(boolean isDialog, boolean isUserGesture) {
if (webClient_ != null) {
// TODO(pwnall): figure out what to do here
Message resultMsg = new Message();
resultMsg.setTarget(null);
resultMsg.obj = null; // WebView.WebViewTransport
return webClient_.onCreateWindow(view_, isDialog,
isUserGesture, resultMsg);
} else {
return false;
}
}
@Override
protected void onRequestFocus() {
if (webClient_ != null)
webClient_.onRequestFocus(view_);
}
@Override
protected void onCloseWindow() {
if (webClient_ != null)
webClient_.onCloseWindow(view_);
}
@Override
public void onGeolocationPermissionsShowPrompt(String origin,
Callback callback) {
if (webClient_ != null) {
webClient_.onGeolocationPermissionsShowPrompt(origin, callback);
} else {
callback.invoke(origin, false, false);
}
}
@Override
public void onGeolocationPermissionsHidePrompt() {
if (webClient_ != null)
webClient_.onGeolocationPermissionsHidePrompt();
}
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if (webClient_ != null) {
return webClient_.onConsoleMessage(consoleMessage);
} else {
return false;
}
}
@Override
protected View getVideoLoadingProgressView() {
if (webClient_ != null) {
return webClient_.getVideoLoadingProgressView();
} else {
return null;
}
}
@Override
public void getVisitedHistory(ValueCallback<String[]> callback) {
if (webClient_ != null) {
webClient_.getVisitedHistory(callback);
} else {
callback.onReceiveValue(new String[] {});
}
}
@Override
public void onReceivedTitle(String title) {
if (viewClient_ != null) {
webClient_.onReceivedTitle(view_, title);
}
}
//// WebViewClient proxy methods.
@Override
public void onPageStarted(String url) {
if (viewClient_ != null)
viewClient_.onPageStarted(view_, url, null);
}
@Override
public void onPageFinished(String url) {
if (viewClient_ != null)
viewClient_.onPageFinished(view_, url);
}
@Override
public void onLoadResource(String url) {
if (viewClient_ != null)
viewClient_.onLoadResource(view_, url);
}
@Override
public InterceptedRequestData shouldInterceptRequest(String url) {
if (viewClient_ != null) {
WebResourceResponse response =
viewClient_.shouldInterceptRequest(view_, url);
if (response != null) {
return new InterceptedRequestData(response.getMimeType(),
response.getEncoding(), response.getData());
}
}
return null;
}
@Override
public void onReceivedError(int errorCode, String description,
String failingUrl) {
if (viewClient_ != null) {
viewClient_.onReceivedError(view_, errorCode, description, failingUrl);
}
}
@Override
public void onFormResubmission(Message dontResend, Message resend) {
if (viewClient_ != null) {
viewClient_.onFormResubmission(view_, dontResend, resend);
} else {
dontResend.sendToTarget();
}
}
@Override
public void doUpdateVisitedHistory(String url, boolean isReload) {
if (viewClient_ != null)
viewClient_.doUpdateVisitedHistory(view_, url, isReload);
}
@Override
public void onReceivedSslError(ValueCallback<Boolean> callback,
SslError error) {
if (viewClient_ != null) {
ChromeSslErrorHandlerProxy handler =
new ChromeSslErrorHandlerProxy(callback);
viewClient_.onReceivedSslError(view_, handler, error);
} else {
callback.onReceiveValue(false);
}
}
@Override
public void onReceivedHttpAuthRequest(AwHttpAuthHandler handler,
String host, String realm) {
if (viewClient_ != null) {
ChromeHttpAuthHandlerProxy httpAuthHandler =
new ChromeHttpAuthHandlerProxy(handler);
viewClient_.onReceivedHttpAuthRequest(view_, httpAuthHandler,
host, realm);
} else {
handler.cancel();
}
}
@Override
public void onUnhandledKeyEvent(KeyEvent event) {
if (viewClient_ != null)
viewClient_.onUnhandledKeyEvent(view_, event);
}
@Override
public void onScaleChangedScaled(float oldScale, float newScale) {
if (viewClient_ != null)
viewClient_.onScaleChanged(view_, oldScale, newScale);
}
@Override
public void onReceivedLoginRequest(String realm, String account,
String args) {
if (viewClient_ != null) {
viewClient_.onReceivedLoginRequest(view_, realm, account,
args);
}
}
@Override
public boolean shouldOverrideKeyEvent(KeyEvent event) {
if (viewClient_ != null) {
return viewClient_.shouldOverrideKeyEvent(view_, event);
} else {
return false;
}
}
@Override
public boolean shouldOverrideUrlLoading(String url) {
if (viewClient_ != null) {
return viewClient_.shouldOverrideUrlLoading(view_, url);
} else {
return false;
}
}
// DownloadListener proxy methods.
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimeType, long contentLength) {
if (downloadListener_ != null) {
downloadListener_.onDownloadStart(url, userAgent, contentDisposition,
mimeType, contentLength);
}
}
// FindListener proxy methods.
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onFindResultReceived(int activeMatchOrdinal,
int numberOfMatches, boolean isDoneCounting) {
if (findListener_ != null) {
findListener_.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
isDoneCounting);
}
}
// PictureListener is deprecated, so we don't proxy it.
@Override
public void onNewPicture(Picture picture) {
return;
}
}