Chromium Code Reviews| 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 181 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. | 192 * Constructor called by the API 22 version of {@link WebViewFactory} and la ter. |
| 193 */ | 193 */ |
| 194 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { | 194 public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegat e) { |
| 195 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); | 195 initialize(WebViewDelegateFactory.createProxyDelegate(delegate)); |
| 196 } | 196 } |
| 197 | 197 |
| 198 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") | 198 @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") |
| 199 private void initialize(WebViewDelegate webViewDelegate) { | 199 private void initialize(WebViewDelegate webViewDelegate) { |
| 200 mWebViewDelegate = webViewDelegate; | 200 mWebViewDelegate = webViewDelegate; |
| 201 | 201 |
| 202 checkStorageIsNotDeviceProtected(mWebViewDelegate.getApplication()); | 202 switchStorageContextIfDeviceProtectedStorage(mWebViewDelegate.getApplica tion()); |
| 203 | 203 |
| 204 // 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. |
| 205 ContextUtils.initApplicationContext( | 205 ContextUtils.initApplicationContext( |
| 206 ResourcesContextWrapperFactory.get( | 206 ResourcesContextWrapperFactory.get( |
| 207 mWebViewDelegate.getApplication().getApplicationContext( ))); | 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); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 static void switchStorageContextIfDeviceProtectedStorage(Context context) { |
| 257 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) | 257 if ((Build.VERSION.CODENAME.equals("N") || Build.VERSION.SDK_INT > Build .VERSION_CODES.M) |
| 258 && context.isDeviceProtectedStorage()) { | 258 && context.isDeviceProtectedStorage()) { |
| 259 throw new IllegalArgumentException( | 259 // Try to switch to a CE-protected context |
| 260 "WebView cannot be used with device protected storage"); | 260 try { |
| 261 context.createCredentialProtectedStorageContext(); | |
|
Torne
2016/09/15 10:15:59
This doesn't actually switch anything - you aren't
| |
| 262 } catch (Exception e) { | |
| 263 throw new IllegalArgumentException( | |
| 264 "WebView cannot be used with device protected storage"); | |
| 265 } | |
| 261 } | 266 } |
| 262 } | 267 } |
| 263 | 268 |
| 264 private static boolean isBuildDebuggable() { | 269 private static boolean isBuildDebuggable() { |
| 265 return !Build.TYPE.equals("user"); | 270 return !Build.TYPE.equals("user"); |
| 266 } | 271 } |
| 267 | 272 |
| 268 /** | 273 /** |
| 269 * Both versionCodes should be from a WebView provider package implemented b y Chromium. | 274 * 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. | 275 * VersionCodes from other kinds of packages won't make any sense in this me thod. |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); | 651 mWebViewDatabase = new WebViewDatabaseAdapter(this, awDatabase); |
| 647 } | 652 } |
| 648 } | 653 } |
| 649 return mWebViewDatabase; | 654 return mWebViewDatabase; |
| 650 } | 655 } |
| 651 | 656 |
| 652 WebViewDelegate getWebViewDelegate() { | 657 WebViewDelegate getWebViewDelegate() { |
| 653 return mWebViewDelegate; | 658 return mWebViewDelegate; |
| 654 } | 659 } |
| 655 } | 660 } |
| OLD | NEW |