Skip to content
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
31 changes: 30 additions & 1 deletion src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ window.assignManager = {
const siteIsolatedReloadInDefault =
await this._maybeSiteIsolatedReloadInDefault(siteSettings, tab);

if (!siteIsolatedReloadInDefault) {
const fallbackCookieStoreId = (!siteSettings && !siteIsolatedReloadInDefault)
? await this._maybeFallbackContainerCookieStoreId(tab)
: null;

if (!siteIsolatedReloadInDefault && !fallbackCookieStoreId) {
if (!siteSettings
|| userContextId === siteSettings.userContextId
|| this.storageArea.isExempted(options.url, tab.id)) {
Expand Down Expand Up @@ -328,6 +332,15 @@ window.assignManager = {
openTabId,
tab.groupId
);
} else if (fallbackCookieStoreId) {
this.createTabWrapper(
options.url,
fallbackCookieStoreId,
tab.index + 1,
tab.active,
openTabId,
tab.groupId
);
} else {
this.reloadPageInContainer(
options.url,
Expand Down Expand Up @@ -396,6 +409,22 @@ window.assignManager = {
return currentContainerState && currentContainerState.isIsolated;
},

async _maybeFallbackContainerCookieStoreId(tab) {
const { fallbackContainerCookieStoreId } = await browser.storage.local.get("fallbackContainerCookieStoreId");
if (!fallbackContainerCookieStoreId) return null;
// Already in the fallback container, no redirect needed
if (tab.cookieStoreId === fallbackContainerCookieStoreId) return null;
// Verify the container still exists
try {
await browser.contextualIdentities.get(fallbackContainerCookieStoreId);
return fallbackContainerCookieStoreId;
} catch {
// Container was deleted, clean up the setting
browser.storage.local.remove("fallbackContainerCookieStoreId");
return null;
}
},

maybeAddProxyListeners() {
if (browser.proxy) {
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
Expand Down
33 changes: 33 additions & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ async function changeTheme(event) {
await browser.storage.local.set({currentThemeId: theme.selectedIndex});
}

async function setupDefaultContainerSelect() {
const select = document.querySelector("#defaultContainerSelect");
const identities = await browser.contextualIdentities.query({});

const noneOption = document.createElement("option");
noneOption.value = "";
noneOption.textContent = browser.i18n.getMessage("defaultContainerNone");
select.appendChild(noneOption);

for (const identity of identities) {
const option = document.createElement("option");
option.value = identity.cookieStoreId;
option.textContent = identity.name;
select.appendChild(option);
}

const { fallbackContainerCookieStoreId } = await browser.storage.local.get("fallbackContainerCookieStoreId");
if (fallbackContainerCookieStoreId) {
select.value = fallbackContainerCookieStoreId;
}
}

async function changeDefaultContainer(event) {
const cookieStoreId = event.target.value || null;
if (cookieStoreId) {
await browser.storage.local.set({ fallbackContainerCookieStoreId: cookieStoreId });
} else {
await browser.storage.local.remove("fallbackContainerCookieStoreId");
}
}

async function setupOptions() {
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
Expand All @@ -68,6 +99,7 @@ async function setupOptions() {
document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled;
document.querySelector("#changeTheme").selectedIndex = currentThemeId;
setupContainerShortcutSelects();
setupDefaultContainerSelect();
}

async function setupContainerShortcutSelects () {
Expand Down Expand Up @@ -124,6 +156,7 @@ document.addEventListener("DOMContentLoaded", setupOptions);
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab);
document.querySelector("#changeTheme").addEventListener( "change", changeTheme);
document.querySelector("#defaultContainerSelect").addEventListener("change", changeDefaultContainer);

maybeShowPermissionsWarningIcon();
for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
Expand Down
10 changes: 10 additions & 0 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ <h3 data-i18n-message-id="theme"></h3>
</select>
</label></p>

<h3 data-i18n-message-id="defaultContainer"></h3>
<div class="settings-group">
<label class="keyboard-shortcut">
<span data-i18n-message-id="defaultContainerLabel"></span>
<select id="defaultContainerSelect">
</select>
</label>
<p><em data-i18n-message-id="defaultContainerDescription"></em></p>
</div>

<h3 data-i18n-message-id="keyboardShortCuts"></h3>
<p><em data-i18n-message-id="editWhichContainer"></em></p>

Expand Down