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

Uplift NTP SI to 1.4.x #4461

Merged
merged 9 commits into from
Jan 30, 2020
Merged
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
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
14 changes: 14 additions & 0 deletions .storybook/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ 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!',
rewardsWidgetEnableBrandedWallpaperSubTitle: 'Turn on $3 to claim your share. You can also choose to $1hide sponsored images$2.',
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 @@ -136,6 +136,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 @@ -166,6 +167,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
19 changes: 19 additions & 0 deletions browser/ntp_sponsored_images/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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/components/ntp_sponsored_images/common",
"//brave/common",
"//brave/components/brave_ads/browser",
"//chrome/common",
"//content/public/browser",
"//components/keyed_service/content",
"//components/prefs",
"//components/pref_registry",
]
}
80 changes: 80 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,80 @@
// 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 "brave/components/ntp_sponsored_images/common/pref_names.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) {
ViewCounterService::RegisterProfilePrefs(registry);
}

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