Skip to content

Switch to disable redirection and restriction of a container temporary #2751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion bin/addons-linter.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 10 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/img/disable-redirect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 20 additions & 5 deletions src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,20 @@ window.assignManager = {
return {};
}
this.removeContextMenu();
const [tab, siteSettings] = await Promise.all([
const a = await Promise.all([
browser.tabs.get(options.tabId),
this.storageArea.get(options.url)
]);
let container;
const tab = a[0];
let siteSettings = a[1];
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;
}
Expand All @@ -243,6 +249,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
Expand Down Expand Up @@ -392,7 +406,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() {
Expand Down
20 changes: 19 additions & 1 deletion src/js/background/backgroundLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ const backgroundLogic = {
}
},

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;
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");
Expand Down Expand Up @@ -321,7 +338,8 @@ const backgroundLogic = {
hasOpenTabs: !!openTabs.length,
numberOfHiddenTabs: containerState.hiddenTabs.length,
numberOfOpenTabs: openTabs.length,
isIsolated: !!containerState.isIsolated
isIsolated: !!containerState.isIsolated,
redirectDisable: containerState.redirectDisable
};
return;
});
Expand Down
5 changes: 5 additions & 0 deletions src/js/background/messageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ const messageHandler = {
windowId: m.windowId
});
break;
case "setRedirectState":
response = backgroundLogic.setRedirectState(
m.cookieStoreId, m.state, m.global
);
break;
case "checkIncompatibleAddons":
// TODO
break;
Expand Down
45 changes: 44 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const Logic = {
_previousPanelPath: [],
_panels: {},
_onboardingVariation: null,
_initPromise: null,

async init() {
browser.runtime.sendMessage({
Expand Down Expand Up @@ -258,6 +259,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];
Expand Down Expand Up @@ -756,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({
Expand Down Expand Up @@ -998,6 +1019,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({
Expand All @@ -1019,6 +1041,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) {
Expand Down Expand Up @@ -2400,7 +2443,7 @@ Logic.registerPanel(P_CONTAINERS_ACHIEVEMENT, {
},
});

Logic.init();
Logic.initPromise = Logic.init();

window.addEventListener("resize", function () {
//for overflow menu
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -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__",
Expand Down
16 changes: 16 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ <h3 class="title">Firefox Multi-Account Containers</h3>
</span>
</td>
</tr>
<tr class="menu-item hover-highlight keyboard-nav" id="disable-redirect-all" tabindex="0">
<td>
<img class="menu-icon" alt="" src="/img/disable-redirect.svg" />
<span class="menu-text" data-i18n-message-id="disableRedirectAllContainer"></span>
<span class="menu-arrow">
</span>
</td>
</tr>
</table>
<hr>
<div class="sub-header-wrapper flx-row flx-space-between">
Expand Down Expand Up @@ -247,6 +255,14 @@ <h3 class="title" id="container-info-title" data-i18n-attribute-message-id="pers
</span>
</td>
</tr>
<tr class="menu-item hover-highlight keyboard-nav" id="disable-redirect" tabindex="0">
<td>
<img class="menu-icon" alt="" src="/img/disable-redirect.svg" />
<span class="menu-text" id="disable-redirect-this-container" data-i18n-message-id="disableRedirectThisContainer"></span>
<span class="menu-arrow">
</span>
</td>
</tr>
<tr class="menu-item hover-highlight keyboard-nav" id="clear-container-storage" tabindex="0">
<td>
<img class="menu-icon clear-storage-icon" alt="" src="img/container-delete.svg" />
Expand Down