Remove tab counting code as also not needed, change tab counting to be per window. Prevent reopening of hidden tabs doesn't call itself. Fixes #750, Fixes #753, Fixes #756
This commit is contained in:
@@ -13,7 +13,10 @@ const identityState = {
|
||||
if (storageResponse && storeKey in storageResponse) {
|
||||
return storageResponse[storeKey];
|
||||
}
|
||||
return null;
|
||||
const defaultContainerState = identityState._createIdentityState();
|
||||
await this.set(cookieStoreId, defaultContainerState);
|
||||
|
||||
return defaultContainerState;
|
||||
},
|
||||
|
||||
set(cookieStoreId, data) {
|
||||
@@ -29,19 +32,13 @@ const identityState = {
|
||||
}
|
||||
},
|
||||
|
||||
async _isKnownContainer(userContextId) {
|
||||
const cookieStoreId = backgroundLogic.cookieStoreId(userContextId);
|
||||
const state = await this.storageArea.get(cookieStoreId);
|
||||
return !!state;
|
||||
},
|
||||
|
||||
_createTabObject(tab) {
|
||||
return Object.assign({}, tab);
|
||||
},
|
||||
|
||||
async storeHidden(cookieStoreId) {
|
||||
async storeHidden(cookieStoreId, windowId) {
|
||||
const containerState = await this.storageArea.get(cookieStoreId);
|
||||
const tabsByContainer = await this._matchTabsByContainer(cookieStoreId);
|
||||
const tabsByContainer = await browser.tabs.query({cookieStoreId, windowId});
|
||||
tabsByContainer.forEach((tab) => {
|
||||
const tabObject = this._createTabObject(tab);
|
||||
// This tab is going to be closed. Let's mark this tabObject as
|
||||
@@ -54,89 +51,9 @@ const identityState = {
|
||||
return this.storageArea.set(cookieStoreId, containerState);
|
||||
},
|
||||
|
||||
async containersCounts() {
|
||||
let containersCounts = { // eslint-disable-line prefer-const
|
||||
"shown": 0,
|
||||
"hidden": 0,
|
||||
"total": 0
|
||||
};
|
||||
const containers = await browser.contextualIdentities.query({});
|
||||
for (const id in containers) {
|
||||
const container = containers[id];
|
||||
await this.remapTabsIfMissing(container.cookieStoreId);
|
||||
const containerState = await this.storageArea.get(container.cookieStoreId);
|
||||
if (containerState.openTabs > 0) {
|
||||
++containersCounts.shown;
|
||||
++containersCounts.total;
|
||||
continue;
|
||||
} else if (containerState.hiddenTabs.length > 0) {
|
||||
++containersCounts.hidden;
|
||||
++containersCounts.total;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return containersCounts;
|
||||
},
|
||||
|
||||
async containerTabCount(cookieStoreId) {
|
||||
// Returns the total of open and hidden tabs with this userContextId
|
||||
let containerTabsCount = 0;
|
||||
await identityState.remapTabsIfMissing(cookieStoreId);
|
||||
const containerState = await this.storageArea.get(cookieStoreId);
|
||||
containerTabsCount += containerState.openTabs;
|
||||
containerTabsCount += containerState.hiddenTabs.length;
|
||||
return containerTabsCount;
|
||||
},
|
||||
|
||||
async totalContainerTabsCount() {
|
||||
// Returns the number of total open tabs across ALL containers
|
||||
let totalContainerTabsCount = 0;
|
||||
const containers = await browser.contextualIdentities.query({});
|
||||
for (const id in containers) {
|
||||
const container = containers[id];
|
||||
const cookieStoreId = container.cookieStoreId;
|
||||
await identityState.remapTabsIfMissing(cookieStoreId);
|
||||
totalContainerTabsCount += await this.storageArea.get(cookieStoreId).openTabs;
|
||||
}
|
||||
return totalContainerTabsCount;
|
||||
},
|
||||
|
||||
async totalNonContainerTabsCount() {
|
||||
// Returns the number of open tabs NOT IN a container
|
||||
let totalNonContainerTabsCount = 0;
|
||||
const tabs = await browser.tabs.query({});
|
||||
for (const tab of tabs) {
|
||||
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId);
|
||||
if (userContextId === 0) {
|
||||
++totalNonContainerTabsCount;
|
||||
}
|
||||
}
|
||||
return totalNonContainerTabsCount;
|
||||
},
|
||||
|
||||
async remapTabsIfMissing(cookieStoreId) {
|
||||
// We already know this cookieStoreId.
|
||||
const containerState = await this.storageArea.get(cookieStoreId) || this._createIdentityState();
|
||||
|
||||
await this.storageArea.set(cookieStoreId, containerState);
|
||||
await this.remapTabsFromUserContextId(cookieStoreId);
|
||||
},
|
||||
|
||||
_matchTabsByContainer(cookieStoreId) {
|
||||
return browser.tabs.query({cookieStoreId});
|
||||
},
|
||||
|
||||
async remapTabsFromUserContextId(cookieStoreId) {
|
||||
const tabsByContainer = await this._matchTabsByContainer(cookieStoreId);
|
||||
const containerState = await this.storageArea.get(cookieStoreId);
|
||||
containerState.openTabs = tabsByContainer.length;
|
||||
await this.storageArea.set(cookieStoreId, containerState);
|
||||
},
|
||||
|
||||
_createIdentityState() {
|
||||
return {
|
||||
hiddenTabs: [],
|
||||
openTabs: 0
|
||||
hiddenTabs: []
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user