commit 5eaa32be35164a86287b561d0f0bc98cf8d2883a
parent 95acafe0ca036d34f8865f2a43b72ea92be49a40
Author: Dale Harvey <dale@arandomurl.com>
Date: Mon, 8 Dec 2025 18:38:04 +0000
Bug 1996276 - Update trustPanel with new content blocking events. r=daisuke,urlbar-reviewers,fluent-reviewers,bolsson
Differential Revision: https://phabricator.services.mozilla.com/D273909
Diffstat:
6 files changed, 129 insertions(+), 53 deletions(-)
diff --git a/browser/base/content/browser-trustPanel.js b/browser/base/content/browser-trustPanel.js
@@ -111,6 +111,7 @@ const SMARTBLOCK_EMBED_INFO = [
class TrustPanel {
#state = null;
#secInfo = null;
+ #host = null;
#uri = null;
#uriHasHost = null;
#pageExtensionPolicy = null;
@@ -173,7 +174,12 @@ class TrustPanel {
this.showPopup({ event, openingReason: "shieldButtonClicked" });
}
- onContentBlockingEvent(event, _webProgress, _isSimulated, _previousState) {
+ async onContentBlockingEvent(
+ event,
+ _webProgress,
+ _isSimulated,
+ _previousState
+ ) {
if (!this.#enabled) {
return;
}
@@ -199,6 +205,10 @@ class TrustPanel {
this.anyDetected = this.anyDetected || blocker.isDetected(event);
this.anyBlocking = this.anyBlocking || blocker.activated;
}
+
+ if (this.#popup) {
+ await this.#updatePopup();
+ }
}
#initializePopup() {
@@ -247,9 +257,10 @@ class TrustPanel {
}
}
- showPopup(opts = {}) {
+ async showPopup(opts = {}) {
this.#initializePopup();
- this.#updatePopup();
+ await this.#updatePopup();
+
this.#openingReason = opts.reason;
let anchor = document.getElementById("trust-icon-container");
@@ -313,20 +324,24 @@ class TrustPanel {
}
async #updatePopup() {
- let secureConnection = this.#isSecurePage();
- let connection = secureConnection ? "secure" : "not-secure";
-
- this.#popup.setAttribute("connection", connection);
+ this.#host = window.gIdentityHandler.getHostForDisplay();
+ this.#popup.setAttribute(
+ "connection",
+ this.#isSecurePage() ? "secure" : "not-secure"
+ );
this.#popup.setAttribute(
"tracking-protection",
this.#trackingProtectionStatus()
);
+ await this.#updateMainView();
+ }
+
+ async #updateMainView() {
+ let secureConnection = this.#isSecurePage();
let assets = this.#trackingProtectionEnabled
? ETP_ENABLED_ASSETS
: ETP_DISABLED_ASSETS;
- let host = window.gIdentityHandler.getHostForDisplay();
- this.host = host;
if (this.#uri) {
let favicon = await PlacesUtils.favicons.getFaviconForPage(this.#uri);
@@ -341,12 +356,12 @@ class TrustPanel {
this.#trackingProtectionEnabled
? "trustpanel-etp-toggle-on"
: "trustpanel-etp-toggle-off",
- { host }
+ { host: this.#host }
);
let hostElement = document.getElementById("trustpanel-popup-host");
- hostElement.setAttribute("value", host);
- hostElement.setAttribute("tooltiptext", host);
+ hostElement.setAttribute("value", this.#host);
+ hostElement.setAttribute("tooltiptext", this.#host);
document.l10n.setAttributes(
document.getElementById("trustpanel-etp-label"),
@@ -371,47 +386,41 @@ class TrustPanel {
: "trustpanel-connection-label-insecure"
);
- let canHandle = ContentBlockingAllowList.canHandle(
- window.gBrowser.selectedBrowser
+ this.#updateAttribute(
+ document.getElementById("trustpanel-blocker-section"),
+ "hidden",
+ !this.anyDetected
);
- document
- .getElementById("trustpanel-toggle")
- .toggleAttribute("disabled", !canHandle);
- document
- .getElementById("trustpanel-toggle-section")
- .toggleAttribute("disabled", !canHandle);
+ await this.#updateBlockerView();
+ }
- if (!this.anyDetected) {
- document.getElementById("trustpanel-blocker-section").hidden = true;
- } else {
- let count = this.#fetchSmartBlocked().length;
- let blocked = [];
- let detected = [];
-
- for (let blocker of Object.values(this.#blockers)) {
- if (blocker.isBlocking(this.#lastEvent)) {
- blocked.push(blocker);
- count += await blocker.getBlockerCount();
- } else if (blocker.isDetected(this.#lastEvent)) {
- detected.push(blocker);
- }
+ async #updateBlockerView() {
+ let count = this.#fetchSmartBlocked().length;
+ let blocked = [];
+ let detected = [];
+
+ for (let blocker of Object.values(this.#blockers)) {
+ if (blocker.isBlocking(this.#lastEvent)) {
+ blocked.push(blocker);
+ count += await blocker.getBlockerCount();
+ } else if (blocker.isDetected(this.#lastEvent)) {
+ detected.push(blocker);
}
+ }
- document.l10n.setArgs(
- document.getElementById("trustpanel-blocker-section-header"),
- { count }
- );
- this.#addButtons("trustpanel-blocked", blocked, true);
- this.#addButtons("trustpanel-detected", detected, false);
+ this.#addButtons("trustpanel-blocked", blocked, true);
+ this.#addButtons("trustpanel-detected", detected, false);
- document
- .getElementById("trustpanel-blocker-section")
- .removeAttribute("hidden");
+ document
+ .getElementById("trustpanel-smartblock-section")
+ .toggleAttribute("hidden", !this.#addSmartblockEmbedToggles());
- document
- .getElementById("trustpanel-smartblock-section")
- .toggleAttribute("hidden", !this.#addSmartblockEmbedToggles());
- }
+ // This element is in the main view but updated in case
+ // any content blocking events were missed.
+ document.l10n.setArgs(
+ document.getElementById("trustpanel-blocker-section-header"),
+ { count }
+ );
}
async #showSecurityPopup() {
@@ -443,7 +452,7 @@ class TrustPanel {
document.l10n.setAttributes(
document.getElementById("trustpanel-securityInformationView"),
"trustpanel-site-information-header",
- { host: this.host }
+ { host: this.#host }
);
let customRoot = this.#isSecureConnection ? this.#hasCustomRoot() : false;
@@ -484,8 +493,9 @@ class TrustPanel {
document.l10n.setAttributes(
document.getElementById("trustpanel-blockerView"),
"trustpanel-blocker-header",
- { host: this.host }
+ { host: this.#host }
);
+ await this.#updateBlockerView();
document
.getElementById("trustpanel-popup-multiView")
.showSubView("trustpanel-blockerView", event.target);
diff --git a/browser/components/controlcenter/content/trustPanel.inc.xhtml b/browser/components/controlcenter/content/trustPanel.inc.xhtml
@@ -47,7 +47,7 @@
</vbox>
</hbox>
<vbox id="trustpanel-blocker-section" class="trustpanel-graphic-inner">
- <label data-l10n-id="trustpanel-blocker-section-header" data-l10n-args='{"count":0}' id="trustpanel-blocker-section-header" class="trustpanel-header"></label>
+ <label data-l10n-id="trustpanel-blocker-section-header2" data-l10n-args='{"count":0}' id="trustpanel-blocker-section-header" class="trustpanel-header"></label>
<label data-l10n-id="trustpanel-blocker-description"></label>
<html:moz-button-group>
<html:moz-button id="trustpanel-blocker-see-all" data-l10n-id="trustpanel-blocker-see-all" default="true" size="small" type="primary"></html:moz-button>
diff --git a/browser/components/urlbar/tests/browser/browser.toml b/browser/components/urlbar/tests/browser/browser.toml
@@ -714,6 +714,7 @@ https_first_disabled = true
["browser_trust_panel.js"]
https_first_disabled = true
+support-files = ["!/browser/base/content/test/protectionsUI/trackingPage.html"]
["browser_trust_panel_pages.js"]
diff --git a/browser/components/urlbar/tests/browser/browser_trust_panel.js b/browser/components/urlbar/tests/browser/browser_trust_panel.js
@@ -12,6 +12,10 @@ ChromeUtils.defineESModuleGetters(this, {
"resource://gre/modules/ContentBlockingAllowList.sys.mjs",
});
+const TRACKING_PAGE =
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ "http://tracking.example.org/browser/browser/base/content/test/protectionsUI/trackingPage.html";
+
const ETP_ACTIVE_ICON = 'url("chrome://browser/skin/trust-icon-active.svg")';
const ETP_DISABLED_ICON =
'url("chrome://browser/skin/trust-icon-disabled.svg")';
@@ -166,3 +170,63 @@ add_task(async function test_drag_and_drop() {
await BrowserTestUtils.removeTab(tabByDnD);
await BrowserTestUtils.removeTab(tab);
});
+
+add_task(async function test_update() {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ [
+ "urlclassifier.features.cryptomining.blacklistHosts",
+ "cryptomining.example.com",
+ ],
+ [
+ "urlclassifier.features.cryptomining.annotate.blacklistHosts",
+ "cryptomining.example.com",
+ ],
+ [
+ "urlclassifier.features.fingerprinting.blacklistHosts",
+ "fingerprinting.example.com",
+ ],
+ [
+ "urlclassifier.features.fingerprinting.annotate.blacklistHosts",
+ "fingerprinting.example.com",
+ ],
+ ],
+ });
+
+ const tab = await BrowserTestUtils.openNewForegroundTab({
+ gBrowser,
+ opening: TRACKING_PAGE,
+ waitForLoad: true,
+ });
+
+ await UrlbarTestUtils.openTrustPanel(window);
+
+ let blockerSection = document.getElementById(
+ "trustpanel-blocker-section-header"
+ );
+ Assert.equal(
+ 0,
+ parseInt(blockerSection.textContent, 10),
+ "Initially not blocked any trackers"
+ );
+
+ await SpecialPowers.spawn(tab.linkedBrowser, [], function () {
+ content.postMessage("cryptomining", "*");
+ });
+
+ await BrowserTestUtils.waitForCondition(
+ () => parseInt(blockerSection.textContent, 10) == 1,
+ "Updated to show new cryptominer blocked"
+ );
+
+ await SpecialPowers.spawn(tab.linkedBrowser, [], function () {
+ content.postMessage("fingerprinting", "*");
+ });
+
+ await BrowserTestUtils.waitForCondition(
+ () => parseInt(blockerSection.textContent, 10) == 2,
+ "Updated to show new fingerprinter blocked"
+ );
+
+ BrowserTestUtils.removeTab(tab);
+});
diff --git a/browser/locales/en-US/browser/browser.ftl b/browser/locales/en-US/browser/browser.ftl
@@ -1418,9 +1418,9 @@ trustpanel-blocker-header =
## Variables
## $count (String): the number of trackers blocked.
-trustpanel-blocker-section-header = { $count ->
- [one] <span>{ $count }</span> Tracker blocked on this site
- *[other] <span>{ $count }</span> Trackers blocked on this site
+trustpanel-blocker-section-header2 = { $count ->
+ [one] <span data-l10n-name="count">{ $count }</span> Tracker blocked on this site
+ *[other] <span data-l10n-name="count">{ $count }</span> Trackers blocked on this site
}
trustpanel-blocker-description = { -brand-product-name } thinks companies should follow you less. So we block as many as we can.
trustpanel-blocked-header = { -brand-product-name } blocked these things for you:
diff --git a/tools/lint/rejected-words.yml b/tools/lint/rejected-words.yml
@@ -56,6 +56,7 @@ avoid-blacklist-and-whitelist:
- browser/components/tabbrowser/test/browser/tabs/browser_new_file_whitelisted_http_tab.js
- browser/components/tabbrowser/test/browser/tabs/browser_tab_drag_drop_perwindow.js
- browser/components/urlbar/tests/browser/browser_searchSingleWordNotification.js
+ - browser/components/urlbar/tests/browser/browser_trust_panel.js
- browser/components/urlbar/tests/browser/browser_UrlbarInput_trimURLs.js
- browser/components/urlbar/tests/unit/test_providerHeuristicFallback.js
- browser/components/urlbar/tests/unit/test_search_suggestions.js