Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java

Issue 2544973002: Make chrome://flags control whether the WebAPK feature is on (Closed)
Patch Set: Merge branch 'master' into feature_on_default Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.content.DialogInterface; 8 import android.content.DialogInterface;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.StrictMode; 10 import android.os.StrictMode;
11 import android.provider.Settings; 11 import android.provider.Settings;
12 import android.support.v7.app.AlertDialog; 12 import android.support.v7.app.AlertDialog;
13 import android.text.TextUtils; 13 import android.text.TextUtils;
14 14
15 import org.chromium.base.CommandLine;
16 import org.chromium.base.ContextUtils; 15 import org.chromium.base.ContextUtils;
17 import org.chromium.base.Log; 16 import org.chromium.base.Log;
18 import org.chromium.base.annotations.CalledByNative; 17 import org.chromium.base.annotations.CalledByNative;
19 import org.chromium.chrome.R; 18 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.ChromeFeatureList; 19 import org.chromium.chrome.browser.ChromeFeatureList;
21 import org.chromium.chrome.browser.ChromeSwitches;
22 import org.chromium.chrome.browser.ChromeVersionInfo; 20 import org.chromium.chrome.browser.ChromeVersionInfo;
23 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 21 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
24 import org.chromium.components.variations.VariationsAssociatedData; 22 import org.chromium.components.variations.VariationsAssociatedData;
25 import org.chromium.webapk.lib.client.WebApkValidator; 23 import org.chromium.webapk.lib.client.WebApkValidator;
26 24
27 /** 25 /**
28 * Contains functionality needed for Chrome to host WebAPKs. 26 * Contains functionality needed for Chrome to host WebAPKs.
29 */ 27 */
30 public class ChromeWebApkHost { 28 public class ChromeWebApkHost {
31 /** Flag to enable installing WebAPKs using Google Play. */ 29 /** Flag to enable installing WebAPKs using Google Play. */
(...skipping 14 matching lines...) Expand all
46 public static boolean isEnabled() { 44 public static boolean isEnabled() {
47 if (sEnabledForTesting != null) return sEnabledForTesting; 45 if (sEnabledForTesting != null) return sEnabledForTesting;
48 46
49 return isEnabledInPrefs(); 47 return isEnabledInPrefs();
50 } 48 }
51 49
52 /** Return whether installing WebAPKs using Google Play is enabled. */ 50 /** Return whether installing WebAPKs using Google Play is enabled. */
53 public static boolean canUseGooglePlayToInstallWebApk() { 51 public static boolean canUseGooglePlayToInstallWebApk() {
54 if (!isEnabled()) return false; 52 if (!isEnabled()) return false;
55 return TextUtils.equals(VariationsAssociatedData.getVariationParamValue( 53 return TextUtils.equals(VariationsAssociatedData.getVariationParamValue(
56 ChromeFeatureList.WEBAPKS, PLAY_INSTALL), "true"); 54 ChromeFeatureList.IMPROVED_A2HS, PLAY_INSTALL), "true");
57 } 55 }
58 56
59 @CalledByNative 57 @CalledByNative
60 private static boolean areWebApkEnabled() { 58 private static boolean areWebApkEnabled() {
61 return ChromeWebApkHost.isEnabled(); 59 return ChromeWebApkHost.isEnabled();
62 } 60 }
63 61
64 /** 62 /**
65 * Check the cached value to figure out if the feature is enabled. We have t o use the cached 63 * Check the cached value to figure out if the feature is enabled. We have t o use the cached
66 * value because native library may not yet been loaded. 64 * value because native library may not yet been loaded.
67 * @return Whether the feature is enabled. 65 * @return Whether the feature is enabled.
68 */ 66 */
69 private static boolean isEnabledInPrefs() { 67 private static boolean isEnabledInPrefs() {
70 // Will go away once the feature is enabled for everyone by default. 68 // Will go away once the feature is enabled for everyone by default.
71 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); 69 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
72 try { 70 try {
73 return ChromePreferenceManager.getInstance( 71 return ChromePreferenceManager.getInstance(
74 ContextUtils.getApplicationContext()).getCachedWebApkRuntime Enabled(); 72 ContextUtils.getApplicationContext()).getCachedWebApkRuntime Enabled();
75 } finally { 73 } finally {
76 StrictMode.setThreadPolicy(oldPolicy); 74 StrictMode.setThreadPolicy(oldPolicy);
77 } 75 }
78 } 76 }
79 77
80 /** 78 /**
81 * Show dialog warning user that "installation from unknown sources" is requ ired by the WebAPK 79 * Show dialog warning user that "installation from unknown sources" is requ ired by the WebAPK
82 * experiment if: 80 * experiment if the user enabled "Improved Add to Home screen" via chrome:/ /flags.
83 * - The user toggled the --enable-improved-a2hs command line flag via chrom e://flags
84 * AND
85 * - WebAPKs are not disabled via variations kill switch.
86 * Must be run prior to {@link cacheEnabledStateForNextLaunch}.
87 */ 81 */
88 public static void launchWebApkRequirementsDialogIfNeeded(Context context) { 82 public static void launchWebApkRequirementsDialogIfNeeded(Context context) {
89 // Show dialog on Canary & Dev. Installation via "unknown sources" is di sabled via 83 // Show dialog on Canary & Dev. Installation via "unknown sources" is di sabled via
90 // variations on other channels. 84 // variations on other channels.
91 if (!ChromeVersionInfo.isCanaryBuild() && !ChromeVersionInfo.isDevBuild( )) return; 85 if (!ChromeVersionInfo.isCanaryBuild() && !ChromeVersionInfo.isDevBuild( )) return;
92 86
93 Context applicationContext = ContextUtils.getApplicationContext(); 87 if (ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROVED_A2HS)
94 boolean wasCommandLineFlagEnabled = ChromePreferenceManager.getInstance( applicationContext) 88 && !installingFromUnknownSourcesAllowed()) {
95 .getCachedWebApkCommandLineE nabled();
96 if (computeEnabled() && !wasCommandLineFlagEnabled
97 && !installingFromUnknownSourcesAllowed(applicationContext)) {
98 showUnknownSourcesNeededDialog(context); 89 showUnknownSourcesNeededDialog(context);
99 } 90 }
100 } 91 }
101 92
102 /** 93 /**
103 * Once native is loaded we can consult the command-line (set via about:flag s) and also finch 94 * Once native is loaded we can consult the command-line (set via about:flag s) and also finch
104 * state to see if we should enable WebAPKs. 95 * state to see if we should enable WebAPKs.
105 */ 96 */
106 public static void cacheEnabledStateForNextLaunch() { 97 public static void cacheEnabledStateForNextLaunch() {
107 ChromePreferenceManager preferenceManager = 98 ChromePreferenceManager preferenceManager =
108 ChromePreferenceManager.getInstance(ContextUtils.getApplicationC ontext()); 99 ChromePreferenceManager.getInstance(ContextUtils.getApplicationC ontext());
109 100
110 boolean wasCommandLineEnabled = preferenceManager.getCachedWebApkCommand LineEnabled();
111 boolean isCommandLineEnabled = isCommandLineFlagSet();
112 if (isCommandLineEnabled != wasCommandLineEnabled) {
113 // {@link launchWebApkRequirementsDialogIfNeeded()} is skipped the f irst time Chrome is
114 // launched so do caching here instead.
115 preferenceManager.setCachedWebApkCommandLineEnabled(isCommandLineEna bled);
116 }
117
118 boolean wasEnabled = isEnabledInPrefs(); 101 boolean wasEnabled = isEnabledInPrefs();
119 boolean isEnabled = computeEnabled(); 102 boolean isEnabled = ChromeFeatureList.isEnabled(ChromeFeatureList.IMPROV ED_A2HS);
120 if (isEnabled != wasEnabled) { 103 if (isEnabled != wasEnabled) {
121 Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnable d); 104 Log.d(TAG, "WebApk setting changed (%s => %s)", wasEnabled, isEnable d);
122 preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled); 105 preferenceManager.setCachedWebApkRuntimeEnabled(isEnabled);
123 } 106 }
124 } 107 }
125 108
126 /** Returns whether the --enable-improved-a2hs command line flag is set */
127 private static boolean isCommandLineFlagSet() {
128 return CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK) ;
129 }
130
131 /** Returns whether we should enable WebAPKs */
132 private static boolean computeEnabled() {
133 return isCommandLineFlagSet() && ChromeFeatureList.isEnabled(ChromeFeatu reList.WEBAPKS);
134 }
135
136 /** 109 /**
137 * Returns whether the user has enabled installing apps from sources other t han the Google Play 110 * Returns whether the user has enabled installing apps from sources other t han the Google Play
138 * Store. 111 * Store.
139 */ 112 */
140 private static boolean installingFromUnknownSourcesAllowed(Context context) { 113 private static boolean installingFromUnknownSourcesAllowed() {
114 Context applicationContext = ContextUtils.getApplicationContext();
141 try { 115 try {
142 return Settings.Secure.getInt( 116 return Settings.Secure.getInt(applicationContext.getContentResolver( ),
143 context.getContentResolver(), Settings.Secure.INSTALL _NON_MARKET_APPS) 117 Settings.Secure.INSTALL_NON_MARKET_APPS)
144 == 1; 118 == 1;
145 } catch (Settings.SettingNotFoundException e) { 119 } catch (Settings.SettingNotFoundException e) {
146 return false; 120 return false;
147 } 121 }
148 } 122 }
149 123
150 /** 124 /**
151 * Show dialog warning user that "installation from unknown sources" is requ ired by the WebAPK 125 * Show dialog warning user that "installation from unknown sources" is requ ired by the WebAPK
152 * experiment. 126 * experiment.
153 */ 127 */
(...skipping 11 matching lines...) Expand all
165 } 139 }
166 }); 140 });
167 builder.setNegativeButton(android.R.string.cancel, new DialogInterface.O nClickListener() { 141 builder.setNegativeButton(android.R.string.cancel, new DialogInterface.O nClickListener() {
168 @Override 142 @Override
169 public void onClick(DialogInterface dialog, int id) {} 143 public void onClick(DialogInterface dialog, int id) {}
170 }); 144 });
171 AlertDialog dialog = builder.create(); 145 AlertDialog dialog = builder.create();
172 dialog.show(); 146 dialog.show();
173 } 147 }
174 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698