1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/search/ntp_features.h"
7 #include "base/feature_list.h"
8 #include "base/metrics/field_trial_params.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h"
11 #include "base/time/time.h"
12 #include "build/build_config.h"
14 namespace ntp_features {
16 // If enabled, shows a confirm dialog before removing search suggestions from
17 // the New Tab page real search box ("realbox").
18 BASE_FEATURE(kConfirmSuggestionRemovals,
19 "ConfirmNtpSuggestionRemovals",
20 base::FEATURE_DISABLED_BY_DEFAULT);
22 // If enabled, the OneGooleBar cached response is sent back to NTP.
23 BASE_FEATURE(kCacheOneGoogleBar,
25 base::FEATURE_DISABLED_BY_DEFAULT);
27 // If enabled, Customize Chrome will be an option in the Unified Side Panel
28 // when on the New Tab Page.
29 BASE_FEATURE(kCustomizeChromeSidePanel,
30 "CustomizeChromeSidePanel",
31 base::FEATURE_DISABLED_BY_DEFAULT);
33 // Enables the removal of the NTP background scrim and forced dark foreground
34 // colors for a specific subset of Chrome Web Store themes (see
35 // crbug.com/1329552). This is enabled by default to allow finch to disable this
36 // NTP treatment in the case of unexpected regressions.
37 BASE_FEATURE(kCwsScrimRemoval,
39 base::FEATURE_ENABLED_BY_DEFAULT);
41 // If enabled, "middle slot" promos on the bottom of the NTP will show a dismiss
42 // UI that allows users to close them and not see them again.
43 BASE_FEATURE(kDismissPromos,
45 base::FEATURE_DISABLED_BY_DEFAULT);
47 // If enabled, the NTP "realbox" will be themed like the omnibox
48 // (same background/text/selected/hover colors).
49 BASE_FEATURE(kRealboxMatchOmniboxTheme,
50 "NtpRealboxMatchOmniboxTheme",
51 base::FEATURE_DISABLED_BY_DEFAULT);
53 // If enabled, the NTP "realbox" will have same border/drop shadow in hover
54 // state as searchbox.
55 BASE_FEATURE(kRealboxMatchSearchboxTheme,
56 "NtpRealboxMatchSearchboxTheme",
57 base::FEATURE_DISABLED_BY_DEFAULT);
59 // If enabled, the NTP "realbox" will have the same rounded corners as
61 BASE_FEATURE(kRealboxRoundedCorners,
62 "NtpRealboxRoundedCorners",
63 base::FEATURE_DISABLED_BY_DEFAULT);
65 // If enabled, the real search box ("realbox") on the New Tab page will show a
66 // Google (g) icon instead of the typical magnifying glass (aka loupe).
67 BASE_FEATURE(kRealboxUseGoogleGIcon,
68 "NtpRealboxUseGoogleGIcon",
69 base::FEATURE_DISABLED_BY_DEFAULT);
71 // If enabled, chrome cart module will be shown.
72 BASE_FEATURE(kNtpChromeCartModule,
73 "NtpChromeCartModule",
74 base::FEATURE_ENABLED_BY_DEFAULT);
76 // If enabled, Comprehensive Theming color changes will be applied to elements
77 // on the New Tab Page.
78 BASE_FEATURE(kNtpComprehensiveTheming,
79 "NtpComprehensiveTheming",
80 base::FEATURE_DISABLED_BY_DEFAULT);
82 #if !defined(OFFICIAL_BUILD)
83 // If enabled, dummy modules will be shown.
84 BASE_FEATURE(kNtpDummyModules,
86 base::FEATURE_DISABLED_BY_DEFAULT);
89 // If enabled, Google Drive module will be shown.
90 BASE_FEATURE(kNtpDriveModule,
92 base::FEATURE_ENABLED_BY_DEFAULT);
94 // If enabled, handles navigations from the Most Visited tiles explicitly and
95 // overrides the navigation's transition type to bookmark navigation before the
96 // navigation is issued.
97 // TODO(crbug.com/1147589): When removing this flag, also remove the workaround
98 // in ChromeContentBrowserClient::OverrideNavigationParams.
99 BASE_FEATURE(kNtpHandleMostVisitedNavigationExplicitly,
100 "HandleMostVisitedNavigationExplicitly",
101 base::FEATURE_ENABLED_BY_DEFAULT);
103 // If enabled, logo will be shown.
104 BASE_FEATURE(kNtpLogo, "NtpLogo", base::FEATURE_ENABLED_BY_DEFAULT);
106 // If enabled, middle slot promo will be shown.
107 BASE_FEATURE(kNtpMiddleSlotPromo,
108 "NtpMiddleSlotPromo",
109 base::FEATURE_ENABLED_BY_DEFAULT);
111 // If enabled, middle slot promo will be dismissed from New Tab Page until new
112 // promo message is populated
113 BASE_FEATURE(kNtpMiddleSlotPromoDismissal,
114 "NtpMiddleSlotPromoDismissal",
115 base::FEATURE_ENABLED_BY_DEFAULT);
117 // Dummy feature to set param "NtpModulesLoadTimeoutMillisecondsParam".
118 BASE_FEATURE(kNtpModulesLoadTimeoutMilliseconds,
119 "NtpModulesLoadTimeoutMilliseconds",
120 base::FEATURE_DISABLED_BY_DEFAULT);
122 // Dummy feature to set param "NtpModulesOrderParam".
123 BASE_FEATURE(kNtpModulesOrder,
125 base::FEATURE_DISABLED_BY_DEFAULT);
127 // If enabled, modules will be able to be reordered via dragging and dropping
128 BASE_FEATURE(kNtpModulesDragAndDrop,
129 "NtpModulesDragAndDrop",
130 base::FEATURE_DISABLED_BY_DEFAULT);
132 // If enabled, the first run experience for Modular NTP Desktop v1 will show.
133 BASE_FEATURE(kNtpModulesFirstRunExperience,
134 "NtpModulesFirstRunExperience",
135 base::FEATURE_ENABLED_BY_DEFAULT);
137 // If enabled, modules will be loaded but not shown. This is useful to determine
138 // if a user would have seen modules in order to counterfactually log or
140 BASE_FEATURE(kNtpModulesLoad,
142 base::FEATURE_DISABLED_BY_DEFAULT);
144 // If enabled, redesigned modules will be shown.
145 BASE_FEATURE(kNtpModulesRedesigned,
146 "NtpModulesRedesigned",
147 base::FEATURE_DISABLED_BY_DEFAULT);
149 // If enabled, a different module layout where modules are organized in rows and
150 // columns will be shown.
151 BASE_FEATURE(kNtpModulesRedesignedLayout,
152 "NtpModulesRedesignedLayout",
153 base::FEATURE_DISABLED_BY_DEFAULT);
155 // If enabled, OneGoogleBar will be shown.
156 BASE_FEATURE(kNtpOneGoogleBar,
158 base::FEATURE_ENABLED_BY_DEFAULT);
160 // If enabled, Google Photos module will be shown.
161 BASE_FEATURE(kNtpPhotosModule,
163 base::FEATURE_DISABLED_BY_DEFAULT);
165 // If enabled, a customized title will be shown on the opt-in card.
166 BASE_FEATURE(kNtpPhotosModuleCustomizedOptInTitle,
167 "NtpPhotosModuleCustomizedOptInTitle",
168 base::FEATURE_DISABLED_BY_DEFAULT);
170 // If enabled, a customized art work will be shown on the opt-in card.
171 BASE_FEATURE(kNtpPhotosModuleCustomizedOptInArtWork,
172 "NtpPhotosModuleCustomizedOptInArtWork",
173 base::FEATURE_DISABLED_BY_DEFAULT);
175 // If enabled, Google Photos opt-in card will show a button to soft opt-out.
176 BASE_FEATURE(kNtpPhotosModuleSoftOptOut,
177 "NtpPhotosModuleSoftOptOut",
178 base::FEATURE_DISABLED_BY_DEFAULT);
180 // If enabled, the single svg image show in Photos opt-in screen will be
181 // replaced by constituent images to support i18n.
182 BASE_FEATURE(kNtpPhotosModuleSplitSvgOptInArtWork,
183 "NtpPhotosModuleSplitSvgOptInArtWork",
184 base::FEATURE_DISABLED_BY_DEFAULT);
186 // If enabled, Following Feed module will be shown.
187 BASE_FEATURE(kNtpFeedModule,
189 base::FEATURE_DISABLED_BY_DEFAULT);
191 // If enabled, Google Lens image search will be shown in the NTP Realbox.
192 BASE_FEATURE(kNtpRealboxLensSearch,
193 "NtpRealboxLensSearch",
194 base::FEATURE_DISABLED_BY_DEFAULT);
196 // If enabled, recipe tasks module will be shown.
197 BASE_FEATURE(kNtpRecipeTasksModule,
198 "NtpRecipeTasksModule",
199 base::FEATURE_ENABLED_BY_DEFAULT);
201 // Controls whether the scrim is removed.
202 BASE_FEATURE(kNtpRemoveScrim,
204 base::FEATURE_DISABLED_BY_DEFAULT);
206 // If enabled, SafeBrowsing module will be shown to a target user.
207 BASE_FEATURE(kNtpSafeBrowsingModule,
208 "NtpSafeBrowsingModule",
209 base::FEATURE_DISABLED_BY_DEFAULT);
211 // If enabled, shortcuts will be shown.
212 BASE_FEATURE(kNtpShortcuts, "NtpShortcuts", base::FEATURE_ENABLED_BY_DEFAULT);
214 const base::FeatureParam<std::string> kNtpOgbButtonSelectorParam{
215 &kNtpRemoveScrim, "NtpOgbButtonSelectorParam", ".gb_A"};
217 const base::FeatureParam<std::string> kNtpOgbUnprotectedTextSelectorParam{
218 &kNtpRemoveScrim, "NtpOgbUnprotectedTextSelectorParam", ".gb_d"};
220 const char kNtpModulesEligibleForHappinessTrackingSurveyParam[] =
221 "NtpModulesEligibleForHappinessTrackingSurveyParam";
222 const char kNtpModulesLoadTimeoutMillisecondsParam[] =
223 "NtpModulesLoadTimeoutMillisecondsParam";
224 const char kNtpModulesOrderParam[] = "NtpModulesOrderParam";
225 const char kNtpChromeCartModuleDataParam[] = "NtpChromeCartModuleDataParam";
226 const char kNtpChromeCartModuleAbandonedCartDiscountParam[] =
227 "NtpChromeCartModuleAbandonedCartDiscountParam";
228 const char kNtpChromeCartModuleAbandonedCartDiscountUseUtmParam[] =
229 "NtpChromeCartModuleAbandonedCartDiscountUseUtmParam";
230 const char kNtpChromeCartModuleHeuristicsImprovementParam[] =
231 "NtpChromeCartModuleHeuristicsImprovementParam";
232 const char kNtpChromeCartModuleCouponParam[] = "NtpChromeCartModuleCouponParam";
233 const char kNtpDriveModuleDataParam[] = "NtpDriveModuleDataParam";
234 const char kNtpDriveModuleManagedUsersOnlyParam[] =
235 "NtpDriveModuleManagedUsersOnlyParam";
236 const char kNtpDriveModuleCacheMaxAgeSParam[] =
237 "NtpDriveModuleCacheMaxAgeSParam";
238 const char kNtpDriveModuleExperimentGroupParam[] =
239 "NtpDriveModuleExperimentGroupParam";
240 const char kNtpMiddleSlotPromoDismissalParam[] =
241 "NtpMiddleSlotPromoDismissalParam";
242 const char kNtpPhotosModuleDataParam[] = "NtpPhotosModuleDataParam";
243 const char kNtpPhotosModuleOptInTitleParam[] = "NtpPhotosModuleOptInTitleParam";
244 const char kNtpPhotosModuleOptInArtWorkParam[] =
245 "NtpPhotosModuleOptInArtWorkParam";
246 const char kNtpSafeBrowsingModuleCooldownPeriodDaysParam[] =
247 "NtpSafeBrowsingModuleCooldownPeriodDaysParam";
248 const char kNtpSafeBrowsingModuleCountMaxParam[] =
249 "NtpSafeBrowsingModuleCountMaxParam";
250 const char kRealboxMatchOmniboxThemeVariantParam[] =
251 "RealboxMatchOmniboxThemeVariantParam";
252 const char kNtpRecipeTasksModuleDataParam[] = "NtpRecipeTasksModuleDataParam";
253 const char kNtpRecipeTasksModuleCacheMaxAgeSParam[] =
254 "NtpRecipeTasksModuleCacheMaxAgeSParam";
255 const char kNtpRecipeTasksModuleExperimentGroupParam[] =
256 "NtpRecipeTasksModuleExperimentGroupParam";
258 base::TimeDelta GetModulesLoadTimeout() {
259 std::string param_value = base::GetFieldTrialParamValueByFeature(
260 kNtpModulesLoadTimeoutMilliseconds,
261 kNtpModulesLoadTimeoutMillisecondsParam);
262 // If the field trial param is not found or cannot be parsed to an unsigned
263 // integer, return the default value.
264 unsigned int param_value_as_int = 0;
265 if (!base::StringToUint(param_value, ¶m_value_as_int)) {
266 return base::Seconds(3);
268 return base::Milliseconds(param_value_as_int);
271 std::vector<std::string> GetModulesOrder() {
272 return base::SplitString(base::GetFieldTrialParamValueByFeature(
273 kNtpModulesOrder, kNtpModulesOrderParam),
274 ",:;", base::WhitespaceHandling::TRIM_WHITESPACE,
275 base::SplitResult::SPLIT_WANT_NONEMPTY);
278 } // namespace ntp_features