blob: 25edfb17f33455da8fc4c9b95fd073f590332e6f [file] [log] [blame]
sdefresne14900ee2015-11-27 14:43:211// Copyright 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Implementation of about_flags for iOS that sets flags based on experimental
6// settings.
7
8#include "ios/chrome/browser/about_flags.h"
9
avi571943672015-12-22 02:12:4910#include <stddef.h>
11#include <stdint.h>
sdefresne14900ee2015-11-27 14:43:2112#import <UIKit/UIKit.h>
13
Gregory Chatzinofff6523722017-11-21 01:33:5314#include "base/base_switches.h"
sdefresne14900ee2015-11-27 14:43:2115#include "base/bind.h"
16#include "base/command_line.h"
17#include "base/logging.h"
avi571943672015-12-22 02:12:4918#include "base/macros.h"
sdefresne14900ee2015-11-27 14:43:2119#include "base/memory/singleton.h"
20#include "base/strings/stringprintf.h"
21#include "base/strings/sys_string_conversions.h"
22#include "base/sys_info.h"
Moe Ahmadic3fd7cd2018-05-11 21:40:2223#include "components/autofill/core/browser/autofill_experiments.h"
Mohamad Ahmadic4df81f2017-12-20 04:41:5924#include "components/autofill/core/common/autofill_features.h"
Olivier Robin3d60411622018-02-23 10:03:2225#include "components/autofill/ios/browser/autofill_switches.h"
sdefresne14900ee2015-11-27 14:43:2126#include "components/dom_distiller/core/dom_distiller_switches.h"
Tommy Nyquistc1d6dea12017-07-26 20:37:2327#include "components/feature_engagement/public/feature_constants.h"
28#include "components/feature_engagement/public/feature_list.h"
sdefresne14900ee2015-11-27 14:43:2129#include "components/flags_ui/feature_entry.h"
30#include "components/flags_ui/feature_entry_macros.h"
31#include "components/flags_ui/flags_storage.h"
32#include "components/flags_ui/flags_ui_switches.h"
noyau4cfb1332016-10-25 17:05:4233#include "components/ntp_tiles/switches.h"
Justin Donnelly33d712e2017-08-23 21:32:5134#include "components/omnibox/browser/omnibox_field_trial.h"
Ioana Pandeled14ce9e2017-11-28 14:41:4635#include "components/password_manager/core/common/password_manager_features.h"
mathp9b4c11d2017-07-06 20:24:1336#include "components/payments/core/features.h"
Marc Treib5fc99e1f2017-11-08 12:19:1837#include "components/search_provider_logos/switches.h"
Emily Starkbafa9062017-12-27 15:22:4638#include "components/security_state/core/features.h"
Jérôme Lebelfa6c5ae2018-03-29 13:46:5739#include "components/signin/core/browser/profile_management_switches.h"
David Rogera6c88122017-10-25 13:02:4640#include "components/signin/core/browser/signin_switches.h"
sdefresne36579782016-02-05 11:08:2541#include "components/strings/grit/components_strings.h"
Sylvain Defresneae6987e2018-03-01 13:21:4042#include "ios/chrome/browser/browsing_data/browsing_data_features.h"
sdefresne14900ee2015-11-27 14:43:2143#include "ios/chrome/browser/chrome_switches.h"
Jean-François Geyelin30be5912017-08-25 12:05:3844#include "ios/chrome/browser/drag_and_drop/drag_and_drop_flag.h"
vabr0215a8e2017-03-28 12:47:3445#include "ios/chrome/browser/ios_chrome_flag_descriptions.h"
mrefaat390f99c0d2018-05-10 19:44:2446#include "ios/chrome/browser/itunes_urls/itunes_urls_flag.h"
Daniel Blakemore72387d32018-02-13 23:45:5547#include "ios/chrome/browser/mailto/features.h"
Mike Doughertya5e5ad52017-08-05 00:11:5848#include "ios/chrome/browser/ssl/captive_portal_features.h"
Louis Romerod11747a2017-10-20 20:10:3549#include "ios/chrome/browser/ui/external_search/features.h"
Kurt Horimoto4da682b022018-04-12 07:43:3550#import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h"
sczsa0c91942017-10-26 18:39:5951#import "ios/chrome/browser/ui/history/history_base_feature.h"
Rohit Rao6a3a481d2017-09-25 19:31:4152#include "ios/chrome/browser/ui/main/main_feature_flags.h"
Gauthier Ambard2746a4b2018-03-20 12:52:1653#import "ios/chrome/browser/ui/popup_menu/popup_menu_flags.h"
sczs6ca1d262017-10-30 20:27:1354#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_base_feature.h"
Justin Cohen2d81c582018-01-22 14:46:4455#include "ios/chrome/browser/ui/ui_feature_flags.h"
Peter K. Lee88137d52018-02-20 19:59:3956#include "ios/chrome/browser/ui/user_feedback_features.h"
sdefresne14900ee2015-11-27 14:43:2157#include "ios/chrome/grit/ios_strings.h"
msardafc76f662017-02-24 12:46:2858#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
Danyao Wang34da6ff2017-10-30 15:16:5659#include "ios/web/public/features.h"
sdefresne14900ee2015-11-27 14:43:2160#include "ios/web/public/user_agent.h"
61#include "ios/web/public/web_view_creation_util.h"
62
63#if !defined(OFFICIAL_BUILD)
64#include "components/variations/variations_switches.h"
vitaliii489217aa2017-01-30 14:50:2265#endif
stkhapuginc1be1792016-12-13 14:30:5366
67#if !defined(__has_feature) || !__has_feature(objc_arc)
68#error "This file requires ARC support."
69#endif
sdefresne14900ee2015-11-27 14:43:2170
elawrence816f6790e2017-06-16 18:19:2871using flags_ui::FeatureEntry;
72
sdefresne14900ee2015-11-27 14:43:2173namespace {
Emily Starkbafa9062017-12-27 15:22:4674
75const FeatureEntry::FeatureParam kMarkHttpAsDangerous[] = {
76 {security_state::features::kMarkHttpAsFeatureParameterName,
77 security_state::features::kMarkHttpAsParameterDangerous}};
78const FeatureEntry::FeatureParam kMarkHttpAsWarning[] = {
79 {security_state::features::kMarkHttpAsFeatureParameterName,
80 security_state::features::kMarkHttpAsParameterWarning}};
81const FeatureEntry::FeatureParam kMarkHttpAsWarningAndDangerousOnFormEdits[] = {
82 {security_state::features::kMarkHttpAsFeatureParameterName,
83 security_state::features::
84 kMarkHttpAsParameterWarningAndDangerousOnFormEdits}};
85const FeatureEntry::FeatureParam
86 kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards[] = {
87 {security_state::features::kMarkHttpAsFeatureParameterName,
88 security_state::features::
89 kMarkHttpAsParameterWarningAndDangerousOnPasswordsAndCreditCards}};
90
91const FeatureEntry::FeatureVariation kMarkHttpAsFeatureVariations[] = {
92 {"(mark as actively dangerous)", kMarkHttpAsDangerous,
93 arraysize(kMarkHttpAsDangerous), nullptr},
94 {"(mark with a Not Secure warning)", kMarkHttpAsWarning,
95 arraysize(kMarkHttpAsWarning), nullptr},
96 {"(mark with a Not Secure warning and dangerous on form edits)",
97 kMarkHttpAsWarningAndDangerousOnFormEdits,
98 arraysize(kMarkHttpAsWarningAndDangerousOnFormEdits), nullptr},
99 {"(mark with a Not Secure warning and dangerous on passwords and credit "
100 "card fields)",
101 kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards,
102 arraysize(kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards),
103 nullptr}};
elawrence816f6790e2017-06-16 18:19:28104
Marc Treib5fc99e1f2017-11-08 12:19:18105const FeatureEntry::Choice kUseDdljsonApiChoices[] = {
106 {flags_ui::kGenericExperimentChoiceDefault, "", ""},
107 {"(force test doodle 0)", search_provider_logos::switches::kGoogleDoodleUrl,
108 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios0.json"},
109 {"(force test doodle 1)", search_provider_logos::switches::kGoogleDoodleUrl,
110 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios1.json"},
111 {"(force test doodle 2)", search_provider_logos::switches::kGoogleDoodleUrl,
112 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios2.json"},
113 {"(force test doodle 3)", search_provider_logos::switches::kGoogleDoodleUrl,
114 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios3.json"},
115 {"(force test doodle 4)", search_provider_logos::switches::kGoogleDoodleUrl,
116 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios4.json"},
117};
Marc Treib2752e8b2017-08-04 14:12:09118
Olivier Robin3d60411622018-02-23 10:03:22119const FeatureEntry::Choice kAutofillIOSDelayBetweenFieldsChoices[] = {
120 {flags_ui::kGenericExperimentChoiceDefault, "", ""},
121 {"0", autofill::switches::kAutofillIOSDelayBetweenFields, "0"},
122 {"10", autofill::switches::kAutofillIOSDelayBetweenFields, "10"},
123 {"20", autofill::switches::kAutofillIOSDelayBetweenFields, "20"},
124 {"50", autofill::switches::kAutofillIOSDelayBetweenFields, "50"},
125 {"100", autofill::switches::kAutofillIOSDelayBetweenFields, "100"},
126 {"200", autofill::switches::kAutofillIOSDelayBetweenFields, "200"},
127 {"500", autofill::switches::kAutofillIOSDelayBetweenFields, "500"},
128 {"1000", autofill::switches::kAutofillIOSDelayBetweenFields, "1000"},
129};
130
Cooper Knaak1e026562017-07-26 05:22:28131// To add a new entry, add to the end of kFeatureEntries. There are four
sdefresne14900ee2015-11-27 14:43:21132// distinct types of entries:
Cooper Knaak1e026562017-07-26 05:22:28133// . ENABLE_DISABLE_VALUE: entry is either enabled, disabled, or uses the
134// default value for this feature. Use the ENABLE_DISABLE_VALUE_TYPE
sdefresne14900ee2015-11-27 14:43:21135// macro for this type supplying the command line to the macro.
136// . MULTI_VALUE: a list of choices, the first of which should correspond to a
137// deactivated state for this lab (i.e. no command line option). To specify
138// this type of entry use the macro MULTI_VALUE_TYPE supplying it the
139// array of choices.
Cooper Knaak1e026562017-07-26 05:22:28140// . FEATURE_VALUE: entry is associated with a base::Feature instance. Entry is
141// either enabled, disabled, or uses the default value of the associated
142// base::Feature instance. To specify this type of entry use the macro
143// FEATURE_VALUE_TYPE supplying it the base::Feature instance.
144// . FEATURE_WITH_PARAM_VALUES: a list of choices associated with a
145// base::Feature instance. Choices corresponding to the default state, a
146// universally enabled state, and a universally disabled state are
147// automatically included. To specify this type of entry use the macro
148// FEATURE_WITH_PARAMS_VALUE_TYPE supplying it the base::Feature instance and
149// the array of choices.
150//
sdefresne14900ee2015-11-27 14:43:21151// See the documentation of FeatureEntry for details on the fields.
152//
153// When adding a new choice, add it to the end of the list.
154const flags_ui::FeatureEntry kFeatureEntries[] = {
Emily Starkbafa9062017-12-27 15:22:46155 {"enable-mark-http-as", flag_descriptions::kMarkHttpAsName,
elawrence816f6790e2017-06-16 18:19:28156 flag_descriptions::kMarkHttpAsDescription, flags_ui::kOsIos,
Emily Starkbafa9062017-12-27 15:22:46157 FEATURE_WITH_PARAMS_VALUE_TYPE(
158 security_state::features::kMarkHttpAsFeature,
159 kMarkHttpAsFeatureVariations,
160 "MarkHttpAs")},
mathp9b4c11d2017-07-06 20:24:13161 {"web-payments", flag_descriptions::kWebPaymentsName,
162 flag_descriptions::kWebPaymentsDescription, flags_ui::kOsIos,
163 FEATURE_VALUE_TYPE(payments::features::kWebPayments)},
Randall Raymond59766ac2017-08-09 16:28:58164 {"web-payments-native-apps", flag_descriptions::kWebPaymentsNativeAppsName,
165 flag_descriptions::kWebPaymentsNativeAppsDescription, flags_ui::kOsIos,
166 FEATURE_VALUE_TYPE(payments::features::kWebPaymentsNativeApps)},
Mike Doughertya5e5ad52017-08-05 00:11:58167 {"ios-captive-portal", flag_descriptions::kCaptivePortalName,
168 flag_descriptions::kCaptivePortalDescription, flags_ui::kOsIos,
169 FEATURE_VALUE_TYPE(kCaptivePortalFeature)},
Mike Doughertyc20eefa2018-02-20 19:20:33170 {"ios-captive-portal-metrics", flag_descriptions::kCaptivePortalMetricsName,
171 flag_descriptions::kCaptivePortalMetricsDescription, flags_ui::kOsIos,
172 FEATURE_VALUE_TYPE(kCaptivePortalMetrics)},
Cooper Knaak1e026562017-07-26 05:22:28173 {"in-product-help-demo-mode-choice",
174 flag_descriptions::kInProductHelpDemoModeName,
175 flag_descriptions::kInProductHelpDemoModeDescription, flags_ui::kOsIos,
176 FEATURE_WITH_PARAMS_VALUE_TYPE(
Tommy Nyquistc1d6dea12017-07-26 20:37:23177 feature_engagement::kIPHDemoMode,
178 feature_engagement::kIPHDemoModeChoiceVariations,
Marc Treib2752e8b2017-08-04 14:12:09179 "IPH_DemoMode")},
180 {"use-ddljson-api", flag_descriptions::kUseDdljsonApiName,
181 flag_descriptions::kUseDdljsonApiDescription, flags_ui::kOsIos,
Marc Treib5fc99e1f2017-11-08 12:19:18182 MULTI_VALUE_TYPE(kUseDdljsonApiChoices)},
Justin Donnelly33d712e2017-08-23 21:32:51183 {"omnibox-ui-elide-suggestion-url-after-host",
184 flag_descriptions::kOmniboxUIElideSuggestionUrlAfterHostName,
185 flag_descriptions::kOmniboxUIElideSuggestionUrlAfterHostDescription,
186 flags_ui::kOsIos,
187 FEATURE_VALUE_TYPE(omnibox::kUIExperimentElideSuggestionUrlAfterHost)},
Jean-François Geyelin30be5912017-08-25 12:05:38188#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)
189 {"drag_and_drop", flag_descriptions::kDragAndDropName,
190 flag_descriptions::kDragAndDropDescription, flags_ui::kOsIos,
Rohit Rao6a3a481d2017-09-25 19:31:41191 FEATURE_VALUE_TYPE(kDragAndDrop)},
Jean-François Geyelin30be5912017-08-25 12:05:38192#endif
Rohit Rao6a3a481d2017-09-25 19:31:41193 {"tab_switcher_presents_bvc",
194 flag_descriptions::kTabSwitcherPresentsBVCName,
195 flag_descriptions::kTabSwitcherPresentsBVCDescription, flags_ui::kOsIos,
Jean-François Geyelined4cde72017-10-11 11:34:50196 FEATURE_VALUE_TYPE(kTabSwitcherPresentsBVC)},
Louis Romerod11747a2017-10-20 20:10:35197 {"external-search", flag_descriptions::kExternalSearchName,
198 flag_descriptions::kExternalSearchDescription, flags_ui::kOsIos,
199 FEATURE_VALUE_TYPE(kExternalSearch)},
sczsa0c91942017-10-26 18:39:59200 {"history-batch-updates-filter",
201 flag_descriptions::kHistoryBatchUpdatesFilterName,
202 flag_descriptions::kHistoryBatchUpdatesFilterDescription, flags_ui::kOsIos,
203 FEATURE_VALUE_TYPE(kHistoryBatchUpdatesFilter)},
Danyao Wang34da6ff2017-10-30 15:16:56204 {"slim-navigation-manager", flag_descriptions::kSlimNavigationManagerName,
205 flag_descriptions::kSlimNavigationManagerDescription, flags_ui::kOsIos,
206 FEATURE_VALUE_TYPE(web::features::kSlimNavigationManager)},
Eugene But88083f42018-01-30 17:51:37207 {"new-file-download", flag_descriptions::kNewFileDownloadName,
208 flag_descriptions::kNewFileDownloadDescription, flags_ui::kOsIos,
209 FEATURE_VALUE_TYPE(web::features::kNewFileDownload)},
sczsdc2e8e02018-01-09 18:39:32210 {"memex-tab-switcher", flag_descriptions::kMemexTabSwitcherName,
211 flag_descriptions::kMemexTabSwitcherDescription, flags_ui::kOsIos,
212 FEATURE_VALUE_TYPE(kMemexTabSwitcher)},
nikhild70e7cb52017-12-26 07:38:20213 {"PasswordExport", flag_descriptions::kPasswordExportName,
Ioana Pandeled14ce9e2017-11-28 14:41:46214 flag_descriptions::kPasswordExportDescription, flags_ui::kOsIos,
mrefaata6501d92017-12-11 19:50:50215 FEATURE_VALUE_TYPE(password_manager::features::kPasswordExport)},
216 {"wk-http-system-cookie-store",
217 flag_descriptions::kWKHTTPSystemCookieStoreName,
218 flag_descriptions::kWKHTTPSystemCookieStoreName, flags_ui::kOsIos,
Mohamad Ahmadic4df81f2017-12-20 04:41:59219 FEATURE_VALUE_TYPE(web::features::kWKHTTPSystemCookieStore)},
Moe Ahmadic3fd7cd2018-05-11 21:40:22220 {"enable-autofill-credit-card-upload",
221 flag_descriptions::kAutofillCreditCardUploadName,
222 flag_descriptions::kAutofillCreditCardUploadDescription, flags_ui::kOsIos,
223 FEATURE_VALUE_TYPE(autofill::kAutofillUpstream)},
Moe Ahmadi3fd9f202018-05-10 17:39:24224 {"enable-autofill-credit-card-upload-google-pay-branding",
225 flag_descriptions::kAutofillUpstreamUseGooglePayBrandingOnMobileName,
226 flag_descriptions::
227 kAutofillUpstreamUseGooglePayBrandingOnMobileDescription,
228 flags_ui::kOsIos,
229 FEATURE_VALUE_TYPE(
230 autofill::features::kAutofillUpstreamUseGooglePayBrandingOnMobile)},
Mohamad Ahmadic4df81f2017-12-20 04:41:59231 {"show-autofill-type-predictions",
232 flag_descriptions::kShowAutofillTypePredictionsName,
233 flag_descriptions::kShowAutofillTypePredictionsDescription,
234 flags_ui::kOsIos,
Gauthier Ambardcfd85182018-01-05 10:37:46235 FEATURE_VALUE_TYPE(autofill::features::kAutofillShowTypePredictions)},
Olivier Robin3d60411622018-02-23 10:03:22236 {"autofill-ios-delay-between-fields",
237 flag_descriptions::kAutofillIOSDelayBetweenFieldsName,
238 flag_descriptions::kAutofillIOSDelayBetweenFieldsDescription,
239 flags_ui::kOsIos, MULTI_VALUE_TYPE(kAutofillIOSDelayBetweenFieldsChoices)},
Justin Cohen2d81c582018-01-22 14:46:44240 {"ui-refresh-phase-1", flag_descriptions::kUIRefreshPhase1Name,
241 flag_descriptions::kUIRefreshPhase1Description, flags_ui::kOsIos,
242 FEATURE_VALUE_TYPE(kUIRefreshPhase1)},
sczs44d54dc2018-03-12 15:56:02243 {"collections-ui-reboot", flag_descriptions::kCollectionsUIRebootName,
244 flag_descriptions::kCollectionsUIRebootDescription, flags_ui::kOsIos,
245 FEATURE_VALUE_TYPE(kCollectionsUIReboot)},
Peter K. Lee1e176752018-05-04 20:48:09246 {"infobars-ui-reboot", flag_descriptions::kInfobarsUIRebootName,
247 flag_descriptions::kInfobarsUIRebootDescription, flags_ui::kOsIos,
248 FEATURE_VALUE_TYPE(kInfobarsUIReboot)},
Mike Dougherty5f188d92018-02-02 07:10:35249 {"context-menu-element-post-message",
250 flag_descriptions::kContextMenuElementPostMessageName,
251 flag_descriptions::kContextMenuElementPostMessageDescription,
252 flags_ui::kOsIos,
253 FEATURE_VALUE_TYPE(web::features::kContextMenuElementPostMessage)},
Daniel Blakemore72387d32018-02-13 23:45:55254 {"mailto-handling-google-ui",
255 flag_descriptions::kMailtoHandlingWithGoogleUIName,
256 flag_descriptions::kMailtoHandlingWithGoogleUIDescription,
257 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kMailtoHandledWithGoogleUI)},
Peter K. Lee88137d52018-02-20 19:59:39258 {"feedback-kit-v2", flag_descriptions::kFeedbackKitV2Name,
259 flag_descriptions::kFeedbackKitV2Description, flags_ui::kOsIos,
260 FEATURE_VALUE_TYPE(kFeedbackKitV2)},
Peter K. Lee302c8b82018-03-29 23:54:51261 {"feedback-kit-v2-sso-service",
262 flag_descriptions::kFeedbackKitV2WithSSOServiceName,
263 flag_descriptions::kFeedbackKitV2WithSSOServiceDescription,
264 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kFeedbackKitV2WithSSOService)},
Sylvain Defresneae6987e2018-03-01 13:21:40265 {"new-clear-browsing-data-ui",
266 flag_descriptions::kNewClearBrowsingDataUIName,
267 flag_descriptions::kNewClearBrowsingDataUIDescription, flags_ui::kOsIos,
268 FEATURE_VALUE_TYPE(kNewClearBrowsingDataUI)},
Gauthier Ambard2746a4b2018-03-20 12:52:16269 {"new-tools_menu", flag_descriptions::kNewToolsMenuName,
270 flag_descriptions::kNewToolsMenuDescription, flags_ui::kOsIos,
271 FEATURE_VALUE_TYPE(kNewToolsMenu)},
mrefaat390f99c0d2018-05-10 19:44:24272 {"itunes-urls-store-kit-handling",
273 flag_descriptions::kITunesUrlsStoreKitHandlingName,
274 flag_descriptions::kITunesUrlsStoreKitHandlingDescription,
275 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kITunesUrlsStoreKitHandling)},
Jérôme Lebelfa6c5ae2018-03-29 13:46:57276 {"unified-consent", flag_descriptions::kUnifiedConsentName,
277 flag_descriptions::kUnifiedConsentDescription, flags_ui::kOsIos,
278 FEATURE_VALUE_TYPE(signin::kUnifiedConsent)},
sebsg93dc01c2018-04-05 16:42:48279 {"autofill-dynamic-forms", flag_descriptions::kAutofillDynamicFormsName,
280 flag_descriptions::kAutofillDynamicFormsDescription, flags_ui::kOsIos,
281 FEATURE_VALUE_TYPE(autofill::features::kAutofillDynamicForms)},
Moe Ahmadid3ddfcb2018-04-20 19:51:08282 {"autofill-restrict-formless-form-extraction",
283 flag_descriptions::kAutofillRestrictUnownedFieldsToFormlessCheckoutName,
284 flag_descriptions::
285 kAutofillRestrictUnownedFieldsToFormlessCheckoutDescription,
286 flags_ui::kOsIos,
287 FEATURE_VALUE_TYPE(
288 autofill::features::kAutofillRestrictUnownedFieldsToFormlessCheckout)},
[email protected]dbcd4d52018-04-10 09:17:58289 {"ui-refresh-location-bar", flag_descriptions::kUIRefreshLocationBarName,
290 flag_descriptions::kUIRefreshLocationBarDescription, flags_ui::kOsIos,
291 FEATURE_VALUE_TYPE(kUIRefreshLocationBar)},
Kurt Horimotodc33af32018-05-01 01:39:14292 {"fullscreen-viewport-adjustment-experiment",
293 flag_descriptions::kFullscreenViewportAdjustmentExperimentName,
294 flag_descriptions::kFullscreenViewportAdjustmentExperimentDescription,
295 flags_ui::kOsIos,
296 MULTI_VALUE_TYPE(
297 fullscreen::features::kViewportAdjustmentExperimentChoices)},
Roger McFarlane1a37d7b2018-04-20 22:45:19298 {"autofill-enforce-min-required-fields-for-heuristics",
299 flag_descriptions::kAutofillEnforceMinRequiredFieldsForHeuristicsName,
300 flag_descriptions::
301 kAutofillEnforceMinRequiredFieldsForHeuristicsDescription,
302 flags_ui::kOsIos,
303 FEATURE_VALUE_TYPE(
304 autofill::features::kAutofillEnforceMinRequiredFieldsForHeuristics)},
305 {"autofill-enforce-min-required-fields-for-query",
306 flag_descriptions::kAutofillEnforceMinRequiredFieldsForQueryName,
307 flag_descriptions::kAutofillEnforceMinRequiredFieldsForQueryDescription,
308 flags_ui::kOsIos,
309 FEATURE_VALUE_TYPE(
310 autofill::features::kAutofillEnforceMinRequiredFieldsForQuery)},
311 {"autofill-enforce-min-required-fields-for-upload",
312 flag_descriptions::kAutofillEnforceMinRequiredFieldsForUploadName,
313 flag_descriptions::kAutofillEnforceMinRequiredFieldsForUploadDescription,
314 flags_ui::kOsIos,
315 FEATURE_VALUE_TYPE(
316 autofill::features::kAutofillEnforceMinRequiredFieldsForUpload)},
Gauthier Ambard4417f852018-04-26 14:24:32317 {"browser-container-fullscreen",
318 flag_descriptions::kBrowserContainerFullscreenName,
319 flag_descriptions::kBrowserContainerFullscreenDescription,
320 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kBrowserContainerFullscreen)},
Gauthier Ambardcfd85182018-01-05 10:37:46321};
sdefresne14900ee2015-11-27 14:43:21322
323// Add all switches from experimental flags to |command_line|.
324void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) {
325 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
326
sdefresne14900ee2015-11-27 14:43:21327 // Set the UA flag if UseMobileSafariUA is enabled.
328 if ([defaults boolForKey:@"UseMobileSafariUA"]) {
329 // Safari uses "Vesion/", followed by the OS version excluding bugfix, where
330 // Chrome puts its product token.
avi571943672015-12-22 02:12:49331 int32_t major = 0;
332 int32_t minor = 0;
333 int32_t bugfix = 0;
sdefresne14900ee2015-11-27 14:43:21334 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);
335 std::string product = base::StringPrintf("Version/%d.%d", major, minor);
336
337 command_line->AppendSwitchASCII(switches::kUserAgent,
338 web::BuildUserAgentFromProduct(product));
339 }
340
341 // Freeform commandline flags. These are added last, so that any flags added
342 // earlier in this function take precedence.
343 if ([defaults boolForKey:@"EnableFreeformCommandLineFlags"]) {
344 base::CommandLine::StringVector flags;
345 // Append an empty "program" argument.
346 flags.push_back("");
347
348 // The number of flags corresponds to the number of text fields in
349 // Experimental.plist.
350 const int kNumFreeformFlags = 5;
351 for (int i = 1; i <= kNumFreeformFlags; ++i) {
352 NSString* key =
353 [NSString stringWithFormat:@"FreeformCommandLineFlag%d", i];
354 NSString* flag = [defaults stringForKey:key];
355 if ([flag length]) {
356 flags.push_back(base::SysNSStringToUTF8(flag));
357 }
358 }
359
360 base::CommandLine temp_command_line(flags);
361 command_line->AppendArguments(temp_command_line, false);
362 }
msardafc76f662017-02-24 12:46:28363
justincohendacc85d2017-06-28 23:34:10364 // Populate command line flag for 3rd party keyboard omnibox workaround.
365 NSString* enableThirdPartyKeyboardWorkaround =
366 [defaults stringForKey:@"EnableThirdPartyKeyboardWorkaround"];
367 if ([enableThirdPartyKeyboardWorkaround isEqualToString:@"Enabled"]) {
368 command_line->AppendSwitch(switches::kEnableThirdPartyKeyboardWorkaround);
369 } else if ([enableThirdPartyKeyboardWorkaround isEqualToString:@"Disabled"]) {
370 command_line->AppendSwitch(switches::kDisableThirdPartyKeyboardWorkaround);
371 }
372
msardafc76f662017-02-24 12:46:28373 ios::GetChromeBrowserProvider()->AppendSwitchesFromExperimentalSettings(
374 defaults, command_line);
sdefresne14900ee2015-11-27 14:43:21375}
376
377bool SkipConditionalFeatureEntry(const flags_ui::FeatureEntry& entry) {
378 return false;
379}
380
381class FlagsStateSingleton {
382 public:
383 FlagsStateSingleton()
384 : flags_state_(kFeatureEntries, arraysize(kFeatureEntries)) {}
385 ~FlagsStateSingleton() {}
386
387 static FlagsStateSingleton* GetInstance() {
388 return base::Singleton<FlagsStateSingleton>::get();
389 }
390
391 static flags_ui::FlagsState* GetFlagsState() {
392 return &GetInstance()->flags_state_;
393 }
394
395 private:
396 flags_ui::FlagsState flags_state_;
397
398 DISALLOW_COPY_AND_ASSIGN(FlagsStateSingleton);
399};
400} // namespace
401
402void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
403 base::CommandLine* command_line) {
Gregory Chatzinoff31305112017-12-20 21:56:02404 AppendSwitchesFromExperimentalSettings(command_line);
sdefresne14900ee2015-11-27 14:43:21405 FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches(
sdefresnec9763902015-12-02 10:30:11406 flags_storage, command_line, flags_ui::kAddSentinels,
Gregory Chatzinofff6523722017-11-21 01:33:53407 switches::kEnableFeatures, switches::kDisableFeatures);
sdefresne14900ee2015-11-27 14:43:21408}
409
jkrcalbf073372016-07-29 07:21:31410std::vector<std::string> RegisterAllFeatureVariationParameters(
411 flags_ui::FlagsStorage* flags_storage,
412 base::FeatureList* feature_list) {
413 return FlagsStateSingleton::GetFlagsState()
414 ->RegisterAllFeatureVariationParameters(flags_storage, feature_list);
415}
416
sdefresne14900ee2015-11-27 14:43:21417void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage,
418 flags_ui::FlagAccess access,
419 base::ListValue* supported_entries,
420 base::ListValue* unsupported_entries) {
421 FlagsStateSingleton::GetFlagsState()->GetFlagFeatureEntries(
422 flags_storage, access, supported_entries, unsupported_entries,
423 base::Bind(&SkipConditionalFeatureEntry));
424}
425
426void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage,
427 const std::string& internal_name,
428 bool enable) {
429 FlagsStateSingleton::GetFlagsState()->SetFeatureEntryEnabled(
430 flags_storage, internal_name, enable);
431}
432
433void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) {
434 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage);
435}
436
437namespace testing {
438
439const flags_ui::FeatureEntry* GetFeatureEntries(size_t* count) {
440 *count = arraysize(kFeatureEntries);
441 return kFeatureEntries;
442}
443
444} // namespace testing