Chromium Code Reviews| 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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; | 30 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; |
| 31 | 31 |
| 32 import org.chromium.android_webview.AwBrowserContext; | 32 import org.chromium.android_webview.AwBrowserContext; |
| 33 import org.chromium.android_webview.AwBrowserProcess; | 33 import org.chromium.android_webview.AwBrowserProcess; |
| 34 import org.chromium.android_webview.AwContents; | 34 import org.chromium.android_webview.AwContents; |
| 35 import org.chromium.android_webview.AwContentsClient; | 35 import org.chromium.android_webview.AwContentsClient; |
| 36 import org.chromium.android_webview.AwContentsStatics; | 36 import org.chromium.android_webview.AwContentsStatics; |
| 37 import org.chromium.android_webview.AwCookieManager; | 37 import org.chromium.android_webview.AwCookieManager; |
| 38 import org.chromium.android_webview.AwDevToolsServer; | 38 import org.chromium.android_webview.AwDevToolsServer; |
| 39 import org.chromium.android_webview.AwGeolocationPermissions; | |
| 39 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; | 40 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; |
| 40 import org.chromium.android_webview.AwQuotaManagerBridge; | 41 import org.chromium.android_webview.AwQuotaManagerBridge; |
| 41 import org.chromium.android_webview.AwResource; | 42 import org.chromium.android_webview.AwResource; |
| 42 import org.chromium.android_webview.AwSettings; | 43 import org.chromium.android_webview.AwSettings; |
| 44 import org.chromium.android_webview.HttpAuthDatabase; | |
| 43 import org.chromium.android_webview.R; | 45 import org.chromium.android_webview.R; |
| 44 import org.chromium.android_webview.ResourcesContextWrapperFactory; | 46 import org.chromium.android_webview.ResourcesContextWrapperFactory; |
| 47 import org.chromium.base.BuildConfig; | |
| 45 import org.chromium.base.CommandLine; | 48 import org.chromium.base.CommandLine; |
| 46 import org.chromium.base.ContextUtils; | 49 import org.chromium.base.ContextUtils; |
| 47 import org.chromium.base.MemoryPressureListener; | 50 import org.chromium.base.MemoryPressureListener; |
| 48 import org.chromium.base.PathService; | 51 import org.chromium.base.PathService; |
| 49 import org.chromium.base.PathUtils; | 52 import org.chromium.base.PathUtils; |
| 50 import org.chromium.base.ThreadUtils; | 53 import org.chromium.base.ThreadUtils; |
| 51 import org.chromium.base.TraceEvent; | 54 import org.chromium.base.TraceEvent; |
| 52 import org.chromium.base.annotations.SuppressFBWarnings; | 55 import org.chromium.base.annotations.SuppressFBWarnings; |
| 53 import org.chromium.base.library_loader.LibraryLoader; | 56 import org.chromium.base.library_loader.LibraryLoader; |
| 54 import org.chromium.base.library_loader.LibraryProcessType; | 57 import org.chromium.base.library_loader.LibraryProcessType; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 boolean hasStarted() { | 375 boolean hasStarted() { |
| 373 return mStarted; | 376 return mStarted; |
| 374 } | 377 } |
| 375 | 378 |
| 376 void startYourEngines(boolean onMainThread) { | 379 void startYourEngines(boolean onMainThread) { |
| 377 synchronized (mLock) { | 380 synchronized (mLock) { |
| 378 ensureChromiumStartedLocked(onMainThread); | 381 ensureChromiumStartedLocked(onMainThread); |
| 379 } | 382 } |
| 380 } | 383 } |
| 381 | 384 |
| 382 AwBrowserContext getBrowserContext() { | 385 // Only on UI thread. |
| 383 synchronized (mLock) { | 386 AwBrowserContext getBrowserContextOnUiThread() { |
| 384 return getBrowserContextLocked(); | 387 assert mStarted; |
| 388 if (BuildConfig.DCHECK_IS_ON && !ThreadUtils.runningOnUiThread()) { | |
| 389 throw new RuntimeException( | |
| 390 "getBrowserContextOnUiThread called on " + Thread.currentThr ead()); | |
| 385 } | 391 } |
| 386 } | |
| 387 | 392 |
| 388 private AwBrowserContext getBrowserContextLocked() { | |
| 389 assert Thread.holdsLock(mLock); | |
| 390 assert mStarted; | |
| 391 if (mBrowserContext == null) { | 393 if (mBrowserContext == null) { |
| 392 mBrowserContext = | 394 mBrowserContext = |
| 393 new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicat ionContext()); | 395 new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicat ionContext()); |
| 394 } | 396 } |
| 395 return mBrowserContext; | 397 return mBrowserContext; |
| 396 } | 398 } |
| 397 | 399 |
| 398 private void setWebContentsDebuggingEnabled(boolean enable) { | 400 private void setWebContentsDebuggingEnabled(boolean enable) { |
| 399 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { | 401 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { |
| 400 throw new RuntimeException( | 402 throw new RuntimeException( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 @Override | 476 @Override |
| 475 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { | 477 public WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess) { |
| 476 return new WebViewChromium(this, webView, privateAccess); | 478 return new WebViewChromium(this, webView, privateAccess); |
| 477 } | 479 } |
| 478 | 480 |
| 479 @Override | 481 @Override |
| 480 public GeolocationPermissions getGeolocationPermissions() { | 482 public GeolocationPermissions getGeolocationPermissions() { |
| 481 synchronized (mLock) { | 483 synchronized (mLock) { |
| 482 if (mGeolocationPermissions == null) { | 484 if (mGeolocationPermissions == null) { |
| 483 ensureChromiumStartedLocked(true); | 485 ensureChromiumStartedLocked(true); |
| 484 mGeolocationPermissions = new GeolocationPermissionsAdapter( | 486 AwGeolocationPermissions awGelocationPermissions = ThreadUtils.r unningOnUiThread() |
| 485 getBrowserContextLocked().getGeolocationPermissions()); | 487 ? getBrowserContextOnUiThread().getGeolocationPermission s() |
|
Torne
2016/07/29 11:24:26
minor thing: seems like it might be preferable to
boliu
2016/07/29 13:23:55
I guess we don't do that in WebVIewChromium becaus
| |
| 488 : runOnUiThreadBlocking(new Callable<AwGeolocationPermis sions>() { | |
| 489 @Override | |
| 490 public AwGeolocationPermissions call() { | |
| 491 return getBrowserContextOnUiThread().getGeolocat ionPermissions(); | |
| 492 } | |
| 493 }); | |
| 494 mGeolocationPermissions = | |
| 495 new GeolocationPermissionsAdapter(awGelocationPermission s); | |
| 486 } | 496 } |
| 487 } | 497 } |
| 488 return mGeolocationPermissions; | 498 return mGeolocationPermissions; |
| 489 } | 499 } |
| 490 | 500 |
| 491 @Override | 501 @Override |
| 492 public CookieManager getCookieManager() { | 502 public CookieManager getCookieManager() { |
| 493 synchronized (mLock) { | 503 synchronized (mLock) { |
| 494 if (mCookieManager == null) { | 504 if (mCookieManager == null) { |
| 495 mCookieManager = new CookieManagerAdapter(new AwCookieManager()) ; | 505 mCookieManager = new CookieManagerAdapter(new AwCookieManager()) ; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 507 } | 517 } |
| 508 } | 518 } |
| 509 return mWebIconDatabase; | 519 return mWebIconDatabase; |
| 510 } | 520 } |
| 511 | 521 |
| 512 @Override | 522 @Override |
| 513 public WebStorage getWebStorage() { | 523 public WebStorage getWebStorage() { |
| 514 synchronized (mLock) { | 524 synchronized (mLock) { |
| 515 if (mWebStorage == null) { | 525 if (mWebStorage == null) { |
| 516 ensureChromiumStartedLocked(true); | 526 ensureChromiumStartedLocked(true); |
| 517 mWebStorage = new WebStorageAdapter(AwQuotaManagerBridge.getInst ance()); | 527 AwQuotaManagerBridge awQuotaManager = ThreadUtils.runningOnUiThr ead() |
| 528 ? AwQuotaManagerBridge.getInstance() | |
| 529 : runOnUiThreadBlocking(new Callable<AwQuotaManagerBridg e>() { | |
| 530 @Override | |
| 531 public AwQuotaManagerBridge call() { | |
| 532 return AwQuotaManagerBridge.getInstance(); | |
| 533 } | |
| 534 }); | |
| 535 mWebStorage = new WebStorageAdapter(awQuotaManager); | |
| 518 } | 536 } |
| 519 } | 537 } |
| 520 return mWebStorage; | 538 return mWebStorage; |
| 521 } | 539 } |
| 522 | 540 |
| 523 @Override | 541 @Override |
| 524 public WebViewDatabase getWebViewDatabase(Context context) { | 542 public WebViewDatabase getWebViewDatabase(final Context context) { |
| 525 synchronized (mLock) { | 543 synchronized (mLock) { |
| 526 if (mWebViewDatabase == null) { | 544 if (mWebViewDatabase == null) { |
| 527 ensureChromiumStartedLocked(true); | 545 ensureChromiumStartedLocked(true); |
| 528 AwBrowserContext browserContext = getBrowserContextLocked(); | 546 HttpAuthDatabase awDatabase = ThreadUtils.runningOnUiThread() |
| 529 mWebViewDatabase = new WebViewDatabaseAdapter( | 547 ? getBrowserContextOnUiThread().getHttpAuthDatabase(cont ext) |
| 530 browserContext.getHttpAuthDatabase(context)); | 548 : runOnUiThreadBlocking(new Callable<HttpAuthDatabase>() { |
| 549 @Override | |
| 550 public HttpAuthDatabase call() { | |
| 551 return getBrowserContextOnUiThread().getHttpAuth Database(context); | |
| 552 } | |
| 553 }); | |
| 554 mWebViewDatabase = new WebViewDatabaseAdapter(awDatabase); | |
| 531 } | 555 } |
| 532 } | 556 } |
| 533 return mWebViewDatabase; | 557 return mWebViewDatabase; |
| 534 } | 558 } |
| 535 | 559 |
| 536 WebViewDelegate getWebViewDelegate() { | 560 WebViewDelegate getWebViewDelegate() { |
| 537 return mWebViewDelegate; | 561 return mWebViewDelegate; |
| 538 } | 562 } |
| 539 } | 563 } |
| OLD | NEW |