Remap tabs in case a userContextId is unknown #75
This commit is contained in:
parent
a9a0cc1ba2
commit
2238775d0c
1 changed files with 46 additions and 16 deletions
62
index.js
62
index.js
|
@ -81,20 +81,9 @@ const ContainerService = {
|
||||||
|
|
||||||
// Map of identities.
|
// Map of identities.
|
||||||
ContextualIdentityService.getIdentities().forEach(identity => {
|
ContextualIdentityService.getIdentities().forEach(identity => {
|
||||||
this._identitiesState[identity.userContextId] = {
|
this._remapTabsIfMissing(identity.userContextId);
|
||||||
hiddenTabUrls: [],
|
|
||||||
openTabs: 0
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// It can happen that this jsm is loaded after the opening a container tab.
|
|
||||||
for (let tab of tabs) { // eslint-disable-line prefer-const
|
|
||||||
const userContextId = this._getUserContextIdFromTab(tab);
|
|
||||||
if (userContextId) {
|
|
||||||
++this._identitiesState[userContextId].openTabs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tabs.on("open", tab => {
|
tabs.on("open", tab => {
|
||||||
const userContextId = this._getUserContextIdFromTab(tab);
|
const userContextId = this._getUserContextIdFromTab(tab);
|
||||||
if (userContextId) {
|
if (userContextId) {
|
||||||
|
@ -216,6 +205,25 @@ const ContainerService = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_createIdentityState() {
|
||||||
|
return {
|
||||||
|
hiddenTabUrls: [],
|
||||||
|
openTabs: 0
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
_remapTabsIfMissing(userContextId) {
|
||||||
|
// We already know this userContextId.
|
||||||
|
if (userContextId in this._identitiesState) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._identitiesState[userContextId] = this._createIdentityState();
|
||||||
|
this._containerTabIterator(userContextId, () => {
|
||||||
|
++this._identitiesState[userContextId].openTabs;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
// Tabs management
|
// Tabs management
|
||||||
|
|
||||||
hideTabs(args) {
|
hideTabs(args) {
|
||||||
|
@ -225,6 +233,14 @@ const ContainerService = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._remapTabsIfMissing(args.userContextId);
|
||||||
|
|
||||||
|
// We should check if this userContextId exists.
|
||||||
|
if ((args.userContextId in this._identitiesState)) {
|
||||||
|
resolve(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._containerTabIterator(args.userContextId, tab => {
|
this._containerTabIterator(args.userContextId, tab => {
|
||||||
const object = this._createTabObject(tab);
|
const object = this._createTabObject(tab);
|
||||||
|
|
||||||
|
@ -251,6 +267,14 @@ const ContainerService = {
|
||||||
return Promise.reject("showTabs must be called with userContextId argument.");
|
return Promise.reject("showTabs must be called with userContextId argument.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._remapTabsIfMissing(args.userContextId);
|
||||||
|
|
||||||
|
// We should check if this userContextId exists.
|
||||||
|
if (!(args.userContextId in this._identitiesState)) {
|
||||||
|
resolve(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
|
||||||
for (let object 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
|
||||||
|
@ -319,6 +343,14 @@ const ContainerService = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._remapTabsIfMissing(args.userContextId);
|
||||||
|
|
||||||
|
// We should check if this userContextId exists.
|
||||||
|
if (!(args.userContextId in this._identitiesState)) {
|
||||||
|
resolve([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const list = [];
|
const list = [];
|
||||||
this._containerTabIterator(args.userContextId, tab => {
|
this._containerTabIterator(args.userContextId, tab => {
|
||||||
list.push(this._createTabObject(tab));
|
list.push(this._createTabObject(tab));
|
||||||
|
@ -433,6 +465,7 @@ const ContainerService = {
|
||||||
const identities = [];
|
const identities = [];
|
||||||
|
|
||||||
ContextualIdentityService.getIdentities().forEach(identity => {
|
ContextualIdentityService.getIdentities().forEach(identity => {
|
||||||
|
this._remapTabsIfMissing(identity.userContextId);
|
||||||
const convertedIdentity = this._convert(identity);
|
const convertedIdentity = this._convert(identity);
|
||||||
identities.push(convertedIdentity);
|
identities.push(convertedIdentity);
|
||||||
});
|
});
|
||||||
|
@ -462,10 +495,7 @@ const ContainerService = {
|
||||||
|
|
||||||
const identity = ContextualIdentityService.create(args.name, icon, color);
|
const identity = ContextualIdentityService.create(args.name, icon, color);
|
||||||
|
|
||||||
this._identitiesState[identity.userContextId] = {
|
this._identitiesState[identity.userContextId] = this._createIdentityState();
|
||||||
hiddenTabUrls: [],
|
|
||||||
openTabs: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
this._refreshNeeded().then(() => {
|
this._refreshNeeded().then(() => {
|
||||||
return this._convert(identity);
|
return this._convert(identity);
|
||||||
|
|
Loading…
Add table
Reference in a new issue