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; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.SharedPreferences; | 12 import android.content.SharedPreferences; |
13 import android.content.pm.PackageInfo; | 13 import android.content.pm.PackageInfo; |
14 import android.content.pm.PackageManager; | 14 import android.content.pm.PackageManager; |
15 import android.content.pm.PackageManager.NameNotFoundException; | 15 import android.content.pm.PackageManager.NameNotFoundException; |
16 import android.net.Uri; | 16 import android.net.Uri; |
17 import android.os.Build; | 17 import android.os.Build; |
18 import android.os.Looper; | 18 import android.os.Looper; |
19 import android.os.Process; | 19 import android.os.Process; |
20 import android.os.StrictMode; | 20 import android.os.StrictMode; |
| 21 import android.provider.Settings; |
21 import android.util.Log; | 22 import android.util.Log; |
22 import android.webkit.CookieManager; | 23 import android.webkit.CookieManager; |
23 import android.webkit.GeolocationPermissions; | 24 import android.webkit.GeolocationPermissions; |
| 25 import android.webkit.ServiceWorkerController; |
| 26 import android.webkit.TokenBindingService; |
24 import android.webkit.WebStorage; | 27 import android.webkit.WebStorage; |
25 import android.webkit.WebView; | 28 import android.webkit.WebView; |
26 import android.webkit.WebViewDatabase; | 29 import android.webkit.WebViewDatabase; |
27 import android.webkit.WebViewFactory; | 30 import android.webkit.WebViewFactory; |
28 import android.webkit.WebViewFactoryProvider; | 31 import android.webkit.WebViewFactoryProvider; |
29 import android.webkit.WebViewProvider; | 32 import android.webkit.WebViewProvider; |
30 | 33 |
31 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; | 34 import com.android.webview.chromium.WebViewDelegateFactory.WebViewDelegate; |
32 | 35 |
33 import org.chromium.android_webview.AwBrowserContext; | 36 import org.chromium.android_webview.AwBrowserContext; |
34 import org.chromium.android_webview.AwBrowserProcess; | 37 import org.chromium.android_webview.AwBrowserProcess; |
35 import org.chromium.android_webview.AwContents; | 38 import org.chromium.android_webview.AwContents; |
36 import org.chromium.android_webview.AwContentsClient; | 39 import org.chromium.android_webview.AwContentsClient; |
37 import org.chromium.android_webview.AwContentsStatics; | 40 import org.chromium.android_webview.AwContentsStatics; |
38 import org.chromium.android_webview.AwCookieManager; | 41 import org.chromium.android_webview.AwCookieManager; |
39 import org.chromium.android_webview.AwDevToolsServer; | 42 import org.chromium.android_webview.AwDevToolsServer; |
40 import org.chromium.android_webview.AwGeolocationPermissions; | 43 import org.chromium.android_webview.AwGeolocationPermissions; |
41 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; | 44 import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; |
42 import org.chromium.android_webview.AwQuotaManagerBridge; | 45 import org.chromium.android_webview.AwQuotaManagerBridge; |
43 import org.chromium.android_webview.AwResource; | 46 import org.chromium.android_webview.AwResource; |
| 47 import org.chromium.android_webview.AwServiceWorkerController; |
44 import org.chromium.android_webview.AwSettings; | 48 import org.chromium.android_webview.AwSettings; |
45 import org.chromium.android_webview.HttpAuthDatabase; | 49 import org.chromium.android_webview.HttpAuthDatabase; |
46 import org.chromium.android_webview.R; | 50 import org.chromium.android_webview.R; |
47 import org.chromium.android_webview.ResourcesContextWrapperFactory; | 51 import org.chromium.android_webview.ResourcesContextWrapperFactory; |
48 import org.chromium.base.BuildConfig; | 52 import org.chromium.base.BuildConfig; |
49 import org.chromium.base.CommandLine; | 53 import org.chromium.base.CommandLine; |
50 import org.chromium.base.ContextUtils; | 54 import org.chromium.base.ContextUtils; |
51 import org.chromium.base.MemoryPressureListener; | 55 import org.chromium.base.MemoryPressureListener; |
52 import org.chromium.base.PathService; | 56 import org.chromium.base.PathService; |
53 import org.chromium.base.PathUtils; | 57 import org.chromium.base.PathUtils; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 152 |
149 // Guards accees to the other members, and is notifyAll() signalled on the U
I thread | 153 // Guards accees to the other members, and is notifyAll() signalled on the U
I thread |
150 // when the chromium process has been started. | 154 // when the chromium process has been started. |
151 private final Object mLock = new Object(); | 155 private final Object mLock = new Object(); |
152 | 156 |
153 // Initialization guarded by mLock. | 157 // Initialization guarded by mLock. |
154 private AwBrowserContext mBrowserContext; | 158 private AwBrowserContext mBrowserContext; |
155 private Statics mStaticMethods; | 159 private Statics mStaticMethods; |
156 private GeolocationPermissionsAdapter mGeolocationPermissions; | 160 private GeolocationPermissionsAdapter mGeolocationPermissions; |
157 private CookieManagerAdapter mCookieManager; | 161 private CookieManagerAdapter mCookieManager; |
| 162 private Object mTokenBindingManager; |
158 private WebIconDatabaseAdapter mWebIconDatabase; | 163 private WebIconDatabaseAdapter mWebIconDatabase; |
159 private WebStorageAdapter mWebStorage; | 164 private WebStorageAdapter mWebStorage; |
160 private WebViewDatabaseAdapter mWebViewDatabase; | 165 private WebViewDatabaseAdapter mWebViewDatabase; |
161 private AwDevToolsServer mDevToolsServer; | 166 private AwDevToolsServer mDevToolsServer; |
| 167 private Object mServiceWorkerController; |
162 | 168 |
163 // Read/write protected by mLock. | 169 // Read/write protected by mLock. |
164 private boolean mStarted; | 170 private boolean mStarted; |
165 | 171 |
166 private SharedPreferences mWebViewPrefs; | 172 private SharedPreferences mWebViewPrefs; |
167 private WebViewDelegate mWebViewDelegate; | 173 private WebViewDelegate mWebViewDelegate; |
168 | 174 |
169 private boolean mShouldDisableThreadChecking; | 175 private boolean mShouldDisableThreadChecking; |
170 | 176 |
171 /** | 177 /** |
(...skipping 14 matching lines...) Expand all Loading... |
186 * Constructor called by the API 22 version of {@link WebViewFactory} and la
ter. | 192 * Constructor called by the API 22 version of {@link WebViewFactory} and la
ter. |
187 */ | 193 */ |
188 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat
e) { | 194 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat
e) { |
189 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); | 195 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); |
190 } | 196 } |
191 | 197 |
192 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 198 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
193 private void initialize(WebViewDelegate webViewDelegate) { | 199 private void initialize(WebViewDelegate webViewDelegate) { |
194 mWebViewDelegate = webViewDelegate; | 200 mWebViewDelegate = webViewDelegate; |
195 | 201 |
| 202 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication()); |
| 203 |
196 // WebView needs to make sure to always use the wrapped application cont
ext. | 204 // WebView needs to make sure to always use the wrapped application cont
ext. |
197 ContextUtils.initApplicationContext( | 205 ContextUtils.initApplicationContext( |
198 ResourcesContextWrapperFactory.get( | 206 ResourcesContextWrapperFactory.get( |
199 mWebViewDelegate.getApplication().getApplicationContext(
))); | 207 mWebViewDelegate.getApplication().getApplicationContext(
))); |
200 | 208 |
201 if (isBuildDebuggable()) { | 209 if (isBuildDebuggable()) { |
202 // Suppress the StrictMode violation as this codepath is only hit on
debuggable builds. | 210 // Suppress the StrictMode violation as this codepath is only hit on
debuggable builds. |
203 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); | 211 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(
); |
204 CommandLine.initFromFile(COMMAND_LINE_FILE); | 212 CommandLine.initFromFile(COMMAND_LINE_FILE); |
205 StrictMode.setThreadPolicy(oldPolicy); | 213 StrictMode.setThreadPolicy(oldPolicy); |
206 } else { | 214 } else { |
207 CommandLine.init(null); | 215 CommandLine.init(null); |
208 } | 216 } |
209 | 217 |
| 218 if (Settings.Global.getInt(ContextUtils.getApplicationContext().getConte
ntResolver(), |
| 219 Settings.Global.WEBVIEW_MULTIPROCESS, 0) |
| 220 == 1) { |
| 221 CommandLine cl = CommandLine.getInstance(); |
| 222 cl.appendSwitch("webview-sandboxed-renderer"); |
| 223 } |
| 224 |
210 ThreadUtils.setWillOverrideUiThread(); | 225 ThreadUtils.setWillOverrideUiThread(); |
211 // Load chromium library. | 226 // Load chromium library. |
212 AwBrowserProcess.loadLibrary(); | 227 AwBrowserProcess.loadLibrary(); |
213 | 228 |
214 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); | 229 final PackageInfo packageInfo = WebViewFactory.getLoadedPackageInfo(); |
215 | 230 |
216 // Load glue-layer support library. | 231 // Load glue-layer support library. |
217 System.loadLibrary("webviewchromium_plat_support"); | 232 System.loadLibrary("webviewchromium_plat_support"); |
218 | 233 |
219 // Use shared preference to check for package downgrade. | 234 // Use shared preference to check for package downgrade. |
(...skipping 11 matching lines...) Expand all Loading... |
231 } | 246 } |
232 if (lastVersion != currentVersion) { | 247 if (lastVersion != currentVersion) { |
233 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply
(); | 248 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply
(); |
234 } | 249 } |
235 | 250 |
236 mShouldDisableThreadChecking = | 251 mShouldDisableThreadChecking = |
237 shouldDisableThreadChecking(ContextUtils.getApplicationContext()
); | 252 shouldDisableThreadChecking(ContextUtils.getApplicationContext()
); |
238 // Now safe to use WebView data directory. | 253 // Now safe to use WebView data directory. |
239 } | 254 } |
240 | 255 |
| 256 static void checkStorageIsNotDeviceProtected(Context context) { |
| 257 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build
.VERSION_CODES.M) |
| 258 && context.isDeviceProtectedStorage()) { |
| 259 throw new IllegalArgumentException( |
| 260 "WebView cannot be used with device protected storage"); |
| 261 } |
| 262 } |
| 263 |
241 private static boolean isBuildDebuggable() { | 264 private static boolean isBuildDebuggable() { |
242 return !Build.TYPE.equals("user"); | 265 return !Build.TYPE.equals("user"); |
243 } | 266 } |
244 | 267 |
245 /** | 268 /** |
246 * Both versionCodes should be from a WebView provider package implemented b
y Chromium. | 269 * Both versionCodes should be from a WebView provider package implemented b
y Chromium. |
247 * VersionCodes from other kinds of packages won't make any sense in this me
thod. | 270 * VersionCodes from other kinds of packages won't make any sense in this me
thod. |
248 * | 271 * |
249 * An introduction to Chromium versionCode scheme: | 272 * An introduction to Chromium versionCode scheme: |
250 * "BBBBPPPAX" | 273 * "BBBBPPPAX" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 381 |
359 PathService.override(PathService.DIR_MODULE, "/system/lib/"); | 382 PathService.override(PathService.DIR_MODULE, "/system/lib/"); |
360 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi
ew/paks"); | 383 PathService.override(DIR_RESOURCE_PAKS_ANDROID, "/system/framework/webvi
ew/paks"); |
361 | 384 |
362 // Make sure that ResourceProvider is initialized before starting the br
owser process. | 385 // Make sure that ResourceProvider is initialized before starting the br
owser process. |
363 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo().
packageName; | 386 final String webViewPackageName = WebViewFactory.getLoadedPackageInfo().
packageName; |
364 setUpResources(webViewPackageName, context); | 387 setUpResources(webViewPackageName, context); |
365 ResourceBundle.initializeLocalePaks(context, R.array.locale_paks); | 388 ResourceBundle.initializeLocalePaks(context, R.array.locale_paks); |
366 initPlatSupportLibrary(); | 389 initPlatSupportLibrary(); |
367 initNetworkChangeNotifier(context); | 390 initNetworkChangeNotifier(context); |
368 final int extraBindFlags = 0; | 391 final int extraBindFlags = Context.BIND_EXTERNAL_SERVICE; |
369 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, extra
BindFlags); | 392 AwBrowserProcess.configureChildProcessLauncher(webViewPackageName, extra
BindFlags); |
370 AwBrowserProcess.start(); | 393 AwBrowserProcess.start(); |
371 | 394 |
372 if (isBuildDebuggable()) { | 395 if (isBuildDebuggable()) { |
373 setWebContentsDebuggingEnabled(true); | 396 setWebContentsDebuggingEnabled(true); |
374 } | 397 } |
375 | 398 |
376 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); | 399 TraceEvent.setATraceEnabled(mWebViewDelegate.isTraceTagEnabled()); |
377 mWebViewDelegate.setOnTraceEnabledChangeListener( | 400 mWebViewDelegate.setOnTraceEnabledChangeListener( |
378 new WebViewDelegate.OnTraceEnabledChangeListener() { | 401 new WebViewDelegate.OnTraceEnabledChangeListener() { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 public CookieManager getCookieManager() { | 564 public CookieManager getCookieManager() { |
542 synchronized (mLock) { | 565 synchronized (mLock) { |
543 if (mCookieManager == null) { | 566 if (mCookieManager == null) { |
544 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; | 567 mCookieManager = new CookieManagerAdapter(new AwCookieManager())
; |
545 } | 568 } |
546 } | 569 } |
547 return mCookieManager; | 570 return mCookieManager; |
548 } | 571 } |
549 | 572 |
550 @Override | 573 @Override |
| 574 public ServiceWorkerController getServiceWorkerController() { |
| 575 synchronized (mLock) { |
| 576 if (mServiceWorkerController == null) { |
| 577 ensureChromiumStartedLocked(true); |
| 578 AwServiceWorkerController awServiceWorkerController = |
| 579 ThreadUtils.runningOnUiThread() |
| 580 ? getBrowserContextOnUiThread().getServiceWorkerControll
er() |
| 581 : runOnUiThreadBlocking(new Callable<AwServiceWorkerCont
roller>() { |
| 582 @Override |
| 583 public AwServiceWorkerController call() { |
| 584 return getBrowserContextOnUiThread().getServiceW
orkerController(); |
| 585 } |
| 586 }); |
| 587 mServiceWorkerController = |
| 588 new ServiceWorkerControllerAdapter(awServiceWorkerContro
ller); |
| 589 } |
| 590 } |
| 591 return (ServiceWorkerController) mServiceWorkerController; |
| 592 } |
| 593 |
| 594 public TokenBindingService getTokenBindingService() { |
| 595 synchronized (mLock) { |
| 596 if (mTokenBindingManager == null) { |
| 597 mTokenBindingManager = new TokenBindingManagerAdapter(this); |
| 598 } |
| 599 } |
| 600 return (TokenBindingService) mTokenBindingManager; |
| 601 } |
| 602 |
| 603 @Override |
551 public android.webkit.WebIconDatabase getWebIconDatabase() { | 604 public android.webkit.WebIconDatabase getWebIconDatabase() { |
552 synchronized (mLock) { | 605 synchronized (mLock) { |
553 if (mWebIconDatabase == null) { | 606 if (mWebIconDatabase == null) { |
554 ensureChromiumStartedLocked(true); | 607 ensureChromiumStartedLocked(true); |
555 mWebIconDatabase = new WebIconDatabaseAdapter(); | 608 mWebIconDatabase = new WebIconDatabaseAdapter(); |
556 } | 609 } |
557 } | 610 } |
558 return mWebIconDatabase; | 611 return mWebIconDatabase; |
559 } | 612 } |
560 | 613 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | 646 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); |
594 } | 647 } |
595 } | 648 } |
596 return mWebViewDatabase; | 649 return mWebViewDatabase; |
597 } | 650 } |
598 | 651 |
599 WebViewDelegate getWebViewDelegate() { | 652 WebViewDelegate getWebViewDelegate() { |
600 return mWebViewDelegate; | 653 return mWebViewDelegate; |
601 } | 654 } |
602 } | 655 } |
OLD | NEW |