From 4331a2612c38ff082d42177d40c436f216211a5f Mon Sep 17 00:00:00 2001 From: baku Date: Wed, 18 Jan 2017 17:32:56 +0100 Subject: [PATCH 1/5] Show tab list if Container is hidden but don't make the rows selectable --- index.js | 28 ++++++++++++++++++++++------ webextension/js/popup.js | 26 +++++++++++++++----------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 28fbb22..7e1a6b5 100644 --- a/index.js +++ b/index.js @@ -160,12 +160,15 @@ const ContainerService = { return parseInt(viewFor(tab).getAttribute("usercontextid") || 0, 10); }, + _createTabObject(tab) { + return { title: tab.title, url: tab.url, id: tab.id, active: true }; + }, + _getTabList(userContextId) { const list = []; for (let tab of tabs) { // eslint-disable-line prefer-const if (userContextId === this._getUserContextIdFromTab(tab)) { - const object = { title: tab.title, url: tab.url, id: tab.id }; - list.push(object); + list.push(this._createTabObject(tab)); } } @@ -186,7 +189,19 @@ const ContainerService = { continue; } - this._identitiesState[args.userContextId].hiddenTabUrls.push(tab.url); + const object = this._createTabObject(tab); + + // This tab is going to be closed. Let's mark this tabObject as + // non-active. + object.active = false; + + getFavicon(object.url).then(url => { + object.favicon = url; + }, () => { + object.favicon = ""; + }); + + this._identitiesState[args.userContextId].hiddenTabUrls.push(object); tab.close(); } @@ -201,8 +216,9 @@ const ContainerService = { const promises = []; - for (let url of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const - promises.push(this.openTab({ userContextId: args.userContextId, url })); + for (let object of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const + promises.push(this.openTab({ userContextId: args.userContextId, + url: object.url })); } this._identitiesState[args.userContextId].hiddenTabUrls = []; @@ -279,7 +295,7 @@ const ContainerService = { } Promise.all(promises).then(() => { - resolve(list); + resolve(list.concat(this._identitiesState[args.userContextId].hiddenTabUrls)); }).catch((e) => { reject(e); }); diff --git a/webextension/js/popup.js b/webextension/js/popup.js index b2ef64e..729555c 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -320,21 +320,25 @@ Logic.registerPanel(P_CONTAINER_INFO, { for (let tab of tabs) { // eslint-disable-line prefer-const const tr = document.createElement("tr"); fragment.appendChild(tr); - tr.classList.add("container-info-tab", "clickable"); + tr.classList.add("container-info-tab"); tr.innerHTML = ` ${tab.title}`; - // On click, we activate this tab. - tr.addEventListener("click", () => { - browser.runtime.sendMessage({ - method: "showTab", - tabId: tab.id, - }).then(() => { - window.close(); - }).catch(() => { - window.close(); + + // On click, we activate this tab. But only if this tab is active. + if (tab.active) { + tr.classList.add("clickable"); + tr.addEventListener("click", () => { + browser.runtime.sendMessage({ + method: "showTab", + tabId: tab.id, + }).then(() => { + window.close(); + }).catch(() => { + window.close(); + }); }); - }); + } } document.getElementById("container-info-table").appendChild(fragment); From 702d5aba4c569a32f2315394f5ed91847afd889e Mon Sep 17 00:00:00 2001 From: baku Date: Wed, 18 Jan 2017 18:07:33 +0100 Subject: [PATCH 2/5] Close the opened tabs when a container is deleted --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 7e1a6b5..5ee34d2 100644 --- a/index.js +++ b/index.js @@ -454,6 +454,13 @@ const ContainerService = { if (!("userContextId" in args)) { return Promise.reject("removeIdentity must be called with userContextId argument."); } + + for (let tab of tabs) { // eslint-disable-line prefer-const + if (args.userContextId === this._getUserContextIdFromTab(tab)) { + tab.close(); + } + } + return Promise.resolve(ContextualIdentityService.remove(args.userContextId)); }, From 5e2c3b4704b2d35ae39a7f5579843d136320c308 Mon Sep 17 00:00:00 2001 From: baku Date: Wed, 18 Jan 2017 18:09:42 +0100 Subject: [PATCH 3/5] Make eslint happy again --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5ee34d2..ff7490a 100644 --- a/index.js +++ b/index.js @@ -197,7 +197,7 @@ const ContainerService = { getFavicon(object.url).then(url => { object.favicon = url; - }, () => { + }).catch(() => { object.favicon = ""; }); @@ -217,8 +217,7 @@ const ContainerService = { const promises = []; for (let object of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const - promises.push(this.openTab({ userContextId: args.userContextId, - url: object.url })); + promises.push(this.openTab({ userContextId: args.userContextId, url: object.url })); } this._identitiesState[args.userContextId].hiddenTabUrls = []; @@ -289,7 +288,7 @@ const ContainerService = { for (let object of list) { // eslint-disable-line prefer-const promises.push(getFavicon(object.url).then(url => { object.favicon = url; - }, () => { + }).catch(() => { object.favicon = ""; })); } From 6a9315f295cfb90391582b0fdc72a70dd7f1bf1a Mon Sep 17 00:00:00 2001 From: baku Date: Wed, 18 Jan 2017 18:22:07 +0100 Subject: [PATCH 4/5] Hide/Show the hide-or-show panel --- webextension/js/popup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 729555c..1dca2a4 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -295,7 +295,7 @@ Logic.registerPanel(P_CONTAINER_INFO, { // Show or not the has-tabs section. for (let trHasTabs of document.getElementsByClassName("container-info-has-tabs")) { // eslint-disable-line prefer-const - trHasTabs.hidden = !identity.hasHiddenTabs && !identity.hasOpenTabs; + trHasTabs.style.display = !identity.hasHiddenTabs && !identity.hasOpenTabs ? "none" : ""; } const hideShowIcon = document.getElementById("container-info-hideorshow-icon"); From 4ce4e2bf7f55feb2c914bc967b41cae248c562c0 Mon Sep 17 00:00:00 2001 From: baku Date: Wed, 18 Jan 2017 18:55:45 +0100 Subject: [PATCH 5/5] Fixed the moving of containers tabs in a separate window --- index.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index ff7490a..37c8889 100644 --- a/index.js +++ b/index.js @@ -164,15 +164,12 @@ const ContainerService = { return { title: tab.title, url: tab.url, id: tab.id, active: true }; }, - _getTabList(userContextId) { - const list = []; + _containerTabIterator(userContextId, cb) { for (let tab of tabs) { // eslint-disable-line prefer-const if (userContextId === this._getUserContextIdFromTab(tab)) { - list.push(this._createTabObject(tab)); + cb(tab); } } - - return list; }, // Tabs management @@ -184,11 +181,7 @@ const ContainerService = { return; } - for (let tab of tabs) { // eslint-disable-line prefer-const - if (args.userContextId !== this._getUserContextIdFromTab(tab)) { - continue; - } - + this._containerTabIterator(args.userContextId, tab => { const object = this._createTabObject(tab); // This tab is going to be closed. Let's mark this tabObject as @@ -203,7 +196,7 @@ const ContainerService = { this._identitiesState[args.userContextId].hiddenTabUrls.push(object); tab.close(); - } + }); resolve(null); }); @@ -282,7 +275,11 @@ const ContainerService = { return; } - const list = this._getTabList(args.userContextId); + const list = []; + this._containerTabIterator(args.userContextId, tab => { + list.push(this._createTabObject(tab)); + }); + const promises = []; for (let object of list) { // eslint-disable-line prefer-const @@ -328,7 +325,10 @@ const ContainerService = { } // Let's create a list of the tabs. - const list = this._getTabList(args.userContextId); + const list = []; + this._containerTabIterator(args.userContextId, tab => { + list.push(tab); + }); // Nothing to do if (list.length === 0) { @@ -344,7 +344,7 @@ const ContainerService = { // Let's move the tab to the new window. for (let tab of list) { // eslint-disable-line prefer-const const newTab = newBrowserWindow.gBrowser.addTab("about:blank"); - newBrowserWindow.gBrowser.swapBrowsersAndCloseOther(newTab, tab); + newBrowserWindow.gBrowser.swapBrowsersAndCloseOther(newTab, viewFor(tab)); // swapBrowsersAndCloseOther is an internal method of gBrowser // an it's not supported by addon SDK. This means that we // don't receive an 'open' event, but only the 'close' one. @@ -454,11 +454,9 @@ const ContainerService = { return Promise.reject("removeIdentity must be called with userContextId argument."); } - for (let tab of tabs) { // eslint-disable-line prefer-const - if (args.userContextId === this._getUserContextIdFromTab(tab)) { - tab.close(); - } - } + this._containerTabIterator(args.userContextId, tab => { + tab.close(); + }); return Promise.resolve(ContextualIdentityService.remove(args.userContextId)); },