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
29 changes: 17 additions & 12 deletions src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ window.assignManager = {
const macConfigs = await this.area.get();
for(const configKey of Object.keys(macConfigs)) {
if (configKey.includes("siteContainerMap@@_")) {
if (String(macConfigs[configKey].userContextId) === "0") continue;
const cookieStoreId =
"firefox-container-" + macConfigs[configKey].userContextId;
const match = identitiesList.find(
Expand Down Expand Up @@ -228,19 +229,22 @@ window.assignManager = {
browser.tabs.get(options.tabId),
this.storageArea.get(options.url)
]);
const isDefaultContainerAssignment = siteSettings && String(siteSettings.userContextId) === "0";
let container;
try {
container = await browser.contextualIdentities
.get(backgroundLogic.cookieStoreId(siteSettings.userContextId));
} catch {
container = false;
}
if (!isDefaultContainerAssignment) {
try {
container = await browser.contextualIdentities
.get(backgroundLogic.cookieStoreId(siteSettings.userContextId));
} catch {
container = false;
}

// The container we have in the assignment map isn't present any
// more so lets remove it then continue the existing load
if (siteSettings && !container) {
this.deleteContainer(siteSettings.userContextId);
return {};
// The container we have in the assignment map isn't present any
// more so lets remove it then continue the existing load
if (siteSettings && !container) {
this.deleteContainer(siteSettings.userContextId);
return {};
}
}
const userContextId = this.getUserContextIdFromCookieStore(tab);

Expand All @@ -267,6 +271,7 @@ window.assignManager = {
if (!siteIsolatedReloadInDefault) {
if (!siteSettings
|| userContextId === siteSettings.userContextId
|| (isDefaultContainerAssignment && tab.cookieStoreId === "firefox-default")
|| this.storageArea.isExempted(options.url, tab.id)) {
return {};
}
Expand Down Expand Up @@ -320,7 +325,7 @@ window.assignManager = {
}
}

if (siteIsolatedReloadInDefault) {
if (siteIsolatedReloadInDefault || isDefaultContainerAssignment) {
this.reloadPageInDefaultContainer(
options.url,
tab.index + 1,
Expand Down
41 changes: 41 additions & 0 deletions src/js/pageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@ async function init() {
const fragment = document.createDocumentFragment();
const identities = await browser.contextualIdentities.query({});

const currentTab = await Utils.currentTab();

{
const tr = document.createElement("tr");
tr.classList.add("menu-item", "hover-highlight");
const td = document.createElement("td");
td.innerHTML = Utils.escaped`
<div class="menu-icon">
<div class="mac-icon">
</div>
</div>
<span class="menu-text">No Container</span>
<img alt="" class="page-action-flag flag-img" src="/img/flags/.png"/>
`;

tr.appendChild(td);
fragment.appendChild(tr);

Utils.addEnterHandler(tr, async () => {
if (currentTab.cookieStoreId !== "firefox-default") {
await browser.runtime.sendMessage({
method: "assignAndReloadInContainer",
url: currentTab.url,
currentUserContextId: false,
newUserContextId: 0,
tabIndex: currentTab.index + 1,
active: currentTab.active,
groupId: currentTab.groupId
});
} else {
await Utils.setOrRemoveAssignment(
currentTab.id,
currentTab.url,
0,
false
);
}
window.close();
});
}

for (const identity of identities) {
const tr = document.createElement("tr");
tr.classList.add("menu-item", "hover-highlight");
Expand Down
86 changes: 78 additions & 8 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ const Logic = {
},

getAssignmentObjectByContainer(userContextId) {
if (!userContextId) {
if (!userContextId && userContextId !== 0 && userContextId !== "0") {
return {};
}
return browser.runtime.sendMessage({
Expand Down Expand Up @@ -1185,6 +1185,31 @@ Logic.registerPanel(MANAGE_CONTAINERS_PICKER, {

const identities = Logic.identities();

{
const noContainerIdentity = {
name: "No Container",
cookieStoreId: "firefox-default",
};
const tr = document.createElement("tr");
tr.classList.add("menu-item", "hover-highlight", "keyboard-nav");
tr.setAttribute("tabindex", "0");
const td = document.createElement("td");

td.innerHTML = Utils.escaped`
<div class="menu-icon hover-highlight">
<div class="mac-icon">
</div>
</div>
<span class="menu-text">No Container</span>`;

tr.appendChild(td);
fragment.appendChild(tr);

Utils.addEnterHandler(tr, () => {
Logic.showPanel(P_CONTAINER_ASSIGNMENTS, noContainerIdentity);
});
}

for (const identity of identities) {
const tr = document.createElement("tr");
tr.classList.add("menu-item", "hover-highlight", "keyboard-nav");
Expand Down Expand Up @@ -1385,6 +1410,46 @@ Logic.registerPanel(ALWAYS_OPEN_IN_PICKER, {

document.getElementById("new-container-div").innerHTML = "";

{
const tr = document.createElement("tr");
tr.classList.add("menu-item", "hover-highlight", "keyboard-nav");
tr.setAttribute("tabindex", "0");
const td = document.createElement("td");

td.innerHTML = Utils.escaped`
<div class="menu-icon hover-highlight">
<div class="mac-icon">
</div>
</div>
<span class="menu-text">No Container</span>`;

tr.appendChild(td);
fragment.appendChild(tr);

Utils.addEnterHandler(tr, async () => {
const currentTab = await Utils.currentTab();
if (currentTab.cookieStoreId !== "firefox-default") {
await browser.runtime.sendMessage({
method: "assignAndReloadInContainer",
url: currentTab.url,
currentUserContextId: false,
newUserContextId: 0,
tabIndex: currentTab.index + 1,
active: currentTab.active,
groupId: currentTab.groupId
});
} else {
await Utils.setOrRemoveAssignment(
currentTab.id,
currentTab.url,
0,
false
);
}
window.close();
});
}

for (const identity of identities) {
const tr = document.createElement("tr");
tr.classList.add("menu-item", "hover-highlight", "keyboard-nav");
Expand Down Expand Up @@ -1432,22 +1497,27 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
// This method is called when the panel is shown.
async prepare() {
const identity = Logic.currentIdentity();
const isNoContainer = identity.cookieStoreId === "firefox-default";

// Populating the panel: name and icon
document.getElementById("edit-assignments-title").textContent = identity.name;

const userContextId = Logic.currentUserContextId();
const userContextId = isNoContainer ? "0" : Logic.currentUserContextId();
const assignments = await Logic.getAssignmentObjectByContainer(userContextId);
this.showAssignedContainers(assignments);
this.showAssignedContainers(assignments, isNoContainer);

return Promise.resolve(null);
},

showAssignedContainers(assignments) {
showAssignedContainers(assignments, isNoContainer) {
const closeContEl = document.querySelector("#close-container-assignment-panel");
Utils.addEnterHandler(closeContEl, () => {
const identity = Logic.currentIdentity();
Logic.showPanel(P_CONTAINER_EDIT, identity, false, false);
if (isNoContainer) {
Logic.showPanel(MANAGE_CONTAINERS_PICKER, null, false, false);
} else {
const identity = Logic.currentIdentity();
Logic.showPanel(P_CONTAINER_EDIT, identity, false, false);
}
});

const assignmentPanel = document.getElementById("edit-sites-assigned");
Expand Down Expand Up @@ -1478,12 +1548,12 @@ Logic.registerPanel(P_CONTAINER_ASSIGNMENTS, {
trElement.getElementsByClassName("favicon")[0].appendChild(Utils.createFavIconElement(assumedUrl));
const deleteButton = trElement.querySelector(".trash-button");
Utils.addEnterHandler(deleteButton, async () => {
const userContextId = Logic.currentUserContextId();
const userContextId = isNoContainer ? "0" : Logic.currentUserContextId();
// Lets show the message to the current tab
// const currentTab = await Utils.currentTab();
Utils.setOrRemoveAssignment(false, assumedUrl, userContextId, true);
delete assignments[siteKey];
this.showAssignedContainers(assignments);
this.showAssignedContainers(assignments, isNoContainer);
});
const resetButton = trElement.querySelector(".reset-button");
Utils.addEnterHandler(resetButton, async () => {
Expand Down