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

Implement NTP Custom homepage ("super referral") #4866

Merged
merged 36 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
809c136
Implement NTP Custom homepage
simonhong Mar 18, 2020
58d3c7d
Use real components as a demo data
simonhong Mar 24, 2020
4c6077a
Use referral term not referrer in ntp_background_images
simonhong Mar 25, 2020
3785e1e
Disable super referral by default
simonhong Mar 25, 2020
1687863
Add themes page in appearance section
simonhong Mar 25, 2020
51c4473
Implement super referral changes to WebUI
simonhong Mar 27, 2020
81fc9a9
Added dummy branded wallpaper images again
simonhong Mar 31, 2020
38ea624
Refactoring NTPBackgroundImages module
simonhong Apr 1, 2020
d5b5f4d
Use l10n for brave default images option label
simonhong Apr 3, 2020
c207cac
Revert to settings-brave-appearance-theme from top.
simonhong Apr 3, 2020
26d6b83
Add retrying logic for fetching mapping table
simonhong Apr 3, 2020
9c52753
Enable Demo Super referral components
simonhong Apr 3, 2020
41f3fb7
lint fixes
bsclifton Apr 3, 2020
991a8d7
Fix broken Storybook after sponsored images update
cezaraugusto Apr 3, 2020
25f3b1c
Apply map table change to demo data
simonhong Apr 3, 2020
8c87d03
Integrate UseLocalXXXData() into Init()
simonhong Apr 3, 2020
72de56b
Rename defaultTopSites to defaultSuperReferralTopSites
simonhong Apr 4, 2020
26ae16e
Fix wrong check for effective ntp images data
simonhong Apr 5, 2020
e57aa60
Fetch map-table data with more strict request flag
simonhong Apr 6, 2020
8c9a636
Make SI data availalbe only after referrals service is initialized
simonhong Apr 6, 2020
d2b94bb
Use alias for mapping table url
simonhong Apr 6, 2020
18cc6e7
Don't show SI data until we can confirm this install is not SR
simonhong Apr 6, 2020
c06275b
Improve handling for failure during first launching
simonhong Apr 7, 2020
9afbb06
Add API for getting theme name
simonhong Apr 8, 2020
fea05ab
Use cached NTP SR component image resource
simonhong Apr 8, 2020
a4b7243
Make recover logic more robust for crash case at first launch
simonhong Apr 8, 2020
5dd91a1
Cache super referrals code
simonhong Apr 9, 2020
8754a09
Add more comments
simonhong Apr 9, 2020
f139bb1
Don't load SR component via demo flag
simonhong Apr 9, 2020
16f827e
Use changed prefs name
simonhong Apr 14, 2020
f25125d
Enable SR regardless of NTPBGImages option
simonhong Apr 14, 2020
c7fe7f5
Always show SR images if current profile choose SR theme
simonhong Apr 14, 2020
4c1b822
Update CODEOWNERS
simonhong Apr 14, 2020
8f1f9b7
Don't use custom homepage term. Use super referral
simonhong Apr 16, 2020
8b37618
Use component for getting mapping table
simonhong Apr 16, 2020
a3eeb48
Don't use different manifest file name for SI and SR component
simonhong Apr 17, 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: 0 additions & 4 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ 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/third_party/ @fmarier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
showSponsoredImagesPref = (ChromeSwitchPreference) findPreference(PREF_SHOW_SPONSORED_IMAGES);
if (showSponsoredImagesPref != null) {
showSponsoredImagesPref.setEnabled(BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE));
showSponsoredImagesPref.setChecked(BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_BRANDED_BACKGROUND_IMAGE));
showSponsoredImagesPref.setChecked(BravePrefServiceBridge.getInstance().getBoolean(BravePref.NTP_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE));
showSponsoredImagesPref.setOnPreferenceChangeListener(this);
}
}
Expand All @@ -81,7 +81,7 @@ public static void setOnPreferenceValue(String preferenceName, boolean newValue)
if (PREF_SHOW_BACKGROUND_IMAGES.equals(preferenceName)) {
BravePrefServiceBridge.getInstance().setBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE, newValue);
} else if (PREF_SHOW_SPONSORED_IMAGES.equals(preferenceName)) {
BravePrefServiceBridge.getInstance().setBoolean(BravePref.NTP_SHOW_BRANDED_BACKGROUND_IMAGE, (boolean)newValue);
BravePrefServiceBridge.getInstance().setBoolean(BravePref.NTP_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE, (boolean)newValue);
} else {
SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private boolean migrateTotalStatsAndPreferences() {
if (sharedPreferences.contains(BackgroundImagesPreferences.PREF_SHOW_BACKGROUND_IMAGES)) {
BravePrefServiceBridge.getInstance().setBoolean(BravePref.NTP_SHOW_BACKGROUND_IMAGE,
sharedPreferences.getBoolean(BackgroundImagesPreferences.PREF_SHOW_BACKGROUND_IMAGES, true));
BravePrefServiceBridge.getInstance().setBoolean(BravePref.NTP_SHOW_BRANDED_BACKGROUND_IMAGE,
BravePrefServiceBridge.getInstance().setBoolean(BravePref.NTP_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE,
sharedPreferences.getBoolean(BackgroundImagesPreferences.PREF_SHOW_SPONSORED_IMAGES, true));
}

Expand Down
6 changes: 6 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_THEMES" desc="The label for brave theme change setting options">
Brave colors
</message>
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_GET_MORE_THEMES" desc="The label for opening theme web store">
Get more themes
</message>
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_DEFAULT_IMAGES_OPTION_LABEL" desc="The label for choosing default images over super referral">
Brave default images
</message>
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_LOCATION_BAR_IS_WIDE" desc="The label for whether the location bar should display wide or not">
Use wide address bar
</message>
Expand Down
6 changes: 4 additions & 2 deletions browser/android/preferences/brave_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.preferences
enum BravePref {
NTP_SHOW_BRANDED_BACKGROUND_IMAGE = 10000,
NTP_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE = 10000,
NTP_SHOW_SUPER_REFERRAL_THEMES_OPTION,
NTP_SHOW_BACKGROUND_IMAGE,
// BRAVE_PREF_NUM_PREFS must be the last entry.
BRAVE_PREF_NUM_PREFS
};

// The indices must match value of Pref.
const char* const kBravePrefsExposedToJava[] = {
ntp_background_images::prefs::kNewTabPageShowBrandedBackgroundImage,
ntp_background_images::prefs::kNewTabPageShowSponsoredImagesBackgroundImage,
ntp_background_images::prefs::kNewTabPageSuperReferralThemesOption,
ntp_background_images::prefs::kNewTabPageShowBackgroundImage,
};

Expand Down
10 changes: 9 additions & 1 deletion browser/brave_browser_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/services/network/public/cpp/system_request_handler.h"
#include "chrome/browser/component_updater/component_updater_utils.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_paths.h"
#include "components/component_updater/component_updater_service.h"
#include "components/component_updater/timer_update_scheduler.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

#if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS)
#include "chrome/browser/notifications/notification_platform_bridge.h"
Expand Down Expand Up @@ -229,8 +231,14 @@ BraveBrowserProcessImpl::ntp_background_images_service() {
return nullptr;

if (!ntp_background_images_service_) {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
ntp_background_images_service_ =
std::make_unique<NTPBackgroundImagesService>(component_updater());
std::make_unique<NTPBackgroundImagesService>(
component_updater(),
local_state(),
user_data_dir);
ntp_background_images_service_->Init();
}

return ntp_background_images_service_.get();
Expand Down
3 changes: 3 additions & 0 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "brave/components/p3a/buildflags.h"
#include "chrome/browser/first_run/first_run.h"
Expand Down Expand Up @@ -44,6 +45,8 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
brave_shields::RegisterPrefsForAdBlockService(registry);
RegisterPrefsForBraveStatsUpdater(registry);
registry->RegisterBooleanPref(kRemoteDebuggingEnabled, false);
ntp_background_images::NTPBackgroundImagesService::RegisterLocalStatePrefs(
registry);
#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
RegisterPrefsForBraveReferralsService(registry);
#endif
Expand Down
3 changes: 0 additions & 3 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_utils.h"
#include "brave/components/speedreader/buildflags.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefs/session_startup_pref.h"
Expand Down Expand Up @@ -193,8 +192,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// IPFS companion extension
registry->RegisterBooleanPref(kIPFSCompanionEnabled, false);

ntp_background_images::RegisterProfilePrefs(registry);

// New Tab Page
registry->RegisterBooleanPref(kNewTabPageShowClock, true);
registry->RegisterBooleanPref(kNewTabPageShowTopSites, true);
Expand Down
9 changes: 7 additions & 2 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
#include "brave/components/brave_wayback_machine/pref_names.h"
#endif


namespace extensions {

using ntp_background_images::prefs::kNewTabPageShowBrandedBackgroundImage;
using ntp_background_images::prefs::kNewTabPageSuperReferralThemesOption;
using
ntp_background_images::prefs::kNewTabPageShowSponsoredImagesBackgroundImage;
using ntp_background_images::prefs::kNewTabPageShowBackgroundImage;

namespace settings_api = api::settings_private;
Expand Down Expand Up @@ -66,8 +69,10 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kAskWidevineInstall] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageSuperReferralThemesOption] =
settings_api::PrefType::PREF_TYPE_NUMBER;
// new tab prefs
(*s_brave_whitelist)[kNewTabPageShowBrandedBackgroundImage] =
(*s_brave_whitelist)[kNewTabPageShowSponsoredImagesBackgroundImage] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageShowBackgroundImage] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ NTPBackgroundImagesBridge::GetCurrentWallpaper(
}

void NTPBackgroundImagesBridge::OnUpdated(NTPBackgroundImagesData* data) {
// Don't have interest about in-effective component data update.
if (data != view_counter_service_->GetCurrentBrandedWallpaperData())
return;

JNIEnv* env = AttachCurrentThread();
Java_NTPBackgroundImagesBridge_onUpdated(env, java_object_);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/md_select_css.html">
<link rel="import" href="chrome://brave-resources/br_elements/br_toolbar/br_toolbar.html">
<link rel="import" href="brave_appearance_browser_proxy.html">
<link rel="import" href="../controls/settings_radio_group.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">
<link rel="import" href="../page_visibility.html">

<dom-module id="settings-brave-appearance-theme">
<template>
<style include="settings-shared md-select iron-flex">
Expand All @@ -21,9 +25,88 @@
</template>
</select>
</div>
<template is="dom-if" if="[[useThemesSubPage_()]]">
<cr-link-row class="hr" id="themes-subpage-trigger"
label="$i18n{themes}" on-click="onThemeTap_"
role-description="$i18n{subpageArrowRoleDescription}">
</cr-link-row>
</template>
</template>
<script src="brave_appearance_page.js"></script>
</dom-module>

<dom-module id="settings-brave-appearance-super-referral">
<template>
<style include="settings-shared md-select iron-flex">
/* The theme mixes a link and a cr-button divided by a separator with
* grit expressions and dom-if templates. That leads to a tricky thing
* to style correctly, these are a workaround. */
#themeRow cr-button {
margin-inline-end: 20px;
}

#themeRow .separator {
margin-inline-start: 0;
}

.radio-group {
margin-left: 80px;
margin-bottom: 20px;
}
</style>

<div class="radio-group">
<settings-radio-group
pref="{{prefs.brave.new_tab_page.super_referral_themes_option}}">
<controlled-radio-button name="[[themeValues_.DEFAULT]]"
pref="{{prefs.brave.new_tab_page.super_referral_themes_option}}"
label="$i18n{appearanceBraveDefaultImagesOptionLabel}">
</controlled-radio-button>
<controlled-radio-button name="[[themeValues_.SUPER_REFERRAL]]"
pref="{{prefs.brave.new_tab_page.super_referral_themes_option}}"
label="[[getSuperReferralThemeName_()]]">
</controlled-radio-button>
</settings-radio-group>
</div>
<div class="settings-box block first">
<div class="hr settings-row continuation" id="themeRow">
<cr-link-row class="label first"
label="$i18n{appearanceSettingsGetMoreThemes}"
sub-label="[[themeSublabel_]]"
on-click="openThemeUrl_" external></cr-link-row>
<if expr="not is_linux">
<template is="dom-if" if="[[prefs.extensions.theme.id.value]]">
<div class="separator"></div>
<cr-button id="useDefault" on-click="onUseDefaultTap_">
$i18n{resetToDefaultTheme}
</cr-button>
</template>
</if>
<if expr="is_linux">
<div class="settings-row continuation"
hidden="[[!showThemesSecondary_(
prefs.extensions.theme.id.value, useSystemTheme_)]]"
id="themesSecondaryActions">
<div class="separator"></div>
<template is="dom-if" if="[[showUseClassic_(
prefs.extensions.theme.id.value, useSystemTheme_)]]" restamp>
<cr-button id="useDefault" on-click="onUseDefaultTap_">
$i18n{useClassicTheme}
</cr-button>
</template>
<template is="dom-if" if="[[showUseSystem_(
prefs.extensions.theme.id.value, useSystemTheme_)]]" restamp>
<cr-button id="useSystem" on-click="onUseSystemTap_">
$i18n{useSystemTheme}
</cr-button>
</template>
</div>
</if>
</div>
</div>
</template>
</dom-module>

<dom-module id="settings-brave-appearance-toolbar">
<template>
<style include="settings-shared md-select iron-flex">
Expand Down
Loading