ntp_features.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. #include "components/search/ntp_features.h"
  5. #include "base/feature_list.h"
  6. #include "base/metrics/field_trial_params.h"
  7. #include "base/strings/string_number_conversions.h"
  8. #include "base/strings/string_split.h"
  9. #include "base/time/time.h"
  10. #include "build/build_config.h"
  11. namespace ntp_features {
  12. // If enabled, shows a confirm dialog before removing search suggestions from
  13. // the New Tab page real search box ("realbox").
  14. const base::Feature kConfirmSuggestionRemovals{
  15. "ConfirmNtpSuggestionRemovals", base::FEATURE_DISABLED_BY_DEFAULT};
  16. // If enabled, the OneGooleBar cached response is sent back to NTP.
  17. const base::Feature kCacheOneGoogleBar{"CacheOneGoogleBar",
  18. base::FEATURE_DISABLED_BY_DEFAULT};
  19. // If enabled, Customize Chrome will be an option in the Unified Side Panel
  20. // when on the New Tab Page.
  21. const base::Feature kCustomizeChromeSidePanel{
  22. "CustomizeChromeSidePanel", base::FEATURE_DISABLED_BY_DEFAULT};
  23. // Enables the removal of the NTP background scrim and forced dark foreground
  24. // colors for a specific subset of Chrome Web Store themes (see
  25. // crbug.com/1329552). This is enabled by default to allow finch to disable this
  26. // NTP treatment in the case of unexpected regressions.
  27. const base::Feature kCwsScrimRemoval{"CwsScrimRemoval",
  28. base::FEATURE_ENABLED_BY_DEFAULT};
  29. // If enabled, "middle slot" promos on the bottom of the NTP will show a dismiss
  30. // UI that allows users to close them and not see them again.
  31. const base::Feature kDismissPromos{"DismissNtpPromos",
  32. base::FEATURE_DISABLED_BY_DEFAULT};
  33. // If enabled, the NTP "realbox" will be themed like the omnibox
  34. // (same background/text/selected/hover colors).
  35. const base::Feature kRealboxMatchOmniboxTheme{
  36. "NtpRealboxMatchOmniboxTheme", base::FEATURE_DISABLED_BY_DEFAULT};
  37. // If enabled, the NTP "realbox" will be themed like the searchbox (same border/
  38. // drop shadow on hover state/rounded corners).
  39. const base::Feature kRealboxMatchSearchboxTheme{
  40. "NtpRealboxMatchSearchboxTheme", base::FEATURE_DISABLED_BY_DEFAULT};
  41. // If enabled, the real search box ("realbox") on the New Tab page will show a
  42. // Google (g) icon instead of the typical magnifying glass (aka loupe).
  43. const base::Feature kRealboxUseGoogleGIcon{"NtpRealboxUseGoogleGIcon",
  44. base::FEATURE_DISABLED_BY_DEFAULT};
  45. // If enabled, chrome cart module will be shown.
  46. const base::Feature kNtpChromeCartModule{"NtpChromeCartModule",
  47. base::FEATURE_ENABLED_BY_DEFAULT};
  48. #if !defined(OFFICIAL_BUILD)
  49. // If enabled, dummy modules will be shown.
  50. const base::Feature kNtpDummyModules{"NtpDummyModules",
  51. base::FEATURE_DISABLED_BY_DEFAULT};
  52. #endif
  53. // If enabled, Google Drive module will be shown.
  54. const base::Feature kNtpDriveModule{"NtpDriveModule",
  55. base::FEATURE_DISABLED_BY_DEFAULT};
  56. // If enabled, handles navigations from the Most Visited tiles explicitly and
  57. // overrides the navigation's transition type to bookmark navigation before the
  58. // navigation is issued.
  59. // TODO(crbug.com/1147589): When removing this flag, also remove the workaround
  60. // in ChromeContentBrowserClient::OverrideNavigationParams.
  61. extern const base::Feature kNtpHandleMostVisitedNavigationExplicitly{
  62. "HandleMostVisitedNavigationExplicitly", base::FEATURE_ENABLED_BY_DEFAULT};
  63. // If enabled, logo will be shown.
  64. const base::Feature kNtpLogo{"NtpLogo", base::FEATURE_ENABLED_BY_DEFAULT};
  65. // If enabled, middle slot promo will be shown.
  66. const base::Feature kNtpMiddleSlotPromo{"NtpMiddleSlotPromo",
  67. base::FEATURE_ENABLED_BY_DEFAULT};
  68. // If enabled, middle slot promo will be dismissed from New Tab Page until new
  69. // promo message is populated
  70. const base::Feature kNtpMiddleSlotPromoDismissal{
  71. "NtpMiddleSlotPromoDismissal", base::FEATURE_ENABLED_BY_DEFAULT};
  72. // Dummy feature to set param "NtpModulesLoadTimeoutMillisecondsParam".
  73. const base::Feature kNtpModulesLoadTimeoutMilliseconds{
  74. "NtpModulesLoadTimeoutMilliseconds", base::FEATURE_DISABLED_BY_DEFAULT};
  75. // Dummy feature to set param "NtpModulesOrderParam".
  76. const base::Feature kNtpModulesOrder{"NtpModulesOrder",
  77. base::FEATURE_DISABLED_BY_DEFAULT};
  78. // If enabled, modules will be able to be reordered via dragging and dropping
  79. const base::Feature kNtpModulesDragAndDrop{"NtpModulesDragAndDrop",
  80. base::FEATURE_DISABLED_BY_DEFAULT};
  81. // If enabled, the first run experience for Modular NTP Desktop v1 will show.
  82. const base::Feature kNtpModulesFirstRunExperience{
  83. "NtpModulesFirstRunExperience", base::FEATURE_ENABLED_BY_DEFAULT};
  84. // If enabled, modules will be loaded but not shown. This is useful to determine
  85. // if a user would have seen modules in order to counterfactually log or
  86. // trigger.
  87. const base::Feature kNtpModulesLoad{"NtpModulesLoad",
  88. base::FEATURE_DISABLED_BY_DEFAULT};
  89. // If enabled, redesigned modules will be shown.
  90. const base::Feature kNtpModulesRedesigned{"NtpModulesRedesigned",
  91. base::FEATURE_DISABLED_BY_DEFAULT};
  92. // If enabled, a different module layout where modules are organized in rows and
  93. // columns will be shown.
  94. const base::Feature kNtpModulesRedesignedLayout{
  95. "NtpModulesRedesignedLayout", base::FEATURE_DISABLED_BY_DEFAULT};
  96. // If enabled, OneGoogleBar will be shown.
  97. const base::Feature kNtpOneGoogleBar{"NtpOneGoogleBar",
  98. base::FEATURE_ENABLED_BY_DEFAULT};
  99. // If enabled, Google Photos module will be shown.
  100. const base::Feature kNtpPhotosModule{"NtpPhotosModule",
  101. base::FEATURE_DISABLED_BY_DEFAULT};
  102. // If enabled, a customized title will be shown on the opt-in card.
  103. const base::Feature kNtpPhotosModuleCustomizedOptInTitle{
  104. "NtpPhotosModuleCustomizedOptInTitle", base::FEATURE_DISABLED_BY_DEFAULT};
  105. // If enabled, a customized art work will be shown on the opt-in card.
  106. const base::Feature kNtpPhotosModuleCustomizedOptInArtWork{
  107. "NtpPhotosModuleCustomizedOptInArtWork", base::FEATURE_DISABLED_BY_DEFAULT};
  108. // If enabled, Google Photos opt-in card will show a button to soft opt-out.
  109. const base::Feature kNtpPhotosModuleSoftOptOut(
  110. "NtpPhotosModuleSoftOptOut",
  111. base::FEATURE_DISABLED_BY_DEFAULT);
  112. // If enabled, the single svg image show in Photos opt-in screen will be
  113. // replaced by constituent images to support i18n.
  114. const base::Feature kNtpPhotosModuleSplitSvgOptInArtWork(
  115. "NtpPhotosModuleSplitSvgOptInArtWork",
  116. base::FEATURE_DISABLED_BY_DEFAULT);
  117. // If enabled, Following Feed module will be shown.
  118. const base::Feature kNtpFeedModule{"NtpFeedModule",
  119. base::FEATURE_DISABLED_BY_DEFAULT};
  120. // If enabled, recipe tasks module will be shown.
  121. const base::Feature kNtpRecipeTasksModule{"NtpRecipeTasksModule",
  122. base::FEATURE_ENABLED_BY_DEFAULT};
  123. // If enabled, SafeBrowsing module will be shown to a target user.
  124. const base::Feature kNtpSafeBrowsingModule{"NtpSafeBrowsingModule",
  125. base::FEATURE_DISABLED_BY_DEFAULT};
  126. // If enabled, shortcuts will be shown.
  127. const base::Feature kNtpShortcuts{"NtpShortcuts",
  128. base::FEATURE_ENABLED_BY_DEFAULT};
  129. const char kNtpModulesLoadTimeoutMillisecondsParam[] =
  130. "NtpModulesLoadTimeoutMillisecondsParam";
  131. const char kNtpModulesOrderParam[] = "NtpModulesOrderParam";
  132. const char kNtpChromeCartModuleDataParam[] = "NtpChromeCartModuleDataParam";
  133. const char kNtpChromeCartModuleAbandonedCartDiscountParam[] =
  134. "NtpChromeCartModuleAbandonedCartDiscountParam";
  135. const char kNtpChromeCartModuleAbandonedCartDiscountUseUtmParam[] =
  136. "NtpChromeCartModuleAbandonedCartDiscountUseUtmParam";
  137. const char kNtpChromeCartModuleHeuristicsImprovementParam[] =
  138. "NtpChromeCartModuleHeuristicsImprovementParam";
  139. const char kNtpChromeCartModuleCouponParam[] = "NtpChromeCartModuleCouponParam";
  140. const char kNtpDriveModuleDataParam[] = "NtpDriveModuleDataParam";
  141. const char kNtpDriveModuleManagedUsersOnlyParam[] =
  142. "NtpDriveModuleManagedUsersOnlyParam";
  143. const char kNtpDriveModuleCacheMaxAgeSParam[] =
  144. "NtpDriveModuleCacheMaxAgeSParam";
  145. const char kNtpDriveModuleExperimentGroupParam[] =
  146. "NtpDriveModuleExperimentGroupParam";
  147. const char kNtpMiddleSlotPromoDismissalParam[] =
  148. "NtpMiddleSlotPromoDismissalParam";
  149. const char kNtpPhotosModuleDataParam[] = "NtpPhotosModuleDataParam";
  150. const char kNtpPhotosModuleOptInTitleParam[] = "NtpPhotosModuleOptInTitleParam";
  151. const char kNtpPhotosModuleOptInArtWorkParam[] =
  152. "NtpPhotosModuleOptInArtWorkParam";
  153. const char kNtpSafeBrowsingModuleCooldownPeriodDaysParam[] =
  154. "NtpSafeBrowsingModuleCooldownPeriodDaysParam";
  155. const char kNtpSafeBrowsingModuleCountMaxParam[] =
  156. "NtpSafeBrowsingModuleCountMaxParam";
  157. const char kRealboxMatchOmniboxThemeVariantParam[] =
  158. "RealboxMatchOmniboxThemeVariantParam";
  159. const char kRealboxMatchSearchboxThemeParam[] =
  160. "RealboxMatchSearchboxThemeParam";
  161. const char kNtpRecipeTasksModuleDataParam[] = "NtpRecipeTasksModuleDataParam";
  162. const char kNtpRecipeTasksModuleCacheMaxAgeSParam[] =
  163. "NtpRecipeTasksModuleCacheMaxAgeSParam";
  164. const char kNtpRecipeTasksModuleExperimentGroupParam[] =
  165. "NtpRecipeTasksModuleExperimentGroupParam";
  166. base::TimeDelta GetModulesLoadTimeout() {
  167. std::string param_value = base::GetFieldTrialParamValueByFeature(
  168. kNtpModulesLoadTimeoutMilliseconds,
  169. kNtpModulesLoadTimeoutMillisecondsParam);
  170. // If the field trial param is not found or cannot be parsed to an unsigned
  171. // integer, return the default value.
  172. unsigned int param_value_as_int = 0;
  173. if (!base::StringToUint(param_value, &param_value_as_int)) {
  174. return base::Seconds(3);
  175. }
  176. return base::Milliseconds(param_value_as_int);
  177. }
  178. std::vector<std::string> GetModulesOrder() {
  179. return base::SplitString(base::GetFieldTrialParamValueByFeature(
  180. kNtpModulesOrder, kNtpModulesOrderParam),
  181. ",:;", base::WhitespaceHandling::TRIM_WHITESPACE,
  182. base::SplitResult::SPLIT_WANT_NONEMPTY);
  183. }
  184. } // namespace ntp_features