From 4c3165e2a0365753b463ed9b10e760d4255cfefd Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Thu, 21 Nov 2019 16:54:30 -0800 Subject: [PATCH] New Tab Page: add brave://flags feature to force dummy content for Branded Wallpaper --- .../new_tab_page_branded_view_counter.cc | 5 ++++- chromium_src/chrome/browser/about_flags.cc | 6 ++++++ chromium_src/chrome/browser/flag_descriptions.cc | 15 +++++++++++++++ chromium_src/chrome/browser/flag_descriptions.h | 16 ++++++++++++++++ chromium_src/chrome/common/chrome_features.cc | 12 ++++++++++++ chromium_src/chrome/common/chrome_features.h | 16 ++++++++++++++++ patches/chrome-browser-about_flags.cc.patch | 8 ++++++++ 7 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 chromium_src/chrome/browser/flag_descriptions.cc create mode 100644 chromium_src/chrome/browser/flag_descriptions.h create mode 100644 chromium_src/chrome/common/chrome_features.cc create mode 100644 chromium_src/chrome/common/chrome_features.h diff --git a/browser/ui/webui/new_tab_page/new_tab_page_branded_view_counter.cc b/browser/ui/webui/new_tab_page/new_tab_page_branded_view_counter.cc index 090b9bbf6b69..43b29f52494e 100644 --- a/browser/ui/webui/new_tab_page/new_tab_page_branded_view_counter.cc +++ b/browser/ui/webui/new_tab_page/new_tab_page_branded_view_counter.cc @@ -11,6 +11,7 @@ #include "brave/common/pref_names.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/chrome_features.h" #include "content/public/browser/browser_context.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h" // NOLINT @@ -77,7 +78,9 @@ NewTabPageBrandedViewCounter::NewTabPageBrandedViewCounter(Profile* profile) // TODO(petemill): Update the private var when the data source gets // new content, when we have a data source! // Set demo wallpaper if a flag is set. - current_wallpaper_ = GetDemoWallpaper(); + if (base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaperDemo)) { + current_wallpaper_ = GetDemoWallpaper(); + } // Observe relevant preferences that affect whether we should show // wallpaper or count views. SetShouldShowFromPreferences(); diff --git a/chromium_src/chrome/browser/about_flags.cc b/chromium_src/chrome/browser/about_flags.cc index e910bb11f61f..d4fb7ae36ad3 100644 --- a/chromium_src/chrome/browser/about_flags.cc +++ b/chromium_src/chrome/browser/about_flags.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#define BRAVE_FEATURE_ENTRIES \ + {"brave-ntp-branded-wallpaper-demo", \ + flag_descriptions::kBraveNTPBrandedWallpaperDemoName, \ + flag_descriptions::kBraveNTPBrandedWallpaperDemoDescription, kOsAll, \ + FEATURE_VALUE_TYPE(features::kBraveNTPBrandedWallpaperDemo)}, + #define SetFeatureEntryEnabled SetFeatureEntryEnabled_ChromiumImpl #include "../../../../chrome/browser/about_flags.cc" // NOLINT #include "../../../../components/flags_ui/flags_state.cc" // NOLINT diff --git a/chromium_src/chrome/browser/flag_descriptions.cc b/chromium_src/chrome/browser/flag_descriptions.cc new file mode 100644 index 000000000000..2a223a50648a --- /dev/null +++ b/chromium_src/chrome/browser/flag_descriptions.cc @@ -0,0 +1,15 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "../../../../chrome/browser/flag_descriptions.cc" + +namespace flag_descriptions { +const char kBraveNTPBrandedWallpaperDemoName[] = + "New Tab Page Demo Branded Wallpaper"; +const char kBraveNTPBrandedWallpaperDemoDescription[] = + "Force dummy data for the Branded Wallpaper New Tab Page Experience. " + "View rate and user opt-in conditionals will still be followed to decide " + "when to display the Branded Wallpaper."; +} diff --git a/chromium_src/chrome/browser/flag_descriptions.h b/chromium_src/chrome/browser/flag_descriptions.h new file mode 100644 index 000000000000..e7fd1ac5d43f --- /dev/null +++ b/chromium_src/chrome/browser/flag_descriptions.h @@ -0,0 +1,16 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FLAG_DESCRIPTIONS_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FLAG_DESCRIPTIONS_H_ + +#include "../../../../chrome/browser/flag_descriptions.h" + +namespace flag_descriptions { +extern const char kBraveNTPBrandedWallpaperDemoName[]; +extern const char kBraveNTPBrandedWallpaperDemoDescription[]; +} + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FLAG_DESCRIPTIONS_H_ diff --git a/chromium_src/chrome/common/chrome_features.cc b/chromium_src/chrome/common/chrome_features.cc new file mode 100644 index 000000000000..3a2bfeac4607 --- /dev/null +++ b/chromium_src/chrome/common/chrome_features.cc @@ -0,0 +1,12 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "../../../../chrome/common/chrome_features.cc" + +namespace features { +const base::Feature kBraveNTPBrandedWallpaperDemo{ + "BraveNTPBrandedWallpaperDemoName", + base::FEATURE_DISABLED_BY_DEFAULT}; +} diff --git a/chromium_src/chrome/common/chrome_features.h b/chromium_src/chrome/common/chrome_features.h new file mode 100644 index 000000000000..4860104b9128 --- /dev/null +++ b/chromium_src/chrome/common/chrome_features.h @@ -0,0 +1,16 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_COMMON_CHROME_FEATURES_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_COMMON_CHROME_FEATURES_H_ + +#include "../../../../chrome/common/chrome_features.h" + +namespace features { +COMPONENT_EXPORT(CHROME_FEATURES) +extern const base::Feature kBraveNTPBrandedWallpaperDemo; +} + +#endif // BRAVE_CHROMIUM_SRC_CHROME_COMMON_CHROME_FEATURES_H_ diff --git a/patches/chrome-browser-about_flags.cc.patch b/patches/chrome-browser-about_flags.cc.patch index 5a17a14d415d..322a62508e4e 100644 --- a/patches/chrome-browser-about_flags.cc.patch +++ b/patches/chrome-browser-about_flags.cc.patch @@ -21,3 +21,11 @@ index 0ab55be2f96853137cec8928621360e9f639b467..34e01378c8e413af12399bc3ca30188b const FeatureEntry::Choice kPassiveListenersChoices[] = { {flags_ui::kGenericExperimentChoiceDefault, "", ""}, +@@ -4688,6 +4688,7 @@ const FeatureEntry kFeatureEntries[] = { + // "LoginCustomFlags" in tools/metrics/histograms/enums.xml. See "Flag + // Histograms" in tools/metrics/histograms/README.md (run the + // AboutFlagsHistogramTest unit test to verify this process). ++ BRAVE_FEATURE_ENTRIES + }; + + class FlagsStateSingleton {