Upload upstream chromium 108.0.5359.1
[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, 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);
32
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,
38              "CwsScrimRemoval",
39              base::FEATURE_ENABLED_BY_DEFAULT);
40
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,
44              "DismissNtpPromos",
45              base::FEATURE_DISABLED_BY_DEFAULT);
46
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);
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, chrome cart module will be shown.
72 BASE_FEATURE(kNtpChromeCartModule,
73              "NtpChromeCartModule",
74              base::FEATURE_ENABLED_BY_DEFAULT);
75
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);
81
82 #if !defined(OFFICIAL_BUILD)
83 // If enabled, dummy modules will be shown.
84 BASE_FEATURE(kNtpDummyModules,
85              "NtpDummyModules",
86              base::FEATURE_DISABLED_BY_DEFAULT);
87 #endif
88
89 // If enabled, Google Drive module will be shown.
90 BASE_FEATURE(kNtpDriveModule,
91              "NtpDriveModule",
92              base::FEATURE_ENABLED_BY_DEFAULT);
93
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);
102
103 // If enabled, logo will be shown.
104 BASE_FEATURE(kNtpLogo, "NtpLogo", base::FEATURE_ENABLED_BY_DEFAULT);
105
106 // If enabled, middle slot promo will be shown.
107 BASE_FEATURE(kNtpMiddleSlotPromo,
108              "NtpMiddleSlotPromo",
109              base::FEATURE_ENABLED_BY_DEFAULT);
110
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);
116
117 // Dummy feature to set param "NtpModulesLoadTimeoutMillisecondsParam".
118 BASE_FEATURE(kNtpModulesLoadTimeoutMilliseconds,
119              "NtpModulesLoadTimeoutMilliseconds",
120              base::FEATURE_DISABLED_BY_DEFAULT);
121
122 // Dummy feature to set param "NtpModulesOrderParam".
123 BASE_FEATURE(kNtpModulesOrder,
124              "NtpModulesOrder",
125              base::FEATURE_DISABLED_BY_DEFAULT);
126
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);
131
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);
136
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
139 // trigger.
140 BASE_FEATURE(kNtpModulesLoad,
141              "NtpModulesLoad",
142              base::FEATURE_DISABLED_BY_DEFAULT);
143
144 // If enabled, redesigned modules will be shown.
145 BASE_FEATURE(kNtpModulesRedesigned,
146              "NtpModulesRedesigned",
147              base::FEATURE_DISABLED_BY_DEFAULT);
148
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);
154
155 // If enabled, OneGoogleBar will be shown.
156 BASE_FEATURE(kNtpOneGoogleBar,
157              "NtpOneGoogleBar",
158              base::FEATURE_ENABLED_BY_DEFAULT);
159
160 // If enabled, Google Photos module will be shown.
161 BASE_FEATURE(kNtpPhotosModule,
162              "NtpPhotosModule",
163              base::FEATURE_DISABLED_BY_DEFAULT);
164
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);
169
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);
174
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);
179
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);
185
186 // If enabled, Following Feed module will be shown.
187 BASE_FEATURE(kNtpFeedModule,
188              "NtpFeedModule",
189              base::FEATURE_DISABLED_BY_DEFAULT);
190
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);
195
196 // If enabled, recipe tasks module will be shown.
197 BASE_FEATURE(kNtpRecipeTasksModule,
198              "NtpRecipeTasksModule",
199              base::FEATURE_ENABLED_BY_DEFAULT);
200
201 // Controls whether the scrim is removed.
202 BASE_FEATURE(kNtpRemoveScrim,
203              "NtpRemoveScrim",
204              base::FEATURE_DISABLED_BY_DEFAULT);
205
206 // If enabled, SafeBrowsing module will be shown to a target user.
207 BASE_FEATURE(kNtpSafeBrowsingModule,
208              "NtpSafeBrowsingModule",
209              base::FEATURE_DISABLED_BY_DEFAULT);
210
211 // If enabled, shortcuts will be shown.
212 BASE_FEATURE(kNtpShortcuts, "NtpShortcuts", base::FEATURE_ENABLED_BY_DEFAULT);
213
214 const base::FeatureParam<std::string> kNtpOgbButtonSelectorParam{
215     &kNtpRemoveScrim, "NtpOgbButtonSelectorParam", ".gb_A"};
216
217 const base::FeatureParam<std::string> kNtpOgbUnprotectedTextSelectorParam{
218     &kNtpRemoveScrim, "NtpOgbUnprotectedTextSelectorParam", ".gb_d"};
219
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";
257
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, &param_value_as_int)) {
266     return base::Seconds(3);
267   }
268   return base::Milliseconds(param_value_as_int);
269 }
270
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);
276 }
277
278 }  // namespace ntp_features