Skip to content

Commit

Permalink
Add Rewards settings to brave://settings
Browse files Browse the repository at this point in the history
  • Loading branch information
emerick committed Oct 27, 2021
1 parent a72fdc4 commit 84588e3
Show file tree
Hide file tree
Showing 27 changed files with 722 additions and 16 deletions.
67 changes: 67 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,73 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_BRAVE_OTHER_SEARCH_ENGINES_DESC" desc="The description for the settings switch controlling the addition of custom search engines">
Automatically indexes websites that follow the OpenSearch spec.
</message>
<!-- Settings / Rewards -->
<message name="IDS_SETTINGS_BRAVE_REWARDS_TITLE" desc="The text label for the Rewards settings page">
Brave Rewards
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_DISABLED_LABEL" desc="The text label for the Rewards disabled state">
Brave Rewards are disabled
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_DISABLED_SUB_LABEL" desc="The text sublabel for the Rewards disabled state">
Click here to learn more
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_DETECTED_ITEM" desc="The menu item for auto-detected settings">
Auto-detected
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_DEFAULT_ITEM" desc="The menu item for default settings">
Default
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_DISABLED_ITEM" desc="The menu item for disabled settings">
Disabled
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_PRIVATE_ADS_TITLE" desc="The text label for the Rewards Private Ads section">
Brave Private Ads
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_PRIVATE_ADS_EARN_TOKENS_LABEL" desc="The text label for the settings switch controlling earning tokens for viewing private ads">
Earn tokens by viewing Brave Ads. Ads presented are based on your interests, as inferred from your browsing behavior. No personal data or browsing history ever leaves your browser.
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_MAX_ADS_TO_DISPLAY_LABEL" desc="The text label for the setting controlling the maximum number of ads to display">
Maximum number of ads to display
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_STATE_LEVEL_AD_TARGETING_LABEL" desc="The text label for the setting controlling subdivision-level ad targeting">
State-level ad targeting
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_STATE_LEVEL_AD_TARGETING_DESC_LABEL" desc="The text label for the description of subdivision-level ad targeting">
This allows Brave to show you ads meant specifically for your state.
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_TITLE" desc="The text label for the Rewards Auto-Contribute section">
Auto-Contribute
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_MONTHLY_LIMIT_LABEL" desc="The text label for the setting controlling the monthly auto-contribution limit">
Monthly auto-contribution limit
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_MIN_VISIT_TIME_LABEL" desc="The text label for the setting controlling the minimum page time before logging a visit">
Minimum page time before logging a visit
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_MIN_VISITS_LABEL" desc="The text label for the setting controlling the minimum page visits for publisher relevancy">
Minimum visits for publisher relevancy
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_SHOW_NON_VERIFIED_SITES_LABEL" desc="The text label for the setting controlling showing non-verified sites in the auto-contribution list">
Show non-verified sites in list
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_ALLOW_VIDEO_CONTRIBUTIONS_LABEL" desc="The text label for the setting controlling allowing contributions for videos">
Allow contributions to videos
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_AUTO_CONTRIBUTE_DESC_LABEL" desc="The text label for the description of auto-contribute">
By turning on Auto-Contribute, you agree to the <ph name="BEGIN_LINK_TOS">&lt;a target="_blank" href="$1"&gt;</ph>Terms of Service<ph name="END_LINK_TOS">&lt;/a&gt;</ph> and <ph name="BEGIN_LINK_PP">&lt;a target="_blank" href="$2"&gt;</ph>Privacy Policy<ph name="END_LINK_PP">&lt;/a&gt;</ph>.
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_TIP_BUTTONS_TITLE" desc="The text label for the Rewards Tip Buttons section">
Tip buttons
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_INLINE_TIP_REDDIT_LABEL" desc="The text label for the setting switch controlling showing inline tip buttons on Reddit">
Reddit
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_INLINE_TIP_TWITTER_LABEL" desc="The text label for the setting switch controlling showing inline tip buttons on Twitter">
Twitter
</message>
<message name="IDS_SETTINGS_BRAVE_REWARDS_INLINE_TIP_GITHUB_LABEL" desc="The text label for the setting switch controlling showing inline tip buttons on Github">
Github
</message>
<!-- New Tab Page -->
<message name="IDS_SETTINGS_NEW_TAB" desc="The text label for the New Tab settings page">
New Tab Page
Expand Down
8 changes: 8 additions & 0 deletions browser/extensions/api/brave_rewards_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/l10n/browser/locale_helper.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "chrome/browser/extensions/extension_service.h"
Expand All @@ -45,6 +46,13 @@ using brave_rewards::RewardsServiceFactory;
namespace extensions {
namespace api {

BraveRewardsGetLocaleFunction::~BraveRewardsGetLocaleFunction() {}

ExtensionFunction::ResponseAction BraveRewardsGetLocaleFunction::Run() {
std::string locale = brave_l10n::LocaleHelper::GetInstance()->GetLocale();
return RespondNow(OneArgument(base::Value(std::move(locale))));
}

BraveRewardsOpenBrowserActionUIFunction::
~BraveRewardsOpenBrowserActionUIFunction() {
}
Expand Down
10 changes: 10 additions & 0 deletions browser/extensions/api/brave_rewards_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
namespace extensions {
namespace api {

class BraveRewardsGetLocaleFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveRewards.getLocale", UNKNOWN)

protected:
~BraveRewardsGetLocaleFunction() override;

ResponseAction Run() override;
};

class BraveRewardsOpenBrowserActionUIFunction :
public ExtensionFunction {
public:
Expand Down
29 changes: 29 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "brave/browser/extensions/api/settings_private/brave_prefs_util.h"

#include "bat/ads/pref_names.h"
#include "brave/browser/ethereum_remote_client/buildflags/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_rewards/common/pref_names.h"
Expand Down Expand Up @@ -117,6 +118,34 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() {
(*s_brave_allowlist)[brave_shields::prefs::kLinkedInEmbedControlType] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;

// Rewards/Ads prefs
(*s_brave_allowlist)[ads::prefs::kEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[ads::prefs::kAdsPerHour] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_brave_allowlist)[ads::prefs::kAdsSubdivisionTargetingCode] =
settings_api::PrefType::PREF_TYPE_STRING;
(*s_brave_allowlist)[brave_rewards::prefs::kEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_rewards::prefs::kAutoContributeEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_rewards::prefs::kAutoContributeAmount] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_brave_allowlist)[brave_rewards::prefs::kMinVisitTime] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_brave_allowlist)[brave_rewards::prefs::kMinVisits] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_brave_allowlist)[brave_rewards::prefs::kAllowNonVerified] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_rewards::prefs::kAllowVideoContribution] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_rewards::prefs::kInlineTipRedditEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_rewards::prefs::kInlineTipTwitterEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_allowlist)[brave_rewards::prefs::kInlineTipGithubEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;

// Search engine prefs
(*s_brave_allowlist)[prefs::kAddOpenSearchEngines] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
Expand Down
5 changes: 5 additions & 0 deletions browser/resources/settings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ preprocess_if_expr("preprocess_generated") {
"brave_new_tab_page/brave_new_tab_page.m.js",
"brave_privacy_page/brave_personalization_options.m.js",
"brave_privacy_page/brave_privacy_page_browser_proxy.m.js",
"brave_rewards_page/brave_rewards_browser_proxy.m.js",
"brave_rewards_page/brave_rewards_page.js",
"brave_search_engines_page/brave_search_engines_page.m.js",
"brave_sync_page/brave_sync_code_dialog.js",
"brave_sync_page/brave_sync_configure.js",
Expand Down Expand Up @@ -236,6 +238,8 @@ ts_library("build_ts") {
"brave_privacy_page/brave_personalization_options.m.js",
"brave_privacy_page/brave_privacy_page_browser_proxy.m.js",
"brave_reset_page/brave_reset_profile_dialog_behavior.js",
"brave_rewards_page/brave_rewards_browser_proxy.m.js",
"brave_rewards_page/brave_rewards_page.js",
"brave_routes.js",
"brave_search_engines_page/brave_search_engines_page.m.js",
"brave_sync_page/brave_sync_browser_proxy.js",
Expand Down Expand Up @@ -284,6 +288,7 @@ group("web_modules") {
"brave_ipfs_page:web_modules",
"brave_new_tab_page:web_modules",
"brave_privacy_page:web_modules",
"brave_rewards_page:web_modules",
"brave_search_engines_page:web_modules",
"brave_sync_page:web_modules",
"brave_wallet_page:web_modules",
Expand Down
6 changes: 6 additions & 0 deletions browser/resources/settings/brave_icons.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<path
d="M11.188 1.361l-7 3.111A1.999 1.999 0 0 0 3 6.3V11c0 7.83 6.439 11.486 9 12 2.561-.514 9-4.17 9-12V6.3a2 2 0 0 0-1.188-1.828l-7-3.111a1.997 1.997 0 0 0-1.624 0zm-.895 14.346l-2.77-2.77a1 1 0 0 1 1.414-1.414L11 13.586l5.085-5.085a1 1 0 0 1 1.414 1.414l-5.792 5.792a1 1 0 0 1-1.414 0z" />
</g>
<g id="rewards" viewBox="0 0 24 24">
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.03697 20.985L7.4778 17.2013L11.9181 9.41949V1.91658C11.801 1.91658 11.6839 1.99467 11.595 2.14999L6.33531 11.3679L1.07601 20.5858C0.987365 20.7413 0.978953 20.8824 1.03697 20.985"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.9182 1.91658V9.41949L16.3583 17.2013L22.7991 20.985C22.8574 20.8824 22.8489 20.7413 22.7603 20.5858L17.5008 11.3679L12.2411 2.14999C12.1522 1.99445 12.0351 1.91658 11.9182 1.91658"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M22.7992 20.985L16.3584 17.2013H7.4779L1.03708 20.985C1.0951 21.088 1.21998 21.1519 1.39771 21.1519H22.4383C22.6161 21.1519 22.7409 21.088 22.7992 20.985"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M7.47787 17.2013H16.3583L11.9182 9.41951L7.47787 17.2013Z" fill="white"/>
</g>
<g id="social-permissions" viewBox="0 0 24 24">
<path
d="M2.75 3c-.414 0-.75.42-.75.938v9.374c0 .518.336.938.75.938h1.5c.414 0 .75-.42.75-.938V3.938C5 3.42 4.664 3 4.25 3h-1.5zm6.125 0A1.866 1.866 0 0 0 7 4.857v9.278c0 .492.197.963.547 1.31l5.185 5.146a1.417 1.417 0 0 0 1.67.239c.548-.297.834-.916.7-1.52l-.932-4.24h5.955A1.866 1.866 0 0 0 22 13.215v-1.855c0-.253-.051-.502-.152-.734l-2.82-6.5A1.876 1.876 0 0 0 17.305 3h-8.43z" />
Expand Down
18 changes: 16 additions & 2 deletions browser/resources/settings/brave_overrides/basic_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../brave_default_extensions_page/brave_default_extensions_page.m.js'
import '../brave_help_tips_page/brave_help_tips_page.m.js'
import '../brave_ipfs_page/brave_ipfs_page.m.js'
import '../brave_new_tab_page/brave_new_tab_page.m.js'
import '../brave_rewards_page/brave_rewards_page.js'
import '../brave_search_engines_page/brave_search_engines_page.m.js'
import '../brave_sync_page/brave_sync_page.js'
import '../brave_wallet_page/brave_wallet_page.m.js'
Expand Down Expand Up @@ -136,7 +137,6 @@ RegisterPolymerTemplateModifications({
'settings-brave-sync-page',
{}
))

const sectionShields = document.createElement('template')
sectionShields.setAttribute('is', 'dom-if')
sectionShields.setAttribute('restamp', true)
Expand All @@ -149,6 +149,18 @@ RegisterPolymerTemplateModifications({
prefs: '{{prefs}}'
}
))
const sectionRewards = document.createElement('template')
sectionRewards.setAttribute('is', 'dom-if')
sectionRewards.setAttribute('restamp', true)
sectionRewards.setAttribute('if', '[[showPage_(pageVisibility.rewards)]]')
sectionRewards.content.appendChild(createSectionElement(
'rewards',
'braveRewards',
'settings-brave-rewards-page',
{
prefs: '{{prefs}}'
}
))
const sectionSocialBlocking = document.createElement('template')
sectionSocialBlocking.setAttribute('is', 'dom-if')
sectionSocialBlocking.setAttribute('restamp', true)
Expand Down Expand Up @@ -194,8 +206,10 @@ RegisterPolymerTemplateModifications({
sectionAppearance.insertAdjacentElement('afterend', sectionNewTab)
// Insert shields
sectionNewTab.insertAdjacentElement('afterend', sectionShields)
// Insert Rewards
sectionShields.insertAdjacentElement('afterend', sectionRewards)
// Insert Social Blocking
sectionShields.insertAdjacentElement('afterend', sectionSocialBlocking)
sectionRewards.insertAdjacentElement('afterend', sectionSocialBlocking)
// Move privacy section to after social blocking
const sectionPrivacy = getSectionElement(actualTemplate.content, 'privacy')
sectionSocialBlocking.insertAdjacentElement('afterend', sectionPrivacy)
Expand Down
10 changes: 9 additions & 1 deletion browser/resources/settings/brave_overrides/settings_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,22 @@ RegisterPolymerTemplateModifications({
'shields',
)
newTabEl.insertAdjacentElement('afterend', shieldsEl)
// Add Rewards item
const rewardsEl = createMenuElement(
loadTimeData.getString('braveRewards'),
'/rewards',
'brave_settings:rewards',
'rewards',
)
shieldsEl.insertAdjacentElement('afterend', rewardsEl)
// Add Embed Blocking item
const embedEl = createMenuElement(
loadTimeData.getString('socialBlocking'),
'/socialBlocking',
'brave_settings:social-permissions',
'socialBlocking',
)
shieldsEl.insertAdjacentElement('afterend', embedEl)
rewardsEl.insertAdjacentElement('afterend', embedEl)
// Add privacy
const privacyEl = getMenuElement(templateContent, '/privacy')
embedEl.insertAdjacentElement('afterend', privacyEl)
Expand Down
26 changes: 26 additions & 0 deletions browser/resources/settings/brave_rewards_page/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2021 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/.

import("//tools/polymer/html_to_js.gni")
import("//ui/webui/resources/tools/js_modulizer.gni")
import("../settings.gni")

# ES Module conversion from HTML Imports code

group("web_modules") {
public_deps = [
":modules",
":templatize",
]
}

html_to_js("templatize") {
js_files = [ "brave_rewards_page.js" ]
}

js_modulizer("modules") {
input_files = [ "brave_rewards_browser_proxy.js" ]
namespace_rewrites = settings_namespace_rewrites
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script src="brave_rewards_browser_proxy.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2021 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/. */

import {addSingletonGetter} from 'chrome://resources/js/cr.m.js';

/** @interface */
export class BraveRewardsBrowserProxy {
getLocale() { /* Intentionally empty */ }
getRewardsEnabled() { /* Intentionally empty */ }
getRewardsParameters() { /* Intentionally empty */ }
}

/**
* @implements {settings.BraveRewardsBrowserProxy}
*/
export class BraveRewardsBrowserProxyImpl {
/** @override */
getLocale () {
return new Promise((resolve) => chrome.braveRewards.getLocale(
(locale) => { resolve(locale) }))
}
/** @override */
getRewardsEnabled () {
return new Promise((resolve) => chrome.braveRewards.getRewardsEnabled(
(enabled) => { resolve(enabled) }))
}
/** @override */
getRewardsParameters () {
return new Promise((resolve) => chrome.braveRewards.getRewardsParameters(
(parameters) => { resolve(parameters) }))
}
}

addSingletonGetter(BraveRewardsBrowserProxyImpl)
Loading

0 comments on commit 84588e3

Please sign in to comment.