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

This commit is contained in:
Jonathan Kingston 2018-04-11 14:12:43 +01:00 committed by stoically
parent 41686fdf6c
commit 5f7f9861e9
No known key found for this signature in database
GPG key ID: 3026ED2F90EE0DE9
2 changed files with 47 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);
@ -19,6 +20,17 @@ const assignManager = {
} }
}, },
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)) {
@ -275,7 +287,6 @@ const assignManager = {
} }
}, },
deleteContainer(userContextId) { deleteContainer(userContextId) {
this.storageArea.deleteContainer(userContextId); this.storageArea.deleteContainer(userContextId);
}, },
@ -290,12 +301,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,8 @@ 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: [],
init() { init() {
// Handles messages from webextension code // Handles messages from webextension code
@ -89,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}) => {