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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 // Initialization guarded by mLock. | 80 // Initialization guarded by mLock. |
81 private AwBrowserContext mBrowserContext; | 81 private AwBrowserContext mBrowserContext; |
82 private Statics mStaticMethods; | 82 private Statics mStaticMethods; |
83 private GeolocationPermissionsAdapter mGeolocationPermissions; | 83 private GeolocationPermissionsAdapter mGeolocationPermissions; |
84 private CookieManagerAdapter mCookieManager; | 84 private CookieManagerAdapter mCookieManager; |
85 private WebIconDatabaseAdapter mWebIconDatabase; | 85 private WebIconDatabaseAdapter mWebIconDatabase; |
86 private WebStorageAdapter mWebStorage; | 86 private WebStorageAdapter mWebStorage; |
87 private WebViewDatabaseAdapter mWebViewDatabase; | 87 private WebViewDatabaseAdapter mWebViewDatabase; |
88 private AwDevToolsServer mDevToolsServer; | 88 private AwDevToolsServer mDevToolsServer; |
| 89 private Context mWrappedAppContext; |
89 | 90 |
90 private ArrayList<WeakReference<WebViewChromium>> mWebViewsToStart = | 91 private ArrayList<WeakReference<WebViewChromium>> mWebViewsToStart = |
91 new ArrayList<WeakReference<WebViewChromium>>(); | 92 new ArrayList<WeakReference<WebViewChromium>>(); |
92 | 93 |
93 // Read/write protected by mLock. | 94 // Read/write protected by mLock. |
94 private boolean mStarted; | 95 private boolean mStarted; |
95 private AwDataReductionProxyManager mProxyManager; | 96 private AwDataReductionProxyManager mProxyManager; |
96 | 97 |
97 private SharedPreferences mWebViewPrefs; | 98 private SharedPreferences mWebViewPrefs; |
98 private WebViewDelegate mWebViewDelegate; | 99 private WebViewDelegate mWebViewDelegate; |
99 | 100 |
100 /** | 101 /** |
101 * 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. |
102 */ | 103 */ |
103 public WebViewChromiumFactoryProvider() { | 104 public WebViewChromiumFactoryProvider() { |
104 initialize(WebViewDelegateFactory.createApi21CompatibilityDelegate()); | 105 initialize(WebViewDelegateFactory.createApi21CompatibilityDelegate()); |
105 } | 106 } |
106 | 107 |
107 /** | 108 /** |
108 * 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. |
109 */ | 110 */ |
110 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat
e) { | 111 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat
e) { |
111 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); | 112 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); |
112 } | 113 } |
113 | 114 |
114 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 115 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
115 private void initialize(WebViewDelegate webViewDelegate) { | 116 private void initialize(WebViewDelegate webViewDelegate) { |
116 mWebViewDelegate = webViewDelegate; | 117 mWebViewDelegate = webViewDelegate; |
117 | |
118 // WebView needs to make sure to always use the wrapped application cont
ext. | |
119 ContextUtils.initApplicationContext( | |
120 ResourcesContextWrapperFactory.get(mWebViewDelegate.getApplicati
on())); | |
121 | |
122 if (isBuildDebuggable()) { | 118 if (isBuildDebuggable()) { |
123 // Suppress the StrictMode violation as this codepath is only hit on
debugglable builds. | 119 // Suppress the StrictMode violation as this codepath is only hit on
debugglable builds. |
124 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); | 120 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); |
125 CommandLine.initFromFile(COMMAND_LINE_FILE); | 121 CommandLine.initFromFile(COMMAND_LINE_FILE); |
126 StrictMode.setThreadPolicy(oldPolicy); | 122 StrictMode.setThreadPolicy(oldPolicy); |
127 } else { | 123 } else { |
128 CommandLine.init(null); | 124 CommandLine.init(null); |
129 } | 125 } |
130 | 126 |
131 ThreadUtils.setWillOverrideUiThread(); | 127 ThreadUtils.setWillOverrideUiThread(); |
132 // Load chromium library. | 128 // Load chromium library. |
133 AwBrowserProcess.loadLibrary(ContextUtils.getApplicationContext()); | 129 AwBrowserProcess.loadLibrary(getWrappedCurrentApplicationContext()); |
134 | 130 |
135 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); | 131 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); |
136 | 132 |
137 // Load glue-layer support library. | 133 // Load glue-layer support library. |
138 System.loadLibrary("webviewchromium_plat_support"); | 134 System.loadLibrary("webviewchromium_plat_support"); |
139 | 135 |
140 // Use shared preference to check for package downgrade. | 136 // Use shared preference to check for package downgrade. |
141 mWebViewPrefs = mWebViewDelegate.getApplication().getSharedPreferences( | 137 mWebViewPrefs = mWebViewDelegate.getApplication().getSharedPreferences( |
142 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); | 138 CHROMIUM_PREFS_NAME, Context.MODE_PRIVATE); |
143 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); | 139 int lastVersion = mWebViewPrefs.getInt(VERSION_CODE_PREF, 0); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 assert Thread.holdsLock(mLock) && ThreadUtils.runningOnUiThread(); | 233 assert Thread.holdsLock(mLock) && ThreadUtils.runningOnUiThread(); |
238 | 234 |
239 // The post-condition of this method is everything is ready, so notify n
ow to cover all | 235 // The post-condition of this method is everything is ready, so notify n
ow to cover all |
240 // return paths. (Other threads will not wake-up until we release |mLock
|, whatever). | 236 // return paths. (Other threads will not wake-up until we release |mLock
|, whatever). |
241 mLock.notifyAll(); | 237 mLock.notifyAll(); |
242 | 238 |
243 if (mStarted) { | 239 if (mStarted) { |
244 return; | 240 return; |
245 } | 241 } |
246 | 242 |
247 Context context = ContextUtils.getApplicationContext(); | 243 Context context = getWrappedCurrentApplicationContext(); |
248 try { | 244 try { |
249 LibraryLoader.get(LibraryProcessType.PROCESS_WEBVIEW).ensureInitiali
zed(context); | 245 LibraryLoader.get(LibraryProcessType.PROCESS_WEBVIEW).ensureInitiali
zed(context); |
250 } catch (ProcessInitException e) { | 246 } catch (ProcessInitException e) { |
251 throw new RuntimeException("Error initializing WebView library", e); | 247 throw new RuntimeException("Error initializing WebView library", e); |
252 } | 248 } |
253 | 249 |
254 PathService.override(PathService.DIR_MODULE, "/system/lib/"); | 250 PathService.override(PathService.DIR_MODULE, "/system/lib/"); |
255 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi
ew/paks"); | 251 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi
ew/paks"); |
256 | 252 |
257 // Make sure that ResourceProvider is initialized before starting the br
owser process. | 253 // 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... |
295 boolean hasStarted() { | 291 boolean hasStarted() { |
296 return mStarted; | 292 return mStarted; |
297 } | 293 } |
298 | 294 |
299 void startYourEngines(boolean onMainThread) { | 295 void startYourEngines(boolean onMainThread) { |
300 synchronized (mLock) { | 296 synchronized (mLock) { |
301 ensureChromiumStartedLocked(onMainThread); | 297 ensureChromiumStartedLocked(onMainThread); |
302 } | 298 } |
303 } | 299 } |
304 | 300 |
| 301 private Context getWrappedCurrentApplicationContext() { |
| 302 if (mWrappedAppContext == null) { |
| 303 mWrappedAppContext = ResourcesContextWrapperFactory.get( |
| 304 mWebViewDelegate.getApplication()); |
| 305 } |
| 306 return mWrappedAppContext; |
| 307 } |
| 308 |
305 AwBrowserContext getBrowserContext() { | 309 AwBrowserContext getBrowserContext() { |
306 synchronized (mLock) { | 310 synchronized (mLock) { |
307 return getBrowserContextLocked(); | 311 return getBrowserContextLocked(); |
308 } | 312 } |
309 } | 313 } |
310 | 314 |
311 private AwBrowserContext getBrowserContextLocked() { | 315 private AwBrowserContext getBrowserContextLocked() { |
312 assert Thread.holdsLock(mLock); | 316 assert Thread.holdsLock(mLock); |
313 assert mStarted; | 317 assert mStarted; |
314 if (mBrowserContext == null) { | 318 if (mBrowserContext == null) { |
315 mBrowserContext = | 319 mBrowserContext = |
316 new AwBrowserContext(mWebViewPrefs, ContextUtils.getApplicat
ionContext()); | 320 new AwBrowserContext(mWebViewPrefs, getWrappedCurrentApplica
tionContext()); |
317 } | 321 } |
318 return mBrowserContext; | 322 return mBrowserContext; |
319 } | 323 } |
320 | 324 |
321 private void setWebContentsDebuggingEnabled(boolean enable) { | 325 private void setWebContentsDebuggingEnabled(boolean enable) { |
322 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { | 326 if (Looper.myLooper() != ThreadUtils.getUiThreadLooper()) { |
323 throw new RuntimeException( | 327 throw new RuntimeException( |
324 "Toggling of Web Contents Debugging must be done on the UI t
hread"); | 328 "Toggling of Web Contents Debugging must be done on the UI t
hread"); |
325 } | 329 } |
326 if (mDevToolsServer == null) { | 330 if (mDevToolsServer == null) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 getBrowserContextLocked().getGeolocationPermissions()); | 420 getBrowserContextLocked().getGeolocationPermissions()); |
417 } | 421 } |
418 } | 422 } |
419 return mGeolocationPermissions; | 423 return mGeolocationPermissions; |
420 } | 424 } |
421 | 425 |
422 @Override | 426 @Override |
423 public CookieManager getCookieManager() { | 427 public CookieManager getCookieManager() { |
424 synchronized (mLock) { | 428 synchronized (mLock) { |
425 if (mCookieManager == null) { | 429 if (mCookieManager == null) { |
| 430 if (!mStarted) { |
| 431 // We can use CookieManager without starting Chromium; the n
ative code |
| 432 // will bring up just the parts it needs to make this work o
n a temporary |
| 433 // basis until Chromium is started for real. The temporary c
ookie manager |
| 434 // needs the application context to have been set. |
| 435 ContextUtils.initApplicationContext(getWrappedCurrentApplica
tionContext()); |
| 436 } |
426 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; | 437 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; |
427 } | 438 } |
428 } | 439 } |
429 return mCookieManager; | 440 return mCookieManager; |
430 } | 441 } |
431 | 442 |
432 @Override | 443 @Override |
433 public android.webkit.WebIconDatabase getWebIconDatabase() { | 444 public android.webkit.WebIconDatabase getWebIconDatabase() { |
434 synchronized (mLock) { | 445 synchronized (mLock) { |
435 if (mWebIconDatabase == null) { | 446 if (mWebIconDatabase == null) { |
(...skipping 25 matching lines...) Expand all Loading... |
461 browserContext.getHttpAuthDatabase(context)); | 472 browserContext.getHttpAuthDatabase(context)); |
462 } | 473 } |
463 } | 474 } |
464 return mWebViewDatabase; | 475 return mWebViewDatabase; |
465 } | 476 } |
466 | 477 |
467 WebViewDelegate getWebViewDelegate() { | 478 WebViewDelegate getWebViewDelegate() { |
468 return mWebViewDelegate; | 479 return mWebViewDelegate; |
469 } | 480 } |
470 } | 481 } |
OLD | NEW |