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.CommandLine; |
10 import org.chromium.base.ContextUtils; | 10 import org.chromium.base.ContextUtils; |
11 import org.chromium.base.FieldTrialList; | 11 import org.chromium.base.FieldTrialList; |
12 import org.chromium.base.Log; | 12 import org.chromium.base.Log; |
| 13 import org.chromium.base.annotations.CalledByNative; |
13 import org.chromium.chrome.browser.ChromeSwitches; | 14 import org.chromium.chrome.browser.ChromeSwitches; |
14 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 15 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
15 import org.chromium.webapk.lib.client.WebApkValidator; | 16 import org.chromium.webapk.lib.client.WebApkValidator; |
16 | 17 |
17 /** | 18 /** |
18 * Contains functionality needed for Chrome to host WebAPKs. | 19 * Contains functionality needed for Chrome to host WebAPKs. |
19 */ | 20 */ |
20 public class ChromeWebApkHost { | 21 public class ChromeWebApkHost { |
21 // The public key to verify whether a WebAPK is signed by WebAPK Minting | 22 // The public key to verify whether a WebAPK is signed by WebAPK Minting |
22 // Server. | 23 // Server. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 public static void initForTesting(boolean enabled) { | 90 public static void initForTesting(boolean enabled) { |
90 sEnabledForTesting = enabled; | 91 sEnabledForTesting = enabled; |
91 } | 92 } |
92 | 93 |
93 public static boolean isEnabled() { | 94 public static boolean isEnabled() { |
94 if (sEnabledForTesting != null) return sEnabledForTesting; | 95 if (sEnabledForTesting != null) return sEnabledForTesting; |
95 | 96 |
96 return isEnabledInPrefs(); | 97 return isEnabledInPrefs(); |
97 } | 98 } |
98 | 99 |
| 100 @CalledByNative |
| 101 private static boolean areWebApkEnabled() { |
| 102 return ChromeWebApkHost.isEnabled(); |
| 103 } |
| 104 |
99 /** | 105 /** |
100 * Check the cached value to figure out if the feature is enabled. We have | 106 * Check the cached value to figure out if the feature is enabled. We have |
101 * to use the cached value because native library may not yet been loaded. | 107 * to use the cached value because native library may not yet been loaded. |
102 * | 108 * |
103 * @return Whether the feature is enabled. | 109 * @return Whether the feature is enabled. |
104 */ | 110 */ |
105 private static boolean isEnabledInPrefs() { | 111 private static boolean isEnabledInPrefs() { |
106 // Will go away once the feature is enabled for everyone by default. | 112 // Will go away once the feature is enabled for everyone by default. |
107 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 113 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
108 try { | 114 try { |
(...skipping 15 matching lines...) Expand all Loading... |
124 boolean isEnabled = (!WEBAPK_RUNTIME_DISABLED.equals(experiment) | 130 boolean isEnabled = (!WEBAPK_RUNTIME_DISABLED.equals(experiment) |
125 && instance.hasSwitch(ChromeSwitches.ENABLE_WEBAPK)); | 131 && instance.hasSwitch(ChromeSwitches.ENABLE_WEBAPK)); |
126 | 132 |
127 if (isEnabled != wasEnabled) { | 133 if (isEnabled != wasEnabled) { |
128 Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnable
d); | 134 Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnable
d); |
129 ChromePreferenceManager.getInstance(ContextUtils.getApplicationConte
xt()) | 135 ChromePreferenceManager.getInstance(ContextUtils.getApplicationConte
xt()) |
130 .setCachedWebApkRuntimeEnabled(isEnabled); | 136 .setCachedWebApkRuntimeEnabled(isEnabled); |
131 } | 137 } |
132 } | 138 } |
133 } | 139 } |
OLD | NEW |