blob: 15067298ab61939f22ac011fc03dec4eb2d745d5 [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"
Mark Cogan02ed6c772018-05-31 17:00:5151#import "ios/chrome/browser/ui/history/features.h"
Rohit Rao6a3a481d2017-09-25 19:31:4152#include "ios/chrome/browser/ui/main/main_feature_flags.h"
Mark Cogan02ed6c772018-05-31 17:00:5153#import "ios/chrome/browser/ui/toolbar/public/features.h"
Justin Cohen2d81c582018-01-22 14:46:4454#include "ios/chrome/browser/ui/ui_feature_flags.h"
Peter K. Lee88137d52018-02-20 19:59:3955#include "ios/chrome/browser/ui/user_feedback_features.h"
sdefresne14900ee2015-11-27 14:43:2156#include "ios/chrome/grit/ios_strings.h"
msardafc76f662017-02-24 12:46:2857#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
Danyao Wang34da6ff2017-10-30 15:16:5658#include "ios/web/public/features.h"
sdefresne14900ee2015-11-27 14:43:2159#include "ios/web/public/user_agent.h"
60#include "ios/web/public/web_view_creation_util.h"
61
62#if !defined(OFFICIAL_BUILD)
63#include "components/variations/variations_switches.h"
vitaliii489217aa2017-01-30 14:50:2264#endif
stkhapuginc1be1792016-12-13 14:30:5365
66#if !defined(__has_feature) || !__has_feature(objc_arc)
67#error "This file requires ARC support."
68#endif
sdefresne14900ee2015-11-27 14:43:2169
elawrence816f6790e2017-06-16 18:19:2870using flags_ui::FeatureEntry;
71
sdefresne14900ee2015-11-27 14:43:2172namespace {
Emily Starkbafa9062017-12-27 15:22:4673
74const FeatureEntry::FeatureParam kMarkHttpAsDangerous[] = {
75 {security_state::features::kMarkHttpAsFeatureParameterName,
76 security_state::features::kMarkHttpAsParameterDangerous}};
77const FeatureEntry::FeatureParam kMarkHttpAsWarning[] = {
78 {security_state::features::kMarkHttpAsFeatureParameterName,
79 security_state::features::kMarkHttpAsParameterWarning}};
80const FeatureEntry::FeatureParam kMarkHttpAsWarningAndDangerousOnFormEdits[] = {
81 {security_state::features::kMarkHttpAsFeatureParameterName,
82 security_state::features::
83 kMarkHttpAsParameterWarningAndDangerousOnFormEdits}};
84const FeatureEntry::FeatureParam
85 kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards[] = {
86 {security_state::features::kMarkHttpAsFeatureParameterName,
87 security_state::features::
88 kMarkHttpAsParameterWarningAndDangerousOnPasswordsAndCreditCards}};
89
90const FeatureEntry::FeatureVariation kMarkHttpAsFeatureVariations[] = {
91 {"(mark as actively dangerous)", kMarkHttpAsDangerous,
92 arraysize(kMarkHttpAsDangerous), nullptr},
93 {"(mark with a Not Secure warning)", kMarkHttpAsWarning,
94 arraysize(kMarkHttpAsWarning), nullptr},
95 {"(mark with a Not Secure warning and dangerous on form edits)",
96 kMarkHttpAsWarningAndDangerousOnFormEdits,
97 arraysize(kMarkHttpAsWarningAndDangerousOnFormEdits), nullptr},
98 {"(mark with a Not Secure warning and dangerous on passwords and credit "
99 "card fields)",
100 kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards,
101 arraysize(kMarkHttpAsWarningAndDangerousOnPasswordsAndCreditCards),
102 nullptr}};
elawrence816f6790e2017-06-16 18:19:28103
Marc Treib5fc99e1f2017-11-08 12:19:18104const FeatureEntry::Choice kUseDdljsonApiChoices[] = {
105 {flags_ui::kGenericExperimentChoiceDefault, "", ""},
106 {"(force test doodle 0)", search_provider_logos::switches::kGoogleDoodleUrl,
107 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios0.json"},
108 {"(force test doodle 1)", search_provider_logos::switches::kGoogleDoodleUrl,
109 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios1.json"},
110 {"(force test doodle 2)", search_provider_logos::switches::kGoogleDoodleUrl,
111 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios2.json"},
112 {"(force test doodle 3)", search_provider_logos::switches::kGoogleDoodleUrl,
113 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios3.json"},
114 {"(force test doodle 4)", search_provider_logos::switches::kGoogleDoodleUrl,
115 "https://www.gstatic.com/chrome/ntp/doodle_test/ddljson_ios4.json"},
116};
Marc Treib2752e8b2017-08-04 14:12:09117
Olivier Robin3d60411622018-02-23 10:03:22118const FeatureEntry::Choice kAutofillIOSDelayBetweenFieldsChoices[] = {
119 {flags_ui::kGenericExperimentChoiceDefault, "", ""},
120 {"0", autofill::switches::kAutofillIOSDelayBetweenFields, "0"},
121 {"10", autofill::switches::kAutofillIOSDelayBetweenFields, "10"},
122 {"20", autofill::switches::kAutofillIOSDelayBetweenFields, "20"},
123 {"50", autofill::switches::kAutofillIOSDelayBetweenFields, "50"},
124 {"100", autofill::switches::kAutofillIOSDelayBetweenFields, "100"},
125 {"200", autofill::switches::kAutofillIOSDelayBetweenFields, "200"},
126 {"500", autofill::switches::kAutofillIOSDelayBetweenFields, "500"},
127 {"1000", autofill::switches::kAutofillIOSDelayBetweenFields, "1000"},
128};
129
Cooper Knaak1e026562017-07-26 05:22:28130// To add a new entry, add to the end of kFeatureEntries. There are four
sdefresne14900ee2015-11-27 14:43:21131// distinct types of entries:
Cooper Knaak1e026562017-07-26 05:22:28132// . ENABLE_DISABLE_VALUE: entry is either enabled, disabled, or uses the
133// default value for this feature. Use the ENABLE_DISABLE_VALUE_TYPE
sdefresne14900ee2015-11-27 14:43:21134// macro for this type supplying the command line to the macro.
135// . MULTI_VALUE: a list of choices, the first of which should correspond to a
136// deactivated state for this lab (i.e. no command line option). To specify
137// this type of entry use the macro MULTI_VALUE_TYPE supplying it the
138// array of choices.
Cooper Knaak1e026562017-07-26 05:22:28139// . FEATURE_VALUE: entry is associated with a base::Feature instance. Entry is
140// either enabled, disabled, or uses the default value of the associated
141// base::Feature instance. To specify this type of entry use the macro
142// FEATURE_VALUE_TYPE supplying it the base::Feature instance.
143// . FEATURE_WITH_PARAM_VALUES: a list of choices associated with a
144// base::Feature instance. Choices corresponding to the default state, a
145// universally enabled state, and a universally disabled state are
146// automatically included. To specify this type of entry use the macro
147// FEATURE_WITH_PARAMS_VALUE_TYPE supplying it the base::Feature instance and
148// the array of choices.
149//
sdefresne14900ee2015-11-27 14:43:21150// See the documentation of FeatureEntry for details on the fields.
151//
152// When adding a new choice, add it to the end of the list.
153const flags_ui::FeatureEntry kFeatureEntries[] = {
Emily Starkbafa9062017-12-27 15:22:46154 {"enable-mark-http-as", flag_descriptions::kMarkHttpAsName,
elawrence816f6790e2017-06-16 18:19:28155 flag_descriptions::kMarkHttpAsDescription, flags_ui::kOsIos,
Emily Starkbafa9062017-12-27 15:22:46156 FEATURE_WITH_PARAMS_VALUE_TYPE(
157 security_state::features::kMarkHttpAsFeature,
158 kMarkHttpAsFeatureVariations,
159 "MarkHttpAs")},
mathp9b4c11d2017-07-06 20:24:13160 {"web-payments", flag_descriptions::kWebPaymentsName,
161 flag_descriptions::kWebPaymentsDescription, flags_ui::kOsIos,
162 FEATURE_VALUE_TYPE(payments::features::kWebPayments)},
Randall Raymond59766ac2017-08-09 16:28:58163 {"web-payments-native-apps", flag_descriptions::kWebPaymentsNativeAppsName,
164 flag_descriptions::kWebPaymentsNativeAppsDescription, flags_ui::kOsIos,
165 FEATURE_VALUE_TYPE(payments::features::kWebPaymentsNativeApps)},
Mike Doughertya5e5ad52017-08-05 00:11:58166 {"ios-captive-portal", flag_descriptions::kCaptivePortalName,
167 flag_descriptions::kCaptivePortalDescription, flags_ui::kOsIos,
168 FEATURE_VALUE_TYPE(kCaptivePortalFeature)},
Mike Doughertyc20eefa2018-02-20 19:20:33169 {"ios-captive-portal-metrics", flag_descriptions::kCaptivePortalMetricsName,
170 flag_descriptions::kCaptivePortalMetricsDescription, flags_ui::kOsIos,
171 FEATURE_VALUE_TYPE(kCaptivePortalMetrics)},
Cooper Knaak1e026562017-07-26 05:22:28172 {"in-product-help-demo-mode-choice",
173 flag_descriptions::kInProductHelpDemoModeName,
174 flag_descriptions::kInProductHelpDemoModeDescription, flags_ui::kOsIos,
175 FEATURE_WITH_PARAMS_VALUE_TYPE(
Tommy Nyquistc1d6dea12017-07-26 20:37:23176 feature_engagement::kIPHDemoMode,
177 feature_engagement::kIPHDemoModeChoiceVariations,
Marc Treib2752e8b2017-08-04 14:12:09178 "IPH_DemoMode")},
179 {"use-ddljson-api", flag_descriptions::kUseDdljsonApiName,
180 flag_descriptions::kUseDdljsonApiDescription, flags_ui::kOsIos,
Marc Treib5fc99e1f2017-11-08 12:19:18181 MULTI_VALUE_TYPE(kUseDdljsonApiChoices)},
Justin Donnelly33d712e2017-08-23 21:32:51182 {"omnibox-ui-elide-suggestion-url-after-host",
183 flag_descriptions::kOmniboxUIElideSuggestionUrlAfterHostName,
184 flag_descriptions::kOmniboxUIElideSuggestionUrlAfterHostDescription,
185 flags_ui::kOsIos,
186 FEATURE_VALUE_TYPE(omnibox::kUIExperimentElideSuggestionUrlAfterHost)},
Jean-François Geyelin30be5912017-08-25 12:05:38187#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0)
188 {"drag_and_drop", flag_descriptions::kDragAndDropName,
189 flag_descriptions::kDragAndDropDescription, flags_ui::kOsIos,
Rohit Rao6a3a481d2017-09-25 19:31:41190 FEATURE_VALUE_TYPE(kDragAndDrop)},
Jean-François Geyelin30be5912017-08-25 12:05:38191#endif
Rohit Rao6a3a481d2017-09-25 19:31:41192 {"tab_switcher_presents_bvc",
193 flag_descriptions::kTabSwitcherPresentsBVCName,
194 flag_descriptions::kTabSwitcherPresentsBVCDescription, flags_ui::kOsIos,
Jean-François Geyelined4cde72017-10-11 11:34:50195 FEATURE_VALUE_TYPE(kTabSwitcherPresentsBVC)},
Louis Romerod11747a2017-10-20 20:10:35196 {"external-search", flag_descriptions::kExternalSearchName,
197 flag_descriptions::kExternalSearchDescription, flags_ui::kOsIos,
198 FEATURE_VALUE_TYPE(kExternalSearch)},
sczsa0c91942017-10-26 18:39:59199 {"history-batch-updates-filter",
200 flag_descriptions::kHistoryBatchUpdatesFilterName,
201 flag_descriptions::kHistoryBatchUpdatesFilterDescription, flags_ui::kOsIos,
202 FEATURE_VALUE_TYPE(kHistoryBatchUpdatesFilter)},
Danyao Wang34da6ff2017-10-30 15:16:56203 {"slim-navigation-manager", flag_descriptions::kSlimNavigationManagerName,
204 flag_descriptions::kSlimNavigationManagerDescription, flags_ui::kOsIos,
205 FEATURE_VALUE_TYPE(web::features::kSlimNavigationManager)},
Eugene But88083f42018-01-30 17:51:37206 {"new-file-download", flag_descriptions::kNewFileDownloadName,
207 flag_descriptions::kNewFileDownloadDescription, flags_ui::kOsIos,
208 FEATURE_VALUE_TYPE(web::features::kNewFileDownload)},
Eugene Buta23c8fb2018-05-14 20:40:23209 {"web-error-pages", flag_descriptions::kWebErrorPagesName,
210 flag_descriptions::kWebErrorPagesDescription, flags_ui::kOsIos,
211 FEATURE_VALUE_TYPE(web::features::kWebErrorPages)},
sczsdc2e8e02018-01-09 18:39:32212 {"memex-tab-switcher", flag_descriptions::kMemexTabSwitcherName,
213 flag_descriptions::kMemexTabSwitcherDescription, flags_ui::kOsIos,
214 FEATURE_VALUE_TYPE(kMemexTabSwitcher)},
nikhild70e7cb52017-12-26 07:38:20215 {"PasswordExport", flag_descriptions::kPasswordExportName,
Ioana Pandeled14ce9e2017-11-28 14:41:46216 flag_descriptions::kPasswordExportDescription, flags_ui::kOsIos,
mrefaata6501d92017-12-11 19:50:50217 FEATURE_VALUE_TYPE(password_manager::features::kPasswordExport)},
218 {"wk-http-system-cookie-store",
219 flag_descriptions::kWKHTTPSystemCookieStoreName,
220 flag_descriptions::kWKHTTPSystemCookieStoreName, flags_ui::kOsIos,
Mohamad Ahmadic4df81f2017-12-20 04:41:59221 FEATURE_VALUE_TYPE(web::features::kWKHTTPSystemCookieStore)},
Moe Ahmadic3fd7cd2018-05-11 21:40:22222 {"enable-autofill-credit-card-upload",
223 flag_descriptions::kAutofillCreditCardUploadName,
224 flag_descriptions::kAutofillCreditCardUploadDescription, flags_ui::kOsIos,
225 FEATURE_VALUE_TYPE(autofill::kAutofillUpstream)},
Lakshmi Kumar Dabbiruee22004e2018-06-01 01:52:27226 {"enable-autofill-credit-card-downstream-google-pay-branding",
227 flag_descriptions::kAutofillDownstreamUseGooglePayBrandingOniOSName,
228 flag_descriptions::kAutofillDownstreamUseGooglePayBrandingOniOSDescription,
229 flags_ui::kOsIos,
230 FEATURE_VALUE_TYPE(
231 autofill::features::kAutofillDownstreamUseGooglePayBrandingOniOS)},
Moe Ahmadi3fd9f202018-05-10 17:39:24232 {"enable-autofill-credit-card-upload-google-pay-branding",
233 flag_descriptions::kAutofillUpstreamUseGooglePayBrandingOnMobileName,
234 flag_descriptions::
235 kAutofillUpstreamUseGooglePayBrandingOnMobileDescription,
236 flags_ui::kOsIos,
237 FEATURE_VALUE_TYPE(
238 autofill::features::kAutofillUpstreamUseGooglePayBrandingOnMobile)},
Mohamad Ahmadic4df81f2017-12-20 04:41:59239 {"show-autofill-type-predictions",
240 flag_descriptions::kShowAutofillTypePredictionsName,
241 flag_descriptions::kShowAutofillTypePredictionsDescription,
242 flags_ui::kOsIos,
Gauthier Ambardcfd85182018-01-05 10:37:46243 FEATURE_VALUE_TYPE(autofill::features::kAutofillShowTypePredictions)},
Olivier Robin3d60411622018-02-23 10:03:22244 {"autofill-ios-delay-between-fields",
245 flag_descriptions::kAutofillIOSDelayBetweenFieldsName,
246 flag_descriptions::kAutofillIOSDelayBetweenFieldsDescription,
247 flags_ui::kOsIos, MULTI_VALUE_TYPE(kAutofillIOSDelayBetweenFieldsChoices)},
Justin Cohen2d81c582018-01-22 14:46:44248 {"ui-refresh-phase-1", flag_descriptions::kUIRefreshPhase1Name,
249 flag_descriptions::kUIRefreshPhase1Description, flags_ui::kOsIos,
250 FEATURE_VALUE_TYPE(kUIRefreshPhase1)},
sczs44d54dc2018-03-12 15:56:02251 {"collections-ui-reboot", flag_descriptions::kCollectionsUIRebootName,
252 flag_descriptions::kCollectionsUIRebootDescription, flags_ui::kOsIos,
253 FEATURE_VALUE_TYPE(kCollectionsUIReboot)},
Peter K. Lee1e176752018-05-04 20:48:09254 {"infobars-ui-reboot", flag_descriptions::kInfobarsUIRebootName,
255 flag_descriptions::kInfobarsUIRebootDescription, flags_ui::kOsIos,
256 FEATURE_VALUE_TYPE(kInfobarsUIReboot)},
Mike Dougherty5f188d92018-02-02 07:10:35257 {"context-menu-element-post-message",
258 flag_descriptions::kContextMenuElementPostMessageName,
259 flag_descriptions::kContextMenuElementPostMessageDescription,
260 flags_ui::kOsIos,
261 FEATURE_VALUE_TYPE(web::features::kContextMenuElementPostMessage)},
Daniel Blakemore72387d32018-02-13 23:45:55262 {"mailto-handling-google-ui",
263 flag_descriptions::kMailtoHandlingWithGoogleUIName,
264 flag_descriptions::kMailtoHandlingWithGoogleUIDescription,
265 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kMailtoHandledWithGoogleUI)},
Peter K. Lee88137d52018-02-20 19:59:39266 {"feedback-kit-v2", flag_descriptions::kFeedbackKitV2Name,
267 flag_descriptions::kFeedbackKitV2Description, flags_ui::kOsIos,
268 FEATURE_VALUE_TYPE(kFeedbackKitV2)},
Peter K. Lee302c8b82018-03-29 23:54:51269 {"feedback-kit-v2-sso-service",
270 flag_descriptions::kFeedbackKitV2WithSSOServiceName,
271 flag_descriptions::kFeedbackKitV2WithSSOServiceDescription,
272 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kFeedbackKitV2WithSSOService)},
Sylvain Defresneae6987e2018-03-01 13:21:40273 {"new-clear-browsing-data-ui",
274 flag_descriptions::kNewClearBrowsingDataUIName,
275 flag_descriptions::kNewClearBrowsingDataUIDescription, flags_ui::kOsIos,
276 FEATURE_VALUE_TYPE(kNewClearBrowsingDataUI)},
mrefaat390f99c0d2018-05-10 19:44:24277 {"itunes-urls-store-kit-handling",
278 flag_descriptions::kITunesUrlsStoreKitHandlingName,
279 flag_descriptions::kITunesUrlsStoreKitHandlingDescription,
280 flags_ui::kOsIos, FEATURE_VALUE_TYPE(kITunesUrlsStoreKitHandling)},
Jérôme Lebelfa6c5ae2018-03-29 13:46:57281 {"unified-consent", flag_descriptions::kUnifiedConsentName,
282 flag_descriptions::kUnifiedConsentDescription, flags_ui::kOsIos,
283 FEATURE_VALUE_TYPE(signin::kUnifiedConsent)},
sebsg93dc01c2018-04-05 16:42:48284 {"autofill-dynamic-forms", flag_descriptions::kAutofillDynamicFormsName,
285 flag_descriptions::kAutofillDynamicFormsDescription, flags_ui::kOsIos,
286 FEATURE_VALUE_TYPE(autofill::features::kAutofillDynamicForms)},
Moe Ahmadid3ddfcb2018-04-20 19:51:08287 {"autofill-restrict-formless-form-extraction",
288 flag_descriptions::kAutofillRestrictUnownedFieldsToFormlessCheckoutName,
289 flag_descriptions::
290 kAutofillRestrictUnownedFieldsToFormlessCheckoutDescription,
291 flags_ui::kOsIos,
292 FEATURE_VALUE_TYPE(
293 autofill::features::kAutofillRestrictUnownedFieldsToFormlessCheckout)},
[email protected]dbcd4d52018-04-10 09:17:58294 {"ui-refresh-location-bar", flag_descriptions::kUIRefreshLocationBarName,
295 flag_descriptions::kUIRefreshLocationBarDescription, flags_ui::kOsIos,
296 FEATURE_VALUE_TYPE(kUIRefreshLocationBar)},
Kurt Horimotodc33af32018-05-01 01:39:14297 {"fullscreen-viewport-adjustment-experiment",
298 flag_descriptions::kFullscreenViewportAdjustmentExperimentName,
299 flag_descriptions::kFullscreenViewportAdjustmentExperimentDescription,
300 flags_ui::kOsIos,
301 MULTI_VALUE_TYPE(
302 fullscreen::features::kViewportAdjustmentExperimentChoices)},
Roger McFarlane1a37d7b2018-04-20 22:45:19303 {"autofill-enforce-min-required-fields-for-heuristics",
304 flag_descriptions::kAutofillEnforceMinRequiredFieldsForHeuristicsName,
305 flag_descriptions::
306 kAutofillEnforceMinRequiredFieldsForHeuristicsDescription,
307 flags_ui::kOsIos,
308 FEATURE_VALUE_TYPE(
309 autofill::features::kAutofillEnforceMinRequiredFieldsForHeuristics)},
310 {"autofill-enforce-min-required-fields-for-query",
311 flag_descriptions::kAutofillEnforceMinRequiredFieldsForQueryName,
312 flag_descriptions::kAutofillEnforceMinRequiredFieldsForQueryDescription,
313 flags_ui::kOsIos,
314 FEATURE_VALUE_TYPE(
315 autofill::features::kAutofillEnforceMinRequiredFieldsForQuery)},
316 {"autofill-enforce-min-required-fields-for-upload",
317 flag_descriptions::kAutofillEnforceMinRequiredFieldsForUploadName,
318 flag_descriptions::kAutofillEnforceMinRequiredFieldsForUploadDescription,
319 flags_ui::kOsIos,
320 FEATURE_VALUE_TYPE(
321 autofill::features::kAutofillEnforceMinRequiredFieldsForUpload)},
Gauthier Ambard4417f852018-04-26 14:24:32322 {"browser-container-fullscreen",
323 flag_descriptions::kBrowserContainerFullscreenName,
324 flag_descriptions::kBrowserContainerFullscreenDescription,
Gauthier Ambard5d7627282018-05-18 08:20:07325 flags_ui::kOsIos,
326 FEATURE_VALUE_TYPE(web::features::kBrowserContainerFullscreen)},
Roger McFarlane2eceba982018-05-18 01:37:11327 {"autofill-cache-query-responses",
328 flag_descriptions::kAutofillCacheQueryResponsesName,
329 flag_descriptions::kAutofillCacheQueryResponsesDescription,
330 flags_ui::kOsIos,
331 FEATURE_VALUE_TYPE(autofill::features::kAutofillCacheQueryResponses)},
Gauthier Ambardcfd85182018-01-05 10:37:46332};
sdefresne14900ee2015-11-27 14:43:21333
334// Add all switches from experimental flags to |command_line|.
335void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) {
336 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
337
sdefresne14900ee2015-11-27 14:43:21338 // Set the UA flag if UseMobileSafariUA is enabled.
339 if ([defaults boolForKey:@"UseMobileSafariUA"]) {
340 // Safari uses "Vesion/", followed by the OS version excluding bugfix, where
341 // Chrome puts its product token.
avi571943672015-12-22 02:12:49342 int32_t major = 0;
343 int32_t minor = 0;
344 int32_t bugfix = 0;
sdefresne14900ee2015-11-27 14:43:21345 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);
346 std::string product = base::StringPrintf("Version/%d.%d", major, minor);
347
348 command_line->AppendSwitchASCII(switches::kUserAgent,
349 web::BuildUserAgentFromProduct(product));
350 }
351
352 // Freeform commandline flags. These are added last, so that any flags added
353 // earlier in this function take precedence.
354 if ([defaults boolForKey:@"EnableFreeformCommandLineFlags"]) {
355 base::CommandLine::StringVector flags;
356 // Append an empty "program" argument.
357 flags.push_back("");
358
359 // The number of flags corresponds to the number of text fields in
360 // Experimental.plist.
361 const int kNumFreeformFlags = 5;
362 for (int i = 1; i <= kNumFreeformFlags; ++i) {
363 NSString* key =
364 [NSString stringWithFormat:@"FreeformCommandLineFlag%d", i];
365 NSString* flag = [defaults stringForKey:key];
366 if ([flag length]) {
367 flags.push_back(base::SysNSStringToUTF8(flag));
368 }
369 }
370
371 base::CommandLine temp_command_line(flags);
372 command_line->AppendArguments(temp_command_line, false);
373 }
msardafc76f662017-02-24 12:46:28374
justincohendacc85d2017-06-28 23:34:10375 // Populate command line flag for 3rd party keyboard omnibox workaround.
376 NSString* enableThirdPartyKeyboardWorkaround =
377 [defaults stringForKey:@"EnableThirdPartyKeyboardWorkaround"];
378 if ([enableThirdPartyKeyboardWorkaround isEqualToString:@"Enabled"]) {
379 command_line->AppendSwitch(switches::kEnableThirdPartyKeyboardWorkaround);
380 } else if ([enableThirdPartyKeyboardWorkaround isEqualToString:@"Disabled"]) {
381 command_line->AppendSwitch(switches::kDisableThirdPartyKeyboardWorkaround);
382 }
383
msardafc76f662017-02-24 12:46:28384 ios::GetChromeBrowserProvider()->AppendSwitchesFromExperimentalSettings(
385 defaults, command_line);
sdefresne14900ee2015-11-27 14:43:21386}
387
388bool SkipConditionalFeatureEntry(const flags_ui::FeatureEntry& entry) {
389 return false;
390}
391
392class FlagsStateSingleton {
393 public:
394 FlagsStateSingleton()
395 : flags_state_(kFeatureEntries, arraysize(kFeatureEntries)) {}
396 ~FlagsStateSingleton() {}
397
398 static FlagsStateSingleton* GetInstance() {
399 return base::Singleton<FlagsStateSingleton>::get();
400 }
401
402 static flags_ui::FlagsState* GetFlagsState() {
403 return &GetInstance()->flags_state_;
404 }
405
406 private:
407 flags_ui::FlagsState flags_state_;
408
409 DISALLOW_COPY_AND_ASSIGN(FlagsStateSingleton);
410};
411} // namespace
412
413void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
414 base::CommandLine* command_line) {
Gregory Chatzinoff31305112017-12-20 21:56:02415 AppendSwitchesFromExperimentalSettings(command_line);
sdefresne14900ee2015-11-27 14:43:21416 FlagsStateSingleton::GetFlagsState()->ConvertFlagsToSwitches(
sdefresnec9763902015-12-02 10:30:11417 flags_storage, command_line, flags_ui::kAddSentinels,
Gregory Chatzinofff6523722017-11-21 01:33:53418 switches::kEnableFeatures, switches::kDisableFeatures);
sdefresne14900ee2015-11-27 14:43:21419}
420
jkrcalbf073372016-07-29 07:21:31421std::vector<std::string> RegisterAllFeatureVariationParameters(
422 flags_ui::FlagsStorage* flags_storage,
423 base::FeatureList* feature_list) {
424 return FlagsStateSingleton::GetFlagsState()
425 ->RegisterAllFeatureVariationParameters(flags_storage, feature_list);
426}
427
sdefresne14900ee2015-11-27 14:43:21428void GetFlagFeatureEntries(flags_ui::FlagsStorage* flags_storage,
429 flags_ui::FlagAccess access,
430 base::ListValue* supported_entries,
431 base::ListValue* unsupported_entries) {
432 FlagsStateSingleton::GetFlagsState()->GetFlagFeatureEntries(
433 flags_storage, access, supported_entries, unsupported_entries,
434 base::Bind(&SkipConditionalFeatureEntry));
435}
436
437void SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage,
438 const std::string& internal_name,
439 bool enable) {
440 FlagsStateSingleton::GetFlagsState()->SetFeatureEntryEnabled(
441 flags_storage, internal_name, enable);
442}
443
444void ResetAllFlags(flags_ui::FlagsStorage* flags_storage) {
445 FlagsStateSingleton::GetFlagsState()->ResetAllFlags(flags_storage);
446}
447
448namespace testing {
449
450const flags_ui::FeatureEntry* GetFeatureEntries(size_t* count) {
451 *count = arraysize(kFeatureEntries);
452 return kFeatureEntries;
453}
454
455} // namespace testing