Skip to content

Commit

Permalink
NTP: Add settings section for Dashboard options
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto authored and simonhong committed Apr 13, 2020
1 parent 703f005 commit 11c598a
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 3 deletions.
28 changes: 28 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,34 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_APPEARANCE_SETTINGS_SHOW_AUTOCOMPLETE_IN_ADDRESS_BAR" desc="The label for settings switch controlling the showing of autocomplete in address bar">
Show autocomplete in address bar
</message>
<!-- New Tab Page -->
<message name="IDS_SETTINGS_NEW_TAB" desc="The text label for the New Tab settings page">
New Tab Page
</message>
<message name="IDS_SETTINGS_NEW_TAB_CUSTOMIZE_BRAVE_DASHBOARD" desc="The description label for Dashboard Customization">
Customize your Brave Dashboard
</message>
<message name="IDS_SETTINGS_NEW_TAB_BACKGROUND_IMAGES" desc="The label for Background images show/hide feature toggle">
Background images
</message>
<message name="IDS_SETTINGS_NEW_TAB_SPONSORED_IMAGES" desc="The label for Sponsored images show/hide feature toggle">
Sponsored images
</message>
<message name="IDS_SETTINGS_NEW_TAB_STATS" desc="The label for Stats show/hide feature toggle">
Brave Stats
</message>
<message name="IDS_SETTINGS_NEW_TAB_BRAVE_REWARDS" desc="The label for Brave Rewards show/hide feature toggle">
Brave Rewards
</message>
<message name="IDS_SETTINGS_NEW_TAB_BINANCE" desc="The label for Binance show/hide feature toggle">
Binance
</message>
<message name="IDS_SETTINGS_NEW_TAB_TOP_SITES" desc="The label for Top Sites show/hide feature toggle">
Top Sites
</message>
<message name="IDS_SETTINGS_NEW_TAB_CLOCK" desc="The label for Clock show/hide feature toggle">
Clock
</message>
<!-- Tor -->
<message name="IDS_NEW_TOR_IDENTITY" desc="The text label of a menu item for requesting new Tor identity">
New Tor Identity
Expand Down
16 changes: 16 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "brave/common/pref_names.h"
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/ntp_background_images/common/pref_names.h"
#include "chrome/browser/extensions/api/settings_private/prefs_util.h"
#include "chrome/common/extensions/api/settings_private.h"
#include "components/browsing_data/core/pref_names.h"
Expand Down Expand Up @@ -62,6 +63,21 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kAskWidevineInstall] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// new tab prefs
(*s_brave_whitelist)[ntp_background_images::prefs::kNewTabPageShowBrandedBackgroundImage] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[ntp_background_images::prefs::kNewTabPageShowBackgroundImage] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageShowClock] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageShowTopSites] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageShowStats] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageShowRewards] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_brave_whitelist)[kNewTabPageShowBinance] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// Clear browsing data on exit prefs.
(*s_brave_whitelist)[browsing_data::prefs::kDeleteBrowsingHistoryOnExit] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
Expand Down
4 changes: 4 additions & 0 deletions browser/resources/settings/brave_icons.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z"></path>
</g>
<g id="new-tab" viewBox="0 0 24 24">
<path
d="M20.125 3c.896 0 1.625.73 1.625 1.625V19.25c0 .896-.73 1.625-1.625 1.625H3.875c-.896 0-1.625-.73-1.625-1.625V4.625C2.25 3.729 2.98 3 3.875 3h16.25zm0 4.875H3.875V19.25h16.25V7.875zM12 9.5c.449 0 .813.364.813.813l-.001 2.437h2.438a.812.812 0 110 1.625h-2.438v2.438a.812.812 0 11-1.624 0l-.001-2.438H8.75a.812.812 0 110-1.625h2.437v-2.438c0-.448.364-.812.813-.812zm8.125-4.875H3.875V6.25h16.25V4.625z" />
</g>
<g id="reset-settings" viewBox="0 0 24 24">
<path
d="M20.292 3.71l-1.234 1.234a9.965 9.965 0 0 0-8.846-2.785c-4.03.704-7.29 3.92-8.035 7.942-1.178 6.346 3.686 11.902 9.822 11.902 5.134 0 9.378-3.89 9.938-8.879a1.009 1.009 0 0 0-1-1.12c-.5 0-.93.367-.985.864-.433 4.005-3.833 7.135-7.953 7.135-4.941 0-8.85-4.5-7.84-9.62.608-3.08 3.074-5.57 6.149-6.204a7.978 7.978 0 0 1 7.334 2.181l-.936.936a1 1 0 0 0 .707 1.707H21a1 1 0 0 0 1-1V4.418a1 1 0 0 0-1.707-.708z" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="href" src="chrome://resources/html/cr.html">
<script src="brave_new_tab_browser_proxy.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* 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/. */

