Handle jailed domains from '@contain-facebook'. Fixes #1182

This commit is contained in:
Jonathan Kingston 2018-04-11 14:12:43 +01:00
parent 4be0164485
commit 1579676b4a
2 changed files with 46 additions and 13 deletions

View file

@ -8,6 +8,7 @@ const assignManager = {
storageArea: { storageArea: {
area: browser.storage.local, area: browser.storage.local,
exemptedTabs: {}, exemptedTabs: {},
jailedUrls: [],
getSiteStoreKey(pageUrl) { getSiteStoreKey(pageUrl) {
const url = new window.URL(pageUrl); const url = new window.URL(pageUrl);
@ -15,6 +16,17 @@ const assignManager = {
return `${storagePrefix}${url.hostname}`; return `${storagePrefix}${url.hostname}`;
}, },
setJailed(urls) {
this.jailedUrls = urls.map((url) => {
return this.getSiteStoreKey(url);
});
},
isJailed(pageUrl) {
const siteStoreKey = this.getSiteStoreKey(pageUrl);
return this.jailedUrls.includes(siteStoreKey);
},
setExempted(pageUrl, tabId) { setExempted(pageUrl, tabId) {
const siteStoreKey = this.getSiteStoreKey(pageUrl); const siteStoreKey = this.getSiteStoreKey(pageUrl);
if (!(siteStoreKey in this.exemptedTabs)) { if (!(siteStoreKey in this.exemptedTabs)) {
@ -271,7 +283,6 @@ const assignManager = {
} }
}, },
deleteContainer(userContextId) { deleteContainer(userContextId) {
this.storageArea.deleteContainer(userContextId); this.storageArea.deleteContainer(userContextId);
}, },
@ -286,12 +297,22 @@ const assignManager = {
isTabPermittedAssign(tab) { isTabPermittedAssign(tab) {
// Ensure we are not an important about url // Ensure we are not an important about url
// Ensure we are not in incognito mode // Ensure we are not in incognito mode
const url = new URL(tab.url); if (!backgroundLogic.isPermissibleURL(tab.url)
if (url.protocol === "about:"
|| url.protocol === "moz-extension:"
|| tab.incognito) { || tab.incognito) {
return false; return false;
} }
if (this.storageArea.isJailed(tab.url)) {
return false;
}
return true;
},
async _jailURLs(urls) {
const removePromises = urls.map((url) => {
return this.storageArea.remove(url);
});
this.storageArea.setJailed(urls);
await Promise.all(removePromises);
return true; return true;
}, },

View file

@ -3,6 +3,7 @@ const messageHandler = {
// We use this to catch redirected tabs that have just opened // We use this to catch redirected tabs that have just opened
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click // If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
LAST_CREATED_TAB_TIMER: 2000, LAST_CREATED_TAB_TIMER: 2000,
CONTAIN_FACEBOOK_ID: "@contain-facebook",
unhideQueue: [], unhideQueue: [],
init() { init() {
@ -90,23 +91,34 @@ const messageHandler = {
} }
response = assignManager.storageArea.get(message.url); response = assignManager.storageArea.get(message.url);
break; break;
case "jailedDomains":
if (sender.id !== messageHandler.CONTAIN_FACEBOOK_ID) {
throw new Error("Only 'contain-facebook' is permitted this method at this time");
}
response = assignManager._jailURLs(message.urls);
break;
default: default:
throw new Error("Unknown message.method"); throw new Error("Unknown message.method");
} }
return response; return response;
}); });
// Delete externalExtensionAllowed if add-on installs/updates; permissions might change browser.runtime.sendMessage("@contain-facebook", {
browser.management.onInstalled.addListener(extensionInfo => { method: "MACListening"
});
function handleExtensionRemoval(extensionInfo) {
// Ensure we reset jailed urls
if (extensionInfo.id === messageHandler.CONTAIN_FACEBOOK_ID) {
assignManager._jailURLs([]);
}
// Delete externalExtensionAllowed if add-on installs/updates; permissions might change
if (externalExtensionAllowed[extensionInfo.id]) { if (externalExtensionAllowed[extensionInfo.id]) {
delete externalExtensionAllowed[extensionInfo.id]; delete externalExtensionAllowed[extensionInfo.id];
} }
}); }
// Delete externalExtensionAllowed if add-on uninstalls; not needed anymore browser.management.onInstalled.addListener(handleExtensionRemoval);
browser.management.onUninstalled.addListener(extensionInfo => { browser.management.onEnabled.addListener(handleExtensionRemoval);
if (externalExtensionAllowed[extensionInfo.id]) { browser.management.onDisabled.addListener(handleExtensionRemoval);
delete externalExtensionAllowed[extensionInfo.id]; browser.management.onUninstalled.addListener(handleExtensionRemoval);
}
});
if (browser.contextualIdentities.onRemoved) { if (browser.contextualIdentities.onRemoved) {
browser.contextualIdentities.onRemoved.addListener(({contextualIdentity}) => { browser.contextualIdentities.onRemoved.addListener(({contextualIdentity}) => {