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.os.UserManager; | |
21 import android.provider.Settings; | 22 import android.provider.Settings; |
22 import android.util.Log; | 23 import android.util.Log; |
23 import android.webkit.CookieManager; | 24 import android.webkit.CookieManager; |
24 import android.webkit.GeolocationPermissions; | 25 import android.webkit.GeolocationPermissions; |
25 import android.webkit.ServiceWorkerController; | 26 import android.webkit.ServiceWorkerController; |
26 import android.webkit.TokenBindingService; | 27 import android.webkit.TokenBindingService; |
27 import android.webkit.WebStorage; | 28 import android.webkit.WebStorage; |
28 import android.webkit.WebView; | 29 import android.webkit.WebView; |
29 import android.webkit.WebViewDatabase; | 30 import android.webkit.WebViewDatabase; |
30 import android.webkit.WebViewFactory; | 31 import android.webkit.WebViewFactory; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter. | 193 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter. |
193 */ | 194 */ |
194 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { | 195 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { |
195 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); | 196 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); |
196 } | 197 } |
197 | 198 |
198 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 199 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
199 private void initialize(WebViewDelegate webViewDelegate) { | 200 private void initialize(WebViewDelegate webViewDelegate) { |
200 mWebViewDelegate = webViewDelegate; | 201 mWebViewDelegate = webViewDelegate; |
201 | 202 |
202 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication()); | 203 Context ctx = switchToCredentialProtectedStorage( |
204 mWebViewDelegate.getApplication().getApplicationContext()); | |
203 | 205 |
204 // WebView needs to make sure to always use the wrapped application cont ext. | 206 // WebView needs to make sure to always use the wrapped application cont ext. |
205 ContextUtils.initApplicationContext( | 207 ContextUtils.initApplicationContext(ResourcesContextWrapperFactory.get(c tx)); |
206 ResourcesContextWrapperFactory.get( | |
207 mWebViewDelegate.getApplication().getApplicationContext( ))); | |
208 | 208 |
209 if (isBuildDebuggable()) { | 209 if (isBuildDebuggable()) { |
210 // 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. |
211 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); | 211 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads( ); |
212 CommandLine.initFromFile(COMMAND_LINE_FILE); | 212 CommandLine.initFromFile(COMMAND_LINE_FILE); |
213 StrictMode.setThreadPolicy(oldPolicy); | 213 StrictMode.setThreadPolicy(oldPolicy); |
214 } else { | 214 } else { |
215 CommandLine.init(null); | 215 CommandLine.init(null); |
216 } | 216 } |
217 | 217 |
(...skipping 28 matching lines...) Expand all Loading... | |
246 } | 246 } |
247 if (lastVersion != currentVersion) { | 247 if (lastVersion != currentVersion) { |
248 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); | 248 mWebViewPrefs.edit().putInt(VERSION_CODE_PREF, currentVersion).apply (); |
249 } | 249 } |
250 | 250 |
251 mShouldDisableThreadChecking = | 251 mShouldDisableThreadChecking = |
252 shouldDisableThreadChecking(ContextUtils.getApplicationContext() ); | 252 shouldDisableThreadChecking(ContextUtils.getApplicationContext() ); |
253 // Now safe to use WebView data directory. | 253 // Now safe to use WebView data directory. |
254 } | 254 } |
255 | 255 |
256 static void checkStorageIsNotDeviceProtected(Context context) { | 256 // Webview must use a CredentialEncrypted Context. If context is a CE contex t, then simply |
257 // return it without modification. Otherwise, create a new CE context and re turn that instead. | |
258 static Context switchToCredentialProtectedStorage(Context context) { | |
259 // For versions N+, android webview must use a CredentialEncrypted Conte xt | |
257 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) | 260 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) |
258 && context.isDeviceProtectedStorage()) { | 261 && context.isDeviceProtectedStorage()) { |
259 throw new IllegalArgumentException( | 262 context = context.createCredentialProtectedStorageContext(); |
260 "WebView cannot be used with device protected storage"); | 263 |
264 if (!context.getSystemService(UserManager.class).isUserUnlocked()) { | |
Torne
2016/09/22 09:59:54
I think you should be getting a lint warning about
Nate Fischer
2016/09/22 19:47:49
I don't think I received a lint warning. I was abl
Torne
2016/09/23 11:13:15
I think they happen during the build, not in presu
| |
265 throw new IllegalArgumentException( | |
266 "WebView cannot be used with device protected storage"); | |
267 } | |
261 } | 268 } |
269 return context; | |
262 } | 270 } |
263 | 271 |
264 private static boolean isBuildDebuggable() { | 272 private static boolean isBuildDebuggable() { |
265 return !Build.TYPE.equals("user"); | 273 return !Build.TYPE.equals("user"); |
266 } | 274 } |
267 | 275 |
268 /** | 276 /** |
269 * Both versionCodes should be from a WebView provider package implemented b y Chromium. | 277 * Both versionCodes should be from a WebView provider package implemented b y Chromium. |
270 * VersionCodes from other kinds of packages won't make any sense in this me thod. | 278 * VersionCodes from other kinds of packages won't make any sense in this me thod. |
271 * | 279 * |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | 654 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); |
647 } | 655 } |
648 } | 656 } |
649 return mWebViewDatabase; | 657 return mWebViewDatabase; |
650 } | 658 } |
651 | 659 |
652 WebViewDelegate getWebViewDelegate() { | 660 WebViewDelegate getWebViewDelegate() { |
653 return mWebViewDelegate; | 661 return mWebViewDelegate; |
654 } | 662 } |
655 } | 663 } |
OLD | NEW |