From a457c60f32bc40a3919a407e1393eac2ae1727f2 Mon Sep 17 00:00:00 2001 From: luke crouch Date: Thu, 12 Nov 2020 10:26:48 -0600 Subject: [PATCH] update proxy code to support more types --- package.json | 4 ++-- src/js/popup.js | 36 ++++++------------------------- src/js/proxified-containers.js | 39 ++++++---------------------------- src/js/utils.js | 6 +++--- src/manifest.json | 2 +- src/popup.html | 4 ++-- 6 files changed, 21 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 47aaeb6..74113d1 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "testpilot-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.", - "version": "7.1.0", + "version": "8.0.0", "author": "Andrea Marchesini, Luke Crouch and Jonathan Kingston", "bugs": { "url": "https://github.com/mozilla/multi-account-containers/issues" @@ -22,9 +22,9 @@ "nyc": "^15.0.0", "sinon": "^7.5.0", "sinon-chai": "^3.3.0", - "stylelint-order": "^4.0.0", "stylelint": "^13.5.0", "stylelint-config-standard": "^20.0.0", + "stylelint-order": "^4.0.0", "web-ext": "^2.9.3", "webextensions-jsdom": "^1.2.1" }, diff --git a/src/js/popup.js b/src/js/popup.js index 79a28d4..c242e12 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -743,33 +743,9 @@ Logic.registerPanel(P_CONTAINER_INFO, { // Note: this is not implemented in messageHandler.js let incompatible = false; try { - const incompatible = await browser.runtime.sendMessage({ + incompatible = await browser.runtime.sendMessage({ 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) { 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 = ""; const edit_proxy_dom = function(result) { - if(result.type === "http") - document.querySelector("#edit-container-panel-proxy").value = `${result.host}:${result.port}`; - else if(result.type === "direct") - document.querySelector("#edit-container-panel-proxy").value = ""; + const proxyInput = document.querySelector("#edit-container-panel-proxy"); + if (result.type === "direct" || typeof result.type === "undefined") { + proxyInput.value = ""; + return; + } + proxyInput.value = `${result.type}://${result.host}:${result.port}`; }; proxifiedContainers.retrieve(identity.cookieStoreId).then((result) => { diff --git a/src/js/proxified-containers.js b/src/js/proxified-containers.js index d52b4de..795ae8e 100644 --- a/src/js/proxified-containers.js +++ b/src/js/proxified-containers.js @@ -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 proxifiedContainers = { @@ -79,6 +62,7 @@ proxifiedContainers = { }); }); }, + set(cookieStoreId, proxy, initialize = false) { return new Promise((resolve, reject) => { 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) { - const regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/; - if (regexp.test(proxy_str) !== true) + const proxyRegexp = /(?(https?)|(socks4?)):\/\/(\b(?\w+):(?\w+)@)?(?((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(?\d+))?/; + if (proxyRegexp.test(proxy_str) !== true) { 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] diff --git a/src/js/utils.js b/src/js/utils.js index fdb4a23..2a045db 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -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! return getBogusProxy(); } - } + }, /** * 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 Object.defineProperty(window.Utils, "DEFAULT_PROXY", { 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 configurable: false }); - -window.Utils = Utils; diff --git a/src/manifest.json b/src/manifest.json index 2d0de71..e2bbc1e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Firefox Multi-Account Containers", - "version": "7.1.0", + "version": "8.0.0", "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.", "icons": { diff --git a/src/popup.html b/src/popup.html index 2ba6b55..878e4ef 100644 --- a/src/popup.html +++ b/src/popup.html @@ -300,8 +300,8 @@ Icon
- HTTP Proxy (Optional) - + Proxy (Optional) +