1 // Copyright 2018 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 #include "components/search/ntp_features.h"
6
7 #include "base/feature_list.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/time/time.h"
10 #include "build/build_config.h"
11
12 namespace ntp_features {
13
14 // If enabled, shows a confirm dialog before removing search suggestions from
15 // the New Tab page real search box ("realbox").
16 const base::Feature kConfirmSuggestionRemovals{
17 "ConfirmNtpSuggestionRemovals", base::FEATURE_DISABLED_BY_DEFAULT};
18
19 // If enabled, "middle slot" promos on the bottom of the NTP will show a dismiss
20 // UI that allows users to close them and not see them again.
21 const base::Feature kDismissPromos{"DismissNtpPromos",
22 base::FEATURE_DISABLED_BY_DEFAULT};
23
24 // If enabled, the OneGooleBar is loaded in an iframe. Otherwise, it is inlined.
25 const base::Feature kIframeOneGoogleBar{"IframeOneGoogleBar",
26 base::FEATURE_DISABLED_BY_DEFAULT};
27
28 // If enabled, queries that are frequently repeated by the user (and are
29 // expected to be issued again) are shown as most visited tiles.
30 const base::Feature kNtpRepeatableQueries{"NtpRepeatableQueries",
31 base::FEATURE_DISABLED_BY_DEFAULT};
32
33 // If enabled, the iframed OneGooleBar shows the overlays modally with a
34 // backdrop.
35 const base::Feature kOneGoogleBarModalOverlays{
36 "OneGoogleBarModalOverlays", base::FEATURE_DISABLED_BY_DEFAULT};
37
38 // Depends on kRealbox being enabled. If enabled, the NTP "realbox" will be
39 // themed like the omnibox (same background/text/selected/hover colors).
40 const base::Feature kRealboxMatchOmniboxTheme{
41 "NtpRealboxMatchOmniboxTheme", base::FEATURE_DISABLED_BY_DEFAULT};
42
43 // If enabled, the real search box ("realbox") on the New Tab page will show a
44 // Google (g) icon instead of the typical magnifying glass (aka loupe).
45 const base::Feature kRealboxUseGoogleGIcon{"NtpRealboxUseGoogleGIcon",
46 base::FEATURE_DISABLED_BY_DEFAULT};
47
48 // If enabled, shows Vasco suggestion chips in the NTP below fakebox/realbox
49 // despite other config except DisableSearchSuggestChips below.
50 const base::Feature kSearchSuggestChips{"SearchSuggestChips",
51 base::FEATURE_DISABLED_BY_DEFAULT};
52
53 // If enabled, hides Vasco suggestion chips in the NTP below fakebox/realbox
54 // despite other config.
55 const base::Feature kDisableSearchSuggestChips{
56 "DisableSearchSuggestChips", base::FEATURE_DISABLED_BY_DEFAULT};
57
58 // If enabled, handles navigations from the Most Visited tiles explicitly and
59 // overrides the navigation's transition type to bookmark navigation before the
60 // navigation is issued.
61 // TODO(crbug.com/1147589): When removing this flag, also remove the workaround
62 // in ChromeContentBrowserClient::OverrideNavigationParams.
63 extern const base::Feature kNtpHandleMostVisitedNavigationExplicitly{
64 "HandleMostVisitedNavigationExplicitly", base::FEATURE_ENABLED_BY_DEFAULT};
65
66 // If enabled, the WebUI new tab page will load when a new tab is created
67 // instead of the local NTP.
68 const base::Feature kWebUI{"NtpWebUI", base::FEATURE_ENABLED_BY_DEFAULT};
69
70 // If enabled, the Doodle will be shown on themed and dark mode NTPs.
71 const base::Feature kWebUIThemeModeDoodles{"WebUIThemeModeDoodles",
72 base::FEATURE_ENABLED_BY_DEFAULT};
73
74 // If enabled, modules will be shown.
75 const base::Feature kModules{"NtpModules", base::FEATURE_DISABLED_BY_DEFAULT};
76
77 // If enabled, recipe tasks module will be shown.
78 const base::Feature kNtpRecipeTasksModule{"NtpRecipeTasksModule",
79 base::FEATURE_DISABLED_BY_DEFAULT};
80
81 // If enabled, shopping tasks module will be shown.
82 const base::Feature kNtpShoppingTasksModule{"NtpShoppingTasksModule",
83 base::FEATURE_DISABLED_BY_DEFAULT};
84
85 const char kNtpRepeatableQueriesAgeThresholdDaysParam[] =
86 "NtpRepeatableQueriesAgeThresholdDays";
87 const char kNtpRepeatableQueriesRecencyHalfLifeSecondsParam[] =
88 "NtpRepeatableQueriesRecencyHalfLifeSeconds";
89 const char kNtpRepeatableQueriesFrequencyExponentParam[] =
90 "NtpRepeatableQueriesFrequencyExponent";
91 const char kNtpRepeatableQueriesInsertPositionParam[] =
92 "NtpRepeatableQueriesInsertPosition";
93
94 const char kNtpStatefulTasksModuleDataParam[] =
95 "NtpStatefulTasksModuleDataParam";
96
GetLocalHistoryRepeatableQueriesAgeThreshold()97 base::Time GetLocalHistoryRepeatableQueriesAgeThreshold() {
98 const base::TimeDelta kLocalHistoryRepeatableQueriesAgeThreshold =
99 base::TimeDelta::FromDays(180); // Six months.
100 std::string param_value = base::GetFieldTrialParamValueByFeature(
101 kNtpRepeatableQueries, kNtpRepeatableQueriesAgeThresholdDaysParam);
102
103 // If the field trial param is not found or cannot be parsed to an unsigned
104 // integer, return the default value.
105 unsigned int param_value_as_int = 0;
106 if (!base::StringToUint(param_value, ¶m_value_as_int)) {
107 return base::Time::Now() - kLocalHistoryRepeatableQueriesAgeThreshold;
108 }
109
110 return (base::Time::Now() - base::TimeDelta::FromDays(param_value_as_int));
111 }
112
GetLocalHistoryRepeatableQueriesRecencyHalfLifeSeconds()113 int GetLocalHistoryRepeatableQueriesRecencyHalfLifeSeconds() {
114 const base::TimeDelta kLocalHistoryRepeatableQueriesRecencyHalfLife =
115 base::TimeDelta::FromDays(7); // One week.
116 std::string param_value = base::GetFieldTrialParamValueByFeature(
117 kNtpRepeatableQueries, kNtpRepeatableQueriesRecencyHalfLifeSecondsParam);
118
119 // If the field trial param is not found or cannot be parsed to an unsigned
120 // integer, return the default value.
121 unsigned int param_value_as_int = 0;
122 if (!base::StringToUint(param_value, ¶m_value_as_int)) {
123 return kLocalHistoryRepeatableQueriesRecencyHalfLife.InSeconds();
124 }
125
126 return param_value_as_int;
127 }
128
GetLocalHistoryRepeatableQueriesFrequencyExponent()129 double GetLocalHistoryRepeatableQueriesFrequencyExponent() {
130 const double kLocalHistoryRepeatableQueriesFrequencyExponent = 2.0;
131 std::string param_value = base::GetFieldTrialParamValueByFeature(
132 kNtpRepeatableQueries, kNtpRepeatableQueriesFrequencyExponentParam);
133
134 // If the field trial param is not found or cannot be parsed to an unsigned
135 // integer, return the default value.
136 double param_value_as_double = 0;
137 if (!base::StringToDouble(param_value, ¶m_value_as_double)) {
138 return kLocalHistoryRepeatableQueriesFrequencyExponent;
139 }
140
141 return param_value_as_double;
142 }
143
GetRepeatableQueriesInsertPosition()144 RepeatableQueriesInsertPosition GetRepeatableQueriesInsertPosition() {
145 std::string param_value = base::GetFieldTrialParamValueByFeature(
146 kNtpRepeatableQueries, kNtpRepeatableQueriesInsertPositionParam);
147 return param_value == "end" ? RepeatableQueriesInsertPosition::kEnd
148 : RepeatableQueriesInsertPosition::kStart;
149 }
150
151 } // namespace ntp_features
152