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.content.Context; | 7 import android.content.Context; |
8 import android.os.StrictMode; | 8 import android.os.StrictMode; |
9 import android.provider.Settings; | 9 import android.provider.Settings; |
10 | 10 |
11 import org.chromium.base.ContextUtils; | 11 import org.chromium.base.ContextUtils; |
12 import org.chromium.base.Log; | 12 import org.chromium.base.Log; |
13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.library_loader.LibraryLoader; | 14 import org.chromium.base.library_loader.LibraryLoader; |
15 import org.chromium.chrome.browser.AppHooks; | 15 import org.chromium.chrome.browser.AppHooks; |
16 import org.chromium.chrome.browser.ChromeFeatureList; | 16 import org.chromium.chrome.browser.ChromeFeatureList; |
17 import org.chromium.chrome.browser.GooglePlayInstallState; | 17 import org.chromium.chrome.browser.GooglePlayInstallState; |
18 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; | 18 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
19 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; | 19 import org.chromium.chrome.browser.externalauth.UserRecoverableErrorHandler; |
20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 20 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
21 import org.chromium.webapk.lib.client.WebApkValidator; | 21 import org.chromium.webapk.lib.client.WebApkValidator; |
22 | 22 |
23 /** | 23 /** Contains functionality needed for Chrome to host WebAPKs. */ |
24 * Contains functionality needed for Chrome to host WebAPKs. | |
25 */ | |
26 public class ChromeWebApkHost { | 24 public class ChromeWebApkHost { |
27 private static final String TAG = "ChromeWebApkHost"; | 25 private static final String TAG = "ChromeWebApkHost"; |
28 | 26 |
29 /** Whether installing WebAPks from Google Play is possible. */ | 27 /** Whether installing WebAPks from Google Play is possible. */ |
30 private static Integer sGooglePlayInstallState; | 28 private static Integer sGooglePlayInstallState; |
31 | 29 |
32 private static Boolean sEnabledForTesting; | 30 private static Boolean sEnabledForTesting; |
33 | 31 |
34 public static void init() { | 32 public static void init() { |
35 WebApkValidator.initWithBrowserHostSignature(ChromeWebApkHostSignature.E XPECTED_SIGNATURE); | 33 WebApkValidator.initWithBrowserHostSignature( |
34 ChromeWebApkHostSignature.EXPECTED_SIGNATURE, ChromeWebApkHostSi gnature.PUBLIC_KEY); | |
36 } | 35 } |
37 | 36 |
38 public static void initForTesting(boolean enabled) { | 37 public static void initForTesting(boolean enabled) { |
39 sEnabledForTesting = enabled; | 38 sEnabledForTesting = enabled; |
40 } | 39 } |
41 | 40 |
42 public static boolean isEnabled() { | 41 public static boolean isEnabled() { |
43 if (sEnabledForTesting != null) return sEnabledForTesting; | 42 if (sEnabledForTesting != null) return sEnabledForTesting; |
44 | 43 |
45 return isEnabledInPrefs(); | 44 return isEnabledInPrefs(); |
(...skipping 25 matching lines...) Expand all Loading... | |
71 GooglePlayWebApkInstallDelegate delegate = | 70 GooglePlayWebApkInstallDelegate delegate = |
72 AppHooks.get().getGooglePlayWebApkInstallDelegate(); | 71 AppHooks.get().getGooglePlayWebApkInstallDelegate(); |
73 if (delegate == null) { | 72 if (delegate == null) { |
74 return GooglePlayInstallState.DISABLED_OTHER; | 73 return GooglePlayInstallState.DISABLED_OTHER; |
75 } | 74 } |
76 | 75 |
77 return GooglePlayInstallState.SUPPORTED; | 76 return GooglePlayInstallState.SUPPORTED; |
78 } | 77 } |
79 | 78 |
80 /** | 79 /** |
81 * Returns whether installing WebAPKs from Google Play is possible. | 80 * Returns whether installing WebAPKs from Google Play is possible. If {@lin k |
pkotwicz
2017/03/31 03:59:24
Keep {@link} on the same line
ScottK
2017/04/03 17:44:17
done.
| |
82 * If {@link sCanUseGooglePlayInstall} hasn't been set yet, it returns false immediately and | 81 * sCanUseGooglePlayInstall} hasn't been set yet, it returns false immediate ly and calls the |
83 * calls the Google Play Install API to update {@link sCanUseGooglePlayInsta ll} asynchronously. | 82 * Google Play Install API to update {@link sCanUseGooglePlayInstall} asynch ronously. |
84 */ | 83 */ |
85 private static boolean canUseGooglePlayToInstallWebApk() { | 84 public static boolean canUseGooglePlayToInstallWebApk() { |
pkotwicz
2017/03/31 03:59:24
Why this change?
ScottK
2017/04/03 17:44:17
I don't understand this change, unless it was a b
| |
86 return getGooglePlayInstallState() == GooglePlayInstallState.SUPPORTED; | 85 return getGooglePlayInstallState() == GooglePlayInstallState.SUPPORTED; |
87 } | 86 } |
88 | 87 |
89 /** | 88 /** |
90 * Returns whether Google Play install is enabled by Chrome. Does not check whether installing | 89 * Returns whether Google Play install is enabled by Chrome. Does not check whether installing |
91 * from Google Play is possible. | 90 * from Google Play is possible. |
92 */ | 91 */ |
93 public static boolean isGooglePlayInstallEnabledByChromeFeature() { | 92 public static boolean isGooglePlayInstallEnabledByChromeFeature() { |
94 return isEnabled() && LibraryLoader.isInitialized() | 93 return isEnabled() && LibraryLoader.isInitialized() |
95 && nativeCanUseGooglePlayToInstallWebApk(); | 94 && nativeCanUseGooglePlayToInstallWebApk(); |
(...skipping 19 matching lines...) Expand all Loading... | |
115 | 114 |
116 /* Returns whether launching renderer in WebAPK process is enabled by Chrome . */ | 115 /* Returns whether launching renderer in WebAPK process is enabled by Chrome . */ |
117 public static boolean canLaunchRendererInWebApkProcess() { | 116 public static boolean canLaunchRendererInWebApkProcess() { |
118 return isEnabled() && LibraryLoader.isInitialized() | 117 return isEnabled() && LibraryLoader.isInitialized() |
119 && nativeCanLaunchRendererInWebApkProcess(); | 118 && nativeCanLaunchRendererInWebApkProcess(); |
120 } | 119 } |
121 | 120 |
122 /** | 121 /** |
123 * Check the cached value to figure out if the feature is enabled. We have t o use the cached | 122 * Check the cached value to figure out if the feature is enabled. We have t o use the cached |
124 * value because native library may not yet been loaded. | 123 * value because native library may not yet been loaded. |
124 * | |
125 * @return Whether the feature is enabled. | 125 * @return Whether the feature is enabled. |
126 */ | 126 */ |
127 private static boolean isEnabledInPrefs() { | 127 private static boolean isEnabledInPrefs() { |
128 // Will go away once the feature is enabled for everyone by default. | 128 // Will go away once the feature is enabled for everyone by default. |
129 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 129 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
130 try { | 130 try { |
131 return ChromePreferenceManager.getInstance().getCachedWebApkRuntimeE nabled(); | 131 return ChromePreferenceManager.getInstance().getCachedWebApkRuntimeE nabled(); |
132 } finally { | 132 } finally { |
133 StrictMode.setThreadPolicy(oldPolicy); | 133 StrictMode.setThreadPolicy(oldPolicy); |
134 } | 134 } |
(...skipping 23 matching lines...) Expand all Loading... | |
158 try { | 158 try { |
159 return Settings.Secure.getInt(applicationContext.getContentResolver( ), | 159 return Settings.Secure.getInt(applicationContext.getContentResolver( ), |
160 Settings.Secure.INSTALL_NON_MARKET_APPS) | 160 Settings.Secure.INSTALL_NON_MARKET_APPS) |
161 == 1; | 161 == 1; |
162 } catch (Settings.SettingNotFoundException e) { | 162 } catch (Settings.SettingNotFoundException e) { |
163 return false; | 163 return false; |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 private static native boolean nativeCanUseGooglePlayToInstallWebApk(); | 167 private static native boolean nativeCanUseGooglePlayToInstallWebApk(); |
168 | |
168 private static native boolean nativeCanLaunchRendererInWebApkProcess(); | 169 private static native boolean nativeCanLaunchRendererInWebApkProcess(); |
170 | |
169 private static native boolean nativeCanInstallFromUnknownSources(); | 171 private static native boolean nativeCanInstallFromUnknownSources(); |
170 } | 172 } |
OLD | NEW |