diff --git a/.eslintrc.js b/.eslintrc.js
index f2a7957..d9f7270 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -9,6 +9,7 @@ module.exports = {
"webextensions": true
},
"globals": {
+ "Utils": true,
"CustomizableUI": true,
"CustomizableWidgets": true,
"SessionStore": true,
diff --git a/webextension/background.js b/webextension/background.js
index ca01d89..ebedf66 100644
--- a/webextension/background.js
+++ b/webextension/background.js
@@ -56,19 +56,25 @@ const assignManager = {
return this.area.remove([siteStoreKey]);
},
- deleteContainer(userContextId) {
- const removeKeys = [];
- this.area.get().then((siteConfigs) => {
- Object.keys(siteConfigs).forEach((key) => {
- // For some reason this is stored as string... lets check them both as that
- if (String(siteConfigs[key].userContextId) === String(userContextId)) {
- removeKeys.push(key);
- }
- });
- this.area.remove(removeKeys);
- }).catch((e) => {
- throw e;
+ async deleteContainer(userContextId) {
+ const sitesByContainer = await this.getByContainer(userContextId);
+ this.area.remove(Object.keys(sitesByContainer));
+ },
+
+ async getByContainer(userContextId) {
+ const sites = {};
+ const siteConfigs = await this.area.get();
+ Object.keys(siteConfigs).forEach((key) => {
+ // For some reason this is stored as string... lets check them both as that
+ if (String(siteConfigs[key].userContextId) === String(userContextId)) {
+ const site = siteConfigs[key];
+ // In hindsight we should have stored this
+ // TODO file a follow up to clean the storage onLoad
+ site.hostname = key.replace(/^siteContainerMap@@_/, "");
+ sites[key] = site;
+ }
});
+ return sites;
}
},
@@ -104,6 +110,7 @@ const assignManager = {
if (options.frameId !== 0 || options.tabId === -1) {
return {};
}
+ this.removeContextMenu();
return Promise.all([
browser.tabs.get(options.tabId),
this.storageArea.get(options.url)
@@ -151,15 +158,11 @@ const assignManager = {
// let actionName;
let remove;
if (info.menuItemId === this.MENU_ASSIGN_ID) {
- //actionName = "added";
- // storageAction = this._setAssignment(info.pageUrl, userContextId, setOrRemove);
remove = false;
} else {
- // actionName = "removed";
- //storageAction = this.storageArea.remove(info.pageUrl);
remove = true;
}
- await this._setOrRemoveAssignment(info.pageUrl, userContextId, remove);
+ await this._setOrRemoveAssignment(tab.id, info.pageUrl, userContextId, remove);
this.calculateContextMenu(tab);
}
},
@@ -192,7 +195,7 @@ const assignManager = {
return true;
},
- async _setOrRemoveAssignment(pageUrl, userContextId, remove) {
+ async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) {
let actionName;
if (!remove) {
await this.storageArea.set(pageUrl, {
@@ -205,11 +208,8 @@ const assignManager = {
await this.storageArea.remove(pageUrl);
actionName = "removed";
}
- browser.notifications.create({
- type: "basic",
- title: "Containers",
- message: `Successfully ${actionName} site to always open in this container`,
- iconUrl: browser.extension.getURL("/img/onboarding-1.png")
+ browser.tabs.sendMessage(tabId, {
+ text: `Successfully ${actionName} site to always open in this container`
});
backgroundLogic.sendTelemetryPayload({
event: `${actionName}-container-assignment`,
@@ -227,7 +227,11 @@ const assignManager = {
return false;
},
- async calculateContextMenu(tab) {
+ _getByContainer(userContextId) {
+ return this.storageArea.getByContainer(userContextId);
+ },
+
+ removeContextMenu() {
// There is a focus issue in this menu where if you change window with a context menu click
// you get the wrong menu display because of async
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1215376#c16
@@ -235,6 +239,10 @@ const assignManager = {
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1352102
browser.contextMenus.remove(this.MENU_ASSIGN_ID);
browser.contextMenus.remove(this.MENU_REMOVE_ID);
+ },
+
+ async calculateContextMenu(tab) {
+ this.removeContextMenu();
const siteSettings = await this._getAssignment(tab);
// ✓ This is to mitigate https://bugzilla.mozilla.org/show_bug.cgi?id=1351418
let prefix = " "; // Alignment of non breaking space, unknown why this requires so many spaces to align with the tick
@@ -429,10 +437,13 @@ const messageHandler = {
return assignManager._getAssignment(tab);
});
break;
+ case "getAssignmentObjectByContainer":
+ response = assignManager._getByContainer(m.message.userContextId);
+ break;
case "setOrRemoveAssignment":
response = browser.tabs.get(m.tabId).then((tab) => {
const userContextId = assignManager.getUserContextIdFromCookieStore(tab);
- return assignManager._setOrRemoveAssignment(tab.url, userContextId, m.value);
+ return assignManager._setOrRemoveAssignment(tab.id, tab.url, userContextId, m.value);
});
break;
case "exemptContainerAssignment":
@@ -474,6 +485,7 @@ const messageHandler = {
});
browser.tabs.onActivated.addListener((info) => {
+ assignManager.removeContextMenu();
browser.tabs.get(info.tabId).then((tab) => {
tabPageCounter.initTabCounter(tab);
assignManager.calculateContextMenu(tab);
@@ -483,6 +495,7 @@ const messageHandler = {
});
browser.windows.onFocusChanged.addListener((windowId) => {
+ assignManager.removeContextMenu();
browser.tabs.query({active: true, windowId}).then((tabs) => {
if (tabs && tabs[0]) {
tabPageCounter.initTabCounter(tabs[0]);
@@ -511,6 +524,7 @@ const messageHandler = {
if (details.frameId !== 0 || details.tabId === -1) {
return {};
}
+ assignManager.removeContextMenu();
browser.tabs.get(details.tabId).then((tab) => {
tabPageCounter.incrementTabCount(tab);
diff --git a/webextension/confirm-page.html b/webextension/confirm-page.html
index 09d4852..20d11c8 100644
--- a/webextension/confirm-page.html
+++ b/webextension/confirm-page.html
@@ -27,6 +27,7 @@
+