Merge pull request #91 from bakulf/tablist
many things, all together in 1 big PR
This commit is contained in:
commit
fe41394da8
2 changed files with 55 additions and 31 deletions
58
index.js
58
index.js
|
@ -160,16 +160,16 @@ const ContainerService = {
|
||||||
return parseInt(viewFor(tab).getAttribute("usercontextid") || 0, 10);
|
return parseInt(viewFor(tab).getAttribute("usercontextid") || 0, 10);
|
||||||
},
|
},
|
||||||
|
|
||||||
_getTabList(userContextId) {
|
_createTabObject(tab) {
|
||||||
const list = [];
|
return { title: tab.title, url: tab.url, id: tab.id, active: true };
|
||||||
|
},
|
||||||
|
|
||||||
|
_containerTabIterator(userContextId, cb) {
|
||||||
for (let tab of tabs) { // eslint-disable-line prefer-const
|
for (let tab of tabs) { // eslint-disable-line prefer-const
|
||||||
if (userContextId === this._getUserContextIdFromTab(tab)) {
|
if (userContextId === this._getUserContextIdFromTab(tab)) {
|
||||||
const object = { title: tab.title, url: tab.url, id: tab.id };
|
cb(tab);
|
||||||
list.push(object);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Tabs management
|
// Tabs management
|
||||||
|
@ -181,14 +181,22 @@ const ContainerService = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let tab of tabs) { // eslint-disable-line prefer-const
|
this._containerTabIterator(args.userContextId, tab => {
|
||||||
if (args.userContextId !== this._getUserContextIdFromTab(tab)) {
|
const object = this._createTabObject(tab);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._identitiesState[args.userContextId].hiddenTabUrls.push(tab.url);
|
// 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;
|
||||||
|
}).catch(() => {
|
||||||
|
object.favicon = "";
|
||||||
|
});
|
||||||
|
|
||||||
|
this._identitiesState[args.userContextId].hiddenTabUrls.push(object);
|
||||||
tab.close();
|
tab.close();
|
||||||
}
|
});
|
||||||
|
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
|
@ -201,8 +209,8 @@ const ContainerService = {
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
for (let url of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const
|
for (let object of this._identitiesState[args.userContextId].hiddenTabUrls) { // eslint-disable-line prefer-const
|
||||||
promises.push(this.openTab({ userContextId: args.userContextId, url }));
|
promises.push(this.openTab({ userContextId: args.userContextId, url: object.url }));
|
||||||
}
|
}
|
||||||
|
|
||||||
this._identitiesState[args.userContextId].hiddenTabUrls = [];
|
this._identitiesState[args.userContextId].hiddenTabUrls = [];
|
||||||
|
@ -267,19 +275,23 @@ const ContainerService = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const list = this._getTabList(args.userContextId);
|
const list = [];
|
||||||
|
this._containerTabIterator(args.userContextId, tab => {
|
||||||
|
list.push(this._createTabObject(tab));
|
||||||
|
});
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
for (let object of list) { // eslint-disable-line prefer-const
|
for (let object of list) { // eslint-disable-line prefer-const
|
||||||
promises.push(getFavicon(object.url).then(url => {
|
promises.push(getFavicon(object.url).then(url => {
|
||||||
object.favicon = url;
|
object.favicon = url;
|
||||||
}, () => {
|
}).catch(() => {
|
||||||
object.favicon = "";
|
object.favicon = "";
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
Promise.all(promises).then(() => {
|
||||||
resolve(list);
|
resolve(list.concat(this._identitiesState[args.userContextId].hiddenTabUrls));
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
|
@ -313,7 +325,10 @@ const ContainerService = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's create a list of the tabs.
|
// 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
|
// Nothing to do
|
||||||
if (list.length === 0) {
|
if (list.length === 0) {
|
||||||
|
@ -329,7 +344,7 @@ const ContainerService = {
|
||||||
// Let's move the tab to the new window.
|
// Let's move the tab to the new window.
|
||||||
for (let tab of list) { // eslint-disable-line prefer-const
|
for (let tab of list) { // eslint-disable-line prefer-const
|
||||||
const newTab = newBrowserWindow.gBrowser.addTab("about:blank");
|
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
|
// swapBrowsersAndCloseOther is an internal method of gBrowser
|
||||||
// an it's not supported by addon SDK. This means that we
|
// an it's not supported by addon SDK. This means that we
|
||||||
// don't receive an 'open' event, but only the 'close' one.
|
// don't receive an 'open' event, but only the 'close' one.
|
||||||
|
@ -438,6 +453,11 @@ const ContainerService = {
|
||||||
if (!("userContextId" in args)) {
|
if (!("userContextId" in args)) {
|
||||||
return Promise.reject("removeIdentity must be called with userContextId argument.");
|
return Promise.reject("removeIdentity must be called with userContextId argument.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._containerTabIterator(args.userContextId, tab => {
|
||||||
|
tab.close();
|
||||||
|
});
|
||||||
|
|
||||||
return Promise.resolve(ContextualIdentityService.remove(args.userContextId));
|
return Promise.resolve(ContextualIdentityService.remove(args.userContextId));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
|
||||||
|
|
||||||
// Show or not the has-tabs section.
|
// Show or not the has-tabs section.
|
||||||
for (let trHasTabs of document.getElementsByClassName("container-info-has-tabs")) { // eslint-disable-line prefer-const
|
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");
|
const hideShowIcon = document.getElementById("container-info-hideorshow-icon");
|
||||||
|
@ -320,11 +320,14 @@ Logic.registerPanel(P_CONTAINER_INFO, {
|
||||||
for (let tab of tabs) { // eslint-disable-line prefer-const
|
for (let tab of tabs) { // eslint-disable-line prefer-const
|
||||||
const tr = document.createElement("tr");
|
const tr = document.createElement("tr");
|
||||||
fragment.appendChild(tr);
|
fragment.appendChild(tr);
|
||||||
tr.classList.add("container-info-tab", "clickable");
|
tr.classList.add("container-info-tab");
|
||||||
tr.innerHTML = `
|
tr.innerHTML = `
|
||||||
<td><img class="icon" src="${tab.favicon}" /></td>
|
<td><img class="icon" src="${tab.favicon}" /></td>
|
||||||
<td>${tab.title}</td>`;
|
<td>${tab.title}</td>`;
|
||||||
// On click, we activate this tab.
|
|
||||||
|
// On click, we activate this tab. But only if this tab is active.
|
||||||
|
if (tab.active) {
|
||||||
|
tr.classList.add("clickable");
|
||||||
tr.addEventListener("click", () => {
|
tr.addEventListener("click", () => {
|
||||||
browser.runtime.sendMessage({
|
browser.runtime.sendMessage({
|
||||||
method: "showTab",
|
method: "showTab",
|
||||||
|
@ -336,6 +339,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("container-info-table").appendChild(fragment);
|
document.getElementById("container-info-table").appendChild(fragment);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue