update proxy code to support more types

This commit is contained in:
luke crouch 2020-11-12 10:26:48 -06:00
parent 63996ce416
commit a457c60f32
6 changed files with 21 additions and 70 deletions

View file

@ -2,7 +2,7 @@
"name": "testpilot-containers", "name": "testpilot-containers",
"title": "Multi-Account Containers", "title": "Multi-Account Containers",
"description": "Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.", "description": "Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.",
"version": "7.1.0", "version": "8.0.0",
"author": "Andrea Marchesini, Luke Crouch and Jonathan Kingston", "author": "Andrea Marchesini, Luke Crouch and Jonathan Kingston",
"bugs": { "bugs": {
"url": "https://github.com/mozilla/multi-account-containers/issues" "url": "https://github.com/mozilla/multi-account-containers/issues"
@ -22,9 +22,9 @@
"nyc": "^15.0.0", "nyc": "^15.0.0",
"sinon": "^7.5.0", "sinon": "^7.5.0",
"sinon-chai": "^3.3.0", "sinon-chai": "^3.3.0",
"stylelint-order": "^4.0.0",
"stylelint": "^13.5.0", "stylelint": "^13.5.0",
"stylelint-config-standard": "^20.0.0", "stylelint-config-standard": "^20.0.0",
"stylelint-order": "^4.0.0",
"web-ext": "^2.9.3", "web-ext": "^2.9.3",
"webextensions-jsdom": "^1.2.1" "webextensions-jsdom": "^1.2.1"
}, },

View file

