tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b6486f25f206d2b07757e3fdca966a24e6f9d4ad
parent 67d3b441bf4fde550e9fe624c867a807e5717d77
Author: Rebecca King <rking@mozilla.com>
Date:   Wed, 10 Dec 2025 16:27:51 +0000

Bug 2004111 - Update ever used site exceptions flag to work with exclusions only - r=ip-protection-reviewers,kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D275272

Diffstat:
Mbrowser/components/ipprotection/IPPOnboardingMessageHelper.sys.mjs | 38+++++++++++++++++++++++++++-----------
Mbrowser/components/ipprotection/tests/xpcshell/test_IPPOnboardingMessageHelper.js | 41+++++++++++++++++++++++------------------
2 files changed, 50 insertions(+), 29 deletions(-)

diff --git a/browser/components/ipprotection/IPPOnboardingMessageHelper.sys.mjs b/browser/components/ipprotection/IPPOnboardingMessageHelper.sys.mjs @@ -14,7 +14,6 @@ ChromeUtils.defineESModuleGetters(lazy, { const ONBOARDING_MESSAGE_MASK_PREF = "browser.ipProtection.onboardingMessageMask"; const AUTOSTART_PREF = "browser.ipProtection.autoStartEnabled"; -const MODE_PREF = "browser.ipProtection.exceptionsMode"; const PERM_NAME = "ipp-vpn"; /** @@ -23,9 +22,20 @@ const PERM_NAME = "ipp-vpn"; * according to feature (general VPN, autostart, site exceptions) through bit mask */ class IPPOnboardingMessageHelper { + #observingPermChanges = false; + constructor() { this.handleEvent = this.#handleEvent.bind(this); + // If at least one exception is saved, don't show site exceptions onboarding message + let savedSites = Services.perms.getAllByTypes([PERM_NAME]); + if (savedSites.length) { + this.setOnboardingFlag(ONBOARDING_PREF_FLAGS.EVER_USED_SITE_EXCEPTIONS); + } else { + Services.obs.addObserver(this, "perm-changed"); + this.#observingPermChanges = true; + } + Services.prefs.addObserver(AUTOSTART_PREF, () => this.setOnboardingFlag(ONBOARDING_PREF_FLAGS.EVER_TURNED_ON_AUTOSTART) ); @@ -34,16 +44,6 @@ class IPPOnboardingMessageHelper { if (autoStartPref) { this.setOnboardingFlag(ONBOARDING_PREF_FLAGS.EVER_TURNED_ON_AUTOSTART); } - - Services.prefs.addObserver(MODE_PREF, () => - this.setOnboardingFlag(ONBOARDING_PREF_FLAGS.EVER_USED_SITE_EXCEPTIONS) - ); - - // If at least one exception is saved, don't show site exceptions onboarding message - let savedSites = Services.perms.getAllByTypes([PERM_NAME]); - if (savedSites.length !== 0) { - this.setOnboardingFlag(ONBOARDING_PREF_FLAGS.EVER_USED_SITE_EXCEPTIONS); - } } init() { @@ -56,12 +56,28 @@ class IPPOnboardingMessageHelper { initOnStartupCompleted() {} uninit() { + if (this.#observingPermChanges) { + Services.obs.removeObserver(this, "perm-changed"); + this.#observingPermChanges = false; + } + lazy.IPPProxyManager.removeEventListener( "IPPProxyManager:StateChanged", this.handleEvent ); } + observe(subject, topic, data) { + let permission = subject.QueryInterface(Ci.nsIPermission); + if ( + topic === "perm-changed" && + permission.type === PERM_NAME && + data === "added" + ) { + this.setOnboardingFlag(ONBOARDING_PREF_FLAGS.EVER_USED_SITE_EXCEPTIONS); + } + } + readPrefMask() { return Services.prefs.getIntPref(ONBOARDING_MESSAGE_MASK_PREF, 0); } diff --git a/browser/components/ipprotection/tests/xpcshell/test_IPPOnboardingMessageHelper.js b/browser/components/ipprotection/tests/xpcshell/test_IPPOnboardingMessageHelper.js @@ -11,7 +11,7 @@ const { ONBOARDING_PREF_FLAGS } = ChromeUtils.importESModule( "chrome://browser/content/ipprotection/ipprotection-constants.mjs" ); const AUTOSTART_PREF = "browser.ipProtection.autoStartEnabled"; -const MODE_PREF = "browser.ipProtection.exceptionsMode"; +const PERM_NAME = "ipp-vpn"; add_setup(async function () { await putServerInRemoteSettings(); @@ -59,34 +59,39 @@ add_task(async function test_IPPOnboardingMessage() { "IP Protection service should be active after starting" ); - // Check for ever turned on VPN flag + let maskAfterVpn = IPPOnboardingMessage.readPrefMask(); Assert.notStrictEqual( - IPPOnboardingMessage.readPrefMask() & - ONBOARDING_PREF_FLAGS.EVER_TURNED_ON_VPN, + maskAfterVpn & ONBOARDING_PREF_FLAGS.EVER_TURNED_ON_VPN, 0, "Ever turned on VPN flag should be set" ); // Turn on autostart Services.prefs.setBoolPref(AUTOSTART_PREF, true); - // Check for ever turned on autostart flag - Assert.notStrictEqual( - IPPOnboardingMessage.readPrefMask() & - ONBOARDING_PREF_FLAGS.EVER_TURNED_ON_AUTOSTART, - 0, - "Ever turned on autostart flag should be set" + let maskAfterAutostart = IPPOnboardingMessage.readPrefMask(); + Assert.strictEqual( + maskAfterAutostart, + maskAfterVpn | ONBOARDING_PREF_FLAGS.EVER_TURNED_ON_AUTOSTART, + "Autostart flag should be added to the mask" ); - // Turn on site exceptions - Services.prefs.setStringPref(MODE_PREF, "select"); - // Check for ever turned on site exceptions flag - Assert.notStrictEqual( - IPPOnboardingMessage.readPrefMask() & - ONBOARDING_PREF_FLAGS.EVER_USED_SITE_EXCEPTIONS, - 0, - "Ever used site exceptions flag should be set" + // Add site exception + const site = "https://www.example.com"; + const principal = + Services.scriptSecurityManager.createContentPrincipalFromOrigin(site); + const capability = Ci.nsIPermissionManager.DENY_ACTION; + Services.perms.addFromPrincipal(principal, PERM_NAME, capability); + + let maskAfterSiteException = IPPOnboardingMessage.readPrefMask(); + Assert.strictEqual( + maskAfterSiteException, + maskAfterAutostart | ONBOARDING_PREF_FLAGS.EVER_USED_SITE_EXCEPTIONS, + "Site exceptions flag should be added to the mask" ); + // Cleanup + Services.perms.removeByType(PERM_NAME); IPProtectionService.uninit(); + IPPOnboardingMessage.uninit(); sandbox.restore(); });