diff --git a/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.html b/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.html
index d7fcf69f3374..3eefaf16e883 100644
--- a/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.html
+++ b/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.html
@@ -324,27 +324,32 @@
sub-label="$i18n{adblockDeveloperModeDesc}">
-
-
-
- $i18n{adblockCustomFiltersLabel}
+
+
+
+
+ $i18n{adblockCustomFiltersLabel}
+
+
+
-
-
-
+
-
+
$i18n{adblockCustomSciptletsListLabel}
-
+
+
diff --git a/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.ts b/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.ts
index 4d5cae0581f5..6e2a0a4e6c37 100644
--- a/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.ts
+++ b/browser/resources/settings/default_brave_shields_page/brave_adblock_subpage.ts
@@ -20,6 +20,7 @@ import {
BraveAdblockBrowserProxy,
BraveAdblockBrowserProxyImpl,
FilterList,
+ Scriptlet,
SubscriptionInfo
} from './brave_adblock_browser_proxy.js'
@@ -49,22 +50,26 @@ class AdBlockSubpage extends AdBlockSubpageBase {
type: Boolean,
value: false
},
- cosmeticFilteringCustomScriptletsEnabled_: {
- type: Boolean,
- value: loadTimeData.getBoolean(
- 'cosmeticFilteringCustomScriptletsEnabled'
- )
- }
+ shouldShowCustomFilters_: Boolean,
+ shouldShowCustomScriptlets_: Boolean
}
}
+ static get observers() {
+ return [
+ 'updateState_(prefs.brave.ad_block.developer_mode.value, customFilters_, customScriptlets_)'
+ ]
+ }
+
private filterList_: FilterList[]
private subscriptionList_: SubscriptionInfo[]
private customFilters_: string
private subscribeUrl_: string
private listsUpdatingState_: string
private hasListExpanded_: boolean
- private cosmeticFilteringCustomScriptletsEnabled_: boolean
+ private shouldShowCustomFilters_: boolean
+ private shouldShowCustomScriptlets_: boolean
+ private customScriptlets_: Scriptlet[]
private browserProxy_: BraveAdblockBrowserProxy =
BraveAdblockBrowserProxyImpl.getInstance()
@@ -86,10 +91,42 @@ class AdBlockSubpage extends AdBlockSubpageBase {
this.customFilters_ = value
})
+ this.browserProxy_.getCustomScriptlets().then((value: Scriptlet[]) => {
+ this.customScriptlets_ = value
+ })
+
this.browserProxy_.addWebUiListener(
'brave_adblock.onGetListSubscriptions', (value: SubscriptionInfo[]) => {
this.subscriptionList_ = value
})
+ this.browserProxy_.addWebUiListener(
+ 'brave_adblock.onCustomFiltersChanged',
+ (value: string) => {
+ this.customFilters_ = value
+ }
+ )
+ }
+
+ private updateState_(
+ devMode: boolean,
+ customFilters: string,
+ customScriptlets: Scriptlet[]
+ ) {
+ this.shouldShowCustomScriptlets_ =
+ devMode !== undefined &&
+ customScriptlets != undefined &&
+ loadTimeData.getBoolean('cosmeticFilteringCustomScriptletsEnabled') &&
+ (customScriptlets.length > 0 || devMode)
+
+ this.shouldShowCustomFilters_ =
+ devMode !== undefined &&
+ customFilters !== undefined &&
+ (customFilters.trim().length > 0 || devMode)
+ }
+
+ private handleSciptletsChanged_(e: CustomEvent) {
+ const value = e.detail.value as Scriptlet[]
+ this.customScriptlets_ = value
}
private handleShowList_() {
diff --git a/browser/resources/settings/default_brave_shields_page/components/brave_adblock_editor.ts b/browser/resources/settings/default_brave_shields_page/components/brave_adblock_editor.ts
index 5ad5039dc36d..21ea2065e5a6 100644
--- a/browser/resources/settings/default_brave_shields_page/components/brave_adblock_editor.ts
+++ b/browser/resources/settings/default_brave_shields_page/components/brave_adblock_editor.ts
@@ -28,7 +28,7 @@ class AdBlockFiltersEditor extends AdBlockFiltersEditorBase {
return {
value: {
type: String
- }
+ },
}
}
diff --git a/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.html b/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.html
index e818591a9c3c..f91e103ecbc3 100644
--- a/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.html
+++ b/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.html
@@ -20,6 +20,10 @@
.scriptlet:last-of-type {
border-bottom: none;
}
+
+ cr-icon-button[disabled] {
+ pointer-events: none;
+ }
@@ -30,9 +34,11 @@
[[item.name]]
-
+
-
+
diff --git a/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.ts b/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.ts
index a892da311e31..a1e4c7c60c88 100644
--- a/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.ts
+++ b/browser/resources/settings/default_brave_shields_page/components/brave_adblock_scriptlet_list.ts
@@ -48,7 +48,7 @@ class AdblockScriptletList extends AdblockScriptletListBase {
}
static get observers() {
- return ['onDevModeChanged_(prefs.brave.ad_block.developer_mode.value)']
+ return ['onSctiptelsListChanged_(customScriptletsList_)']
}
customScriptletsList_: Scriptlet[]
@@ -71,18 +71,6 @@ class AdblockScriptletList extends AdblockScriptletListBase {
})
}
- private onDevModeChanged_(value: boolean) {
- if (!value) {
- this.customScriptletsList_ = []
- } else {
- setTimeout(() => {
- this.browserProxy_.getCustomScriptlets().then((scriptlets) => {
- this.customScriptletsList_ = scriptlets
- })
- })
- }
- }
-
handleAdd_(_: any) {
this.editingScriptlet_ = new Scriptlet()
this.isEditing_ = true
@@ -117,6 +105,10 @@ class AdblockScriptletList extends AdblockScriptletListBase {
this.customScriptletsList_ = scriptlets
})
}
+
+ private onSctiptelsListChanged_(scriptlets: Scriptlet[]) {
+ this.fire('list-changed', { value: scriptlets })
+ }
}
customElements.define(AdblockScriptletList.is, AdblockScriptletList)
diff --git a/browser/ui/webui/settings/brave_adblock_handler.cc b/browser/ui/webui/settings/brave_adblock_handler.cc
index faca5c1d8443..5b9a76b0bbfc 100644
--- a/browser/ui/webui/settings/brave_adblock_handler.cc
+++ b/browser/ui/webui/settings/brave_adblock_handler.cc
@@ -5,7 +5,6 @@
#include "brave/browser/ui/webui/settings/brave_adblock_handler.h"
-#include
#include
#include
@@ -20,11 +19,9 @@
#include "brave/components/brave_shields/core/browser/ad_block_component_service_manager.h"
#include "brave/components/brave_shields/core/browser/ad_block_custom_resource_provider.h"
#include "brave/components/brave_shields/core/common/features.h"
+#include "brave/components/brave_shields/core/common/pref_names.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "content/public/browser/web_ui.h"
#include "ui/base/l10n/time_format.h"
@@ -34,7 +31,6 @@ BraveAdBlockHandler::BraveAdBlockHandler() = default;
BraveAdBlockHandler::~BraveAdBlockHandler() = default;
void BraveAdBlockHandler::RegisterMessages() {
- profile_ = Profile::FromWebUI(web_ui());
web_ui()->RegisterMessageCallback(
"brave_adblock.getRegionalLists",
base::BindRepeating(&BraveAdBlockHandler::GetRegionalLists,
@@ -109,15 +105,21 @@ void BraveAdBlockHandler::RegisterMessages() {
"brave_adblock.removeCustomScriptlet",
base::BindRepeating(&BraveAdBlockHandler::RemoveCustomScriptlet,
base::Unretained(this)));
+ pref_change_registrar_.Init(g_browser_process->local_state());
}
void BraveAdBlockHandler::OnJavascriptAllowed() {
service_observer_.Observe(g_brave_browser_process->ad_block_service()
->subscription_service_manager());
+ pref_change_registrar_.Add(
+ brave_shields::prefs::kAdBlockCustomFilters,
+ base::BindRepeating(&BraveAdBlockHandler::RefreshCustomFilters,
+ weak_factory_.GetWeakPtr()));
}
void BraveAdBlockHandler::OnJavascriptDisallowed() {
service_observer_.Reset();
+ pref_change_registrar_.RemoveAll();
}
void BraveAdBlockHandler::OnServiceUpdateEvent() {
@@ -364,6 +366,15 @@ void BraveAdBlockHandler::RefreshSubscriptionsList() {
FireWebUIListener("brave_adblock.onGetListSubscriptions", GetSubscriptions());
}
+void BraveAdBlockHandler::RefreshCustomFilters() {
+ const std::string& custom_filters =
+ g_brave_browser_process->ad_block_service()
+ ->custom_filters_provider()
+ ->GetCustomFilters();
+ FireWebUIListener("brave_adblock.onCustomFiltersChanged",
+ base::Value(custom_filters));
+}
+
base::Value::List BraveAdBlockHandler::GetSubscriptions() {
auto list_subscriptions = g_brave_browser_process->ad_block_service()
->subscription_service_manager()
diff --git a/browser/ui/webui/settings/brave_adblock_handler.h b/browser/ui/webui/settings/brave_adblock_handler.h
index 90656c8ca324..66c2f62f8802 100644
--- a/browser/ui/webui/settings/brave_adblock_handler.h
+++ b/browser/ui/webui/settings/brave_adblock_handler.h
@@ -8,13 +8,13 @@
#include
-#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "brave/components/brave_shields/content/browser/ad_block_subscription_service_manager.h"
#include "brave/components/brave_shields/content/browser/ad_block_subscription_service_manager_observer.h"
#include "brave/components/brave_shields/core/browser/ad_block_custom_resource_provider.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
+#include "components/prefs/pref_change_registrar.h"
class Profile;
using brave_shields::AdBlockSubscriptionServiceManager;
@@ -60,17 +60,18 @@ class BraveAdBlockHandler : public settings::SettingsPageUIHandler,
brave_shields::AdBlockCustomResourceProvider::ErrorCode error_code);
void RefreshSubscriptionsList();
+ void RefreshCustomFilters();
base::Value::List GetSubscriptions();
void OnFilterListsUpdated(std::string callback_id, bool success);
- raw_ptr profile_ = nullptr;
-
base::ScopedObservation
service_observer_{this};
+ PrefChangeRegistrar pref_change_registrar_;
+
base::WeakPtrFactory weak_factory_{this};
};