From 238930dcb0565a5b884ef8426dabde4e0370584c Mon Sep 17 00:00:00 2001 From: gholk Date: Sun, 20 Apr 2025 17:00:43 +0800 Subject: [PATCH 1/4] feat: redirect disable basic --- package-lock.json | 28 ++++++++++------------------ src/js/background/assignManager.js | 23 ++++++++++++++++++----- src/js/background/backgroundLogic.js | 13 ++++++++++++- src/js/background/messageHandler.js | 3 +++ src/js/popup.js | 23 +++++++++++++++++++++++ src/popup.html | 8 ++++++++ 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index c9da2dc..0ce68d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "testpilot-containers", - "version": "8.1.3", + "version": "8.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "testpilot-containers", - "version": "8.1.1", + "version": "8.2.0", "license": "MPL-2.0", "devDependencies": { "addons-linter": "^5.28.0", @@ -15032,8 +15032,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, - "requires": {} + "dev": true }, "acorn-walk": { "version": "7.2.0", @@ -17246,15 +17245,13 @@ "version": "4.0.2", "resolved": "https://registry.npmjs.org/eslint-plugin-no-unsanitized/-/eslint-plugin-no-unsanitized-4.0.2.tgz", "integrity": "sha512-Pry0S9YmHoz8NCEMRQh7N0Yexh2MYCNPIlrV52hTmS7qXnTghWsjXouF08bgsrrZqaW9tt1ZiK3j5NEmPE+EjQ==", - "dev": true, - "requires": {} + "dev": true }, "eslint-plugin-promise": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-5.2.0.tgz", "integrity": "sha512-SftLb1pUG01QYq2A/hGAWfDRXqYD82zE7j7TopDOyNdU+7SvvoXREls/+PRTY17vUXzXnZA/zfnyKgRH6x4JJw==", - "dev": true, - "requires": {} + "dev": true }, "eslint-scope": { "version": "5.1.1", @@ -19763,8 +19760,7 @@ "version": "7.5.9", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", - "dev": true, - "requires": {} + "dev": true } } }, @@ -21971,8 +21967,7 @@ "version": "0.36.2", "resolved": "https://registry.npmjs.org/postcss-syntax/-/postcss-syntax-0.36.2.tgz", "integrity": "sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==", - "dev": true, - "requires": {} + "dev": true }, "postcss-value-parser": { "version": "4.2.0", @@ -22826,8 +22821,7 @@ "version": "3.7.0", "resolved": "https://registry.npmjs.org/sinon-chai/-/sinon-chai-3.7.0.tgz", "integrity": "sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g==", - "dev": true, - "requires": {} + "dev": true }, "slash": { "version": "3.0.0", @@ -23571,8 +23565,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-3.0.0.tgz", "integrity": "sha512-F6yTRuc06xr1h5Qw/ykb2LuFynJ2IxkKfCMf+1xqPffkxh0S09Zc902XCffcsw/XMFq/OzQ1w54fLIDtmRNHnQ==", - "dev": true, - "requires": {} + "dev": true }, "stylelint-config-standard": { "version": "20.0.0", @@ -24946,8 +24939,7 @@ "version": "8.12.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.12.0.tgz", "integrity": "sha512-kU62emKIdKVeEIOIKVegvqpXMSTAMLJozpHZaJNDYqBjzlSYXQGviYwN1osDLJ9av68qHd4a2oSjd7yD4pacig==", - "dev": true, - "requires": {} + "dev": true }, "xdg-basedir": { "version": "5.1.0", diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index 0962a1d..8a462db 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -225,14 +225,18 @@ window.assignManager = { return {}; } this.removeContextMenu(); - const [tab, siteSettings] = await Promise.all([ + let [tab, siteSettings] = await Promise.all([ browser.tabs.get(options.tabId), this.storageArea.get(options.url) ]); - let container; + let container = false; + let cookieStoreId = false; + if (siteSettings) { + cookieStoreId = backgroundLogic.cookieStoreId(siteSettings.userContextId) + } try { - container = await browser.contextualIdentities - .get(backgroundLogic.cookieStoreId(siteSettings.userContextId)); + container = cookieStoreId && await browser.contextualIdentities + .get(cookieStoreId); } catch (e) { container = false; } @@ -243,6 +247,14 @@ window.assignManager = { this.deleteContainer(siteSettings.userContextId); return {}; } + + if (siteSettings && container) { + const containerState = await identityState.storageArea.get(cookieStoreId); + if (containerState.redirectDisable) { + container = false; + siteSettings = null; + } + } const userContextId = this.getUserContextIdFromCookieStore(tab); // https://github.com/mozilla/multi-account-containers/issues/847 @@ -392,7 +404,8 @@ window.assignManager = { // Requested page is not assigned to a specific container. If the current tab's container // is locked, then the page must be reloaded in the default container. const currentContainerState = await identityState.storageArea.get(tab.cookieStoreId); - return currentContainerState && currentContainerState.isIsolated; + return currentContainerState && currentContainerState.isIsolated && + !currentContainerState.redirectDisable; }, maybeAddProxyListeners() { diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 54bdd0e..7554c95 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -215,6 +215,16 @@ const backgroundLogic = { } }, + async setRedirectState(cookieStoreId, enable) { + const containerState = await identityState.storageArea.get(cookieStoreId); + try { + containerState.redirectDisable = !enable + return await identityState.storageArea.set(cookieStoreId, containerState); + } catch (error) { + // console.error(`No container: ${cookieStoreId}`); + } + }, + async moveTabsToWindow(options) { const requiredArguments = ["cookieStoreId", "windowId"]; this.checkArgs(requiredArguments, options, "moveTabsToWindow"); @@ -321,7 +331,8 @@ const backgroundLogic = { hasOpenTabs: !!openTabs.length, numberOfHiddenTabs: containerState.hiddenTabs.length, numberOfOpenTabs: openTabs.length, - isIsolated: !!containerState.isIsolated + isIsolated: !!containerState.isIsolated, + redirectDisable: containerState.redirectDisable }; return; }); diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 96dbc68..621773c 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -63,6 +63,9 @@ const messageHandler = { windowId: m.windowId }); break; + case "setRedirectState": + response = backgroundLogic.setRedirectState(m.cookieStoreId, m.state); + break; case "checkIncompatibleAddons": // TODO break; diff --git a/src/js/popup.js b/src/js/popup.js index 61a3fda..74fcbd3 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -258,6 +258,7 @@ const Logic = { identity.numberOfHiddenTabs = stateObject.numberOfHiddenTabs; identity.numberOfOpenTabs = stateObject.numberOfOpenTabs; identity.isIsolated = stateObject.isIsolated; + identity.redirectDisable = stateObject.redirectDisable; } if (containerOrder) { identity.order = containerOrder[identity.cookieStoreId]; @@ -998,6 +999,7 @@ Logic.registerPanel(P_CONTAINER_INFO, { } this.intializeShowHide(identity); + this.initializeRedirectSwitch(identity); // Let's retrieve the list of tabs. const tabs = await browser.runtime.sendMessage({ @@ -1019,6 +1021,27 @@ Logic.registerPanel(P_CONTAINER_INFO, { return this.buildOpenTabTable(tabs); }, + initializeRedirectSwitch(identity) { + const redirectEl = document.querySelector("#disable-redirect"); + Utils.addEnterHandler(redirectEl, async () => { + try { + browser.runtime.sendMessage({ + method: "setRedirectState", + state: identity.redirectDisable, + cookieStoreId: Logic.currentCookieStoreId() + }); + window.close(); + } catch (e) { + window.close(); + } + }); + + // const hideShowIcon = document.getElementById("container-info-hideorshow-icon"); + // hideShowIcon.src = identity.hasHiddenTabs ? CONTAINER_UNHIDE_SRC : CONTAINER_HIDE_SRC; + + const redirectLabel = document.getElementById("disable-redirect-this-container"); + redirectLabel.textContent = browser.i18n.getMessage(identity.redirectDisable ? "enableRedirectThisContainer" : "disableRedirectThisContainer"); + }, intializeShowHide(identity) { const hideContEl = document.querySelector("#hideorshow-container"); if (identity.numberOfOpenTabs === 0 && !identity.hasHiddenTabs) { diff --git a/src/popup.html b/src/popup.html index ae46080..b2bae8d 100644 --- a/src/popup.html +++ b/src/popup.html @@ -247,6 +247,14 @@ + + + + + + + + From 89b96fa5aebe3b04e066e37190ec47ba7dd5feed Mon Sep 17 00:00:00 2001 From: gholk Date: Sun, 20 Apr 2025 17:28:16 +0800 Subject: [PATCH 2/4] fix: pass the test --- bin/addons-linter.sh | 2 +- src/_locales | 2 +- src/js/background/assignManager.js | 6 ++++-- src/js/background/backgroundLogic.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/addons-linter.sh b/bin/addons-linter.sh index 09161b8..2a8798d 100755 --- a/bin/addons-linter.sh +++ b/bin/addons-linter.sh @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash # 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 diff --git a/src/_locales b/src/_locales index bdaa012..7df9158 160000 --- a/src/_locales +++ b/src/_locales @@ -1 +1 @@ -Subproject commit bdaa01291b7367a5e815470fd263ea36c862fe32 +Subproject commit 7df9158b9dfddab256285d8fb7f342dc8a3a8c1d diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index 8a462db..fec0dbb 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -225,14 +225,16 @@ window.assignManager = { return {}; } this.removeContextMenu(); - let [tab, siteSettings] = await Promise.all([ + const a = await Promise.all([ browser.tabs.get(options.tabId), this.storageArea.get(options.url) ]); + const tab = a[0]; + let siteSettings = a[1]; let container = false; let cookieStoreId = false; if (siteSettings) { - cookieStoreId = backgroundLogic.cookieStoreId(siteSettings.userContextId) + cookieStoreId = backgroundLogic.cookieStoreId(siteSettings.userContextId); } try { container = cookieStoreId && await browser.contextualIdentities diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 7554c95..4516888 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -218,7 +218,7 @@ const backgroundLogic = { async setRedirectState(cookieStoreId, enable) { const containerState = await identityState.storageArea.get(cookieStoreId); try { - containerState.redirectDisable = !enable + containerState.redirectDisable = !enable; return await identityState.storageArea.set(cookieStoreId, containerState); } catch (error) { // console.error(`No container: ${cookieStoreId}`); From 767fad14b2c67c26b347914a0612afa93760d9a1 Mon Sep 17 00:00:00 2001 From: gholk Date: Sun, 20 Apr 2025 21:56:45 +0800 Subject: [PATCH 3/4] feat: redirect disable globally button --- src/_locales | 2 +- src/img/disable-redirect.svg | 9 +++++++++ src/js/background/backgroundLogic.js | 9 ++++++++- src/js/background/messageHandler.js | 4 +++- src/js/popup.js | 22 +++++++++++++++++++++- src/manifest.json | 2 +- src/popup.html | 8 ++++++++ 7 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/img/disable-redirect.svg diff --git a/src/_locales b/src/_locales index 7df9158..4c5fb04 160000 --- a/src/_locales +++ b/src/_locales @@ -1 +1 @@ -Subproject commit 7df9158b9dfddab256285d8fb7f342dc8a3a8c1d +Subproject commit 4c5fb04b020eb47f3238971f6f04b096c2dea2c0 diff --git a/src/img/disable-redirect.svg b/src/img/disable-redirect.svg new file mode 100644 index 0000000..6786b5e --- /dev/null +++ b/src/img/disable-redirect.svg @@ -0,0 +1,9 @@ + + + + + + + diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 4516888..c25016b 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -215,7 +215,14 @@ const backgroundLogic = { } }, - async setRedirectState(cookieStoreId, enable) { + async setRedirectState(cookieStoreId, enable, global) { + if (global) { + const containers = await identityState.getCookieStoreIDuuidMap(); + for (const id in containers) { + await this.setRedirectState(id, enable, false);; + } + return; + } const containerState = await identityState.storageArea.get(cookieStoreId); try { containerState.redirectDisable = !enable; diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 621773c..5d79e07 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -64,7 +64,9 @@ const messageHandler = { }); break; case "setRedirectState": - response = backgroundLogic.setRedirectState(m.cookieStoreId, m.state); + response = backgroundLogic.setRedirectState( + m.cookieStoreId, m.state, m.global + ); break; case "checkIncompatibleAddons": // TODO diff --git a/src/js/popup.js b/src/js/popup.js index 74fcbd3..d894eca 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -60,6 +60,7 @@ const Logic = { _previousPanelPath: [], _panels: {}, _onboardingVariation: null, + _initPromise: null, async init() { browser.runtime.sendMessage({ @@ -757,6 +758,25 @@ Logic.registerPanel(P_CONTAINERS_LIST, { Utils.addEnterHandler(document.querySelector("#always-open-in"), () => { Logic.showPanel(ALWAYS_OPEN_IN_PICKER); }); + const redirectEl = document.querySelector("#disable-redirect-all"); + let redirectSwitchStateTo = false; + Logic.initPromise.then(() => { + const identities = Logic.identities(); + redirectSwitchStateTo = identities.some(id => id.redirectDisable); + redirectEl.querySelector('.menu-text').textContent = browser.i18n.getMessage(redirectSwitchStateTo ? "enableRedirectAllContainer" : "disableRedirectAllContainer"); + }); + Utils.addEnterHandler(redirectEl, async () => { + try { + await browser.runtime.sendMessage({ + method: "setRedirectState", + state: redirectSwitchStateTo, + global: true + }); + window.close(); + } catch (e) { + window.close(); + } + }); Utils.addEnterHandler(document.querySelector("#sort-containers-link"), async () => { try { await browser.runtime.sendMessage({ @@ -2423,7 +2443,7 @@ Logic.registerPanel(P_CONTAINERS_ACHIEVEMENT, { }, }); -Logic.init(); +Logic.initPromise = Logic.init(); window.addEventListener("resize", function () { //for overflow menu diff --git a/src/manifest.json b/src/manifest.json index daebff1..027781b 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,6 +1,6 @@ { "manifest_version": 2, - "name": "Firefox Multi-Account Containers", + "name": "Firefox Multi-Account Containers DEV", "version": "8.2.0", "incognito": "not_allowed", "description": "__MSG_extensionDescription__", diff --git a/src/popup.html b/src/popup.html index b2bae8d..d59eaa0 100644 --- a/src/popup.html +++ b/src/popup.html @@ -149,6 +149,14 @@ + + + + + + + +
From 02f5ef86f30d26d59370e02e10676be3defa0b24 Mon Sep 17 00:00:00 2001 From: gholk Date: Sun, 20 Apr 2025 22:06:26 +0800 Subject: [PATCH 4/4] sync i18n submodule --- .gitmodules | 2 +- src/_locales | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index acf9a70..a4c92c7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "src/_locales"] branch = main path = src/_locales - url = https://github.com/mozilla-l10n/multi-account-containers-l10n.git + url = https://github.com/GHolk/multi-account-containers-l10n.git ignore=all diff --git a/src/_locales b/src/_locales index 4c5fb04..e9fb992 160000 --- a/src/_locales +++ b/src/_locales @@ -1 +1 @@ -Subproject commit 4c5fb04b020eb47f3238971f6f04b096c2dea2c0 +Subproject commit e9fb99295ceb14eaa9cb8cdc24887f6258949012