Move the permission observers in the background scripts

This commit is contained in:
Andrea Marchesini 2021-11-30 20:13:48 +01:00 committed by Lesley Norton
parent 1b165aebb5
commit c146a0bd11
No known key found for this signature in database
GPG key ID: E98FBAEE3F13956E
6 changed files with 47 additions and 29 deletions

View file

@ -386,7 +386,6 @@ window.assignManager = {
if (browser.proxy) {
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
}
return;
},
init() {

View file

@ -19,6 +19,40 @@ const backgroundLogic = {
}
}
});
browser.permissions.onAdded.addListener(permissions => {
permissions.permissions.forEach(permission => {
switch (permission) {
case "bookmarks":
break;
case "nativeMessaging":
break;
case "proxy":
assignManager.maybeAddProxyListeners();
break;
}
});
});
browser.permissions.onRemoved.addListener(permissions => {
permissions.permissions.forEach(async permission => {
switch (permission) {
case "bookmarks":
assignManager.resetBookmarksMenuItem();
break;
case "nativeMessaging":
await MozillaVPN_Background.removeMozillaVpnProxies();
await browser.runtime.reload();
break;
case "proxy":
break;
}
});
});
},
async getExtensionInfo() {

View file

@ -20,9 +20,6 @@ const messageHandler = {
case "resetSync":
response = sync.resetSync();
break;
case "resetBookmarksContext":
response = assignManager.resetBookmarksMenuItem();
break;
case "deleteContainer":
response = backgroundLogic.deleteContainer(m.message.userContextId);
break;
@ -91,9 +88,6 @@ const messageHandler = {
true
);
break;
case "maybeAddProxyListeners":
response = await assignManager.maybeAddProxyListeners();
break;
case "assignAndReloadInContainer":
tab = await assignManager.reloadPageInContainer(
m.url,

View file

@ -100,6 +100,19 @@ const MozillaVPN_Background = {
get isolationKey() {
return this._isolationKey;
},
async removeMozillaVpnProxies() {
const proxies = await proxifiedContainers.retrieveAll();
if (!proxies) {
return;
}
for (const proxyObj of proxies) {
const { proxy } = proxyObj;
if (proxy.countryCode !== undefined) {
await proxifiedContainers.delete(proxyObj.cookieStoreId);
}
}
},
};
MozillaVPN_Background.init();

View file

@ -252,19 +252,6 @@ const MozillaVPN = {
}
return nextServer;
},
async removeMozillaVpnProxies() {
const proxies = await proxifiedContainers.retrieveAll();
if (!proxies) {
return;
}
for (const proxyObj of proxies) {
const { proxy } = proxyObj;
if (proxy.countryCode !== undefined) {
await proxifiedContainers.delete(proxyObj.cookieStoreId);
}
}
}
};
window.MozillaVPN = MozillaVPN;

View file

@ -14,15 +14,6 @@ document.querySelectorAll("[data-permission-id]").forEach( async(el) => {
} else {
await browser.permissions.remove({ permissions: [permissionId] });
}
switch (permissionId) {
case "bookmarks":
return await browser.runtime.sendMessage({ method: "resetBookmarksContext" });
case "nativeMessaging":
await MozillaVPN.removeMozillaVpnProxies();
return await browser.runtime.reload();
case "proxy":
return await browser.runtime.sendMessage({ method: "maybeAddProxyListeners" });
}
});
});