Move the permission observers in the background scripts
This commit is contained in:
parent
1b165aebb5
commit
c146a0bd11
6 changed files with 47 additions and 29 deletions
|
@ -386,7 +386,6 @@ window.assignManager = {
|
||||||
if (browser.proxy) {
|
if (browser.proxy) {
|
||||||
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
|
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
|
@ -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() {
|
async getExtensionInfo() {
|
||||||
|
|
|
@ -20,9 +20,6 @@ const messageHandler = {
|
||||||
case "resetSync":
|
case "resetSync":
|
||||||
response = sync.resetSync();
|
response = sync.resetSync();
|
||||||
break;
|
break;
|
||||||
case "resetBookmarksContext":
|
|
||||||
response = assignManager.resetBookmarksMenuItem();
|
|
||||||
break;
|
|
||||||
case "deleteContainer":
|
case "deleteContainer":
|
||||||
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
||||||
break;
|
break;
|
||||||
|
@ -91,9 +88,6 @@ const messageHandler = {
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "maybeAddProxyListeners":
|
|
||||||
response = await assignManager.maybeAddProxyListeners();
|
|
||||||
break;
|
|
||||||
case "assignAndReloadInContainer":
|
case "assignAndReloadInContainer":
|
||||||
tab = await assignManager.reloadPageInContainer(
|
tab = await assignManager.reloadPageInContainer(
|
||||||
m.url,
|
m.url,
|
||||||
|
|
|
@ -100,6 +100,19 @@ const MozillaVPN_Background = {
|
||||||
get isolationKey() {
|
get isolationKey() {
|
||||||
return this._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();
|
MozillaVPN_Background.init();
|
||||||
|
|
|
@ -252,19 +252,6 @@ const MozillaVPN = {
|
||||||
}
|
}
|
||||||
return nextServer;
|
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;
|
window.MozillaVPN = MozillaVPN;
|
||||||
|
|
|
@ -14,15 +14,6 @@ document.querySelectorAll("[data-permission-id]").forEach( async(el) => {
|
||||||
} else {
|
} else {
|
||||||
await browser.permissions.remove({ permissions: [permissionId] });
|
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" });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue