Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Tab Page Branded Wallpapers (desktop) #4075

Merged
merged 59 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2d693a8
add brave://flags overriding infrastructure
antonok-edm Nov 22, 2019
2f3ca18
New Tab Page WebUI: Introduce Branded Wallpaper
petemill Nov 26, 2019
528ef67
New Tab Page WebUI: grid is more modular, allows items to collapse an…
petemill Dec 4, 2019
0de449e
New Tab Page: Backend and API for Branded Wallpaper, including correc…
petemill Dec 5, 2019
e6b4265
New Tab Page: Responsive grid sizing
petemill Dec 5, 2019
22bc549
New Tab Page WebUI: tweak font sizing as per design
petemill Dec 5, 2019
473ac52
New Tab Page WebUI: display setting for opting out of branded wallpaper
petemill Dec 6, 2019
9b1d676
New Tab Page: Rewards widget variations for Branded Wallpaper
petemill Dec 6, 2019
4471768
New Tab Page WebUI: Widget menu becomes optional
petemill Dec 12, 2019
d408bb2
New Tab Page WebUI: grid items only take up the width they need
petemill Jan 16, 2020
f289bc1
New Tab Page WebUI: Show external link indicator on Branded Wallpaper…
petemill Dec 12, 2019
7376699
New Tab Page: Componentize BrandedWallpaper and NewTabPageBrandedView…
petemill Dec 12, 2019
3442c4f
New Tab Page: Put branded wallpaper features behind two brave://flags:
petemill Nov 22, 2019
e5bf80a
New Tab Page: Support multiple branded wallpaper images
petemill Dec 16, 2019
f4c8432
Implement backend service for ntp sponsored images
simonhong Jan 3, 2020
436f74f
Rename NTPSponsoredImagesService to NTPSponsoredImagesComponentManager
simonhong Jan 9, 2020
580ea35
Implement NTPSponsoredImagesService
simonhong Jan 9, 2020
9c1d5ff
Implement NTPSponsoredImageSource::StartDataRequest()
simonhong Jan 9, 2020
b522095
Fix lint error and comments
simonhong Jan 9, 2020
a5d3ed6
Add test for ntp component manager
simonhong Jan 9, 2020
5cac240
Update method definition of overloaded operator=
simonhong Jan 12, 2020
41d7574
Use one URLDataSource for branded-wallpaper host
simonhong Jan 15, 2020
46be4d4
New Tab Page: Integrate component fetching service with UI layer
petemill Jan 15, 2020
4024f49
New Tab Page: Allow CLI switch for local files containing branded wal…
petemill Jan 15, 2020
3029302
Export constants
simonhong Jan 15, 2020
5b05c41
Support full region list for ntp sponsorship
simonhong Jan 16, 2020
f2b3da8
Don't build ntp_sponsored_images as a component
simonhong Jan 17, 2020
f50183c
Storybook - support webui component translations
petemill Jan 17, 2020
d244e46
WebUI string helper to extract components of translated strings desti…
petemill Jan 17, 2020
c7c2b2b
New Tab Page WebUI: Allow Widgets to have widget functionality disabl…
petemill Jan 17, 2020
81c21ba
New Tab Page WebUI: Rewards widget re-design and more Branded Wallpap…
petemill Jan 17, 2020
63c654b
Provide default move constructor to NTPSponsoredImagesData
simonhong Jan 17, 2020
64b2359
Fix unitest build failure
simonhong Jan 17, 2020
25a3313
Relaxed no_deps rules of ntp_sponsored_images target
simonhong Jan 17, 2020
689cbc3
Disable no_deps in ntp_sponsored_images target
simonhong Jan 17, 2020
a6c6dab
New Tab Page WebUI: Fix rewards widget thinks ads are off when reward…
petemill Jan 18, 2020
6f49c34
Modified photo.json parse logic
simonhong Jan 20, 2020
5ad6513
Use Raw string literal for test json string
simonhong Jan 20, 2020
c1722d9
New Tab Page: Do not show branded wallpaper for users in a non-ad-sup…
petemill Jan 21, 2020
d3730f9
New Tab Page WebUI: All widget scenarios allow for branded logo to si…
petemill Jan 22, 2020
4c10929
New Tab Page: Branded wallpaper notification show and dismiss logic b…
petemill Jan 22, 2020
4479a41
New Tab Page: Start NewTabPageBrandedViewCounter at profile init so t…
petemill Jan 22, 2020
9607758
New Tab Page: Move sponsored images component to correct browser subd…
petemill Jan 23, 2020
7292ef2
Deprecate BrandedWallpaper data structure
simonhong Jan 23, 2020
5e8c044
Cleanup NTPBrandedViewCounter regarding data manager observation
simonhong Jan 23, 2020
c0f9f88
Fix some lint errors and invalid comments
simonhong Jan 23, 2020
36fd337
Correct current_wallpaper_image_index_ calculation
simonhong Jan 23, 2020
9fea909
Introduce ViewCounterModel to test easier
simonhong Jan 23, 2020
789fccd
Delete deprecated DISALLOW_XXX
simonhong Jan 23, 2020
42d6865
Launch NewTabPageBrandedViewCounter only when it is needed
simonhong Jan 23, 2020
4ba3931
Rename ViewCounterModel::Reset() to ResetCurrentWallpaperImageIndex()
simonhong Jan 23, 2020
9ed5bf0
New Tab Page WebUI: better naming for imported Page components
petemill Jan 24, 2020
bc02497
New Tab Page: Do not count private page views for sponsored image cou…
petemill Jan 24, 2020
9dd4b60
Make NewTabPageBrandedViewCounter add URLDataSource
simonhong Jan 24, 2020
aeab4ad
Use ComponentInstallerPolicy for registering NTP component
simonhong Jan 24, 2020
bc8dda3
Rename NTPSponsoredImagesComponentManager
simonhong Jan 24, 2020
5cad9f5
Add target for browser/ntp_sponsored_images
simonhong Jan 24, 2020
278fb27
refactor to remove brave/browser and chrome/browser dependencies outs…
bridiver Jan 26, 2020
2d86102
fix hash size for component
bridiver Jan 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ browser/widevine @simonhong
browser/ui/views/infobars/brave_wayback_machine_* @simonhong
components/brave_wayback_machine @simonhong