@ -743,33 +743,9 @@ Logic.registerPanel(P_CONTAINER_INFO, {
// Note: this is not implemented in messageHandler.js // Note: this is not implemented in messageHandler.js
let incompatible = false; let incompatible = false;
try { try {
const incompatible = await browser.runtime.sendMessage({ incompatible = await browser.runtime.sendMessage({
method: "checkIncompatibleAddons" method: "checkIncompatibleAddons"
}); });
const moveTabsEl = document.querySelector("#container-info-movetabs");
if (incompatible) {
const fragment = document.createDocumentFragment();
const incompatEl = document.createElement("div");
moveTabsEl.classList.remove("clickable");
moveTabsEl.setAttribute("title", "Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs.");
fragment.appendChild(incompatEl);
incompatEl.setAttribute("id", "container-info-movetabs-incompat");
incompatEl.textContent = "Incompatible with other Experiments.";
incompatEl.classList.add("container-info-tab-row");
moveTabsEl.parentNode.insertBefore(fragment, moveTabsEl.nextSibling);
} else {
Logic.addEnterHandler(moveTabsEl, async function () {
await browser.runtime.sendMessage({
method: "moveTabsToWindow",
windowId: browser.windows.WINDOW_ID_CURRENT,
cookieStoreId: Logic.currentIdentity().cookieStoreId,
});
window.close();
});
}
} catch (e) { } catch (e) {
throw new Error("Could not check for incompatible add-ons."); throw new Error("Could not check for incompatible add-ons.");
} }
@ -1391,10 +1367,12 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
document.querySelector("#edit-container-panel-proxy").value = ""; document.querySelector("#edit-container-panel-proxy").value = "";
const edit_proxy_dom = function(result) { const edit_proxy_dom = function(result) {
if(result.type === "http") const proxyInput = document.querySelector("#edit-container-panel-proxy");
document.querySelector("#edit-container-panel-proxy").value = `${result.host}:${result.port}`; if (result.type === "direct" || typeof result.type === "undefined") {
else if(result.type === "direct") proxyInput.value = "";
document.querySelector("#edit-container-panel-proxy").value = ""; return;
}
proxyInput.value = `${result.type}://${result.host}:${result.port}`;
}; };
proxifiedContainers.retrieve(identity.cookieStoreId).then((result) => { proxifiedContainers.retrieve(identity.cookieStoreId).then((result) => {

View file

@ -1,20 +1,3 @@
// Below lets us print errors, huge thanks to Jonathan @ https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify
if (!("toJSON" in Error.prototype))
Object.defineProperty(Error.prototype, "toJSON", {
value: function() {
const alt = {};
Object.getOwnPropertyNames(this).forEach(function(key) {
alt[key] = this[key];
}, this);
return alt;
},
configurable: true,
writable: true
});
// This object allows other scripts to access the list mapping containers to their proxies // This object allows other scripts to access the list mapping containers to their proxies
proxifiedContainers = { proxifiedContainers = {
@ -79,6 +62,7 @@ proxifiedContainers = {
}); });
}); });
}, },
set(cookieStoreId, proxy, initialize = false) { set(cookieStoreId, proxy, initialize = false) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (initialize === true) { if (initialize === true) {
@ -125,25 +109,14 @@ proxifiedContainers = {
}); });
}, },
//Parses a proxy description string of the format host[:port] or username:password@host[:port] (port is optional) //Parses a proxy description string of the format type://host[:port] or type://username:password@host[:port] (port is optional)
parseProxy(proxy_str) { parseProxy(proxy_str) {
const regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/; const proxyRegexp = /(?<type>(https?)|(socks4?)):\/\/(\b(?<username>\w+):(?<password>\w+)@)?(?<host>((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(?<port>\d+))?/;
if (regexp.test(proxy_str) !== true) if (proxyRegexp.test(proxy_str) !== true) {
return false; return false;
else {
const matches = regexp.exec(proxy_str);
const result = {
type: "http",
host: matches[4],
port: parseInt(matches[11], 10) || 8080,
username: matches[2] || "",
password: matches[3] || ""
};
return result;
} }
const matches = proxyRegexp.exec(proxy_str);
return matches.groups;
}, },
// Deletes the proxy information object for a specified cookieStoreId [useful for cleaning] // Deletes the proxy information object for a specified cookieStoreId [useful for cleaning]

View file

@ -52,7 +52,7 @@ const Utils = {
// The only issue with this approach is that if (for some unknown reason) pregeneratedString is not saved, it will result in an infinite loop - but better than a privacy leak! // The only issue with this approach is that if (for some unknown reason) pregeneratedString is not saved, it will result in an infinite loop - but better than a privacy leak!
return getBogusProxy(); return getBogusProxy();
} }
} },
/** /**
* Escapes any occurances of &, ", <, > or / with XML entities. * Escapes any occurances of &, ", <, > or / with XML entities.
@ -167,6 +167,8 @@ const Utils = {
} }
}; };
window.Utils = Utils;
// The following creates a fake (but convincing) constant Utils.DEFAULT_PROXY // The following creates a fake (but convincing) constant Utils.DEFAULT_PROXY
Object.defineProperty(window.Utils, "DEFAULT_PROXY", { Object.defineProperty(window.Utils, "DEFAULT_PROXY", {
value: Object.freeze({type: "direct"}), value: Object.freeze({type: "direct"}),
@ -176,5 +178,3 @@ Object.defineProperty(window.Utils, "DEFAULT_PROXY", {
// Setting configurable to false avoids deletion of Utils.DEFAULT_PROXY // Setting configurable to false avoids deletion of Utils.DEFAULT_PROXY
configurable: false configurable: false
}); });
window.Utils = Utils;

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Firefox Multi-Account Containers", "name": "Firefox Multi-Account Containers",
"version": "7.1.0", "version": "8.0.0",
"incognito": "not_allowed", "incognito": "not_allowed",
"description": "Multi-Account Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.", "description": "Multi-Account Containers helps you keep all the parts of your online life contained in different tabs. Custom labels and color-coded tabs help keep different activities — like online shopping, travel planning, or checking work email — separate.",
"icons": { "icons": {

View file

@ -300,8 +300,8 @@
<legend class="form-header">Icon</legend> <legend class="form-header">Icon</legend>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>HTTP Proxy (Optional)</legend> <legend>Proxy (Optional)</legend>
<input type="text" name="container-proxy" id="edit-container-panel-proxy" maxlength="15" placeholder="IP:PORT or USER:PASS@IP:PORT"/> <input type="text" name="container-proxy" id="edit-container-panel-proxy" maxlength="50" placeholder="type://host:port"/>
</fieldset> </fieldset>
</form> </form>
<div id="edit-container-options"> <div id="edit-container-options">