| 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 org.chromium.chrome.browser.util; | 5 package org.chromium.chrome.browser.util; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 import org.chromium.base.ContextUtils; | 21 import org.chromium.base.ContextUtils; |
| 22 import org.chromium.base.FieldTrialList; | 22 import org.chromium.base.FieldTrialList; |
| 23 import org.chromium.base.Log; | 23 import org.chromium.base.Log; |
| 24 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
| 25 import org.chromium.base.VisibleForTesting; | 25 import org.chromium.base.VisibleForTesting; |
| 26 import org.chromium.chrome.browser.AppLinkHandler; | 26 import org.chromium.chrome.browser.AppLinkHandler; |
| 27 import org.chromium.chrome.browser.ChromeApplication; | 27 import org.chromium.chrome.browser.ChromeApplication; |
| 28 import org.chromium.chrome.browser.ChromeSwitches; | 28 import org.chromium.chrome.browser.ChromeSwitches; |
| 29 import org.chromium.chrome.browser.ChromeVersionInfo; | 29 import org.chromium.chrome.browser.ChromeVersionInfo; |
| 30 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 30 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
| 31 import org.chromium.chrome.browser.preferences.DocumentModeManager; | 31 import org.chromium.chrome.browser.tabmodel.DocumentModeAssassin; |
| 32 import org.chromium.sync.signin.AccountManagerHelper; | 32 import org.chromium.sync.signin.AccountManagerHelper; |
| 33 import org.chromium.ui.base.DeviceFormFactor; | 33 import org.chromium.ui.base.DeviceFormFactor; |
| 34 | 34 |
| 35 import java.util.List; | 35 import java.util.List; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * A utility {@code class} meant to help determine whether or not certain featur
es are supported by | 38 * A utility {@code class} meant to help determine whether or not certain featur
es are supported by |
| 39 * this device. | 39 * this device. |
| 40 */ | 40 */ |
| 41 public class FeatureUtilities { | 41 public class FeatureUtilities { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Bundle userRestrictions = manager.getUserRestrictions(); | 108 Bundle userRestrictions = manager.getUserRestrictions(); |
| 109 return !userRestrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS
, false); | 109 return !userRestrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS
, false); |
| 110 } | 110 } |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * Check whether Chrome should be running on document mode. | 113 * Check whether Chrome should be running on document mode. |
| 114 * @param context The context to use for checking configuration. | 114 * @param context The context to use for checking configuration. |
| 115 * @return Whether Chrome should be running on document mode. | 115 * @return Whether Chrome should be running on document mode. |
| 116 */ | 116 */ |
| 117 public static boolean isDocumentMode(Context context) { | 117 public static boolean isDocumentMode(Context context) { |
| 118 if (sDocumentModeDisabled == null && CommandLine.isInitialized()) { | 118 return isDocumentModeEligible(context) && !DocumentModeAssassin.isOptedO
utOfDocumentMode(); |
| 119 initResetListener(); | |
| 120 sDocumentModeDisabled = CommandLine.getInstance().hasSwitch( | |
| 121 ChromeSwitches.DISABLE_DOCUMENT_MODE); | |
| 122 } | |
| 123 return isDocumentModeEligible(context) | |
| 124 && !DocumentModeManager.getInstance(context).isOptedOutOfDocumen
tMode() | |
| 125 && (sDocumentModeDisabled == null || !sDocumentModeDisabled.bool
eanValue()); | |
| 126 } | 119 } |
| 127 | 120 |
| 128 /** | 121 /** |
| 129 * Whether the device could possibly run in Document mode (may return true e
ven if the document | 122 * Whether the device could possibly run in Document mode (may return true e
ven if the document |
| 130 * mode is turned off). | 123 * mode is turned off). |
| 131 * | 124 * |
| 132 * This function can't be changed to return false (even if document mode is
deleted) because we | 125 * This function can't be changed to return false (even if document mode is
deleted) because we |
| 133 * need to know whether a user needs to be migrated away. | 126 * need to know whether a user needs to be migrated away. |
| 134 * | 127 * |
| 135 * @param context The context to use for checking configuration. | 128 * @param context The context to use for checking configuration. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 */ | 174 */ |
| 182 public static boolean isTabSwitchingEnabledInDocumentMode(Context context) { | 175 public static boolean isTabSwitchingEnabledInDocumentMode(Context context) { |
| 183 return isDocumentMode(context) && isTabSwitchingEnabledInDocumentModeInt
ernal(); | 176 return isDocumentMode(context) && isTabSwitchingEnabledInDocumentModeInt
ernal(); |
| 184 } | 177 } |
| 185 | 178 |
| 186 private static boolean isTabSwitchingEnabledInDocumentModeInternal() { | 179 private static boolean isTabSwitchingEnabledInDocumentModeInternal() { |
| 187 return CommandLine.getInstance().hasSwitch( | 180 return CommandLine.getInstance().hasSwitch( |
| 188 ChromeSwitches.ENABLE_TAB_SWITCHER_IN_DOCUMENT_MODE); | 181 ChromeSwitches.ENABLE_TAB_SWITCHER_IN_DOCUMENT_MODE); |
| 189 } | 182 } |
| 190 | 183 |
| 191 private static void initResetListener() { | |
| 192 if (sResetListener != null) return; | |
| 193 | |
| 194 sResetListener = new CommandLine.ResetListener() { | |
| 195 @Override | |
| 196 public void onCommandLineReset() { | |
| 197 sDocumentModeDisabled = null; | |
| 198 } | |
| 199 }; | |
| 200 CommandLine.addResetListener(sResetListener); | |
| 201 } | |
| 202 | |
| 203 private static boolean isHerbDisallowed(Context context) { | 184 private static boolean isHerbDisallowed(Context context) { |
| 204 return isDocumentMode(context) || ChromeVersionInfo.isStableBuild() | 185 return isDocumentMode(context) || ChromeVersionInfo.isStableBuild() |
| 205 || ChromeVersionInfo.isBetaBuild() || DeviceFormFactor.isTablet(
context); | 186 || ChromeVersionInfo.isBetaBuild() || DeviceFormFactor.isTablet(
context); |
| 206 } | 187 } |
| 207 | 188 |
| 208 /** | 189 /** |
| 209 * @return Which flavor of Herb is being tested. See {@link ChromeSwitches#
HERB_FLAVOR_ANISE} | 190 * @return Which flavor of Herb is being tested. See {@link ChromeSwitches#
HERB_FLAVOR_ANISE} |
| 210 * and its related switches. | 191 * and its related switches. |
| 211 */ | 192 */ |
| 212 public static String getHerbFlavor() { | 193 public static String getHerbFlavor() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 271 |
| 291 if (!TextUtils.equals(oldFlavor, newFlavor)) { | 272 if (!TextUtils.equals(oldFlavor, newFlavor)) { |
| 292 ChromePreferenceManager.getInstance(context).setCachedHerbFlavor(new
Flavor); | 273 ChromePreferenceManager.getInstance(context).setCachedHerbFlavor(new
Flavor); |
| 293 } | 274 } |
| 294 } | 275 } |
| 295 | 276 |
| 296 private static native void nativeSetDocumentModeEnabled(boolean enabled); | 277 private static native void nativeSetDocumentModeEnabled(boolean enabled); |
| 297 private static native void nativeSetCustomTabVisible(boolean visible); | 278 private static native void nativeSetCustomTabVisible(boolean visible); |
| 298 private static native void nativeSetIsInMultiWindowMode(boolean isInMultiWin
dowMode); | 279 private static native void nativeSetIsInMultiWindowMode(boolean isInMultiWin
dowMode); |
| 299 } | 280 } |
| OLD | NEW |