Skip to content

Commit

Permalink
Remember choice for default container 'always open' option
Browse files Browse the repository at this point in the history
  • Loading branch information
rafeerahman committed Jul 18, 2024
1 parent 0acc48a commit c48a75a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,17 @@ window.assignManager = {

},


_neverAsk(m) {
const pageUrl = m.pageUrl;
const defaultContainer = m.defaultContainer;

if (m.neverAsk === true) {
if (defaultContainer) {
this.storageArea.remove(pageUrl);
return;
}

// If we have existing data and for some reason it hasn't been
// deleted etc lets update it
this.storageArea.get(pageUrl).then((siteSettings) => {
Expand Down Expand Up @@ -257,7 +265,6 @@ window.assignManager = {
// - in this case, we must re-open "www.amazon.com" in a new tab in the default container
const siteIsolatedReloadInDefault =
await this._maybeSiteIsolatedReloadInDefault(siteSettings, tab);

if (!siteIsolatedReloadInDefault) {
if (!siteSettings
|| userContextId === siteSettings.userContextId
Expand Down Expand Up @@ -764,7 +771,7 @@ window.assignManager = {
async initBookmarksMenu() {
browser.contextMenus.create({
id: this.OPEN_IN_CONTAINER,
title: "Open Bookmark in Container Tab",
title: browser.i18n.getMessage("openBookmarkInContainerTab"),
contexts: ["bookmark"],
});

Expand Down
25 changes: 22 additions & 3 deletions src/js/confirm-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ async function load() {

document.getElementById("deny").addEventListener("click", (e) => {
e.preventDefault();
denySubmit(redirectUrl);
denySubmit(redirectUrl, currentCookieStoreId);
});

document.getElementById("deny-no-container").addEventListener("click", (e) => {
e.preventDefault();
denySubmit(redirectUrl);
denySubmit(redirectUrl, currentCookieStoreId);
});

const container = await browser.contextualIdentities.get(cookieStoreId);
Expand Down Expand Up @@ -52,6 +52,9 @@ function appendFavicon(pageUrl, redirectUrlElement) {
redirectUrlElement.prepend(favIconElement);
}

/**
* Runs when the previously selected container option is clicked.
*/
function confirmSubmit(redirectUrl, cookieStoreId) {
const neverAsk = document.getElementById("never-ask").checked;
// Sending neverAsk message to background to store for next time we see this process
Expand All @@ -72,13 +75,29 @@ function getCurrentTab() {
});
}

async function denySubmit(redirectUrl) {
/**
* Runs when the newly selected container or default container option is clicked.
*/
async function denySubmit(redirectUrl, currentCookieStoreId) {
const tab = await getCurrentTab();
const currentContainer = currentCookieStoreId ? await browser.contextualIdentities.get(currentCookieStoreId) : null;
const neverAsk = document.getElementById("never-ask").checked;

if (neverAsk && !currentContainer) {
await browser.runtime.sendMessage({
method: "neverAsk",
neverAsk: true,
defaultContainer: true,
pageUrl: redirectUrl
});
}

await browser.runtime.sendMessage({
method: "exemptContainerAssignment",
tabId: tab[0].id,
pageUrl: redirectUrl
});

document.location.replace(redirectUrl);
}

Expand Down

0 comments on commit c48a75a

Please sign in to comment.