| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 // Initialization guarded by mLock. | 81 // Initialization guarded by mLock. |
| 82 private AwBrowserContext mBrowserContext; | 82 private AwBrowserContext mBrowserContext; |
| 83 private Statics mStaticMethods; | 83 private Statics mStaticMethods; |
| 84 private GeolocationPermissionsAdapter mGeolocationPermissions; | 84 private GeolocationPermissionsAdapter mGeolocationPermissions; |
| 85 private CookieManagerAdapter mCookieManager; | 85 private CookieManagerAdapter mCookieManager; |
| 86 private WebIconDatabaseAdapter mWebIconDatabase; | 86 private WebIconDatabaseAdapter mWebIconDatabase; |
| 87 private WebStorageAdapter mWebStorage; | 87 private WebStorageAdapter mWebStorage; |
| 88 private WebViewDatabaseAdapter mWebViewDatabase; | 88 private WebViewDatabaseAdapter mWebViewDatabase; |
| 89 private AwDevToolsServer mDevToolsServer; | 89 private AwDevToolsServer mDevToolsServer; |
| 90 private Context mWrappedAppContext; | |
| 91 | 90 |
| 92 private ArrayList<WeakReference<WebViewChromium>> mWebViewsToStart = | 91 private ArrayList<WeakReference<WebViewChromium>> mWebViewsToStart = |
| 93 new ArrayList<WeakReference<WebViewChromium>>(); | 92 new ArrayList<WeakReference<WebViewChromium>>(); |
| 94 | 93 |
| 95 // Read/write protected by mLock. | 94 // Read/write protected by mLock. |
| 96 private boolean mStarted; | 95 private boolean mStarted; |
| 97 private AwDataReductionProxyManager mProxyManager; | 96 private AwDataReductionProxyManager mProxyManager; |
| 98 | 97 |
| 99 private SharedPreferences mWebViewPrefs; | 98 private SharedPreferences mWebViewPrefs; |
| 100 private WebViewDelegate mWebViewDelegate; | 99 private WebViewDelegate mWebViewDelegate; |
| 101 | 100 |
| 102 /** | 101 /** |
| 103 * Constructor called by the API 21 version of {@link WebViewFactory} and ea
rlier. | 102 * Constructor called by the API 21 version of {@link WebViewFactory} and ea
rlier. |
| 104 */ | 103 */ |
| 105 public WebViewChromiumFactoryProvider() { | 104 public WebViewChromiumFactoryProvider() { |
| 106 initialize(WebViewDelegateFactory.createApi21CompatibilityDelegate()); | 105 initialize(WebViewDelegateFactory.createApi21CompatibilityDelegate()); |
| 107 } | 106 } |
| 108 | 107 |
| 109 /** | 108 /** |
| 110 * Constructor called by the API 22 version of {@link WebViewFactory} and la
ter. | 109 * Constructor called by the API 22 version of {@link WebViewFactory} and la
ter. |
| 111 */ | 110 */ |
| 112 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat
e) { | 111 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat
e) { |
| 113 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); | 112 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); |
| 114 } | 113 } |
| 115 | 114 |
| 116 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 115 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
| 117 private void initialize(WebViewDelegate webViewDelegate) { | 116 private void initialize(WebViewDelegate webViewDelegate) { |
| 118 mWebViewDelegate = webViewDelegate; | 117 mWebViewDelegate = webViewDelegate; |
| 118 |
| 119 // WebView needs to make sure to always use the wrapped application cont
ext. |
| 120 ContextUtils.initApplicationContext( |
| 121 ResourcesContextWrapperFactory.get(mWebViewDelegate.getApplicati
on())); |
| 122 |
| 119 if (isBuildDebuggable()) { | 123 if (isBuildDebuggable()) { |
| 120 // Suppress the StrictMode violation as this codepath is only hit on
debugglable builds. | 124 // Suppress the StrictMode violation as this codepath is only hit on
debugglable builds. |
| 121 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); | 125 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); |
| 122 CommandLine.initFromFile(COMMAND_LINE_FILE); | 126 CommandLine.initFromFile(COMMAND_LINE_FILE); |
| 123 StrictMode.setThreadPolicy(oldPolicy); | 127 StrictMode.setThreadPolicy(oldPolicy); |
| 124 } else { | 128 } else { |
| 125 CommandLine.init(null); | 129 CommandLine.init(null); |
| 126 } | 130 } |
| 127 | 131 |
| 128 ThreadUtils.setWillOverrideUiThread(); | 132 ThreadUtils.setWillOverrideUiThread(); |
| 129 // Load chromium library. | 133 // Load chromium library. |
| 130 AwBrowserProcess.loadLibrary(getWrappedCurrentApplicationContext()); | 134 AwBrowserProcess.loadLibrary(ContextUtils.getApplicationContext()); |
| 131 | 135 |
| 132 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); | 136 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); |
| 133 | 137 |
| 134 // Load glue-layer support library. | 138 // Load glue-layer support library. |
| 135 System.loadLibrary("webviewchromium_plat_support"); | 139 System.loadLibrary("webviewchromium_plat_support"); |
| 136 | 140 |
| 137 // Use shared preference to check for package downgrade. | 141 // Use shared preference to check for package downgrade. |
| 138 mWebViewPrefs = mWebViewDelegate.getApplication().getSharedPreferences( | 142 mWebViewPrefs = mWebViewDelegate.getApplication().getSharedPreferences( |
| 139 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); | 143 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); |
| 140 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); | 144 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 assert Thread.holdsLock(mLock) && ThreadUtils.runningOnUiThread(); | 261 assert Thread.holdsLock(mLock) && ThreadUtils.runningOnUiThread(); |
| 258 | 262 |
| 259 // The post-condition of this method is everything is ready, so notify n
ow to cover all | 263 // The post-condition of this method is everything is ready, so notify n
ow to cover all |
| 260 // return paths. (Other threads will not wake-up until we release |mLock
|, whatever). | 264 // return paths. (Other threads will not wake-up until we release |mLock
|, whatever). |
| 261 mLock.notifyAll(); | 265 mLock.notifyAll(); |
| 262 | 266 |
| 263 if (mStarted) { | 267 if (mStarted) { |
| 264 return; | 268 return; |
| 265 } | 269 } |
| 266 | 270 |
| 267 Context context = getWrappedCurrentApplicationContext(); | 271 Context context = ContextUtils.getApplicationContext(); |
| 268 try { | 272 try { |
| 269 LibraryLoader.get(LibraryProcessType.PROCESS_WEBVIEW).ensureInitiali
zed(context); | 273 LibraryLoader.get(LibraryProcessType.PROCESS_WEBVIEW).ensureInitiali
zed(context); |
| 270 } catch (ProcessInitException e) { | 274 } catch (ProcessInitException e) { |
| 271 throw new RuntimeException("Error initializing WebView library", e); | 275 throw new RuntimeException("Error initializing WebView library", e); |
| 272 } | 276 } |
| 273 | 277 |
| 274 PathService.override(PathService.DIR_MODULE, "/system/lib/"); | 278 PathService.override(PathService.DIR_MODULE, "/system/lib/"); |
| 275 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi
ew/paks"); | 279 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi
ew/paks"); |
| 276 | 280 |
| 277 // Make sure that ResourceProvider is initialized before starting the br
owser process. | 281 // Make sure that ResourceProvider is initialized before starting the br
owser process. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 boolean hasStarted() { | 319 boolean hasStarted() { |
| 316 return mStarted; | 320 return mStarted; |
| 317 } | 321 } |
| 318 | 322 |
| 319 void startYourEngines(boolean onMainThread) { | 323 void startYourEngines(boolean onMainThread) { |
| 320 synchronized (mLock) { | 324 synchronized (mLock) { |
| 321 ensureChromiumStartedLocked(onMainThread); | 325 ensureChromiumStartedLocked(onMainThread); |
| 322 } | 326 } |
| 323 } | 327 } |
| 324 | 328 |
| 325 private Context getWrappedCurrentApplicationContext() { | |
| 326 if (mWrappedAppContext == null) { | |
| 327 mWrappedAppContext = ResourcesContextWrapperFactory.get( | |
| 328 mWebViewDelegate.getApplication()); | |
| 329 } | |
| 330 return mWrappedAppContext; | |
| 331 } | |
| 332 | |
| 333 AwBrowserContext getBrowserContext() { | 329 AwBrowserContext getBrowserContext() { |
| 334 synchronized (mLock) { | 330 synchronized (mLock) { |
| 335 return getBrowserContextLocked(); | 331 return getBrowserContextLocked(); |
| 336 } | 332 } |
| 337 } | 333 } |
| 338 | 334 |
| 339 private AwBrowserContext getBrowserContextLocked() { | 335 private AwBrowserContext getBrowserContextLocked() { |
| 340 assert Thread.holdsLock(mLock); | 336 assert Thread.holdsLock(mLock); |
| 341 assert mStarted; | 337 assert mStarted; |
| 342 if (mBrowserContext == null) { | 338 if (mBrowserContext == null) { |
| 343 mBrowserContext = | 339 mBrowserContext = |
| 344 new AwBrowserContext(mWebViewPrefs, getWrappedCurrentApplica
tionContext()); | 340 new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicat
ionContext()); |
| 345 } | 341 } |
| 346 return mBrowserContext; | 342 return mBrowserContext; |
| 347 } | 343 } |
| 348 | 344 |
| 349 private void setWebContentsDebuggingEnabled(boolean enable) { | 345 private void setWebContentsDebuggingEnabled(boolean enable) { |
| 350 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { | 346 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { |
| 351 throw new RuntimeException( | 347 throw new RuntimeException( |
| 352 "Toggling of Web Contents Debugging must be done on the UI t
hread"); | 348 "Toggling of Web Contents Debugging must be done on the UI t
hread"); |
| 353 } | 349 } |
| 354 if (mDevToolsServer == null) { | 350 if (mDevToolsServer == null) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 getBrowserContextLocked().getGeolocationPermissions()); | 440 getBrowserContextLocked().getGeolocationPermissions()); |
| 445 } | 441 } |
| 446 } | 442 } |
| 447 return mGeolocationPermissions; | 443 return mGeolocationPermissions; |
| 448 } | 444 } |
| 449 | 445 |
| 450 @Override | 446 @Override |
| 451 public CookieManager getCookieManager() { | 447 public CookieManager getCookieManager() { |
| 452 synchronized (mLock) { | 448 synchronized (mLock) { |
| 453 if (mCookieManager == null) { | 449 if (mCookieManager == null) { |
| 454 if (!mStarted) { | |
| 455 // We can use CookieManager without starting Chromium; the n
ative code | |
| 456 // will bring up just the parts it needs to make this work o
n a temporary | |
| 457 // basis until Chromium is started for real. The temporary c
ookie manager | |
| 458 // needs the application context to have been set. | |
| 459 ContextUtils.initApplicationContext(getWrappedCurrentApplica
tionContext()); | |
| 460 } | |
| 461 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; | 450 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; |
| 462 } | 451 } |
| 463 } | 452 } |
| 464 return mCookieManager; | 453 return mCookieManager; |
| 465 } | 454 } |
| 466 | 455 |
| 467 @Override | 456 @Override |
| 468 public android.webkit.WebIconDatabase getWebIconDatabase() { | 457 public android.webkit.WebIconDatabase getWebIconDatabase() { |
| 469 synchronized (mLock) { | 458 synchronized (mLock) { |
| 470 if (mWebIconDatabase == null) { | 459 if (mWebIconDatabase == null) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 496 browserContext.getHttpAuthDatabase(context)); | 485 browserContext.getHttpAuthDatabase(context)); |
| 497 } | 486 } |
| 498 } | 487 } |
| 499 return mWebViewDatabase; | 488 return mWebViewDatabase; |
| 500 } | 489 } |
| 501 | 490 |
| 502 WebViewDelegate getWebViewDelegate() { | 491 WebViewDelegate getWebViewDelegate() { |
| 503 return mWebViewDelegate; | 492 return mWebViewDelegate; |
| 504 } | 493 } |
| 505 } | 494 } |
| OLD | NEW |