Skip to content

Commit

Permalink
Refactored shields settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
taher authored and petemill committed May 16, 2022
1 parent 0cc4843 commit 1f9a690
Show file tree
Hide file tree
Showing 21 changed files with 1,444 additions and 300 deletions.
6 changes: 5 additions & 1 deletion browser/resources/settings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ preprocess_if_expr("preprocess") {
"brave_reset_page/brave_reset_profile_dialog_behavior.js",
"brave_routes.js",
"brave_sync_page/brave_sync_browser_proxy.js",
"default_brave_shields_page/brave_adblock_browser_proxy.js",
]
}

Expand Down Expand Up @@ -164,7 +165,10 @@ preprocess_if_expr("preprocess_generated") {
"brave_wallet_page/brave_wallet_page.js",
"brave_wallet_page/wallet_networks_subpage.js",
"default_brave_shields_page/default_brave_shields_browser_proxy.m.js",
"default_brave_shields_page/default_brave_shields_page.m.js",
"default_brave_shields_page/default_brave_shields_page.js",
"default_brave_shields_page/brave_adblock_subpage.js",
"default_brave_shields_page/components/brave_adblock_subscribe_dropdown.js",
"default_brave_shields_page/components/brave_adblock_editor.js",
"getting_started_page/getting_started.js",
"social_blocking_page/social_blocking_page.m.js",
]
Expand Down
2 changes: 1 addition & 1 deletion browser/resources/settings/brave_overrides/basic_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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.js'
import '../default_brave_shields_page/default_brave_shields_page.m.js'
import '../default_brave_shields_page/default_brave_shields_page.js'
import '../getting_started_page/getting_started.js'
import '../social_blocking_page/social_blocking_page.m.js'

Expand Down
1 change: 1 addition & 0 deletions browser/resources/settings/brave_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function addBraveRoutes(r) {
}
}
r.SHIELDS = r.BASIC.createSection('/shields', 'shields')
r.SHIELDS_ADBLOCK = r.SHIELDS.createChild('/shields/content-filters')
r.REWARDS = r.BASIC.createSection('/rewards', 'rewards')
r.SOCIAL_BLOCKING = r.BASIC.createSection('/socialBlocking', 'socialBlocking')
r.EXTENSIONS = r.BASIC.createSection('/extensions', 'extensions')
Expand Down
101 changes: 26 additions & 75 deletions browser/resources/settings/default_brave_shields_page/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,49 @@
# you can obtain one at http://mozilla.org/MPL/2.0/.

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

# HTML Imports compatible compiles
# # HTML Imports compatible compiles

js_type_check("closure_compile") {
deps = [
":default_brave_shields_browser_proxy",
":default_brave_shields_page",
]
}

js_library("default_brave_shields_browser_proxy") {
deps = [
"//ui/webui/resources/js:cr",
]
externs_list = [
"$externs_path/chrome_send.js",
]
}

js_library("default_brave_shields_page") {
deps = [
":default_brave_shields_browser_proxy",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:load_time_data",
]
externs_list = [
"$externs_path/settings_private.js",
]
}

# ES Module compatible compiles

js_type_check("closure_compile_module") {
is_polymer3 = true
deps = [
":default_brave_shields_browser_proxy.m",
":default_brave_shields_page.m",
]
}
# js_type_check("closure_compile") {
# deps = [
# ":default_brave_shields_browser_proxy",
# ":default_brave_shields_page",
# ]
# }

js_library("default_brave_shields_browser_proxy.m") {
deps = [
"//ui/webui/resources/js:cr.m",
]
externs_list = [
"$externs_path/chrome_send.js",
]
extra_deps = [
":default_brave_shields_browser_proxy_module",
]
}
# # ES Module compatible compiles

js_library("default_brave_shields_page.m") {
deps = [
":default_brave_shields_browser_proxy.m",
"//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:load_time_data.m",
]
externs_list = [
"$externs_path/settings_private.js",
]
extra_deps = [
":default_brave_shields_page_module",
]
}
# js_type_check("closure_compile_module") {
# is_polymer3 = true
# deps = [
# ":default_brave_shields_browser_proxy.m",
# ":default_brave_shields_page",
# ]
# }

# ES Module conversion from HTML Imports code

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

polymer_modulizer("default_brave_shields_page") {
js_file = "default_brave_shields_page.js"
html_file = "default_brave_shields_page.html"
html_type = "dom-module"
auto_imports = settings_auto_imports + [
"brave/browser/resources/settings/default_brave_shields_page/default_brave_shields_browser_proxy.html|DefaultBraveShieldsBrowserProxy, DefaultBraveShieldsBrowserProxyImpl",
]
js_modulizer("modules") {
input_files = [ "default_brave_shields_browser_proxy.js" ]
namespace_rewrites = settings_namespace_rewrites
}

js_modulizer("default_brave_shields_browser_proxy_module") {
input_files = [
"default_brave_shields_browser_proxy.js",
html_to_js("templatize") {
js_files = [
"default_brave_shields_page.js",
"brave_adblock_subpage.js",
"components/brave_adblock_subscribe_dropdown.js",
"components/brave_adblock_editor.js",
]
namespace_rewrites = settings_namespace_rewrites
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* Copyright 2022 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 { sendWithPromise, addWebUIListener } from 'chrome://resources/js/cr.m.js';

/** @interface */
export class BraveAdblockBrowserProxy {
getInstance() { }
getRegionalLists() { }
enableFilterList() { }
getListSubscriptions() { }
getCustomFilters() { }
setSubscriptionEnabled() { }
addSubscription() { }
addWebUIListener() { }
updateSubscription() { }
deleteSubscription() { }
viewSubscription() { }
}

/**
* @implements {BraveAdblockBrowserProxy}
*/
export class BraveAdblockBrowserProxyImpl {
/** @instance */
static getInstance() {
return instance || (instance = new BraveAdblockBrowserProxyImpl());
}

/** @returns {Promise} */
getRegionalLists () {
return sendWithPromise('brave_adblock.getRegionalLists')
}

/** @returns {Promise} */
getListSubscriptions () {
return sendWithPromise('brave_adblock.getListSubscriptions')
}

/** @returns {Promise} */
getCustomFilters () {
return sendWithPromise('brave_adblock.getCustomFilters')
}

enableFilterList (uuid, enabled) {
chrome.send('brave_adblock.enableFilterList', [uuid, enabled])
}

setSubscriptionEnabled (url, enabled) {
chrome.send('brave_adblock.setSubscriptionEnabled', [url, enabled])
}

addSubscription (url) {
chrome.send('brave_adblock.addSubscription', [url])
}

updateSubscription (url) {
chrome.send('brave_adblock.updateSubscription', [url])
}

updateCustomFilters (value) {
chrome.send('brave_adblock.updateCustomFilters', [value])
}

deleteSubscription (url) {
chrome.send('brave_adblock.deleteSubscription', [url])
}

viewSubscription (url) {
chrome.send('brave_adblock.viewSubscription', [url])
}

addWebUIListener (event_name, callback) {
addWebUIListener(event_name, callback)
}
}

/** @type {BraveAdblockBrowserProxyImpl} */
let instance
Loading

0 comments on commit 1f9a690

Please sign in to comment.