From dba0b9707293529abe7d36457471ae83af3affa4 Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 17:44:55 +0100 Subject: [PATCH 1/7] Icon+Color must be refreshed when tab changes --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 915c442..6946647 100644 --- a/index.js +++ b/index.js @@ -956,12 +956,16 @@ const ContainerService = { const userContextId = ContainerService._getUserContextIdFromTab(tab); return ContainerService.getIdentity({userContextId}).then(identity => { + const hbox = viewFor(tab.window).document.getElementById("userContext-icons"); + if (!identity) { + hbox.setAttribute("data-identity-color", ""); + hbox.hidden = true; return; } - const hbox = viewFor(tab.window).document.getElementById("userContext-icons"); hbox.setAttribute("data-identity-color", identity.color); + hbox.hidden = false; const label = viewFor(tab.window).document.getElementById("userContext-label"); label.setAttribute("value", identity.name); From 29dc974fd6cff5c384f663c2139779a7db2e5c66 Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 18:04:46 +0100 Subject: [PATCH 2/7] Show tabs before opening a link from the context menu - #288 --- index.js | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 6946647..c80dafa 100644 --- a/index.js +++ b/index.js @@ -584,8 +584,15 @@ const ContainerService = { const promises = []; - for (let object of this._identitiesState[args.userContextId].hiddenTabs) { // eslint-disable-line prefer-const - promises.push(this.openTab({ userContextId: args.userContextId, url: object.url })); + const hiddenTabs = this._identitiesState[args.userContextId].hiddenTabs; + this._identitiesState[args.userContextId].hiddenTabs = []; + + for (let object of hiddenTabs) { // eslint-disable-line prefer-const + promises.push(this.openTab({ + userContextId: args.userContextId, + url: object.url, + nofocus: args.nofocus || false, + })); } this._identitiesState[args.userContextId].hiddenTabs = []; @@ -773,6 +780,7 @@ const ContainerService = { return this._recentBrowserWindow().then(browserWin => { const userContextId = ("userContextId" in args) ? args.userContextId : 0; const source = ("source" in args) ? args.source : null; + const nofocus = ("nofocus" in args) ? args.nofocus : false; // Only send telemetry for tabs opened by UI - i.e., not via showTabs if (source && userContextId) { @@ -793,8 +801,10 @@ const ContainerService = { return promise.then(() => { const tab = browserWin.gBrowser.addTab(args.url || DEFAULT_TAB, { userContextId }); - browserWin.gBrowser.selectedTab = tab; - browserWin.focusAndSelectUrlBar(); + if (!nofocus) { + browserWin.gBrowser.selectedTab = tab; + browserWin.focusAndSelectUrlBar(); + } return true; }); }).catch(() => false); @@ -1253,9 +1263,14 @@ ContainerWindow.prototype = { _configureAllTabsMenu() { return this._configureMenu("alltabs_containersTab", null, e => { const userContextId = parseInt(e.target.getAttribute("data-usercontextid"), 10); - ContainerService.openTab({ - userContextId: userContextId, - source: "alltabs-menu" + ContainerService.showTabs({ + userContextId, + nofocus: true + }).then(() => { + return ContainerService.openTab({ + userContextId, + source: "alltabs-menu" + }); }); }); }, @@ -1271,6 +1286,9 @@ ContainerWindow.prototype = { // This is a super internal method. Hopefully it will be stable in the // next FF releases. this._window.gContextMenu.openLinkInTab(e); + + let userContextId = parseInt(e.target.getAttribute('data-usercontextid'), 10); + ContainerService.showTabs({ userContextId, nofocus: true }); } ); }, From 35ddc045e6beaaca320f4b83d5c195f685234b9e Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 18:27:55 +0100 Subject: [PATCH 3/7] Correct window should be used if known - issue #287 --- index.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index c80dafa..20c3806 100644 --- a/index.js +++ b/index.js @@ -592,6 +592,7 @@ const ContainerService = { userContextId: args.userContextId, url: object.url, nofocus: args.nofocus || false, + window: args.window || null, })); } @@ -777,7 +778,15 @@ const ContainerService = { }, openTab(args) { - return this._recentBrowserWindow().then(browserWin => { + return new Promise(resolve => { + if ("window" in args && args.window) { + resolve(args.window); + } else { + this._recentBrowserWindow().then(browserWin => { + resolve(browserWin); + }); + } + }).then(browserWin => { const userContextId = ("userContextId" in args) ? args.userContextId : 0; const source = ("source" in args) ? args.source : null; const nofocus = ("nofocus" in args) ? args.nofocus : false; @@ -1219,7 +1228,8 @@ ContainerWindow.prototype = { menuItemElement.addEventListener("command", (e) => { ContainerService.openTab({ userContextId: identity.userContextId, - source: "tab-bar" + source: "tab-bar", + window: this._window, }); e.stopPropagation(); }); @@ -1255,7 +1265,8 @@ ContainerWindow.prototype = { const userContextId = parseInt(e.target.getAttribute("data-usercontextid"), 10); ContainerService.openTab({ userContextId: userContextId, - source: "file-menu" + source: "file-menu", + window: this._window, }); }); }, @@ -1265,11 +1276,13 @@ ContainerWindow.prototype = { const userContextId = parseInt(e.target.getAttribute("data-usercontextid"), 10); ContainerService.showTabs({ userContextId, - nofocus: true + nofocus: true, + window: this._window, }).then(() => { return ContainerService.openTab({ userContextId, - source: "alltabs-menu" + source: "alltabs-menu", + window: this._window, }); }); }); @@ -1288,7 +1301,11 @@ ContainerWindow.prototype = { this._window.gContextMenu.openLinkInTab(e); let userContextId = parseInt(e.target.getAttribute('data-usercontextid'), 10); - ContainerService.showTabs({ userContextId, nofocus: true }); + ContainerService.showTabs({ + userContextId, + nofocus: true, + window: this._window, + }); } ); }, From d66c3b8576b0387983c7516077560f8bb0c28009 Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 18:32:38 +0100 Subject: [PATCH 4/7] eslint is happy again --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 20c3806..43aeb83 100644 --- a/index.js +++ b/index.js @@ -784,7 +784,7 @@ const ContainerService = { } else { this._recentBrowserWindow().then(browserWin => { resolve(browserWin); - }); + }).catch(() => {}); } }).then(browserWin => { const userContextId = ("userContextId" in args) ? args.userContextId : 0; @@ -1284,7 +1284,7 @@ ContainerWindow.prototype = { source: "alltabs-menu", window: this._window, }); - }); + }).catch(() => {}); }); }, @@ -1300,7 +1300,7 @@ ContainerWindow.prototype = { // next FF releases. this._window.gContextMenu.openLinkInTab(e); - let userContextId = parseInt(e.target.getAttribute('data-usercontextid'), 10); + const userContextId = parseInt(e.target.getAttribute("data-usercontextid"), 10); ContainerService.showTabs({ userContextId, nofocus: true, From 9806087e98a9f98b6fbb12d16cc89bf12458b680 Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 18:39:34 +0100 Subject: [PATCH 5/7] The context menu must be recreated each time we change tab - issue #289 --- index.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 43aeb83..9f01173 100644 --- a/index.js +++ b/index.js @@ -228,15 +228,16 @@ const ContainerService = { tabs.on("activate", tab => { this._hideAllPanels(); this._restyleActiveTab(tab).catch(() => {}); + this._configureActiveWindows(); this._remapTab(tab); }); // Modify CSS and other stuff for each window. - this.configureWindows().catch(() => {}); + this._configureWindows().catch(() => {}); windows.browserWindows.on("open", window => { - this.configureWindow(viewFor(window)).catch(() => {}); + this._configureWindow(viewFor(window)).catch(() => {}); }); windows.browserWindows.on("close", window => { @@ -934,18 +935,30 @@ const ContainerService = { // Styling the window - configureWindows() { + _configureWindows() { const promises = []; for (let window of windows.browserWindows) { // eslint-disable-line prefer-const - promises.push(this.configureWindow(viewFor(window))); + promises.push(this._configureWindow(viewFor(window))); } return Promise.all(promises); }, - configureWindow(window) { + _configureWindow(window) { return this._getOrCreateContainerWindow(window).configure(); }, + _configureActiveWindows() { + const promises = []; + for (let window of windows.browserWindows) { // eslint-disable-line prefer-const + promises.push(this._configureActiveWindow(viewFor(window))); + } + return Promise.all(promises); + }, + + _configureActiveWindow(window) { + return this._getOrCreateContainerWindow(window).configureActive(); + }, + closeWindow(window) { this._windowMap.delete(window); }, @@ -1136,11 +1149,15 @@ ContainerWindow.prototype = { this._configureActiveTab(), this._configureFileMenu(), this._configureAllTabsMenu(), - this._configureContextMenu(), this._configureTabStyle(), + this.configureActive(), ]); }, + configureActive() { + return this._configureContextMenu(); + }, + handleEvent(e) { let el = e.target; switch (e.type) { From 46d688196d2b054766213eaecf283309411c2f4c Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 18:41:53 +0100 Subject: [PATCH 6/7] No .npm directory in the xpi - issue #291 --- .jpmignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.jpmignore b/.jpmignore index 100666b..eb8ed79 100644 --- a/.jpmignore +++ b/.jpmignore @@ -1,6 +1,7 @@ .git/ docs/ test/ +.npm/ node_modules/ .env From c565058d2b95a8d180b25120fe43975762b587ca Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 28 Feb 2017 19:05:55 +0100 Subject: [PATCH 7/7] No 'hidden' needed for hiding the label and the icon in the tab --- index.js | 2 -- package.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 9f01173..52cfcec 100644 --- a/index.js +++ b/index.js @@ -992,12 +992,10 @@ const ContainerService = { if (!identity) { hbox.setAttribute("data-identity-color", ""); - hbox.hidden = true; return; } hbox.setAttribute("data-identity-color", identity.color); - hbox.hidden = false; const label = viewFor(tab.window).document.getElementById("userContext-label"); label.setAttribute("value", identity.name); diff --git a/package.json b/package.json index c0b48e9..4956e1b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "testpilot-containers", "title": "Containers Experiment", "description": "Containers works by isolating cookie jars using separate origin-attributes defined visually by colored ‘Container Tabs’. This add-on is a modified version of the containers feature for Firefox Test Pilot.", - "version": "1.0.1", + "version": "1.0.2", "author": "Andrea Marchesini, Luke Crouch and Jonathan Kingston", "bugs": { "url": "https://github.com/mozilla/testpilot-containers/issues"