# NTP sponsored images
browser/ntp_sponsored_images @simonhong @petemill
components/ntp_sponsored_images @simonhong @petemill

# Licensing of third-party components
common/licenses/ @fmarier
components/brave_new_tab_ui/data/backgrounds.ts @fmarier
Expand Down
5 changes: 5 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ addParameters({

function loadStories() {
initLocale(locale)
window.loadTimeData = {
getString (key) {
return locale[key] || key
}
}
const req = require.context('../components/', true, /\/stories\/.*\.tsx$/)
req.keys().forEach(filename => req(filename))
}
Expand Down
13 changes: 13 additions & 0 deletions .storybook/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ const locale: Record<string, string> = {
rewardsRestoreText4: 'Enter your recovery key or',
rewardsSummary: 'Rewards Summary',
rewardsWhy: 'Why Brave Rewards…',
rewardsWidgetBraveRewards: 'Brave Rewards',
rewardsWidgetBat: 'BAT',
rewardsWidgetEstimatedEarnings: 'Estimated earnings so far this month',
rewardsWidgetAdsOptInDescription: 'Earn tokens by viewing privacy-respecting ads.',
rewardsWidgetMonthlyTips: 'Tips and contributions this month',
rewardsWidgetNotificationTitle: 'Way to Go!',
rewardsWidgetBrandedNotificationTitle: 'You\'re getting paid to view this background image.',
rewardsWidgetBrandedNotificationDescription: '$1Learn more$2 about sponsored images in Brave Rewards.',
rewardsWidgetAboutRewards: '$1Learn more$2 about Brave Rewards',
rewardsWidgetTurnOnAds: 'Turn on Brave Ads',
rewardsWidgetTurnOnRewards: 'Turn on Rewards',
rewardsWidgetServiceText: 'By turning on Rewards, you agree to the $1Terms of Service$2.',
rewardsWidgetTurnOnLearnMore: 'Learn more',
saveAd: 'Save',
saveAsFile: 'Save',
saved: 'Saved',
Expand Down
2 changes: 2 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ source_set("browser_process") {
"//brave/components/brave_webtorrent/browser/buildflags",
"//brave/components/content_settings/core/browser",
"//brave/components/greaselion/browser/buildflags",
"//brave/components/ntp_sponsored_images/browser",
"//brave/components/ntp_tiles",
"//brave/components/p3a",
"//brave/components/resources",
Expand Down Expand Up @@ -165,6 +166,7 @@ source_set("browser_process") {
"//extensions/buildflags",
"//brave/chromium_src:browser",
"themes",
"ntp_sponsored_images",
"//services/network/public/cpp",
"//services/service_manager/embedder",
"//third_party/widevine/cdm:buildflags",
Expand Down
19 changes: 19 additions & 0 deletions browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "brave/browser/tor/buildflags.h"
#include "brave/browser/ui/brave_browser_command_controller.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "brave/components/brave_component_updater/browser/local_data_files_service.h"
#include "brave/components/brave_shields/browser/ad_block_custom_filters_service.h"
#include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h"
Expand All @@ -28,11 +29,13 @@
#include "brave/components/brave_shields/browser/https_everywhere_service.h"
#include "brave/components/brave_shields/browser/referrer_whitelist_service.h"
#include "brave/components/brave_shields/browser/tracking_protection_service.h"
#include "brave/components/ntp_sponsored_images/browser/ntp_sponsored_images_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/brave_histogram_rewrite.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/services/network/public/cpp/system_request_handler.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/webui/components_ui.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_paths.h"
#include "components/component_updater/component_updater_service.h"
Expand Down Expand Up @@ -74,6 +77,8 @@
#include "chrome/browser/ui/browser.h"
#endif

using ntp_sponsored_images::NTPSponsoredImagesService;

namespace {

// Initializes callback for SystemRequestHandler
Expand Down Expand Up @@ -127,6 +132,9 @@ BraveBrowserProcessImpl::BraveBrowserProcessImpl(StartupData* startup_data)
void BraveBrowserProcessImpl::Init() {
BrowserProcessImpl::Init();

brave_component_updater::BraveOnDemandUpdater::GetInstance()->
RegisterOnDemandUpdateCallback(
base::BindRepeating(&ComponentsUI::OnDemandUpdate));
UpdateBraveDarkMode();
pref_change_registrar_.Add(
kBraveDarkMode,
Expand Down Expand Up @@ -207,6 +215,17 @@ BraveBrowserProcessImpl::ad_block_regional_service_manager() {
return ad_block_regional_service_manager_.get();
}

NTPSponsoredImagesService*
BraveBrowserProcessImpl::ntp_sponsored_images_service() {
if (!ntp_sponsored_images_service_) {
ntp_sponsored_images_service_ =
std::make_unique<NTPSponsoredImagesService>(
component_updater());
}

return ntp_sponsored_images_service_.get();
}

brave_shields::AutoplayWhitelistService*
BraveBrowserProcessImpl::autoplay_whitelist_service() {
if (!autoplay_whitelist_service_) {
Expand Down
7 changes: 7 additions & 0 deletions browser/brave_browser_process_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ class GreaselionDownloadService;
#endif
} // namespace greaselion

namespace ntp_sponsored_images {
class NTPSponsoredImagesService;
} // namespace ntp_sponsored_images

namespace extensions {
class BraveTorClientUpdater;
}

using brave_component_updater::BraveComponent;
using ntp_sponsored_images::NTPSponsoredImagesService;

class BraveBrowserProcessImpl : public BrowserProcessImpl {
public:
Expand Down Expand Up @@ -91,6 +96,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
BraveWidevineBundleManager* brave_widevine_bundle_manager();
#endif
brave::BraveStatsUpdater* brave_stats_updater();
NTPSponsoredImagesService* ntp_sponsored_images_service();

private:
// BrowserProcessImpl overrides:
Expand Down Expand Up @@ -145,6 +151,7 @@ class BraveBrowserProcessImpl : public BrowserProcessImpl {
std::unique_ptr<BraveWidevineBundleManager> brave_widevine_bundle_manager_;
#endif
scoped_refptr<brave::BraveP3AService> brave_p3a_service_;
std::unique_ptr<NTPSponsoredImagesService> ntp_sponsored_images_service_;

SEQUENCE_CHECKER(sequence_checker_);

Expand Down
2 changes: 2 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/brave_rewards/browser/rewards_service_factory.h"
#include "brave/components/greaselion/browser/buildflags/buildflags.h"
#include "brave/browser/ntp_sponsored_images/view_counter_service_factory.h"

#if BUILDFLAG(ENABLE_GREASELION)
#include "brave/browser/greaselion/greaselion_service_factory.h"
Expand All @@ -33,6 +34,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#endif
TorProfileServiceFactory::GetInstance();
SearchEngineProviderServiceFactory::GetInstance();
ntp_sponsored_images::ViewCounterServiceFactory::GetInstance();

#if !defined(OS_ANDROID)
BookmarkPrefsServiceFactory::GetInstance();
Expand Down
5 changes: 3 additions & 2 deletions browser/component_updater/brave_component_updater_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#include "base/sequenced_task_runner.h"
#include "base/task/post_task.h"
#include "brave/browser/component_updater/brave_component_installer.h"
#include "chrome/browser/ui/webui/components_ui.h"
#include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h"
#include "chrome/browser/browser_process.h"
#include "components/component_updater/component_updater_service.h"

using brave_component_updater::BraveComponent;
using brave_component_updater::BraveOnDemandUpdater;

namespace brave {

Expand Down Expand Up @@ -46,7 +47,7 @@ bool BraveComponentUpdaterDelegate::Unregister(

void BraveComponentUpdaterDelegate::OnDemandUpdate(
const std::string& component_id) {
ComponentsUI::OnDemandUpdate(component_id);
BraveOnDemandUpdater::GetInstance()->OnDemandUpdate(component_id);
}

scoped_refptr<base::SequencedTaskRunner>
Expand Down
18 changes: 18 additions & 0 deletions browser/ntp_sponsored_images/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
source_set("ntp_sponsored_images") {
sources = [
"view_counter_service_factory.cc",
"view_counter_service_factory.h",
]

deps = [
"//base",
"//brave/components/ntp_sponsored_images/browser",
"//brave/common",
"//brave/components/brave_ads/browser",
"//chrome/common",
"//content/public/browser",
"//components/keyed_service/content",
"//components/prefs",
"//components/pref_registry",
]
}
82 changes: 82 additions & 0 deletions browser/ntp_sponsored_images/view_counter_service_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) 2020 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 "brave/browser/ntp_sponsored_images/view_counter_service_factory.h"

#include "brave/browser/brave_browser_process_impl.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/browser/ads_service_factory.h"
#include "brave/components/ntp_sponsored_images/browser/features.h"
#include "brave/components/ntp_sponsored_images/browser/ntp_sponsored_images_service.h"
#include "brave/components/ntp_sponsored_images/browser/view_counter_service.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"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"

namespace ntp_sponsored_images {

// static
ViewCounterService* ViewCounterServiceFactory::GetForProfile(Profile* profile) {
if (base::FeatureList::IsEnabled(features::kBraveNTPBrandedWallpaper))
return static_cast<ViewCounterService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));

return nullptr;
}

// static
ViewCounterServiceFactory* ViewCounterServiceFactory::GetInstance() {
return base::Singleton<ViewCounterServiceFactory>::get();
}

ViewCounterServiceFactory::ViewCounterServiceFactory()
: BrowserContextKeyedServiceFactory(
"ViewCounterService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(brave_ads::AdsServiceFactory::GetInstance());
}

ViewCounterServiceFactory::~ViewCounterServiceFactory() {}

KeyedService* ViewCounterServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* browser_context) const {
Profile* profile = Profile::FromBrowserContext(browser_context);

bool is_supported_locale = false;
auto* ads_service = brave_ads::AdsServiceFactory::GetForProfile(profile);
if (!ads_service) {
LOG(ERROR) << "Ads service was disabled at build time!";
} else {
is_supported_locale = ads_service->IsSupportedLocale();
}

auto* service = g_brave_browser_process->ntp_sponsored_images_service();
service->AddDataSource(browser_context);

ViewCounterService* instance = new ViewCounterService(
service,
profile->GetPrefs(),
is_supported_locale);
return instance;
}

void ViewCounterServiceFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(
kBrandedWallpaperNotificationDismissed, false);
registry->RegisterBooleanPref(
kNewTabPageShowBrandedBackgroundImage, true);
}

bool ViewCounterServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}

} // namespace ntp_sponsored_images
50 changes: 50 additions & 0 deletions browser/ntp_sponsored_images/view_counter_service_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* 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_BROWSER_NTP_SPONSORED_IMAGES_VIEW_COUNTER_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_NTP_SPONSORED_IMAGES_VIEW_COUNTER_SERVICE_FACTORY_H_

#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

class Profile;

namespace content {
class BrowserContext;
}

namespace user_prefs {
class PrefRegistrySyncable;
}

namespace ntp_sponsored_images {

class ViewCounterService;

class ViewCounterServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static ViewCounterService* GetForProfile(Profile* profile);
static ViewCounterServiceFactory* GetInstance();

private:
friend struct base::DefaultSingletonTraits<ViewCounterServiceFactory>;

ViewCounterServiceFactory();
~ViewCounterServiceFactory() override;

// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) override;

DISALLOW_COPY_AND_ASSIGN(ViewCounterServiceFactory);
};

} // namespace ntp_sponsored_images

#endif // BRAVE_BROWSER_NTP_SPONSORED_IMAGES_VIEW_COUNTER_SERVICE_FACTORY_H_
1 change: 1 addition & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ source_set("ui") {
"//brave/components/brave_adblock_ui:generated_resources",
"//brave/components/webcompat_reporter/ui:generated_resources",
"//brave/components/brave_new_tab_ui:generated_resources",
"//brave/components/brave_ads/browser",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_rewards/resources",
"//brave/components/brave_shields/browser",
Expand Down
Loading