Merge pull request #637 from jonathanKingston/cleanup-exemption-code

Cleanup exemption code. On assignment set/remove clear exemptions and…
This commit is contained in:
luke crouch 2017-06-27 15:54:59 -07:00 committed by GitHub
commit 2178e26220

View file

@ -15,19 +15,24 @@ const assignManager = {
}, },
setExempted(pageUrl, tabId) { setExempted(pageUrl, tabId) {
if (!(tabId in this.exemptedTabs)) {
this.exemptedTabs[tabId] = [];
}
const siteStoreKey = this.getSiteStoreKey(pageUrl); const siteStoreKey = this.getSiteStoreKey(pageUrl);
this.exemptedTabs[tabId].push(siteStoreKey); if (!(siteStoreKey in this.exemptedTabs)) {
this.exemptedTabs[siteStoreKey] = [];
}
this.exemptedTabs[siteStoreKey].push(tabId);
},
removeExempted(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
this.exemptedTabs[siteStoreKey] = [];
}, },
isExempted(pageUrl, tabId) { isExempted(pageUrl, tabId) {
if (!(tabId in this.exemptedTabs)) { const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (!(siteStoreKey in this.exemptedTabs)) {
return false; return false;
} }
const siteStoreKey = this.getSiteStoreKey(pageUrl); return this.exemptedTabs[siteStoreKey].includes(tabId);
return this.exemptedTabs[tabId].includes(siteStoreKey);
}, },
get(pageUrl) { get(pageUrl) {
@ -44,8 +49,13 @@ const assignManager = {
}); });
}, },
set(pageUrl, data) { set(pageUrl, data, exemptedTabIds) {
const siteStoreKey = this.getSiteStoreKey(pageUrl); const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (exemptedTabIds) {
exemptedTabIds.forEach((tabId) => {
this.setExempted(pageUrl, tabId);
});
}
return this.area.set({ return this.area.set({
[siteStoreKey]: data [siteStoreKey]: data
}); });
@ -53,6 +63,8 @@ const assignManager = {
remove(pageUrl) { remove(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl); const siteStoreKey = this.getSiteStoreKey(pageUrl);
// When we remove an assignment we should clear all the exemptions
this.removeExempted(pageUrl);
return this.area.remove([siteStoreKey]); return this.area.remove([siteStoreKey]);
}, },
@ -204,11 +216,24 @@ const assignManager = {
userContextId = String(userContextId); userContextId = String(userContextId);
if (!remove) { if (!remove) {
const tabs = await browser.tabs.query({});
const assignmentStoreKey = this.storageArea.getSiteStoreKey(pageUrl);
const exemptedTabIds = tabs.filter((tab) => {
const tabStoreKey = this.storageArea.getSiteStoreKey(tab.url);
/* Auto exempt all tabs that exist for this hostname that are not in the same container */
if (tabStoreKey === assignmentStoreKey &&
this.getUserContextIdFromCookieStore(tab) !== userContextId) {
return true;
}
return false;
}).map((tab) => {
return tab.id;
});
await this.storageArea.set(pageUrl, { await this.storageArea.set(pageUrl, {
userContextId, userContextId,
neverAsk: false, neverAsk: false
exempted: [] }, exemptedTabIds);
});
actionName = "added"; actionName = "added";
} else { } else {
await this.storageArea.remove(pageUrl); await this.storageArea.remove(pageUrl);