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