Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / components / search / ntp_features.cc
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.
4
5 #include "components/search/ntp_features.h"
6
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"
13
14 namespace ntp_features {
15
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);
21
22 // If enabled, the OneGooleBar cached response is sent back to NTP.
23 BASE_FEATURE(kCacheOneGoogleBar,
24              "CacheOneGoogleBar",
25              base::FEATURE_DISABLED_BY_DEFAULT);
26
27 // If enabled, Chrome theme color will be set to match the NTP background
28 // on NTP Customize Chrome background change.
29 BASE_FEATURE(kCustomizeChromeColorExtraction,
30              "CustomizeChromeColorExtraction",
31              base::FEATURE_DISABLED_BY_DEFAULT);
32
33 // If enabled, Customize Chrome will be an option in the Unified Side Panel
34 // when on the New Tab Page.
35 BASE_FEATURE(kCustomizeChromeSidePanel,
36              "CustomizeChromeSidePanel",
37              base::FEATURE_DISABLED_BY_DEFAULT);
38
39 // Enables the removal of the NTP background scrim and forced dark foreground
40 // colors for a specific subset of Chrome Web Store themes (see
41 // crbug.com/1329552). This is enabled by default to allow finch to disable this
42 // NTP treatment in the case of unexpected regressions.
43 BASE_FEATURE(kCwsScrimRemoval,
44              "CwsScrimRemoval",
45              base::FEATURE_ENABLED_BY_DEFAULT);
46
47 // If enabled, "middle slot" promos on the bottom of the NTP will show a dismiss
48 // UI that allows users to close them and not see them again.
49 BASE_FEATURE(kDismissPromos,
50              "DismissNtpPromos",
51              base::FEATURE_DISABLED_BY_DEFAULT);
52
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);
58
59 // If enabled, the NTP "realbox" will have the same rounded corners as
60 // searchbox.
61 BASE_FEATURE(kRealboxRoundedCorners,
62              "NtpRealboxRoundedCorners",
63              base::FEATURE_DISABLED_BY_DEFAULT);
64
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);
70
71 // If enabled, alpha NTP backgrounds will show in Customize Chrome.
72 BASE_FEATURE(kNtpAlphaBackgroundCollections,
73              "NtpAlphaBackgroundCollections",
74              base::FEATURE_DISABLED_BY_DEFAULT);
75
76 // If enabled, chrome cart module will be shown.
77 BASE_FEATURE(kNtpChromeCartModule,
78              "NtpChromeCartModule",
79              base::FEATURE_ENABLED_BY_DEFAULT);
80
81 // If enabled, Comprehensive Theming color changes will be applied to elements
82 // on the New Tab Page, excluding the Realbox.
83 BASE_FEATURE(kNtpComprehensiveTheming,
84              "NtpComprehensiveTheming",
85              base::FEATURE_ENABLED_BY_DEFAULT);
86
87 // If enabled, Comprehensive Theming color changes will be applied to the
88 // Realbox on the New Tab Page.
89 BASE_FEATURE(kNtpComprehensiveThemeRealbox,
90              "NtpComprehensiveThemeRealbox",
91              base::FEATURE_DISABLED_BY_DEFAULT);
92
93 #if !defined(OFFICIAL_BUILD)
94 // If enabled, dummy modules will be shown.
95 BASE_FEATURE(kNtpDummyModules,
96              "NtpDummyModules",
97              base::FEATURE_DISABLED_BY_DEFAULT);
98 #endif
99
100 // If enabled, Google Drive module will be shown.
101 BASE_FEATURE(kNtpDriveModule,
102              "NtpDriveModule",
103              base::FEATURE_ENABLED_BY_DEFAULT);
104
105 // If enabled, handles navigations from the Most Visited tiles explicitly and
106 // overrides the navigation's transition type to bookmark navigation before the
107 // navigation is issued.
108 // TODO(crbug.com/1147589): When removing this flag, also remove the workaround
109 // in ChromeContentBrowserClient::OverrideNavigationParams.
110 BASE_FEATURE(kNtpHandleMostVisitedNavigationExplicitly,
111              "HandleMostVisitedNavigationExplicitly",
112              base::FEATURE_ENABLED_BY_DEFAULT);
113
114 // If enabled, logo will be shown.
115 BASE_FEATURE(kNtpLogo, "NtpLogo", base::FEATURE_ENABLED_BY_DEFAULT);
116
117 // If enabled, logo will fill up less vertical space.
118 BASE_FEATURE(kNtpReducedLogoSpace,
119              "NtpReducedLogoSpace",
120              base::FEATURE_DISABLED_BY_DEFAULT);
121
122 // If enabled, middle slot promo will be shown.
123 BASE_FEATURE(kNtpMiddleSlotPromo,
124              "NtpMiddleSlotPromo",
125              base::FEATURE_ENABLED_BY_DEFAULT);
126
127 // If enabled, middle slot promo will be dismissed from New Tab Page until new
128 // promo message is populated
129 BASE_FEATURE(kNtpMiddleSlotPromoDismissal,
130              "NtpMiddleSlotPromoDismissal",
131              base::FEATURE_ENABLED_BY_DEFAULT);
132
133 // Dummy feature to set param "NtpModulesLoadTimeoutMillisecondsParam".
134 BASE_FEATURE(kNtpModulesLoadTimeoutMilliseconds,
135              "NtpModulesLoadTimeoutMilliseconds",
136              base::FEATURE_DISABLED_BY_DEFAULT);
137
138 // If true, extends width of modules if space allows.
139 BASE_FEATURE(kNtpWideModules,
140              "NtpWideModules",
141              base::FEATURE_DISABLED_BY_DEFAULT);
142
143 // Dummy feature to set param "NtpModulesOrderParam".
144 BASE_FEATURE(kNtpModulesOrder,
145              "NtpModulesOrder",
146              base::FEATURE_DISABLED_BY_DEFAULT);
147
148 // If enabled, modules will be able to be reordered via dragging and dropping
149 BASE_FEATURE(kNtpModulesDragAndDrop,
150              "NtpModulesDragAndDrop",
151              base::FEATURE_DISABLED_BY_DEFAULT);
152
153 // If enabled, the first run experience for Modular NTP Desktop v1 will show.
154 BASE_FEATURE(kNtpModulesFirstRunExperience,
155              "NtpModulesFirstRunExperience",
156              base::FEATURE_ENABLED_BY_DEFAULT);
157
158 // If enabled, modules will be loaded but not shown. This is useful to determine
159 // if a user would have seen modules in order to counterfactually log or
160 // trigger.
161 BASE_FEATURE(kNtpModulesLoad,
162              "NtpModulesLoad",
163              base::FEATURE_DISABLED_BY_DEFAULT);
164
165 // If enabled, redesigned modules will be shown.
166 BASE_FEATURE(kNtpModulesRedesigned,
167              "NtpModulesRedesigned",
168              base::FEATURE_DISABLED_BY_DEFAULT);
169
170 // If enabled, a different module layout where modules are organized in rows and
171 // columns will be shown.
172 BASE_FEATURE(kNtpModulesRedesignedLayout,
173              "NtpModulesRedesignedLayout",
174              base::FEATURE_DISABLED_BY_DEFAULT);
175
176 // If enabled, OneGoogleBar will be shown.
177 BASE_FEATURE(kNtpOneGoogleBar,
178              "NtpOneGoogleBar",
179              base::FEATURE_ENABLED_BY_DEFAULT);
180
181 // If enabled, Google Photos module will be shown.
182 BASE_FEATURE(kNtpPhotosModule,
183              "NtpPhotosModule",
184              base::FEATURE_DISABLED_BY_DEFAULT);
185
186 // If enabled, a customized title will be shown on the opt-in card.
187 BASE_FEATURE(kNtpPhotosModuleCustomizedOptInTitle,
188              "NtpPhotosModuleCustomizedOptInTitle",
189              base::FEATURE_DISABLED_BY_DEFAULT);
190
191 // If enabled, a customized art work will be shown on the opt-in card.
192 BASE_FEATURE(kNtpPhotosModuleCustomizedOptInArtWork,
193              "NtpPhotosModuleCustomizedOptInArtWork",
194              base::FEATURE_DISABLED_BY_DEFAULT);
195
196 // If enabled, Google Photos opt-in card will show a button to soft opt-out.
197 BASE_FEATURE(kNtpPhotosModuleSoftOptOut,
198              "NtpPhotosModuleSoftOptOut",
199              base::FEATURE_DISABLED_BY_DEFAULT);
200
201 // If enabled, the single svg image show in Photos opt-in screen will be
202 // replaced by constituent images to support i18n.
203 BASE_FEATURE(kNtpPhotosModuleSplitSvgOptInArtWork,
204              "NtpPhotosModuleSplitSvgOptInArtWork",
205              base::FEATURE_DISABLED_BY_DEFAULT);
206
207 // If enabled, Following Feed module will be shown.
208 BASE_FEATURE(kNtpFeedModule,
209              "NtpFeedModule",
210              base::FEATURE_DISABLED_BY_DEFAULT);
211
212 // If enabled, Google Lens image search will be shown in the NTP Realbox.
213 BASE_FEATURE(kNtpRealboxLensSearch,
214              "NtpRealboxLensSearch",
215              base::FEATURE_DISABLED_BY_DEFAULT);
216
217 // If enabled, recipe tasks module will be shown.
218 BASE_FEATURE(kNtpRecipeTasksModule,
219              "NtpRecipeTasksModule",
220              base::FEATURE_ENABLED_BY_DEFAULT);
221
222 // Controls whether the scrim is removed.
223 BASE_FEATURE(kNtpRemoveScrim,
224              "NtpRemoveScrim",
225              base::FEATURE_DISABLED_BY_DEFAULT);
226
227 // If enabled, SafeBrowsing module will be shown to a target user.
228 BASE_FEATURE(kNtpSafeBrowsingModule,
229              "NtpSafeBrowsingModule",
230              base::FEATURE_DISABLED_BY_DEFAULT);
231
232 // If enabled, shortcuts will be shown.
233 BASE_FEATURE(kNtpShortcuts, "NtpShortcuts", base::FEATURE_ENABLED_BY_DEFAULT);
234
235 // If enabled, shortcuts will be shown in a wide single row.
236 BASE_FEATURE(kNtpSingleRowShortcuts,
237              "NtpSingleRowShortcuts",
238              base::FEATURE_DISABLED_BY_DEFAULT);
239
240 // If enabled, the History clusters module will be shown.
241 BASE_FEATURE(kNtpHistoryClustersModule,
242              "NtpHistoryClustersModule",
243              base::FEATURE_DISABLED_BY_DEFAULT);
244
245 // Dummy feature to set kNtpHistoryClustersModuleBeginTimeDurationHoursParam.
246 BASE_FEATURE(kNtpHistoryClustersModuleBeginTimeDuration,
247              "NtpHistoryClustersModuleBeginTimeDuration",
248              base::FEATURE_DISABLED_BY_DEFAULT);
249
250 // Dummy feature to set kNtpHistoryClustersModuleMinimumVisitsRequiredParam.
251 BASE_FEATURE(kNtpHistoryClustersModuleMinimumVisitsRequired,
252              "NtpHistoryClustersModuleMinimumVisitsRequired",
253              base::FEATURE_DISABLED_BY_DEFAULT);
254
255 // Dummy feature to set kNtpHistoryClustersModuleMinimumImagesRequiredParam.
256 BASE_FEATURE(kNtpHistoryClustersModuleMinimumImagesRequired,
257              "NtpHistoryClustersModuleMinimumImagesRequired",
258              base::FEATURE_DISABLED_BY_DEFAULT);
259
260 // Dummy feature to set kNtpHistoryClustersModuleCategoriesParam.
261 BASE_FEATURE(kNtpHistoryClustersModuleCategories,
262              "NtpHistoryClustersModuleCategories",
263              base::FEATURE_DISABLED_BY_DEFAULT);
264
265 // If enabled, the history clusters module will be loaded but not shown. This is
266 // useful to determine if a user would have seen modules in order to
267 // counterfactually log or trigger.
268 BASE_FEATURE(kNtpHistoryClustersModuleLoad,
269              "NtpHistoryClustersModuleLoad",
270              base::FEATURE_DISABLED_BY_DEFAULT);
271
272 // Dummy feature to set kNtpHistoryClustersModuleMaxClustersParam.
273 BASE_FEATURE(kNtpHistoryClustersModuleMaxClusters,
274              "NtpHistoryClustersMaxClusters",
275              base::FEATURE_DISABLED_BY_DEFAULT);
276
277 // If enabled, module headers will display an associated icon.
278 BASE_FEATURE(kNtpModulesHeaderIcon,
279              "NtpModulesHeaderIcon",
280              base::FEATURE_DISABLED_BY_DEFAULT);
281
282 // If enabled, ChromeCart tile will show in the History clusters module when
283 // available.
284 BASE_FEATURE(kNtpChromeCartInHistoryClusterModule,
285              "NtpChromeCartInHistoryClusterModule",
286              base::FEATURE_DISABLED_BY_DEFAULT);
287
288 BASE_FEATURE(kNtpHistoryClustersModuleUseModelRanking,
289              "NtpHistoryClustersModuleUseModelRanking",
290              base::FEATURE_DISABLED_BY_DEFAULT);
291
292 // If enabled, ChromeCart module will show together with ChromeCart+History
293 // cluster module when available.
294 BASE_FEATURE(kNtpChromeCartHistoryClusterCoexist,
295              "NtpChromeCartHistoryClusterCoexist",
296              base::FEATURE_DISABLED_BY_DEFAULT);
297
298 const base::FeatureParam<double>
299     kNtpElementLuminosityChangeForLightBackgroundParam{
300         &kNtpComprehensiveTheming,
301         "NtpElementLuminosityChangeForLightBackgroundParam", 0.1};
302
303 const base::FeatureParam<double>
304     kNtpElementLuminosityChangeForDarkBackgroundParam{
305         &kNtpComprehensiveTheming,
306         "NtpElementLuminosityChangeForDarkBackgroundParam", 0.2};
307
308 const base::FeatureParam<std::string> kNtpOgbButtonSelectorParam{
309     &kNtpRemoveScrim, "NtpOgbButtonSelectorParam", ".gb_A"};
310
311 const base::FeatureParam<std::string> kNtpOgbUnprotectedTextSelectorParam{
312     &kNtpRemoveScrim, "NtpOgbUnprotectedTextSelectorParam", ".gb_d"};
313
314 const char kNtpModulesEligibleForHappinessTrackingSurveyParam[] =
315     "NtpModulesEligibleForHappinessTrackingSurveyParam";
316 const char kNtpModulesLoadTimeoutMillisecondsParam[] =
317     "NtpModulesLoadTimeoutMillisecondsParam";
318 const char kNtpModulesOrderParam[] = "NtpModulesOrderParam";
319 const char kNtpChromeCartModuleDataParam[] = "NtpChromeCartModuleDataParam";
320 const char kNtpChromeCartModuleAbandonedCartDiscountParam[] =
321     "NtpChromeCartModuleAbandonedCartDiscountParam";
322 const char kNtpChromeCartModuleAbandonedCartDiscountUseUtmParam[] =
323     "NtpChromeCartModuleAbandonedCartDiscountUseUtmParam";
324 const char kNtpChromeCartModuleHeuristicsImprovementParam[] =
325     "NtpChromeCartModuleHeuristicsImprovementParam";
326 const char kNtpChromeCartModuleCouponParam[] = "NtpChromeCartModuleCouponParam";
327 const char kNtpDriveModuleDataParam[] = "NtpDriveModuleDataParam";
328 const char kNtpDriveModuleManagedUsersOnlyParam[] =
329     "NtpDriveModuleManagedUsersOnlyParam";
330 const char kNtpDriveModuleCacheMaxAgeSParam[] =
331     "NtpDriveModuleCacheMaxAgeSParam";
332 const char kNtpDriveModuleExperimentGroupParam[] =
333     "NtpDriveModuleExperimentGroupParam";
334 const char kNtpHistoryClustersModuleDataParam[] =
335     "NtpHistoryClustersModuleDataParam";
336 const char kNtpChromeCartInHistoryClustersModuleDataParam[] =
337     "NtpChromeCartInHistoryClustersModuleDataParam";
338 const char kNtpMiddleSlotPromoDismissalParam[] =
339     "NtpMiddleSlotPromoDismissalParam";
340 const char kNtpPhotosModuleDataParam[] = "NtpPhotosModuleDataParam";
341 const char kNtpPhotosModuleOptInTitleParam[] = "NtpPhotosModuleOptInTitleParam";
342 const char kNtpPhotosModuleOptInArtWorkParam[] =
343     "NtpPhotosModuleOptInArtWorkParam";
344 const char kNtpSafeBrowsingModuleCooldownPeriodDaysParam[] =
345     "NtpSafeBrowsingModuleCooldownPeriodDaysParam";
346 const char kNtpSafeBrowsingModuleCountMaxParam[] =
347     "NtpSafeBrowsingModuleCountMaxParam";
348 const char kNtpRecipeTasksModuleDataParam[] = "NtpRecipeTasksModuleDataParam";
349 const char kNtpRecipeTasksModuleCacheMaxAgeSParam[] =
350     "NtpRecipeTasksModuleCacheMaxAgeSParam";
351 const char kNtpRecipeTasksModuleExperimentGroupParam[] =
352     "NtpRecipeTasksModuleExperimentGroupParam";
353 const char kNtpHistoryClustersModuleBeginTimeDurationHoursParam[] =
354     "NtpHistoryClustersModuleBeginTimeDurationHoursParam";
355 const char kNtpHistoryClustersModuleMinimumVisitsRequiredParam[] =
356     "NtpHistoryClustersModuleMinimumVisitsRequiredParam";
357 const char kNtpHistoryClustersModuleMinimumImagesRequiredParam[] =
358     "NtpHistoryClustersModuleMinimumImagesRequiredParam";
359 const char kNtpHistoryClustersModuleCategoriesAllowlistParam[] =
360     "NtpHistoryClustersModuleCategoriesParam";
361 const char kNtpHistoryClustersModuleCategoriesBlocklistParam[] =
362     "NtpHistoryClustersModuleCategoriesBlocklistParam";
363 const char kNtpHistoryClustersModuleCategoriesBoostlistParam[] =
364     "NtpHistoryClustersModuleCategoriesBoostlistParam";
365 const char kNtpHistoryClustersModuleMaxClustersParam[] =
366     "NtpHistoryClustersModuleMaxClustersParam";
367
368 base::TimeDelta GetModulesLoadTimeout() {
369   std::string param_value = base::GetFieldTrialParamValueByFeature(
370       kNtpModulesLoadTimeoutMilliseconds,
371       kNtpModulesLoadTimeoutMillisecondsParam);
372   // If the field trial param is not found or cannot be parsed to an unsigned
373   // integer, return the default value.
374   unsigned int param_value_as_int = 0;
375   if (!base::StringToUint(param_value, &param_value_as_int)) {
376     return base::Seconds(3);
377   }
378   return base::Milliseconds(param_value_as_int);
379 }
380
381 std::vector<std::string> GetModulesOrder() {
382   return base::SplitString(base::GetFieldTrialParamValueByFeature(
383                                kNtpModulesOrder, kNtpModulesOrderParam),
384                            ",:;", base::WhitespaceHandling::TRIM_WHITESPACE,
385                            base::SplitResult::SPLIT_WANT_NONEMPTY);
386 }
387
388 }  // namespace ntp_features