OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.os.StrictMode; | 7 import android.os.StrictMode; |
8 | 8 |
9 import org.chromium.base.CommandLine; | |
9 import org.chromium.base.ContextUtils; | 10 import org.chromium.base.ContextUtils; |
10 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
11 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.base.library_loader.LibraryLoader; | 13 import org.chromium.base.library_loader.LibraryLoader; |
13 import org.chromium.chrome.browser.AppHooks; | 14 import org.chromium.chrome.browser.AppHooks; |
14 import org.chromium.chrome.browser.ChromeFeatureList; | 15 import org.chromium.chrome.browser.ChromeFeatureList; |
16 import org.chromium.chrome.browser.ChromeSwitches; | |
15 import org.chromium.chrome.browser.GooglePlayInstallState; | 17 import org.chromium.chrome.browser.GooglePlayInstallState; |
16 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; | 18 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
17 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; | 19 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; |
18 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
19 import org.chromium.webapk.lib.client.WebApkValidator; | 21 import org.chromium.webapk.lib.client.WebApkValidator; |
20 | 22 |
21 /** | 23 /** |
22 * Contains functionality needed for Chrome to host WebAPKs. | 24 * Contains functionality needed for Chrome to host WebAPKs. |
23 */ | 25 */ |
24 public class ChromeWebApkHost { | 26 public class ChromeWebApkHost { |
25 private static final String TAG = "ChromeWebApkHost"; | 27 private static final String TAG = "ChromeWebApkHost"; |
26 | 28 |
27 /** Whether installing WebAPks from Google Play is possible. */ | 29 /** Whether installing WebAPks from Google Play is possible. */ |
28 private static Integer sGooglePlayInstallState; | 30 private static Integer sGooglePlayInstallState; |
29 | 31 |
30 private static Boolean sEnabledForTesting; | 32 private static Boolean sEnabledForTesting; |
31 | 33 |
32 public static void init() { | 34 public static void init() { |
33 WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.E XPECTED_SIGNATURE); | 35 WebApkValidator.init(isAnyPackageNameEnabledInPrefs(), |
36 ChromeWebApkHostSignature.EXPECTED_SIGNATURE, ChromeWebApkHostSi gnature.PUBLIC_KEY); | |
34 } | 37 } |
35 | 38 |
36 public static void initForTesting(boolean enabled) { | 39 public static void initForTesting(boolean enabled) { |
37 sEnabledForTesting = enabled; | 40 sEnabledForTesting = enabled; |
38 sGooglePlayInstallState = enabled ? GooglePlayInstallState.SUPPORTED | 41 sGooglePlayInstallState = enabled ? GooglePlayInstallState.SUPPORTED |
39 : GooglePlayInstallState.NO_PLAY_SERVI CES; | 42 : GooglePlayInstallState.NO_PLAY_SERVI CES; |
40 } | 43 } |
41 | 44 |
42 public static boolean isEnabled() { | 45 public static boolean isEnabled() { |
43 if (sEnabledForTesting != null) return sEnabledForTesting; | 46 if (sEnabledForTesting != null) return sEnabledForTesting; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 // Will go away once the feature is enabled for everyone by default. | 94 // Will go away once the feature is enabled for everyone by default. |
92 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 95 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
93 try { | 96 try { |
94 return ChromePreferenceManager.getInstance().getCachedWebApkRuntimeE nabled(); | 97 return ChromePreferenceManager.getInstance().getCachedWebApkRuntimeE nabled(); |
95 } finally { | 98 } finally { |
96 StrictMode.setThreadPolicy(oldPolicy); | 99 StrictMode.setThreadPolicy(oldPolicy); |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 /** | 103 /** |
104 * Check the cached value to figure out if any WebAPK package name may be us ed. We have to use | |
105 * the cached value because native library may not yet been loaded. | |
106 * @return Whether the feature is enabled. | |
107 */ | |
108 private static boolean isAnyPackageNameEnabledInPrefs() { | |
109 // Will go away once the feature is enabled for everyone by default. | |
110 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | |
111 try { | |
112 return ChromePreferenceManager.getInstance().getCachedWebApkAnyPacka geName(); | |
113 } finally { | |
114 StrictMode.setThreadPolicy(oldPolicy); | |
115 } | |
116 } | |
117 | |
118 /** | |
101 * Once native is loaded we can consult the command-line (set via about:flag s) and also finch | 119 * Once native is loaded we can consult the command-line (set via about:flag s) and also finch |
102 * state to see if we should enable WebAPKs. | 120 * state to see if we should enable WebAPKs. |
103 */ | 121 */ |
104 public static void cacheEnabledStateForNextLaunch() { | 122 public static void cacheEnabledStateForNextLaunch() { |
105 ChromePreferenceManager preferenceManager = ChromePreferenceManager.getI nstance(); | 123 ChromePreferenceManager preferenceManager = ChromePreferenceManager.getI nstance(); |
106 | 124 |
107 boolean wasEnabled = isEnabledInPrefs(); | 125 boolean wasEnabled = isEnabledInPrefs(); |
108 boolean isEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROV ED_A2HS); | 126 boolean isEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROV ED_A2HS); |
109 if (isEnabled != wasEnabled) { | 127 if (isEnabled != wasEnabled) { |
110 Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnable d); | 128 Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnable d); |
111 preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled); | 129 preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled); |
112 } | 130 } |
131 | |
132 boolean wasAnyPackgeNameEnabled = isAnyPackageNameEnabledInPrefs(); | |
133 boolean isAnyPackgeNameEnabled = | |
Yaron
2017/04/13 20:50:51
isAnyPackageNameEnabled
ScottK
2017/04/13 21:00:48
Done.
| |
134 CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_ANY_WE BAPK_PACKAGE_NAME); | |
135 if (wasAnyPackgeNameEnabled != isAnyPackgeNameEnabled) { | |
136 Log.d(TAG, "WebApk Any Package name setting changed (%s => %s)", was Enabled, isEnabled); | |
137 preferenceManager.setCachedWebApkAnyPackageNameEnabled(isEnabled); | |
138 } | |
113 } | 139 } |
114 | 140 |
115 private static native boolean nativeCanLaunchRendererInWebApkProcess(); | 141 private static native boolean nativeCanLaunchRendererInWebApkProcess(); |
116 } | 142 } |
OLD | NEW |