cr.define('settings', function() {
/** @interface */
class BraveNewTabBrowserProxy {}

/**
* @implements {settings.BraveNewTabBrowserProxy}
*/
class BraveNewTabBrowserProxyImpl {}

cr.addSingletonGetter(BraveNewTabBrowserProxyImpl);

return {
BraveNewTabBrowserProxy,
BraveNewTabBrowserProxyImpl
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<link rel="import" href="chrome://resources/html/polymer.html">

<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="brave_new_tab_browser_proxy.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">

<dom-module id="settings-brave-new-tab-page">
<template>
<style include="settings-shared md-select iron-flex">
.primary-title {
font-weight: 700;
padding-top: 1em;
font-size: 1.05em;
}
.nested-section {
margin-inline-start: 1.5em;
margin-top: -0.5em;
}
.borderless {
border: none;
}
.normalize-margin {
margin: 0 -1.5em 1em;
}
</style>
<div class="settings-box first">
<div class="flex">
<div class="label primary-title">$i18n{braveNewTabCustomizeDashboard}</div>
<div class="normalize-margin">
<settings-toggle-button id="showBackgroundImageControlType"
class="secondary borderless"
pref="{{prefs.brave.new_tab_page.show_background_image}}"
label="$i18n{braveNewTabBackgroundImages}">
</settings-toggle-button>
<settings-toggle-button
class="nested-section borderless"
pref="[[toggleBrandedBackgroundOption_(prefs.brave.new_tab_page.show_background_image.value, prefs.brave.new_tab_page.show_branded_background_image)]]"
disabled="{{!prefs.brave.new_tab_page.show_background_image.value}}"
label="$i18n{braveNewTabSponsoredImages}">
</settings-toggle-button>
</div>
</div>
</div>
<div class="flex">
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_stats}}"
label="$i18n{braveNewTabStats}">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_rewards}}"
label="$i18n{braveNewTabBraveRewards}">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_binance}}"
label="$i18n{braveNewTabBinance}">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_top_sites}}"
label="$i18n{braveNewTabTopSites}">
</settings-toggle-button>
<settings-toggle-button
pref="{{prefs.brave.new_tab_page.show_clock}}"
label="$i18n{braveNewTabClock}">
</settings-toggle-button>
</div>
</template>
<script src="brave_new_tab_page.js"></script>
</dom-module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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/. */

(function() {
'use strict';

/**
* 'settings-brave-new-tab-page' is the settings page containing
* brave's new tab features.
*/
Polymer({
is: 'settings-brave-new-tab-page',

/** @private {?settings.BraveNewTabBrowserProxy} */
browserProxy_: null,

/** @override */
created: function() {
this.browserProxy_ = settings.BraveNewTabBrowserProxyImpl.getInstance();
},

toggleBrandedBackgroundOption_: function(isBackgroundEnabled, isBrandedBackgroundEnabled) {
// If background image setting is not turned ON,
// inform the back-end to also disable the branded wallpaper setting.
// We will later disable interacting with the button as well.
if (isBackgroundEnabled === false) {
return {
key: 'brave.new_tab_page.show_branded_background_image',
type: 'BOOLEAN',
value: false
};
}
return isBrandedBackgroundEnabled;
},
});
})();
1 change: 1 addition & 0 deletions browser/resources/settings/brave_settings_overrides.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<link rel="import" href="social_blocking_page/social_blocking_page.html">
<link rel="import" href="brave_sync_page/brave_sync_page.html">
<link rel="import" href="brave_help_tips_page/brave_help_tips_page.html">
<link rel="import" href="brave_new_tab_page/brave_new_tab_page.html">

