| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package com.android.webview.chromium; | 5 package com.android.webview.chromium; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ActivityNotFoundException; | 8 import android.content.ActivityNotFoundException; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 //--------------------------------------------------------------------------
------------------ | 236 //--------------------------------------------------------------------------
------------------ |
| 237 // Adapter for all the methods. | 237 // Adapter for all the methods. |
| 238 //--------------------------------------------------------------------------
------------------ | 238 //--------------------------------------------------------------------------
------------------ |
| 239 | 239 |
| 240 /** | 240 /** |
| 241 * @see AwContentsClient#getVisitedHistory | 241 * @see AwContentsClient#getVisitedHistory |
| 242 */ | 242 */ |
| 243 @Override | 243 @Override |
| 244 public void getVisitedHistory(ValueCallback<String[]> callback) { | 244 public void getVisitedHistory(ValueCallback<String[]> callback) { |
| 245 TraceEvent.begin(); | 245 try { |
| 246 if (mWebChromeClient != null) { | 246 TraceEvent.begin("WebViewContentsClientAdapter.getVisitedHistory"); |
| 247 if (TRACE) Log.d(TAG, "getVisitedHistory"); | 247 if (mWebChromeClient != null) { |
| 248 mWebChromeClient.getVisitedHistory(callback); | 248 if (TRACE) Log.d(TAG, "getVisitedHistory"); |
| 249 mWebChromeClient.getVisitedHistory(callback); |
| 250 } |
| 251 } finally { |
| 252 TraceEvent.end("WebViewContentsClientAdapter.getVisitedHistory"); |
| 249 } | 253 } |
| 250 TraceEvent.end(); | |
| 251 } | 254 } |
| 252 | 255 |
| 253 /** | 256 /** |
| 254 * @see AwContentsClient#doUpdateVisiteHistory(String, boolean) | 257 * @see AwContentsClient#doUpdateVisiteHistory(String, boolean) |
| 255 */ | 258 */ |
| 256 @Override | 259 @Override |
| 257 public void doUpdateVisitedHistory(String url, boolean isReload) { | 260 public void doUpdateVisitedHistory(String url, boolean isReload) { |
| 258 TraceEvent.begin(); | 261 try { |
| 259 if (TRACE) Log.d(TAG, "doUpdateVisitedHistory=" + url + " reload=" + isR
eload); | 262 TraceEvent.begin("WebViewContentsClientAdapter.doUpdateVisitedHistor
y"); |
| 260 mWebViewClient.doUpdateVisitedHistory(mWebView, url, isReload); | 263 if (TRACE) Log.d(TAG, "doUpdateVisitedHistory=" + url + " reload=" +
isReload); |
| 261 TraceEvent.end(); | 264 mWebViewClient.doUpdateVisitedHistory(mWebView, url, isReload); |
| 265 } finally { |
| 266 TraceEvent.end("WebViewContentsClientAdapter.doUpdateVisitedHistory"
); |
| 267 } |
| 262 } | 268 } |
| 263 | 269 |
| 264 /** | 270 /** |
| 265 * @see AwContentsClient#onProgressChanged(int) | 271 * @see AwContentsClient#onProgressChanged(int) |
| 266 */ | 272 */ |
| 267 @Override | 273 @Override |
| 268 public void onProgressChanged(int progress) { | 274 public void onProgressChanged(int progress) { |
| 269 TraceEvent.begin(); | 275 try { |
| 270 if (mWebChromeClient != null) { | 276 TraceEvent.begin("WebViewContentsClientAdapter.onProgressChanged"); |
| 271 if (TRACE) Log.d(TAG, "onProgressChanged=" + progress); | 277 if (mWebChromeClient != null) { |
| 272 mWebChromeClient.onProgressChanged(mWebView, progress); | 278 if (TRACE) Log.d(TAG, "onProgressChanged=" + progress); |
| 279 mWebChromeClient.onProgressChanged(mWebView, progress); |
| 280 } |
| 281 } finally { |
| 282 TraceEvent.end("WebViewContentsClientAdapter.onProgressChanged"); |
| 273 } | 283 } |
| 274 TraceEvent.end(); | |
| 275 } | 284 } |
| 276 | 285 |
| 277 private static class WebResourceRequestImpl implements WebResourceRequest { | 286 private static class WebResourceRequestImpl implements WebResourceRequest { |
| 278 private final ShouldInterceptRequestParams mParams; | 287 private final ShouldInterceptRequestParams mParams; |
| 279 | 288 |
| 280 public WebResourceRequestImpl(ShouldInterceptRequestParams params) { | 289 public WebResourceRequestImpl(ShouldInterceptRequestParams params) { |
| 281 mParams = params; | 290 mParams = params; |
| 282 } | 291 } |
| 283 | 292 |
| 284 @Override | 293 @Override |
| (...skipping 20 matching lines...) Expand all Loading... |
| 305 public Map<String, String> getRequestHeaders() { | 314 public Map<String, String> getRequestHeaders() { |
| 306 return mParams.requestHeaders; | 315 return mParams.requestHeaders; |
| 307 } | 316 } |
| 308 } | 317 } |
| 309 | 318 |
| 310 /** | 319 /** |
| 311 * @see AwContentsClient#shouldInterceptRequest(java.lang.String) | 320 * @see AwContentsClient#shouldInterceptRequest(java.lang.String) |
| 312 */ | 321 */ |
| 313 @Override | 322 @Override |
| 314 public AwWebResourceResponse shouldInterceptRequest(ShouldInterceptRequestPa
rams params) { | 323 public AwWebResourceResponse shouldInterceptRequest(ShouldInterceptRequestPa
rams params) { |
| 315 TraceEvent.begin(); | 324 try { |
| 316 if (TRACE) Log.d(TAG, "shouldInterceptRequest=" + params.url); | 325 TraceEvent.begin("WebViewContentsClientAdapter.shouldInterceptReques
t"); |
| 317 WebResourceResponse response = | 326 if (TRACE) Log.d(TAG, "shouldInterceptRequest=" + params.url); |
| 318 mWebViewClient.shouldInterceptRequest(mWebView, new WebResourceR
equestImpl(params)); | 327 WebResourceResponse response = mWebViewClient.shouldInterceptRequest
(mWebView, |
| 319 TraceEvent.end(); | 328 new WebResourceRequestImpl(params)); |
| 320 if (response == null) return null; | 329 if (response == null) return null; |
| 321 | 330 |
| 322 // AwWebResourceResponse should support null headers. b/16332774. | 331 // AwWebResourceResponse should support null headers. b/16332774. |
| 323 Map<String, String> responseHeaders = response.getResponseHeaders(); | 332 Map<String, String> responseHeaders = response.getResponseHeaders(); |
| 324 if (responseHeaders == null) responseHeaders = new HashMap<String, Strin
g>(); | 333 if (responseHeaders == null) responseHeaders = new HashMap<String, S
tring>(); |
| 325 | 334 |
| 326 return new AwWebResourceResponse( | 335 return new AwWebResourceResponse( |
| 327 response.getMimeType(), | 336 response.getMimeType(), |
| 328 response.getEncoding(), | 337 response.getEncoding(), |
| 329 response.getData(), | 338 response.getData(), |
| 330 response.getStatusCode(), | 339 response.getStatusCode(), |
| 331 response.getReasonPhrase(), | 340 response.getReasonPhrase(), |
| 332 responseHeaders); | 341 responseHeaders); |
| 342 } finally { |
| 343 TraceEvent.end("WebViewContentsClientAdapter.shouldInterceptRequest"
); |
| 344 } |
| 333 } | 345 } |
| 334 | 346 |
| 335 /** | 347 /** |
| 336 * @see AwContentsClient#shouldOverrideUrlLoading(java.lang.String) | 348 * @see AwContentsClient#shouldOverrideUrlLoading(java.lang.String) |
| 337 */ | 349 */ |
| 338 @Override | 350 @Override |
| 339 public boolean shouldOverrideUrlLoading(String url) { | 351 public boolean shouldOverrideUrlLoading(String url) { |
| 340 TraceEvent.begin(); | 352 try { |
| 341 if (TRACE) Log.d(TAG, "shouldOverrideUrlLoading=" + url); | 353 TraceEvent.begin("WebViewContentsClientAdapter.shouldOverrideUrlLoad
ing"); |
| 342 boolean result = mWebViewClient.shouldOverrideUrlLoading(mWebView, url); | 354 if (TRACE) Log.d(TAG, "shouldOverrideUrlLoading=" + url); |
| 343 TraceEvent.end(); | 355 boolean result = mWebViewClient.shouldOverrideUrlLoading(mWebView, u
rl); |
| 344 return result; | 356 return result; |
| 357 } finally { |
| 358 TraceEvent.end("WebViewContentsClientAdapter.shouldOverrideUrlLoadin
g"); |
| 359 } |
| 345 } | 360 } |
| 346 | 361 |
| 347 /** | 362 /** |
| 348 * @see AwContentsClient#onUnhandledKeyEvent(android.view.KeyEvent) | 363 * @see AwContentsClient#onUnhandledKeyEvent(android.view.KeyEvent) |
| 349 */ | 364 */ |
| 350 @Override | 365 @Override |
| 351 public void onUnhandledKeyEvent(KeyEvent event) { | 366 public void onUnhandledKeyEvent(KeyEvent event) { |
| 352 TraceEvent.begin(); | 367 try { |
| 353 if (TRACE) Log.d(TAG, "onUnhandledKeyEvent"); | 368 TraceEvent.begin("WebViewContentsClientAdapter.onUnhandledKeyEvent")
; |
| 354 mWebViewClient.onUnhandledKeyEvent(mWebView, event); | 369 if (TRACE) Log.d(TAG, "onUnhandledKeyEvent"); |
| 355 TraceEvent.end(); | 370 mWebViewClient.onUnhandledKeyEvent(mWebView, event); |
| 371 } finally { |
| 372 TraceEvent.end("WebViewContentsClientAdapter.onUnhandledKeyEvent"); |
| 373 } |
| 356 } | 374 } |
| 357 | 375 |
| 358 /** | 376 /** |
| 359 * @see AwContentsClient#onConsoleMessage(android.webkit.ConsoleMessage) | 377 * @see AwContentsClient#onConsoleMessage(android.webkit.ConsoleMessage) |
| 360 */ | 378 */ |
| 361 @Override | 379 @Override |
| 362 public boolean onConsoleMessage(ConsoleMessage consoleMessage) { | 380 public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
| 363 TraceEvent.begin(); | 381 try { |
| 364 boolean result; | 382 TraceEvent.begin("WebViewContentsClientAdapter.onConsoleMessage"); |
| 365 if (mWebChromeClient != null) { | 383 boolean result; |
| 366 if (TRACE) Log.d(TAG, "onConsoleMessage: " + consoleMessage.message(
)); | 384 if (mWebChromeClient != null) { |
| 367 result = mWebChromeClient.onConsoleMessage(consoleMessage); | 385 if (TRACE) Log.d(TAG, "onConsoleMessage: " + consoleMessage.mess
age()); |
| 368 String message = consoleMessage.message(); | 386 result = mWebChromeClient.onConsoleMessage(consoleMessage); |
| 369 if (result && message != null && message.startsWith("[blocked]")) { | 387 String message = consoleMessage.message(); |
| 370 Log.e(TAG, "Blocked URL: " + message); | 388 if (result && message != null && message.startsWith("[blocked]")
) { |
| 389 Log.e(TAG, "Blocked URL: " + message); |
| 390 } |
| 391 } else { |
| 392 result = false; |
| 371 } | 393 } |
| 372 } else { | 394 return result; |
| 373 result = false; | 395 } finally { |
| 396 TraceEvent.end("WebViewContentsClientAdapter.onConsoleMessage"); |
| 374 } | 397 } |
| 375 TraceEvent.end(); | |
| 376 return result; | |
| 377 } | 398 } |
| 378 | 399 |
| 379 /** | 400 /** |
| 380 * @see AwContentsClient#onFindResultReceived(int,int,boolean) | 401 * @see AwContentsClient#onFindResultReceived(int,int,boolean) |
| 381 */ | 402 */ |
| 382 @Override | 403 @Override |
| 383 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches
, | 404 public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches
, |
| 384 boolean isDoneCounting) { | 405 boolean isDoneCounting) { |
| 385 if (mFindListener == null) return; | 406 try { |
| 386 TraceEvent.begin(); | 407 TraceEvent.begin("WebViewContentsClientAdapter.onFindResultReceived"
); |
| 387 if (TRACE) Log.d(TAG, "onFindResultReceived"); | 408 if (mFindListener == null) return; |
| 388 mFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches,
isDoneCounting); | 409 if (TRACE) Log.d(TAG, "onFindResultReceived"); |
| 389 TraceEvent.end(); | 410 mFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatch
es, isDoneCounting); |
| 411 } finally { |
| 412 TraceEvent.end("WebViewContentsClientAdapter.onFindResultReceived"); |
| 413 } |
| 390 } | 414 } |
| 391 | 415 |
| 392 /** | 416 /** |
| 393 * @See AwContentsClient#onNewPicture(Picture) | 417 * @See AwContentsClient#onNewPicture(Picture) |
| 394 */ | 418 */ |
| 395 @Override | 419 @Override |
| 396 public void onNewPicture(Picture picture) { | 420 public void onNewPicture(Picture picture) { |
| 397 if (mPictureListener == null) return; | 421 try { |
| 398 TraceEvent.begin(); | 422 TraceEvent.begin("WebViewContentsClientAdapter.onNewPicture"); |
| 399 if (TRACE) Log.d(TAG, "onNewPicture"); | 423 if (mPictureListener == null) return; |
| 400 mPictureListener.onNewPicture(mWebView, picture); | 424 if (TRACE) Log.d(TAG, "onNewPicture"); |
| 401 TraceEvent.end(); | 425 mPictureListener.onNewPicture(mWebView, picture); |
| 426 } finally { |
| 427 TraceEvent.end("WebViewContentsClientAdapter.onNewPicture"); |
| 428 } |
| 402 } | 429 } |
| 403 | 430 |
| 404 @Override | 431 @Override |
| 405 public void onLoadResource(String url) { | 432 public void onLoadResource(String url) { |
| 406 TraceEvent.begin(); | 433 try { |
| 407 if (TRACE) Log.d(TAG, "onLoadResource=" + url); | 434 TraceEvent.begin("WebViewContentsClientAdapter.onLoadResource"); |
| 408 mWebViewClient.onLoadResource(mWebView, url); | 435 if (TRACE) Log.d(TAG, "onLoadResource=" + url); |
| 409 TraceEvent.end(); | 436 mWebViewClient.onLoadResource(mWebView, url); |
| 437 } finally { |
| 438 TraceEvent.end("WebViewContentsClientAdapter.onLoadResource"); |
| 439 } |
| 410 } | 440 } |
| 411 | 441 |
| 412 @Override | 442 @Override |
| 413 public boolean onCreateWindow(boolean isDialog, boolean isUserGesture) { | 443 public boolean onCreateWindow(boolean isDialog, boolean isUserGesture) { |
| 414 Message m = mUiThreadHandler.obtainMessage( | 444 try { |
| 415 NEW_WEBVIEW_CREATED, mWebView.new WebViewTransport()); | 445 TraceEvent.begin("WebViewContentsClientAdapter.onCreateWindow"); |
| 416 TraceEvent.begin(); | 446 Message m = mUiThreadHandler.obtainMessage( |
| 417 boolean result; | 447 NEW_WEBVIEW_CREATED, mWebView.new WebViewTransport()); |
| 418 if (mWebChromeClient != null) { | 448 boolean result; |
| 419 if (TRACE) Log.d(TAG, "onCreateWindow"); | 449 if (mWebChromeClient != null) { |
| 420 result = mWebChromeClient.onCreateWindow(mWebView, isDialog, isUserG
esture, m); | 450 if (TRACE) Log.d(TAG, "onCreateWindow"); |
| 421 } else { | 451 result = mWebChromeClient.onCreateWindow(mWebView, isDialog, isU
serGesture, m); |
| 422 result = false; | 452 } else { |
| 453 result = false; |
| 454 } |
| 455 return result; |
| 456 } finally { |
| 457 TraceEvent.end("WebViewContentsClientAdapter.onCreateWindow"); |
| 423 } | 458 } |
| 424 TraceEvent.end(); | |
| 425 return result; | |
| 426 } | 459 } |
| 427 | 460 |
| 428 /** | 461 /** |
| 429 * @see AwContentsClient#onCloseWindow() | 462 * @see AwContentsClient#onCloseWindow() |
| 430 */ | 463 */ |
| 431 @Override | 464 @Override |
| 432 public void onCloseWindow() { | 465 public void onCloseWindow() { |
| 433 TraceEvent.begin(); | 466 try { |
| 434 if (mWebChromeClient != null) { | 467 TraceEvent.begin("WebViewContentsClientAdapter.onCloseWindow"); |
| 435 if (TRACE) Log.d(TAG, "onCloseWindow"); | 468 if (mWebChromeClient != null) { |
| 436 mWebChromeClient.onCloseWindow(mWebView); | 469 if (TRACE) Log.d(TAG, "onCloseWindow"); |
| 470 mWebChromeClient.onCloseWindow(mWebView); |
| 471 } |
| 472 } finally { |
| 473 TraceEvent.end("WebViewContentsClientAdapter.onCloseWindow"); |
| 437 } | 474 } |
| 438 TraceEvent.end(); | |
| 439 } | 475 } |
| 440 | 476 |
| 441 /** | 477 /** |
| 442 * @see AwContentsClient#onRequestFocus() | 478 * @see AwContentsClient#onRequestFocus() |
| 443 */ | 479 */ |
| 444 @Override | 480 @Override |
| 445 public void onRequestFocus() { | 481 public void onRequestFocus() { |
| 446 TraceEvent.begin(); | 482 try { |
| 447 if (mWebChromeClient != null) { | 483 TraceEvent.begin("WebViewContentsClientAdapter.onRequestFocus"); |
| 448 if (TRACE) Log.d(TAG, "onRequestFocus"); | 484 if (mWebChromeClient != null) { |
| 449 mWebChromeClient.onRequestFocus(mWebView); | 485 if (TRACE) Log.d(TAG, "onRequestFocus"); |
| 486 mWebChromeClient.onRequestFocus(mWebView); |
| 487 } |
| 488 } finally { |
| 489 TraceEvent.end("WebViewContentsClientAdapter.onRequestFocus"); |
| 450 } | 490 } |
| 451 TraceEvent.end(); | |
| 452 } | 491 } |
| 453 | 492 |
| 454 /** | 493 /** |
| 455 * @see AwContentsClient#onReceivedTouchIconUrl(String url, boolean precompo
sed) | 494 * @see AwContentsClient#onReceivedTouchIconUrl(String url, boolean precompo
sed) |
| 456 */ | 495 */ |
| 457 @Override | 496 @Override |
| 458 public void onReceivedTouchIconUrl(String url, boolean precomposed) { | 497 public void onReceivedTouchIconUrl(String url, boolean precomposed) { |
| 459 TraceEvent.begin(); | 498 try { |
| 460 if (mWebChromeClient != null) { | 499 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedTouchIconUr
l"); |
| 461 if (TRACE) Log.d(TAG, "onReceivedTouchIconUrl=" + url); | 500 if (mWebChromeClient != null) { |
| 462 mWebChromeClient.onReceivedTouchIconUrl(mWebView, url, precomposed); | 501 if (TRACE) Log.d(TAG, "onReceivedTouchIconUrl=" + url); |
| 502 mWebChromeClient.onReceivedTouchIconUrl(mWebView, url, precompos
ed); |
| 503 } |
| 504 } finally { |
| 505 TraceEvent.end("WebViewContentsClientAdapter.onReceivedTouchIconUrl"
); |
| 463 } | 506 } |
| 464 TraceEvent.end(); | |
| 465 } | 507 } |
| 466 | 508 |
| 467 /** | 509 /** |
| 468 * @see AwContentsClient#onReceivedIcon(Bitmap bitmap) | 510 * @see AwContentsClient#onReceivedIcon(Bitmap bitmap) |
| 469 */ | 511 */ |
| 470 @Override | 512 @Override |
| 471 public void onReceivedIcon(Bitmap bitmap) { | 513 public void onReceivedIcon(Bitmap bitmap) { |
| 472 TraceEvent.begin(); | 514 try { |
| 473 if (mWebChromeClient != null) { | 515 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedIcon"); |
| 474 if (TRACE) Log.d(TAG, "onReceivedIcon"); | 516 if (mWebChromeClient != null) { |
| 475 mWebChromeClient.onReceivedIcon(mWebView, bitmap); | 517 if (TRACE) Log.d(TAG, "onReceivedIcon"); |
| 518 mWebChromeClient.onReceivedIcon(mWebView, bitmap); |
| 519 } |
| 520 } finally { |
| 521 TraceEvent.end("WebViewContentsClientAdapter.onReceivedIcon"); |
| 476 } | 522 } |
| 477 TraceEvent.end(); | |
| 478 } | 523 } |
| 479 | 524 |
| 480 /** | 525 /** |
| 481 * @see ContentViewClient#onPageStarted(String) | 526 * @see ContentViewClient#onPageStarted(String) |
| 482 */ | 527 */ |
| 483 @Override | 528 @Override |
| 484 public void onPageStarted(String url) { | 529 public void onPageStarted(String url) { |
| 485 TraceEvent.begin(); | 530 try { |
| 486 if (TRACE) Log.d(TAG, "onPageStarted=" + url); | 531 TraceEvent.begin("WebViewContentsClientAdapter.onPageStarted"); |
| 487 mWebViewClient.onPageStarted(mWebView, url, mWebView.getFavicon()); | 532 if (TRACE) Log.d(TAG, "onPageStarted=" + url); |
| 488 TraceEvent.end(); | 533 mWebViewClient.onPageStarted(mWebView, url, mWebView.getFavicon()); |
| 534 } finally { |
| 535 TraceEvent.end("WebViewContentsClientAdapter.onPageStarted"); |
| 536 } |
| 489 } | 537 } |
| 490 | 538 |
| 491 /** | 539 /** |
| 492 * @see ContentViewClient#onPageFinished(String) | 540 * @see ContentViewClient#onPageFinished(String) |
| 493 */ | 541 */ |
| 494 @Override | 542 @Override |
| 495 public void onPageFinished(String url) { | 543 public void onPageFinished(String url) { |
| 496 TraceEvent.begin(); | 544 try { |
| 497 if (TRACE) Log.d(TAG, "onPageFinished=" + url); | 545 TraceEvent.begin("WebViewContentsClientAdapter.onPageFinished"); |
| 498 mWebViewClient.onPageFinished(mWebView, url); | 546 if (TRACE) Log.d(TAG, "onPageFinished=" + url); |
| 499 TraceEvent.end(); | 547 mWebViewClient.onPageFinished(mWebView, url); |
| 500 | 548 |
| 501 // See b/8208948 | 549 // See b/8208948 |
| 502 // This fakes an onNewPicture callback after onPageFinished to allow | 550 // This fakes an onNewPicture callback after onPageFinished to allow |
| 503 // CTS tests to run in an un-flaky manner. This is required as the | 551 // CTS tests to run in an un-flaky manner. This is required as the |
| 504 // path for sending Picture updates in Chromium are decoupled from the | 552 // path for sending Picture updates in Chromium are decoupled from t
he |
| 505 // page loading callbacks, i.e. the Chrome compositor may draw our | 553 // page loading callbacks, i.e. the Chrome compositor may draw our |
| 506 // content and send the Picture before onPageStarted or onPageFinished | 554 // content and send the Picture before onPageStarted or onPageFinish
ed |
| 507 // are invoked. The CTS harness discards any pictures it receives before | 555 // are invoked. The CTS harness discards any pictures it receives be
fore |
| 508 // onPageStarted is invoked, so in the case we get the Picture before th
at and | 556 // onPageStarted is invoked, so in the case we get the Picture befor
e that and |
| 509 // no further updates after onPageStarted, we'll fail the test by timing | 557 // no further updates after onPageStarted, we'll fail the test by ti
ming |
| 510 // out waiting for a Picture. | 558 // out waiting for a Picture. |
| 511 // To ensure backwards compatibility, we need to defer sending Picture u
pdates | 559 // To ensure backwards compatibility, we need to defer sending Pictu
re updates |
| 512 // until onPageFinished has been invoked. This work is being done | 560 // until onPageFinished has been invoked. This work is being done |
| 513 // upstream, and we can revert this hack when it lands. | 561 // upstream, and we can revert this hack when it lands. |
| 514 if (mPictureListener != null) { | 562 if (mPictureListener != null) { |
| 515 ThreadUtils.postOnUiThreadDelayed(new Runnable() { | 563 ThreadUtils.postOnUiThreadDelayed(new Runnable() { |
| 516 @Override | 564 @Override |
| 517 public void run() { | 565 public void run() { |
| 518 UnimplementedWebViewApi.invoke(); | 566 UnimplementedWebViewApi.invoke(); |
| 519 if (mPictureListener != null) { | 567 if (mPictureListener != null) { |
| 520 if (TRACE) Log.d(TAG, "onPageFinished-fake"); | 568 if (TRACE) Log.d(TAG, "onPageFinished-fake"); |
| 521 mPictureListener.onNewPicture(mWebView, new Picture()); | 569 mPictureListener.onNewPicture(mWebView, new Picture(
)); |
| 570 } |
| 522 } | 571 } |
| 523 } | 572 }, 100); |
| 524 }, 100); | 573 } |
| 574 } finally { |
| 575 TraceEvent.end("WebViewContentsClientAdapter.onPageFinished"); |
| 525 } | 576 } |
| 526 } | 577 } |
| 527 | 578 |
| 528 /** | 579 /** |
| 529 * @see ContentViewClient#onReceivedError(int,String,String) | 580 * @see ContentViewClient#onReceivedError(int,String,String) |
| 530 */ | 581 */ |
| 531 @Override | 582 @Override |
| 532 public void onReceivedError(int errorCode, String description, String failin
gUrl) { | 583 public void onReceivedError(int errorCode, String description, String failin
gUrl) { |
| 533 if (description == null || description.isEmpty()) { | 584 try { |
| 534 // ErrorStrings is @hidden, so we can't do this in AwContents. | 585 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedError"); |
| 535 // Normally the net/ layer will set a valid description, but for syn
thesized callbacks | 586 if (description == null || description.isEmpty()) { |
| 536 // (like in the case for intercepted requests) AwContents will pass
in null. | 587 // ErrorStrings is @hidden, so we can't do this in AwContents.
Normally the net/ |
| 537 description = mWebViewDelegate.getErrorString(mContext, errorCode); | 588 // layer will set a valid description, but for synthesized callb
acks (like in the |
| 589 // case for intercepted requests) AwContents will pass in null. |
| 590 description = mWebViewDelegate.getErrorString(mContext, errorCod
e); |
| 591 } |
| 592 if (TRACE) Log.d(TAG, "onReceivedError=" + failingUrl); |
| 593 mWebViewClient.onReceivedError(mWebView, errorCode, description, fai
lingUrl); |
| 594 } finally { |
| 595 TraceEvent.end("WebViewContentsClientAdapter.onReceivedError"); |
| 538 } | 596 } |
| 539 TraceEvent.begin(); | |
| 540 if (TRACE) Log.d(TAG, "onReceivedError=" + failingUrl); | |
| 541 mWebViewClient.onReceivedError(mWebView, errorCode, description, failing
Url); | |
| 542 TraceEvent.end(); | |
| 543 } | 597 } |
| 544 | 598 |
| 545 /** | 599 /** |
| 546 * @see ContentViewClient#onReceivedTitle(String) | 600 * @see ContentViewClient#onReceivedTitle(String) |
| 547 */ | 601 */ |
| 548 @Override | 602 @Override |
| 549 public void onReceivedTitle(String title) { | 603 public void onReceivedTitle(String title) { |
| 550 TraceEvent.begin(); | 604 try { |
| 551 if (mWebChromeClient != null) { | 605 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedTitle"); |
| 552 if (TRACE) Log.d(TAG, "onReceivedTitle"); | 606 if (mWebChromeClient != null) { |
| 553 mWebChromeClient.onReceivedTitle(mWebView, title); | 607 if (TRACE) Log.d(TAG, "onReceivedTitle"); |
| 608 mWebChromeClient.onReceivedTitle(mWebView, title); |
| 609 } |
| 610 } finally { |
| 611 TraceEvent.end("WebViewContentsClientAdapter.onReceivedTitle"); |
| 554 } | 612 } |
| 555 TraceEvent.end(); | |
| 556 } | 613 } |
| 557 | 614 |
| 558 /** | 615 /** |
| 559 * @see ContentViewClient#shouldOverrideKeyEvent(KeyEvent) | 616 * @see ContentViewClient#shouldOverrideKeyEvent(KeyEvent) |
| 560 */ | 617 */ |
| 561 @Override | 618 @Override |
| 562 public boolean shouldOverrideKeyEvent(KeyEvent event) { | 619 public boolean shouldOverrideKeyEvent(KeyEvent event) { |
| 563 // The check below is reflecting Clank's behavior and is a workaround fo
r http://b/7697782. | 620 try { |
| 564 // 1. The check for system key should be made in AwContents or ContentVi
ewCore, before | 621 TraceEvent.begin("WebViewContentsClientAdapter.shouldOverrideKeyEven
t"); |
| 565 // shouldOverrideKeyEvent() is called at all. | 622 // The check below is reflecting Clank's behavior and is a workaroun
d for |
| 566 // 2. shouldOverrideKeyEvent() should be called in onKeyDown/onKeyUp, no
t from | 623 // http://b/7697782. |
| 567 // dispatchKeyEvent(). | 624 // 1. The check for system key should be made in AwContents or Conte
ntViewCore, before |
| 568 if (!ContentViewClient.shouldPropagateKey(event.getKeyCode())) return tr
ue; | 625 // shouldOverrideKeyEvent() is called at all. |
| 569 TraceEvent.begin(); | 626 // 2. shouldOverrideKeyEvent() should be called in onKeyDown/onKeyUp
, not from |
| 570 if (TRACE) Log.d(TAG, "shouldOverrideKeyEvent"); | 627 // dispatchKeyEvent(). |
| 571 boolean result = mWebViewClient.shouldOverrideKeyEvent(mWebView, event); | 628 if (!ContentViewClient.shouldPropagateKey(event.getKeyCode())) retur
n true; |
| 572 TraceEvent.end(); | 629 if (TRACE) Log.d(TAG, "shouldOverrideKeyEvent"); |
| 573 return result; | 630 boolean result = mWebViewClient.shouldOverrideKeyEvent(mWebView, eve
nt); |
| 631 return result; |
| 632 } finally { |
| 633 TraceEvent.end("WebViewContentsClientAdapter.shouldOverrideKeyEvent"
); |
| 634 } |
| 574 } | 635 } |
| 575 | 636 |
| 576 /** | 637 /** |
| 577 * @see ContentViewClient#onStartContentIntent(Context, String) | 638 * @see ContentViewClient#onStartContentIntent(Context, String) |
| 578 * Callback when detecting a click on a content link. | 639 * Callback when detecting a click on a content link. |
| 579 */ | 640 */ |
| 580 // TODO: Delete this method when removed from base class. | 641 // TODO: Delete this method when removed from base class. |
| 581 public void onStartContentIntent(Context context, String contentUrl) { | 642 public void onStartContentIntent(Context context, String contentUrl) { |
| 582 TraceEvent.begin(); | 643 try { |
| 583 if (TRACE) Log.d(TAG, "shouldOverrideUrlLoading=" + contentUrl); | 644 TraceEvent.begin("WebViewContentsClientAdapter.onStartContentIntent"
); |
| 584 mWebViewClient.shouldOverrideUrlLoading(mWebView, contentUrl); | 645 if (TRACE) Log.d(TAG, "shouldOverrideUrlLoading=" + contentUrl); |
| 585 TraceEvent.end(); | 646 mWebViewClient.shouldOverrideUrlLoading(mWebView, contentUrl); |
| 647 } finally { |
| 648 TraceEvent.end("WebViewContentsClientAdapter.onStartContentIntent"); |
| 649 } |
| 586 } | 650 } |
| 587 | 651 |
| 588 @Override | 652 @Override |
| 589 public void onGeolocationPermissionsShowPrompt(String origin, | 653 public void onGeolocationPermissionsShowPrompt(String origin, |
| 590 GeolocationPermissions.Callback callback) { | 654 GeolocationPermissions.Callback callback) { |
| 591 TraceEvent.begin(); | 655 try { |
| 592 if (mWebChromeClient != null) { | 656 TraceEvent.begin("WebViewContentsClientAdapter.onGeolocationPermissi
onsShowPrompt"); |
| 593 if (TRACE) Log.d(TAG, "onGeolocationPermissionsShowPrompt"); | 657 if (mWebChromeClient != null) { |
| 594 mWebChromeClient.onGeolocationPermissionsShowPrompt(origin, callback
); | 658 if (TRACE) Log.d(TAG, "onGeolocationPermissionsShowPrompt"); |
| 659 mWebChromeClient.onGeolocationPermissionsShowPrompt(origin, call
back); |
| 660 } |
| 661 } finally { |
| 662 TraceEvent.end("WebViewContentsClientAdapter.onGeolocationPermission
sShowPrompt"); |
| 595 } | 663 } |
| 596 TraceEvent.end(); | |
| 597 } | 664 } |
| 598 | 665 |
| 599 @Override | 666 @Override |
| 600 public void onGeolocationPermissionsHidePrompt() { | 667 public void onGeolocationPermissionsHidePrompt() { |
| 601 TraceEvent.begin(); | 668 try { |
| 602 if (mWebChromeClient != null) { | 669 TraceEvent.begin("WebViewContentsClientAdapter.onGeolocationPermissi
onsHidePrompt"); |
| 603 if (TRACE) Log.d(TAG, "onGeolocationPermissionsHidePrompt"); | 670 if (mWebChromeClient != null) { |
| 604 mWebChromeClient.onGeolocationPermissionsHidePrompt(); | 671 if (TRACE) Log.d(TAG, "onGeolocationPermissionsHidePrompt"); |
| 672 mWebChromeClient.onGeolocationPermissionsHidePrompt(); |
| 673 } |
| 674 } finally { |
| 675 TraceEvent.end("WebViewContentsClientAdapter.onGeolocationPermission
sHidePrompt"); |
| 605 } | 676 } |
| 606 TraceEvent.end(); | |
| 607 } | 677 } |
| 608 | 678 |
| 609 @Override | 679 @Override |
| 610 public void onPermissionRequest(AwPermissionRequest permissionRequest) { | 680 public void onPermissionRequest(AwPermissionRequest permissionRequest) { |
| 611 TraceEvent.begin(); | 681 try { |
| 612 if (mWebChromeClient != null) { | 682 TraceEvent.begin("WebViewContentsClientAdapter.onPermissionRequest")
; |
| 613 if (TRACE) Log.d(TAG, "onPermissionRequest"); | 683 if (mWebChromeClient != null) { |
| 614 if (mOngoingPermissionRequests == null) { | 684 if (TRACE) Log.d(TAG, "onPermissionRequest"); |
| 615 mOngoingPermissionRequests = new WeakHashMap<AwPermissionRequest
, | 685 if (mOngoingPermissionRequests == null) { |
| 616 WeakReference<PermissionRequestAdapter>>(); | 686 mOngoingPermissionRequests = new WeakHashMap<AwPermissionReq
uest, |
| 687 WeakReference<PermissionRequestAdapter>>(); |
| 688 } |
| 689 PermissionRequestAdapter adapter = new PermissionRequestAdapter(
permissionRequest); |
| 690 mOngoingPermissionRequests.put( |
| 691 permissionRequest, new WeakReference<PermissionRequestAd
apter>(adapter)); |
| 692 mWebChromeClient.onPermissionRequest(adapter); |
| 693 } else { |
| 694 // By default, we deny the permission. |
| 695 permissionRequest.deny(); |
| 617 } | 696 } |
| 618 PermissionRequestAdapter adapter = new PermissionRequestAdapter(perm
issionRequest); | 697 } finally { |
| 619 mOngoingPermissionRequests.put( | 698 TraceEvent.end("WebViewContentsClientAdapter.onPermissionRequest"); |
| 620 permissionRequest, new WeakReference<PermissionRequestAdapte
r>(adapter)); | |
| 621 mWebChromeClient.onPermissionRequest(adapter); | |
| 622 } else { | |
| 623 // By default, we deny the permission. | |
| 624 permissionRequest.deny(); | |
| 625 } | 699 } |
| 626 TraceEvent.end(); | |
| 627 } | 700 } |
| 628 | 701 |
| 629 @Override | 702 @Override |
| 630 public void onPermissionRequestCanceled(AwPermissionRequest permissionReques
t) { | 703 public void onPermissionRequestCanceled(AwPermissionRequest permissionReques
t) { |
| 631 TraceEvent.begin(); | 704 try { |
| 632 if (mWebChromeClient != null && mOngoingPermissionRequests != null) { | 705 TraceEvent.begin("WebViewContentsClientAdapter.onPermissionRequestCa
nceled"); |
| 633 if (TRACE) Log.d(TAG, "onPermissionRequestCanceled"); | 706 if (mWebChromeClient != null && mOngoingPermissionRequests != null)
{ |
| 634 WeakReference<PermissionRequestAdapter> weakRef = | 707 if (TRACE) Log.d(TAG, "onPermissionRequestCanceled"); |
| 635 mOngoingPermissionRequests.get(permissionRequest); | 708 WeakReference<PermissionRequestAdapter> weakRef = |
| 636 // We don't hold strong reference to PermissionRequestAdpater and do
n't expect the | 709 mOngoingPermissionRequests.get(permissionRequest); |
| 637 // user only holds weak reference to it either, if so, user has no w
ay to call | 710 // We don't hold strong reference to PermissionRequestAdpater an
d don't expect the |
| 638 // grant()/deny(), and no need to be notified the cancellation of re
quest. | 711 // user only holds weak reference to it either, if so, user has
no way to call |
| 639 if (weakRef != null) { | 712 // grant()/deny(), and no need to be notified the cancellation o
f request. |
| 640 PermissionRequestAdapter adapter = weakRef.get(); | 713 if (weakRef != null) { |
| 641 if (adapter != null) mWebChromeClient.onPermissionRequestCancele
d(adapter); | 714 PermissionRequestAdapter adapter = weakRef.get(); |
| 715 if (adapter != null) mWebChromeClient.onPermissionRequestCan
celed(adapter); |
| 716 } |
| 642 } | 717 } |
| 718 } finally { |
| 719 TraceEvent.end("WebViewContentsClientAdapter.onPermissionRequestCanc
eled"); |
| 643 } | 720 } |
| 644 TraceEvent.end(); | |
| 645 } | 721 } |
| 646 | 722 |
| 647 private static class JsPromptResultReceiverAdapter implements JsResult.Resul
tReceiver { | 723 private static class JsPromptResultReceiverAdapter implements JsResult.Resul
tReceiver { |
| 648 private JsPromptResultReceiver mChromePromptResultReceiver; | 724 private JsPromptResultReceiver mChromePromptResultReceiver; |
| 649 private JsResultReceiver mChromeResultReceiver; | 725 private JsResultReceiver mChromeResultReceiver; |
| 650 // We hold onto the JsPromptResult here, just to avoid the need to downc
ast | 726 // We hold onto the JsPromptResult here, just to avoid the need to downc
ast |
| 651 // in onJsResultComplete. | 727 // in onJsResultComplete. |
| 652 private final JsPromptResult mPromptResult = new JsPromptResult(this); | 728 private final JsPromptResult mPromptResult = new JsPromptResult(this); |
| 653 | 729 |
| 654 public JsPromptResultReceiverAdapter(JsPromptResultReceiver receiver) { | 730 public JsPromptResultReceiverAdapter(JsPromptResultReceiver receiver) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 676 mChromeResultReceiver.confirm(); | 752 mChromeResultReceiver.confirm(); |
| 677 } else { | 753 } else { |
| 678 mChromeResultReceiver.cancel(); | 754 mChromeResultReceiver.cancel(); |
| 679 } | 755 } |
| 680 } | 756 } |
| 681 } | 757 } |
| 682 } | 758 } |
| 683 | 759 |
| 684 @Override | 760 @Override |
| 685 public void handleJsAlert(String url, String message, JsResultReceiver recei
ver) { | 761 public void handleJsAlert(String url, String message, JsResultReceiver recei
ver) { |
| 686 TraceEvent.begin(); | 762 try { |
| 687 if (mWebChromeClient != null) { | 763 TraceEvent.begin("WebViewContentsClientAdapter.handleJsAlert"); |
| 688 final JsPromptResult res = | 764 if (mWebChromeClient != null) { |
| 689 new JsPromptResultReceiverAdapter(receiver).getPromptResult(
); | 765 final JsPromptResult res = |
| 690 if (TRACE) Log.d(TAG, "onJsAlert"); | 766 new JsPromptResultReceiverAdapter(receiver).getPromptRes
ult(); |
| 691 if (!mWebChromeClient.onJsAlert(mWebView, url, message, res)) { | 767 if (TRACE) Log.d(TAG, "onJsAlert"); |
| 692 new JsDialogHelper(res, JsDialogHelper.ALERT, null, message, url
) | 768 if (!mWebChromeClient.onJsAlert(mWebView, url, message, res)) { |
| 693 .showDialog(mContext); | 769 new JsDialogHelper(res, JsDialogHelper.ALERT, null, message,
url) |
| 770 .showDialog(mContext); |
| 771 } |
| 772 } else { |
| 773 receiver.cancel(); |
| 694 } | 774 } |
| 695 } else { | 775 } finally { |
| 696 receiver.cancel(); | 776 TraceEvent.end("WebViewContentsClientAdapter.handleJsAlert"); |
| 697 } | 777 } |
| 698 TraceEvent.end(); | |
| 699 } | 778 } |
| 700 | 779 |
| 701 @Override | 780 @Override |
| 702 public void handleJsBeforeUnload(String url, String message, JsResultReceive
r receiver) { | 781 public void handleJsBeforeUnload(String url, String message, JsResultReceive
r receiver) { |
| 703 TraceEvent.begin(); | 782 try { |
| 704 if (mWebChromeClient != null) { | 783 TraceEvent.begin("WebViewContentsClientAdapter.handleJsBeforeUnload"
); |
| 705 final JsPromptResult res = | 784 if (mWebChromeClient != null) { |
| 706 new JsPromptResultReceiverAdapter(receiver).getPromptResult(
); | 785 final JsPromptResult res = |
| 707 if (TRACE) Log.d(TAG, "onJsBeforeUnload"); | 786 new JsPromptResultReceiverAdapter(receiver).getPromptRes
ult(); |
| 708 if (!mWebChromeClient.onJsBeforeUnload(mWebView, url, message, res))
{ | 787 if (TRACE) Log.d(TAG, "onJsBeforeUnload"); |
| 709 new JsDialogHelper(res, JsDialogHelper.UNLOAD, null, message, ur
l) | 788 if (!mWebChromeClient.onJsBeforeUnload(mWebView, url, message, r
es)) { |
| 710 .showDialog(mContext); | 789 new JsDialogHelper(res, JsDialogHelper.UNLOAD, null, message
, url) |
| 790 .showDialog(mContext); |
| 791 } |
| 792 } else { |
| 793 receiver.cancel(); |
| 711 } | 794 } |
| 712 } else { | 795 } finally { |
| 713 receiver.cancel(); | 796 TraceEvent.end("WebViewContentsClientAdapter.handleJsBeforeUnload"); |
| 714 } | 797 } |
| 715 TraceEvent.end(); | |
| 716 } | 798 } |
| 717 | 799 |
| 718 @Override | 800 @Override |
| 719 public void handleJsConfirm(String url, String message, JsResultReceiver rec
eiver) { | 801 public void handleJsConfirm(String url, String message, JsResultReceiver rec
eiver) { |
| 720 TraceEvent.begin(); | 802 try { |
| 721 if (mWebChromeClient != null) { | 803 TraceEvent.begin("WebViewContentsClientAdapter.handleJsConfirm"); |
| 722 final JsPromptResult res = | 804 if (mWebChromeClient != null) { |
| 723 new JsPromptResultReceiverAdapter(receiver).getPromptResult(
); | 805 final JsPromptResult res = |
| 724 if (TRACE) Log.d(TAG, "onJsConfirm"); | 806 new JsPromptResultReceiverAdapter(receiver).getPromptRes
ult(); |
| 725 if (!mWebChromeClient.onJsConfirm(mWebView, url, message, res)) { | 807 if (TRACE) Log.d(TAG, "onJsConfirm"); |
| 726 new JsDialogHelper(res, JsDialogHelper.CONFIRM, null, message, u
rl) | 808 if (!mWebChromeClient.onJsConfirm(mWebView, url, message, res))
{ |
| 727 .showDialog(mContext); | 809 new JsDialogHelper(res, JsDialogHelper.CONFIRM, null, messag
e, url) |
| 810 .showDialog(mContext); |
| 811 } |
| 812 } else { |
| 813 receiver.cancel(); |
| 728 } | 814 } |
| 729 } else { | 815 } finally { |
| 730 receiver.cancel(); | 816 TraceEvent.end("WebViewContentsClientAdapter.handleJsConfirm"); |
| 731 } | 817 } |
| 732 TraceEvent.end(); | |
| 733 } | 818 } |
| 734 | 819 |
| 735 @Override | 820 @Override |
| 736 public void handleJsPrompt(String url, String message, String defaultValue, | 821 public void handleJsPrompt(String url, String message, String defaultValue, |
| 737 JsPromptResultReceiver receiver) { | 822 JsPromptResultReceiver receiver) { |
| 738 TraceEvent.begin(); | 823 try { |
| 739 if (mWebChromeClient != null) { | 824 TraceEvent.begin("WebViewContentsClientAdapter.handleJsPrompt"); |
| 740 final JsPromptResult res = | 825 if (mWebChromeClient != null) { |
| 741 new JsPromptResultReceiverAdapter(receiver).getPromptResult(
); | 826 final JsPromptResult res = |
| 742 if (TRACE) Log.d(TAG, "onJsPrompt"); | 827 new JsPromptResultReceiverAdapter(receiver).getPromptRes
ult(); |
| 743 if (!mWebChromeClient.onJsPrompt(mWebView, url, message, defaultValu
e, res)) { | 828 if (TRACE) Log.d(TAG, "onJsPrompt"); |
| 744 new JsDialogHelper(res, JsDialogHelper.PROMPT, defaultValue, mes
sage, url) | 829 if (!mWebChromeClient.onJsPrompt(mWebView, url, message, default
Value, res)) { |
| 745 .showDialog(mContext); | 830 new JsDialogHelper(res, JsDialogHelper.PROMPT, defaultValue,
message, url) |
| 831 .showDialog(mContext); |
| 832 } |
| 833 } else { |
| 834 receiver.cancel(); |
| 746 } | 835 } |
| 747 } else { | 836 } finally { |
| 748 receiver.cancel(); | 837 TraceEvent.end("WebViewContentsClientAdapter.handleJsPrompt"); |
| 749 } | 838 } |
| 750 TraceEvent.end(); | |
| 751 } | 839 } |
| 752 | 840 |
| 753 @Override | 841 @Override |
| 754 public void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String host
, String realm) { | 842 public void onReceivedHttpAuthRequest(AwHttpAuthHandler handler, String host
, String realm) { |
| 755 TraceEvent.begin(); | 843 try { |
| 756 if (TRACE) Log.d(TAG, "onReceivedHttpAuthRequest=" + host); | 844 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedHttpAuthReq
uest"); |
| 757 mWebViewClient.onReceivedHttpAuthRequest( | 845 if (TRACE) Log.d(TAG, "onReceivedHttpAuthRequest=" + host); |
| 758 mWebView, new AwHttpAuthHandlerAdapter(handler), host, realm); | 846 mWebViewClient.onReceivedHttpAuthRequest( |
| 759 TraceEvent.end(); | 847 mWebView, new AwHttpAuthHandlerAdapter(handler), host, realm
); |
| 848 } finally { |
| 849 TraceEvent.end("WebViewContentsClientAdapter.onReceivedHttpAuthReque
st"); |
| 850 } |
| 760 } | 851 } |
| 761 | 852 |
| 762 @Override | 853 @Override |
| 763 public void onReceivedSslError(final ValueCallback<Boolean> callback, SslErr
or error) { | 854 public void onReceivedSslError(final ValueCallback<Boolean> callback, SslErr
or error) { |
| 764 SslErrorHandler handler = new SslErrorHandler() { | 855 try { |
| 765 @Override | 856 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedSslError"); |
| 766 public void proceed() { | 857 SslErrorHandler handler = new SslErrorHandler() { |
| 767 callback.onReceiveValue(true); | 858 @Override |
| 768 } | 859 public void proceed() { |
| 769 @Override | 860 callback.onReceiveValue(true); |
| 770 public void cancel() { | 861 } |
| 771 callback.onReceiveValue(false); | 862 @Override |
| 772 } | 863 public void cancel() { |
| 773 }; | 864 callback.onReceiveValue(false); |
| 774 TraceEvent.begin(); | 865 } |
| 775 if (TRACE) Log.d(TAG, "onReceivedSslError"); | 866 }; |
| 776 mWebViewClient.onReceivedSslError(mWebView, handler, error); | 867 if (TRACE) Log.d(TAG, "onReceivedSslError"); |
| 777 TraceEvent.end(); | 868 mWebViewClient.onReceivedSslError(mWebView, handler, error); |
| 869 } finally { |
| 870 TraceEvent.end("WebViewContentsClientAdapter.onReceivedSslError"); |
| 871 } |
| 778 } | 872 } |
| 779 | 873 |
| 780 private static class ClientCertRequestImpl extends ClientCertRequest { | 874 private static class ClientCertRequestImpl extends ClientCertRequest { |
| 781 private final AwContentsClientBridge.ClientCertificateRequestCallback mC
allback; | 875 private final AwContentsClientBridge.ClientCertificateRequestCallback mC
allback; |
| 782 private final String[] mKeyTypes; | 876 private final String[] mKeyTypes; |
| 783 private final Principal[] mPrincipals; | 877 private final Principal[] mPrincipals; |
| 784 private final String mHost; | 878 private final String mHost; |
| 785 private final int mPort; | 879 private final int mPort; |
| 786 | 880 |
| 787 public ClientCertRequestImpl( | 881 public ClientCertRequestImpl( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 public void cancel() { | 924 public void cancel() { |
| 831 mCallback.cancel(); | 925 mCallback.cancel(); |
| 832 } | 926 } |
| 833 } | 927 } |
| 834 | 928 |
| 835 @Override | 929 @Override |
| 836 public void onReceivedClientCertRequest( | 930 public void onReceivedClientCertRequest( |
| 837 AwContentsClientBridge.ClientCertificateRequestCallback callback, St
ring[] keyTypes, | 931 AwContentsClientBridge.ClientCertificateRequestCallback callback, St
ring[] keyTypes, |
| 838 Principal[] principals, String host, int port) { | 932 Principal[] principals, String host, int port) { |
| 839 if (TRACE) Log.d(TAG, "onReceivedClientCertRequest"); | 933 if (TRACE) Log.d(TAG, "onReceivedClientCertRequest"); |
| 840 TraceEvent.begin(); | 934 try { |
| 841 final ClientCertRequestImpl request = | 935 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedClientCertR
equest"); |
| 842 new ClientCertRequestImpl(callback, keyTypes, principals, host,
port); | 936 final ClientCertRequestImpl request = |
| 843 mWebViewClient.onReceivedClientCertRequest(mWebView, request); | 937 new ClientCertRequestImpl(callback, keyTypes, principals, ho
st, port); |
| 844 TraceEvent.end(); | 938 mWebViewClient.onReceivedClientCertRequest(mWebView, request); |
| 939 } finally { |
| 940 TraceEvent.end("WebViewContentsClientAdapter.onReceivedClientCertReq
uest"); |
| 941 } |
| 845 } | 942 } |
| 846 | 943 |
| 847 @Override | 944 @Override |
| 848 public void onReceivedLoginRequest(String realm, String account, String args
) { | 945 public void onReceivedLoginRequest(String realm, String account, String args
) { |
| 849 TraceEvent.begin(); | 946 try { |
| 850 if (TRACE) Log.d(TAG, "onReceivedLoginRequest=" + realm); | 947 TraceEvent.begin("WebViewContentsClientAdapter.onReceivedLoginReques
t"); |
| 851 mWebViewClient.onReceivedLoginRequest(mWebView, realm, account, args); | 948 if (TRACE) Log.d(TAG, "onReceivedLoginRequest=" + realm); |
| 852 TraceEvent.end(); | 949 mWebViewClient.onReceivedLoginRequest(mWebView, realm, account, args
); |
| 950 } finally { |
| 951 TraceEvent.end("WebViewContentsClientAdapter.onReceivedLoginRequest"
); |
| 952 } |
| 853 } | 953 } |
| 854 | 954 |
| 855 @Override | 955 @Override |
| 856 public void onFormResubmission(Message dontResend, Message resend) { | 956 public void onFormResubmission(Message dontResend, Message resend) { |
| 857 TraceEvent.begin(); | 957 try { |
| 858 if (TRACE) Log.d(TAG, "onFormResubmission"); | 958 TraceEvent.begin("WebViewContentsClientAdapter.onFormResubmission"); |
| 859 mWebViewClient.onFormResubmission(mWebView, dontResend, resend); | 959 if (TRACE) Log.d(TAG, "onFormResubmission"); |
| 860 TraceEvent.end(); | 960 mWebViewClient.onFormResubmission(mWebView, dontResend, resend); |
| 961 } finally { |
| 962 TraceEvent.end("WebViewContentsClientAdapter.onFormResubmission"); |
| 963 } |
| 861 } | 964 } |
| 862 | 965 |
| 863 @Override | 966 @Override |
| 864 public void onDownloadStart( | 967 public void onDownloadStart( |
| 865 String url, | 968 String url, |
| 866 String userAgent, | 969 String userAgent, |
| 867 String contentDisposition, | 970 String contentDisposition, |
| 868 String mimeType, | 971 String mimeType, |
| 869 long contentLength) { | 972 long contentLength) { |
| 870 if (mDownloadListener != null) { | 973 try { |
| 871 TraceEvent.begin(); | 974 TraceEvent.begin("WebViewContentsClientAdapter.onDownloadStart"); |
| 872 if (TRACE) Log.d(TAG, "onDownloadStart"); | 975 if (mDownloadListener != null) { |
| 873 mDownloadListener.onDownloadStart( | 976 if (TRACE) Log.d(TAG, "onDownloadStart"); |
| 874 url, userAgent, contentDisposition, mimeType, contentLength)
; | 977 mDownloadListener.onDownloadStart( |
| 875 TraceEvent.end(); | 978 url, userAgent, contentDisposition, mimeType, contentLen
gth); |
| 979 } |
| 980 } finally { |
| 981 TraceEvent.end("WebViewContentsClientAdapter.onDownloadStart"); |
| 876 } | 982 } |
| 877 } | 983 } |
| 878 | 984 |
| 879 @Override | 985 @Override |
| 880 public void showFileChooser(final ValueCallback<String[]> uploadFileCallback
, | 986 public void showFileChooser(final ValueCallback<String[]> uploadFileCallback
, |
| 881 final AwContentsClient.FileChooserParams fileChooserParams) { | 987 final AwContentsClient.FileChooserParams fileChooserParams) { |
| 882 if (mWebChromeClient == null) { | 988 try { |
| 883 uploadFileCallback.onReceiveValue(null); | 989 TraceEvent.begin("WebViewContentsClientAdapter.showFileChooser"); |
| 884 return; | 990 if (mWebChromeClient == null) { |
| 991 uploadFileCallback.onReceiveValue(null); |
| 992 return; |
| 993 } |
| 994 FileChooserParamsAdapter adapter = |
| 995 new FileChooserParamsAdapter(fileChooserParams, mContext); |
| 996 if (TRACE) Log.d(TAG, "showFileChooser"); |
| 997 ValueCallback<Uri[]> callbackAdapter = new ValueCallback<Uri[]>() { |
| 998 private boolean mCompleted; |
| 999 @Override |
| 1000 public void onReceiveValue(Uri[] uriList) { |
| 1001 if (mCompleted) { |
| 1002 throw new IllegalStateException( |
| 1003 "showFileChooser result was already called"); |
| 1004 } |
| 1005 mCompleted = true; |
| 1006 String s[] = null; |
| 1007 if (uriList != null) { |
| 1008 s = new String[uriList.length]; |
| 1009 for (int i = 0; i < uriList.length; i++) { |
| 1010 s[i] = uriList[i].toString(); |
| 1011 } |
| 1012 } |
| 1013 uploadFileCallback.onReceiveValue(s); |
| 1014 } |
| 1015 }; |
| 1016 |
| 1017 // Invoke the new callback introduced in Lollipop. If the app handle
s |
| 1018 // it, we're done here. |
| 1019 if (mWebChromeClient.onShowFileChooser(mWebView, callbackAdapter, ad
apter)) { |
| 1020 return; |
| 1021 } |
| 1022 |
| 1023 // If the app did not handle it and we are running on Lollipop or ne
wer, then |
| 1024 // abort. |
| 1025 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_
CODES.LOLLIPOP) { |
| 1026 uploadFileCallback.onReceiveValue(null); |
| 1027 return; |
| 1028 } |
| 1029 |
| 1030 // Otherwise, for older apps, attempt to invoke the legacy (hidden)
API for |
| 1031 // backwards compatibility. |
| 1032 ValueCallback<Uri> innerCallback = new ValueCallback<Uri>() { |
| 1033 private boolean mCompleted; |
| 1034 @Override |
| 1035 public void onReceiveValue(Uri uri) { |
| 1036 if (mCompleted) { |
| 1037 throw new IllegalStateException( |
| 1038 "showFileChooser result was already called"); |
| 1039 } |
| 1040 mCompleted = true; |
| 1041 uploadFileCallback.onReceiveValue( |
| 1042 uri == null ? null : new String[] {uri.toString()}); |
| 1043 } |
| 1044 }; |
| 1045 if (TRACE) Log.d(TAG, "openFileChooser"); |
| 1046 mWebChromeClient.openFileChooser( |
| 1047 innerCallback, |
| 1048 fileChooserParams.acceptTypes, |
| 1049 fileChooserParams.capture ? "*" : ""); |
| 1050 } finally { |
| 1051 TraceEvent.end("WebViewContentsClientAdapter.showFileChooser"); |
| 885 } | 1052 } |
| 886 TraceEvent.begin(); | |
| 887 FileChooserParamsAdapter adapter = | |
| 888 new FileChooserParamsAdapter(fileChooserParams, mContext); | |
| 889 if (TRACE) Log.d(TAG, "showFileChooser"); | |
| 890 ValueCallback<Uri[]> callbackAdapter = new ValueCallback<Uri[]>() { | |
| 891 private boolean mCompleted; | |
| 892 @Override | |
| 893 public void onReceiveValue(Uri[] uriList) { | |
| 894 if (mCompleted) { | |
| 895 throw new IllegalStateException("showFileChooser result was
already called"); | |
| 896 } | |
| 897 mCompleted = true; | |
| 898 String s[] = null; | |
| 899 if (uriList != null) { | |
| 900 s = new String[uriList.length]; | |
| 901 for (int i = 0; i < uriList.length; i++) { | |
| 902 s[i] = uriList[i].toString(); | |
| 903 } | |
| 904 } | |
| 905 uploadFileCallback.onReceiveValue(s); | |
| 906 } | |
| 907 }; | |
| 908 | |
| 909 // Invoke the new callback introduced in Lollipop. If the app handles | |
| 910 // it, we're done here. | |
| 911 if (mWebChromeClient.onShowFileChooser(mWebView, callbackAdapter, adapte
r)) { | |
| 912 return; | |
| 913 } | |
| 914 | |
| 915 // If the app did not handle it and we are running on Lollipop or newer,
then | |
| 916 // abort. | |
| 917 if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODE
S.LOLLIPOP) { | |
| 918 uploadFileCallback.onReceiveValue(null); | |
| 919 return; | |
| 920 } | |
| 921 | |
| 922 // Otherwise, for older apps, attempt to invoke the legacy (hidden) API
for | |
| 923 // backwards compatibility. | |
| 924 ValueCallback<Uri> innerCallback = new ValueCallback<Uri>() { | |
| 925 private boolean mCompleted; | |
| 926 @Override | |
| 927 public void onReceiveValue(Uri uri) { | |
| 928 if (mCompleted) { | |
| 929 throw new IllegalStateException("showFileChooser result was
already called"); | |
| 930 } | |
| 931 mCompleted = true; | |
| 932 uploadFileCallback.onReceiveValue( | |
| 933 uri == null ? null : new String[] {uri.toString()}); | |
| 934 } | |
| 935 }; | |
| 936 if (TRACE) Log.d(TAG, "openFileChooser"); | |
| 937 mWebChromeClient.openFileChooser( | |
| 938 innerCallback, fileChooserParams.acceptTypes, fileChooserParams.
capture ? "*" : ""); | |
| 939 TraceEvent.end(); | |
| 940 } | 1053 } |
| 941 | 1054 |
| 942 @Override | 1055 @Override |
| 943 public void onScaleChangedScaled(float oldScale, float newScale) { | 1056 public void onScaleChangedScaled(float oldScale, float newScale) { |
| 944 TraceEvent.begin(); | 1057 try { |
| 945 if (TRACE) Log.d(TAG, " onScaleChangedScaled"); | 1058 TraceEvent.begin("WebViewContentsClientAdapter.onScaleChangedScaled"
); |
| 946 mWebViewClient.onScaleChanged(mWebView, oldScale, newScale); | 1059 if (TRACE) Log.d(TAG, " onScaleChangedScaled"); |
| 947 TraceEvent.end(); | 1060 mWebViewClient.onScaleChanged(mWebView, oldScale, newScale); |
| 1061 } finally { |
| 1062 TraceEvent.end("WebViewContentsClientAdapter.onScaleChangedScaled"); |
| 1063 } |
| 948 } | 1064 } |
| 949 | 1065 |
| 950 @Override | 1066 @Override |
| 951 public void onShowCustomView(View view, CustomViewCallback cb) { | 1067 public void onShowCustomView(View view, CustomViewCallback cb) { |
| 952 TraceEvent.begin(); | 1068 try { |
| 953 if (mWebChromeClient != null) { | 1069 TraceEvent.begin("WebViewContentsClientAdapter.onShowCustomView"); |
| 954 if (TRACE) Log.d(TAG, "onShowCustomView"); | 1070 if (mWebChromeClient != null) { |
| 955 mWebChromeClient.onShowCustomView(view, cb); | 1071 if (TRACE) Log.d(TAG, "onShowCustomView"); |
| 1072 mWebChromeClient.onShowCustomView(view, cb); |
| 1073 } |
| 1074 } finally { |
| 1075 TraceEvent.end("WebViewContentsClientAdapter.onShowCustomView"); |
| 956 } | 1076 } |
| 957 TraceEvent.end(); | |
| 958 } | 1077 } |
| 959 | 1078 |
| 960 @Override | 1079 @Override |
| 961 public void onHideCustomView() { | 1080 public void onHideCustomView() { |
| 962 TraceEvent.begin(); | 1081 try { |
| 963 if (mWebChromeClient != null) { | 1082 TraceEvent.begin("WebViewContentsClientAdapter.onHideCustomView"); |
| 964 if (TRACE) Log.d(TAG, "onHideCustomView"); | 1083 if (mWebChromeClient != null) { |
| 965 mWebChromeClient.onHideCustomView(); | 1084 if (TRACE) Log.d(TAG, "onHideCustomView"); |
| 1085 mWebChromeClient.onHideCustomView(); |
| 1086 } |
| 1087 } finally { |
| 1088 TraceEvent.end("WebViewContentsClientAdapter.onHideCustomView"); |
| 966 } | 1089 } |
| 967 TraceEvent.end(); | |
| 968 } | 1090 } |
| 969 | 1091 |
| 970 @Override | 1092 @Override |
| 971 protected View getVideoLoadingProgressView() { | 1093 protected View getVideoLoadingProgressView() { |
| 972 TraceEvent.begin(); | 1094 try { |
| 973 View result; | 1095 TraceEvent.begin("WebViewContentsClientAdapter.getVideoLoadingProgre
ssView"); |
| 974 if (mWebChromeClient != null) { | 1096 View result; |
| 975 if (TRACE) Log.d(TAG, "getVideoLoadingProgressView"); | 1097 if (mWebChromeClient != null) { |
| 976 result = mWebChromeClient.getVideoLoadingProgressView(); | 1098 if (TRACE) Log.d(TAG, "getVideoLoadingProgressView"); |
| 977 } else { | 1099 result = mWebChromeClient.getVideoLoadingProgressView(); |
| 978 result = null; | 1100 } else { |
| 1101 result = null; |
| 1102 } |
| 1103 return result; |
| 1104 } finally { |
| 1105 TraceEvent.end("WebViewContentsClientAdapter.getVideoLoadingProgress
View"); |
| 979 } | 1106 } |
| 980 TraceEvent.end(); | |
| 981 return result; | |
| 982 } | 1107 } |
| 983 | 1108 |
| 984 @Override | 1109 @Override |
| 985 public Bitmap getDefaultVideoPoster() { | 1110 public Bitmap getDefaultVideoPoster() { |
| 986 TraceEvent.begin(); | 1111 try { |
| 987 Bitmap result = null; | 1112 TraceEvent.begin("WebViewContentsClientAdapter.getDefaultVideoPoster
"); |
| 988 if (mWebChromeClient != null) { | 1113 Bitmap result = null; |
| 989 if (TRACE) Log.d(TAG, "getDefaultVideoPoster"); | 1114 if (mWebChromeClient != null) { |
| 990 result = mWebChromeClient.getDefaultVideoPoster(); | 1115 if (TRACE) Log.d(TAG, "getDefaultVideoPoster"); |
| 1116 result = mWebChromeClient.getDefaultVideoPoster(); |
| 1117 } |
| 1118 if (result == null) { |
| 1119 // The ic_media_video_poster icon is transparent so we need to d
raw it on a gray |
| 1120 // background. |
| 1121 Bitmap poster = BitmapFactory.decodeResource( |
| 1122 mContext.getResources(), R.drawable.ic_media_video_poste
r); |
| 1123 result = Bitmap.createBitmap( |
| 1124 poster.getWidth(), poster.getHeight(), poster.getConfig(
)); |
| 1125 result.eraseColor(Color.GRAY); |
| 1126 Canvas canvas = new Canvas(result); |
| 1127 canvas.drawBitmap(poster, 0f, 0f, null); |
| 1128 } |
| 1129 return result; |
| 1130 } finally { |
| 1131 TraceEvent.end("WebViewContentsClientAdapter.getDefaultVideoPoster")
; |
| 991 } | 1132 } |
| 992 if (result == null) { | |
| 993 // The ic_media_video_poster icon is transparent so we need to draw
it on a gray | |
| 994 // background. | |
| 995 Bitmap poster = BitmapFactory.decodeResource( | |
| 996 mContext.getResources(), R.drawable.ic_media_video_poster); | |
| 997 result = Bitmap.createBitmap(poster.getWidth(), poster.getHeight(),
poster.getConfig()); | |
| 998 result.eraseColor(Color.GRAY); | |
| 999 Canvas canvas = new Canvas(result); | |
| 1000 canvas.drawBitmap(poster, 0f, 0f, null); | |
| 1001 } | |
| 1002 TraceEvent.end(); | |
| 1003 return result; | |
| 1004 } | 1133 } |
| 1005 | 1134 |
| 1006 // TODO: Move to upstream. | 1135 // TODO: Move to upstream. |
| 1007 private static class AwHttpAuthHandlerAdapter extends android.webkit.HttpAut
hHandler { | 1136 private static class AwHttpAuthHandlerAdapter extends android.webkit.HttpAut
hHandler { |
| 1008 private AwHttpAuthHandler mAwHandler; | 1137 private AwHttpAuthHandler mAwHandler; |
| 1009 | 1138 |
| 1010 public AwHttpAuthHandlerAdapter(AwHttpAuthHandler awHandler) { | 1139 public AwHttpAuthHandlerAdapter(AwHttpAuthHandler awHandler) { |
| 1011 mAwHandler = awHandler; | 1140 mAwHandler = awHandler; |
| 1012 } | 1141 } |
| 1013 | 1142 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 else | 1229 else |
| 1101 mAwPermissionRequest.deny(); | 1230 mAwPermissionRequest.deny(); |
| 1102 } | 1231 } |
| 1103 | 1232 |
| 1104 @Override | 1233 @Override |
| 1105 public void deny() { | 1234 public void deny() { |
| 1106 mAwPermissionRequest.deny(); | 1235 mAwPermissionRequest.deny(); |
| 1107 } | 1236 } |
| 1108 } | 1237 } |
| 1109 } | 1238 } |
| OLD | NEW |