| 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.Manifest; | 7 import android.Manifest; |
| 8 import android.app.ActivityManager; | 8 import android.app.ActivityManager; |
| 9 import android.content.ComponentCallbacks2; | 9 import android.content.ComponentCallbacks2; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; | 35 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; |
| 36 | 36 |
| 37 import org.chromium.android_webview.AwBrowserContext; | 37 import org.chromium.android_webview.AwBrowserContext; |
| 38 import org.chromium.android_webview.AwBrowserProcess; | 38 import org.chromium.android_webview.AwBrowserProcess; |
| 39 import org.chromium.android_webview.AwContents; | 39 import org.chromium.android_webview.AwContents; |
| 40 import org.chromium.android_webview.AwContentsClient; | 40 import org.chromium.android_webview.AwContentsClient; |
| 41 import org.chromium.android_webview.AwContentsStatics; | 41 import org.chromium.android_webview.AwContentsStatics; |
| 42 import org.chromium.android_webview.AwCookieManager; | 42 import org.chromium.android_webview.AwCookieManager; |
| 43 import org.chromium.android_webview.AwDevToolsServer; | 43 import org.chromium.android_webview.AwDevToolsServer; |
| 44 import org.chromium.android_webview.AwGeolocationPermissions; | |
| 45 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; | 44 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; |
| 46 import org.chromium.android_webview.AwQuotaManagerBridge; | 45 import org.chromium.android_webview.AwQuotaManagerBridge; |
| 47 import org.chromium.android_webview.AwResource; | 46 import org.chromium.android_webview.AwResource; |
| 48 import org.chromium.android_webview.AwServiceWorkerController; | |
| 49 import org.chromium.android_webview.AwSettings; | 47 import org.chromium.android_webview.AwSettings; |
| 50 import org.chromium.android_webview.HttpAuthDatabase; | 48 import org.chromium.android_webview.HttpAuthDatabase; |
| 51 import org.chromium.android_webview.R; | 49 import org.chromium.android_webview.R; |
| 52 import org.chromium.android_webview.ResourcesContextWrapperFactory; | 50 import org.chromium.android_webview.ResourcesContextWrapperFactory; |
| 53 import org.chromium.base.BuildConfig; | 51 import org.chromium.base.BuildConfig; |
| 54 import org.chromium.base.CommandLine; | 52 import org.chromium.base.CommandLine; |
| 55 import org.chromium.base.ContextUtils; | 53 import org.chromium.base.ContextUtils; |
| 56 import org.chromium.base.MemoryPressureListener; | 54 import org.chromium.base.MemoryPressureListener; |
| 57 import org.chromium.base.PathService; | 55 import org.chromium.base.PathService; |
| 58 import org.chromium.base.PathUtils; | 56 import org.chromium.base.PathUtils; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 77 * Entry point to the WebView. The system framework talks to this class to get i
nstances of the | 75 * Entry point to the WebView. The system framework talks to this class to get i
nstances of the |
| 78 * implementation classes. | 76 * implementation classes. |
| 79 */ | 77 */ |
| 80 @SuppressWarnings("deprecation") | 78 @SuppressWarnings("deprecation") |
| 81 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { | 79 public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { |
| 82 private static final String TAG = "WebViewChromiumFactoryProvider"; | 80 private static final String TAG = "WebViewChromiumFactoryProvider"; |
| 83 | 81 |
| 84 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs"; | 82 private static final String CHROMIUM_PREFS_NAME = "WebViewChromiumPrefs"; |
| 85 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed"; | 83 private static final String VERSION_CODE_PREF = "lastVersionCodeUsed"; |
| 86 private static final String COMMAND_LINE_FILE = "/data/local/tmp/webview-com
mand-line"; | 84 private static final String COMMAND_LINE_FILE = "/data/local/tmp/webview-com
mand-line"; |
| 85 private static final String HTTP_AUTH_DATABASE_FILE = "http_auth.db"; |
| 87 | 86 |
| 88 private class WebViewChromiumRunQueue { | 87 private class WebViewChromiumRunQueue { |
| 89 public WebViewChromiumRunQueue() { | 88 public WebViewChromiumRunQueue() { |
| 90 mQueue = new ConcurrentLinkedQueue<Runnable>(); | 89 mQueue = new ConcurrentLinkedQueue<Runnable>(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 public void addTask(Runnable task) { | 92 public void addTask(Runnable task) { |
| 94 mQueue.add(task); | 93 mQueue.add(task); |
| 95 if (WebViewChromiumFactoryProvider.this.hasStarted()) { | 94 if (WebViewChromiumFactoryProvider.this.hasStarted()) { |
| 96 ThreadUtils.runOnUiThread(new Runnable() { | 95 ThreadUtils.runOnUiThread(new Runnable() { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 404 } |
| 406 | 405 |
| 407 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); | 406 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); |
| 408 mWebViewDelegate.setOnTraceEnabledChangeListener( | 407 mWebViewDelegate.setOnTraceEnabledChangeListener( |
| 409 new WebViewDelegate.OnTraceEnabledChangeListener() { | 408 new WebViewDelegate.OnTraceEnabledChangeListener() { |
| 410 @Override | 409 @Override |
| 411 public void onTraceEnabledChange(boolean enabled) { | 410 public void onTraceEnabledChange(boolean enabled) { |
| 412 TraceEvent.setATraceEnabled(enabled); | 411 TraceEvent.setATraceEnabled(enabled); |
| 413 } | 412 } |
| 414 }); | 413 }); |
| 414 |
| 415 // Initialize thread-unsafe singletons. |
| 416 AwBrowserContext awBrowserContext = getBrowserContextOnUiThread(); |
| 417 mGeolocationPermissions = new GeolocationPermissionsAdapter( |
| 418 this, awBrowserContext.getGeolocationPermissions()); |
| 419 mWebStorage = new WebStorageAdapter(this, AwQuotaManagerBridge.getInstan
ce()); |
| 420 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
| 421 mServiceWorkerController = new ServiceWorkerControllerAdapter( |
| 422 awBrowserContext.getServiceWorkerController()); |
| 423 } |
| 424 |
| 415 mStarted = true; | 425 mStarted = true; |
| 416 mRunQueue.drainQueue(); | 426 mRunQueue.drainQueue(); |
| 417 } | 427 } |
| 418 | 428 |
| 419 boolean hasStarted() { | 429 boolean hasStarted() { |
| 420 return mStarted; | 430 return mStarted; |
| 421 } | 431 } |
| 422 | 432 |
| 423 void startYourEngines(boolean onMainThread) { | 433 void startYourEngines(boolean onMainThread) { |
| 424 synchronized (mLock) { | 434 synchronized (mLock) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 // Ignore this exception and return false. | 556 // Ignore this exception and return false. |
| 547 } | 557 } |
| 548 return false; | 558 return false; |
| 549 } | 559 } |
| 550 | 560 |
| 551 @Override | 561 @Override |
| 552 public GeolocationPermissions getGeolocationPermissions() { | 562 public GeolocationPermissions getGeolocationPermissions() { |
| 553 synchronized (mLock) { | 563 synchronized (mLock) { |
| 554 if (mGeolocationPermissions == null) { | 564 if (mGeolocationPermissions == null) { |
| 555 ensureChromiumStartedLocked(true); | 565 ensureChromiumStartedLocked(true); |
| 556 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r
unningOnUiThread() | |
| 557 ? getBrowserContextOnUiThread().getGeolocationPermission
s() | |
| 558 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis
sions>() { | |
| 559 @Override | |
| 560 public AwGeolocationPermissions call() { | |
| 561 return getBrowserContextOnUiThread().getGeolocat
ionPermissions(); | |
| 562 } | |
| 563 }); | |
| 564 mGeolocationPermissions = | |
| 565 new GeolocationPermissionsAdapter(this, awGelocationPerm
issions); | |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 return mGeolocationPermissions; | 568 return mGeolocationPermissions; |
| 569 } | 569 } |
| 570 | 570 |
| 571 @Override | 571 @Override |
| 572 public CookieManager getCookieManager() { | 572 public CookieManager getCookieManager() { |
| 573 synchronized (mLock) { | 573 synchronized (mLock) { |
| 574 if (mCookieManager == null) { | 574 if (mCookieManager == null) { |
| 575 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; | 575 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 return mCookieManager; | 578 return mCookieManager; |
| 579 } | 579 } |
| 580 | 580 |
| 581 @Override | 581 @Override |
| 582 public ServiceWorkerController getServiceWorkerController() { | 582 public ServiceWorkerController getServiceWorkerController() { |
| 583 synchronized (mLock) { | 583 synchronized (mLock) { |
| 584 if (mServiceWorkerController == null) { | 584 if (mServiceWorkerController == null) { |
| 585 ensureChromiumStartedLocked(true); | 585 ensureChromiumStartedLocked(true); |
| 586 AwServiceWorkerController awServiceWorkerController = | |
| 587 ThreadUtils.runningOnUiThread() | |
| 588 ? getBrowserContextOnUiThread().getServiceWorkerControll
er() | |
| 589 : runOnUiThreadBlocking(new Callable<AwServiceWorkerCont
roller>() { | |
| 590 @Override | |
| 591 public AwServiceWorkerController call() { | |
| 592 return getBrowserContextOnUiThread().getServiceW
orkerController(); | |
| 593 } | |
| 594 }); | |
| 595 mServiceWorkerController = | |
| 596 new ServiceWorkerControllerAdapter(awServiceWorkerContro
ller); | |
| 597 } | 586 } |
| 598 } | 587 } |
| 599 return (ServiceWorkerController) mServiceWorkerController; | 588 return (ServiceWorkerController) mServiceWorkerController; |
| 600 } | 589 } |
| 601 | 590 |
| 602 public TokenBindingService getTokenBindingService() { | 591 public TokenBindingService getTokenBindingService() { |
| 603 synchronized (mLock) { | 592 synchronized (mLock) { |
| 604 if (mTokenBindingManager == null) { | 593 if (mTokenBindingManager == null) { |
| 605 mTokenBindingManager = new TokenBindingManagerAdapter(this); | 594 mTokenBindingManager = new TokenBindingManagerAdapter(this); |
| 606 } | 595 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 617 } | 606 } |
| 618 } | 607 } |
| 619 return mWebIconDatabase; | 608 return mWebIconDatabase; |
| 620 } | 609 } |
| 621 | 610 |
| 622 @Override | 611 @Override |
| 623 public WebStorage getWebStorage() { | 612 public WebStorage getWebStorage() { |
| 624 synchronized (mLock) { | 613 synchronized (mLock) { |
| 625 if (mWebStorage == null) { | 614 if (mWebStorage == null) { |
| 626 ensureChromiumStartedLocked(true); | 615 ensureChromiumStartedLocked(true); |
| 627 AwQuotaManagerBridge awQuotaManager = ThreadUtils.runningOnUiThr
ead() | |
| 628 ? AwQuotaManagerBridge.getInstance() | |
| 629 : runOnUiThreadBlocking(new Callable<AwQuotaManagerBridg
e>() { | |
| 630 @Override | |
| 631 public AwQuotaManagerBridge call() { | |
| 632 return AwQuotaManagerBridge.getInstance(); | |
| 633 } | |
| 634 }); | |
| 635 mWebStorage = new WebStorageAdapter(this, awQuotaManager); | |
| 636 } | 616 } |
| 637 } | 617 } |
| 638 return mWebStorage; | 618 return mWebStorage; |
| 639 } | 619 } |
| 640 | 620 |
| 641 @Override | 621 @Override |
| 642 public WebViewDatabase getWebViewDatabase(final Context context) { | 622 public WebViewDatabase getWebViewDatabase(final Context context) { |
| 643 synchronized (mLock) { | 623 synchronized (mLock) { |
| 644 if (mWebViewDatabase == null) { | 624 if (mWebViewDatabase == null) { |
| 645 ensureChromiumStartedLocked(true); | 625 ensureChromiumStartedLocked(true); |
| 646 HttpAuthDatabase awDatabase = ThreadUtils.runningOnUiThread() | 626 mWebViewDatabase = new WebViewDatabaseAdapter( |
| 647 ? getBrowserContextOnUiThread().getHttpAuthDatabase(cont
ext) | 627 this, HttpAuthDatabase.newInstance(context, HTTP_AUTH_DA
TABASE_FILE)); |
| 648 : runOnUiThreadBlocking(new Callable<HttpAuthDatabase>()
{ | |
| 649 @Override | |
| 650 public HttpAuthDatabase call() { | |
| 651 return getBrowserContextOnUiThread().getHttpAuth
Database(context); | |
| 652 } | |
| 653 }); | |
| 654 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | |
| 655 } | 628 } |
| 656 } | 629 } |
| 657 return mWebViewDatabase; | 630 return mWebViewDatabase; |
| 658 } | 631 } |
| 659 | 632 |
| 660 WebViewDelegate getWebViewDelegate() { | 633 WebViewDelegate getWebViewDelegate() { |
| 661 return mWebViewDelegate; | 634 return mWebViewDelegate; |
| 662 } | 635 } |
| 663 } | 636 } |
| OLD | NEW |