<dom-module id="brave-settings-getting-started">
<template>
Expand Down
21 changes: 18 additions & 3 deletions browser/resources/settings/brave_settings_overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,16 @@ BravePatching.RegisterPolymerTemplateModifications({
// Move Appearance item
const appearanceBrowserEl = getMenuElement(templateContent, '/appearance')
getStartedEl.insertAdjacentElement('afterend', appearanceBrowserEl)
// Add New Tab item
const newTabEl = createMenuElement(loadTimeData.getString('braveNewTab'), '/braveNewTab', 'brave_settings:new-tab')
appearanceBrowserEl.insertAdjacentElement('afterend', newTabEl)
// Add Sync and Help Tips item
const helpTipsEl = createMenuElement(loadTimeData.getString('braveHelpTips'), '/braveHelpTips', 'brave_settings:help')
if (loadTimeData.getBoolean('isSyncDisabled')) {
appearanceBrowserEl.insertAdjacentElement('afterend', helpTipsEl)
newTabEl.insertAdjacentElement('afterend', helpTipsEl)
} else {
const syncEl = createMenuElement(loadTimeData.getString('braveSync'), '/braveSync', 'brave_settings:sync')
appearanceBrowserEl.insertAdjacentElement('afterend', syncEl)
newTabEl.insertAdjacentElement('afterend', syncEl)
syncEl.insertAdjacentElement('afterend', helpTipsEl)
}
// Add Shields item
Expand Down Expand Up @@ -242,6 +245,7 @@ BravePatching.RegisterPolymerTemplateModifications({
r.EXTENSIONS = r.BASIC.createSection('/extensions', 'extensions')
r.BRAVE_SYNC = r.BASIC.createSection('/braveSync', 'braveSync')
r.BRAVE_HELP_TIPS = r.BASIC.createSection('/braveHelpTips', 'braveHelpTips')
r.BRAVE_NEW_TAB = r.BASIC.createSection('/braveNewTab', 'braveNewTab')
if (!r.SITE_SETTINGS) {
console.error('[Brave Settings Overrides] Routes: could not find SITE_SETTINGS page')
}
Expand Down Expand Up @@ -327,13 +331,24 @@ BravePatching.RegisterPolymerTemplateModifications({
<settings-brave-help-tips-page prefs="{{prefs}}"></settings-brave-help-tips-page>
</settings-section>
`
const sectionNewTab = document.createElement('template')
sectionNewTab.setAttribute('is', 'dom-if')
sectionNewTab.setAttribute('restamp', true)
sectionNewTab.setAttribute('if', '[[showPage_(pageVisibility.braveNewTab)]]')
sectionNewTab.innerHTML = `
<settings-section page-title="${loadTimeData.getString('braveNewTab')}" section="braveNewTab">
<settings-brave-new-tab-page prefs="{{prefs}}"></settings-brave-new-tab-page>
</settings-section>
`
// Get Started at top
basicPageEl.insertAdjacentElement('afterbegin', sectionGetStarted)
// Move Appearance item
const sectionAppearance = getSectionElement(actualTemplate.content, 'appearance')
sectionGetStarted.insertAdjacentElement('afterend', sectionAppearance)
// Insert New Tab
sectionAppearance.insertAdjacentElement('afterend', sectionNewTab)
// Insert sync
sectionAppearance.insertAdjacentElement('afterend', sectionSync)
sectionNewTab.insertAdjacentElement('afterend', sectionSync)
// Insert shields
sectionSync.insertAdjacentElement('afterend', sectionShields)
// Insert Social Blocking
Expand Down
5 changes: 5 additions & 0 deletions browser/resources/settings/settings_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<structure name="IDR_SETTINGS_BRAVE_DEFAULT_EXTENSIONS_BROWSER_PROXY_JS" file="brave_default_extensions_page/brave_default_extensions_browser_proxy.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_BRAVE_DEFAULT_EXTENSIONS_PAGE_JS" file="brave_default_extensions_page/brave_default_extensions_page.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_BRAVE_DEFAULT_EXTENSIONS_PAGE_HTML" file="brave_default_extensions_page/brave_default_extensions_page.html" type="chrome_html" preprocess="true" allowexternalscript="true" />
<!-- brave new tab -->
<structure name="IDR_SETTINGS_BRAVE_NEW_TAB_BROWSER_PROXY_HTML" file="brave_new_tab_page/brave_new_tab_browser_proxy.html" type="chrome_html" />
<structure name="IDR_SETTINGS_BRAVE_NEW_TAB_BROWSER_PROXY_JS" file="brave_new_tab_page/brave_new_tab_browser_proxy.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_BRAVE_NEW_TAB_PAGE_JS" file="brave_new_tab_page/brave_new_tab_page.js" type="chrome_html" preprocess="true" />
<structure name="IDR_SETTINGS_BRAVE_NEW_TAB_PAGE_HTML" file="brave_new_tab_page/brave_new_tab_page.html" type="chrome_html" preprocess="true" allowexternalscript="true" />
</structures>
<includes>
<include name="IDR_SETTINGS_BRAVE_STAMP" file="brave_unpack.stamp" type="BINDATA" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_HELP_TIPS},
{"braveHelpTipsWaybackMachineLabel",
IDS_SETTINGS_HELP_TIPS_SHOW_BRAVE_WAYBACK_MACHINE_PROMPT},
// New Tab Page
{ "braveNewTab", IDS_SETTINGS_NEW_TAB },
{ "braveNewTabCustomizeDashboard", IDS_SETTINGS_NEW_TAB_CUSTOMIZE_BRAVE_DASHBOARD },
{ "braveNewTabBackgroundImages", IDS_SETTINGS_NEW_TAB_BACKGROUND_IMAGES },
{ "braveNewTabSponsoredImages", IDS_SETTINGS_NEW_TAB_SPONSORED_IMAGES },
{ "braveNewTabStats", IDS_SETTINGS_NEW_TAB_STATS },
{ "braveNewTabBraveRewards", IDS_SETTINGS_NEW_TAB_BRAVE_REWARDS },
{ "braveNewTabBinance", IDS_SETTINGS_NEW_TAB_BINANCE },
{ "braveNewTabTopSites", IDS_SETTINGS_NEW_TAB_TOP_SITES },
{ "braveNewTabClock", IDS_SETTINGS_NEW_TAB_CLOCK },
// Misc (TODO: Organize this)
{"onExitPageTitle",
IDS_SETTINGS_BRAVE_ON_EXIT},
{"braveDefaultExtensions",
Expand Down

0 comments on commit 11c598a

Please sign in to comment.