Handle jailed domains from '@contain-facebook'. Fixes #1182
This commit is contained in:
parent
41686fdf6c
commit
5f7f9861e9
2 changed files with 47 additions and 13 deletions
|
@ -8,6 +8,7 @@ const assignManager = {
|
|||
storageArea: {
|
||||
area: browser.storage.local,
|
||||
exemptedTabs: {},
|
||||
jailedUrls: [],
|
||||
|
||||
getSiteStoreKey(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) {
|
||||
const siteStoreKey = this.getSiteStoreKey(pageUrl);
|
||||
if (!(siteStoreKey in this.exemptedTabs)) {
|
||||
|
@ -275,7 +287,6 @@ const assignManager = {
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
deleteContainer(userContextId) {
|
||||
this.storageArea.deleteContainer(userContextId);
|
||||
},
|
||||
|
@ -290,12 +301,22 @@ const assignManager = {
|
|||
isTabPermittedAssign(tab) {
|
||||
// Ensure we are not an important about url
|
||||
// Ensure we are not in incognito mode
|
||||
const url = new URL(tab.url);
|
||||
if (url.protocol === "about:"
|
||||
|| url.protocol === "moz-extension:"
|
||||
if (!backgroundLogic.isPermissibleURL(tab.url)
|
||||
|| tab.incognito) {
|
||||
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;
|
||||
},
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ const messageHandler = {
|
|||
// 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
|
||||
LAST_CREATED_TAB_TIMER: 2000,
|
||||
CONTAIN_FACEBOOK_ID: "@contain-facebook",
|
||||
unhideQueue: [],
|
||||
|
||||
init() {
|
||||
// Handles messages from webextension code
|
||||
|
@ -89,23 +91,34 @@ const messageHandler = {
|
|||
}
|
||||
response = assignManager.storageArea.get(message.url);
|
||||
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:
|
||||
throw new Error("Unknown message.method");
|
||||
}
|
||||
return response;
|
||||
});
|
||||
// Delete externalExtensionAllowed if add-on installs/updates; permissions might change
|
||||
browser.management.onInstalled.addListener(extensionInfo => {
|
||||
browser.runtime.sendMessage("@contain-facebook", {
|
||||
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]) {
|
||||
delete externalExtensionAllowed[extensionInfo.id];
|
||||
}
|
||||
});
|
||||
// Delete externalExtensionAllowed if add-on uninstalls; not needed anymore
|
||||
browser.management.onUninstalled.addListener(extensionInfo => {
|
||||
if (externalExtensionAllowed[extensionInfo.id]) {
|
||||
delete externalExtensionAllowed[extensionInfo.id];
|
||||
}
|
||||
});
|
||||
}
|
||||
browser.management.onInstalled.addListener(handleExtensionRemoval);
|
||||
browser.management.onEnabled.addListener(handleExtensionRemoval);
|
||||
browser.management.onDisabled.addListener(handleExtensionRemoval);
|
||||
browser.management.onUninstalled.addListener(handleExtensionRemoval);
|
||||
|
||||
if (browser.contextualIdentities.onRemoved) {
|
||||
browser.contextualIdentities.onRemoved.addListener(({contextualIdentity}) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue