From 66cd627909ad7e758f2a6152001c55d7b50b1d54 Mon Sep 17 00:00:00 2001 From: William Budington Date: Thu, 30 Mar 2017 12:39:48 -0700 Subject: [PATCH 01/11] Naive fix for absence of chrome.windows and chrome.tabs (Fennec) --- chromium/background.js | 27 ++++++++++++++++++--------- chromium/incognito-cache-clearing.js | 8 ++++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/chromium/background.js b/chromium/background.js index 408389fb02d0..0d26b494393d 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -61,12 +61,16 @@ chrome.storage.onChanged.addListener(function(changes, areaName) { } } }); -chrome.tabs.onActivated.addListener(function() { - updateState(); -}); -chrome.windows.onFocusChanged.addListener(function() { - updateState(); -}); +if (chrome.tabs) { + chrome.tabs.onActivated.addListener(function() { + updateState(); + }); +} +if (chrome.windows) { + chrome.windows.onFocusChanged.addListener(function() { + updateState(); + }); +} chrome.webNavigation.onCompleted.addListener(function() { updateState(); }); @@ -106,6 +110,9 @@ loadStoredUserRules(); * disabled: extension is disabled from the popup menu. */ var updateState = function() { + if (!chrome.tabs) { + return; + } chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { if (!tabs || tabs.length === 0) { return; @@ -176,9 +183,11 @@ function AppliedRulesets() { this.active_tab_rules = {}; var that = this; - chrome.tabs.onRemoved.addListener(function(tabId, info) { - that.removeTab(tabId); - }); + if (chrome.tabs) { + chrome.tabs.onRemoved.addListener(function(tabId, info) { + that.removeTab(tabId); + }); + } } AppliedRulesets.prototype = { diff --git a/chromium/incognito-cache-clearing.js b/chromium/incognito-cache-clearing.js index b650253c317a..c0125a2bb5cf 100644 --- a/chromium/incognito-cache-clearing.js +++ b/chromium/incognito-cache-clearing.js @@ -55,7 +55,11 @@ function detect_incognito_destruction(windowId) { // Listen to window creation, so we can detect if an incognito window is created -chrome.windows.onCreated.addListener(detect_incognito_creation); +if (chrome.windows) { + chrome.windows.onCreated.addListener(detect_incognito_creation); +} // Listen to window destruction, so we can clear caches if all incognito windows are destroyed -chrome.windows.onRemoved.addListener(detect_incognito_destruction); +if (chrome.windows) { + chrome.windows.onRemoved.addListener(detect_incognito_destruction); +} From 16f25451310bf64e6b4b2fba080f6bcaa5176443 Mon Sep 17 00:00:00 2001 From: William Budington Date: Tue, 9 May 2017 18:14:06 -0700 Subject: [PATCH 02/11] Ensure that storage api falls back to local when sync is unavailable --- chromium/storage.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chromium/storage.js b/chromium/storage.js index 2597ca379fba..d75fe7794411 100644 --- a/chromium/storage.js +++ b/chromium/storage.js @@ -1,6 +1,10 @@ var storage = chrome.storage.local; if (chrome.storage.sync) { - storage = chrome.storage.sync; + chrome.storage.sync.set({"sync-set-test": true}, () => { + if(!chrome.runtime.lastError){ + storage = chrome.storage.sync; + } + }); } if (typeof exports != 'undefined') { exports = storage; From f5188b4ace9ba9db5e38ef7d3aecde87306aaa03 Mon Sep 17 00:00:00 2001 From: William Budington Date: Mon, 7 Aug 2017 14:13:01 -0700 Subject: [PATCH 03/11] Update manifest.json to add Firefox-specific keys --- chromium/manifest.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chromium/manifest.json b/chromium/manifest.json index a3d91a79311c..26c0a5faddac 100644 --- a/chromium/manifest.json +++ b/chromium/manifest.json @@ -1,4 +1,10 @@ { + "applications": { + "gecko": { + "id": "https-everywhere-eff@eff.org", + "update_url": "https://www.eff.org/files/https-everywhere-updates.json" + } + }, "author": { "email": "eff.software.projects@gmail.com" }, From 95f62d10d4fb15714b307e1a1f0ab245c309d171 Mon Sep 17 00:00:00 2001 From: William Budington Date: Thu, 11 May 2017 17:06:08 -0700 Subject: [PATCH 04/11] Change author key in manifest.json to be a string --- chromium/manifest.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chromium/manifest.json b/chromium/manifest.json index 26c0a5faddac..35bd1f555e50 100644 --- a/chromium/manifest.json +++ b/chromium/manifest.json @@ -5,9 +5,7 @@ "update_url": "https://www.eff.org/files/https-everywhere-updates.json" } }, - "author": { - "email": "eff.software.projects@gmail.com" - }, + "author": "eff.software.projects@gmail.com", "background": { "scripts": [ "rules.js", From a2d1b1d198d19b96526e114b74279dd0e0c827a3 Mon Sep 17 00:00:00 2001 From: William Budington Date: Tue, 23 May 2017 17:07:20 -0700 Subject: [PATCH 05/11] Firefox fix: Private Browsing Mode popups cannot use extension.getBackgroundPage(), see https://bugzilla.mozilla.org/show_bug.cgi?id=1329304 Instead, we're using runtime.sendMessage() to pass messages between the popup and background page. --- chromium/background.js | 35 ++++++++++++ chromium/popup.js | 124 ++++++++++++++++++++++++----------------- 2 files changed, 109 insertions(+), 50 deletions(-) diff --git a/chromium/background.js b/chromium/background.js index 0d26b494393d..a7cdbba109bf 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -627,3 +627,38 @@ chrome.runtime.onConnect.addListener(function (port) { }); } }); + +// This is necessary for communication with the popup in Firefox Private +// Browsing Mode, see https://bugzilla.mozilla.org/show_bug.cgi?id=1329304 +chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ + if (message.type == "get_option") { + storage.get(message.object, function(item){ + sendResponse(item); + }); + return true; + } else if (message.type == "set_option") { + storage.set(message.object); + } else if (message.type == "get_is_extension_enabled") { + sendResponse(isExtensionEnabled); + } else if (message.type == "set_is_extension_enabled") { + isExtensionEnabled = message.object; + sendResponse(isExtensionEnabled); + } else if (message.type == "delete_from_ruleset_cache") { + all_rules.ruleCache.delete(message.object); + } else if (message.type == "get_active_rulesets") { + sendResponse(activeRulesets.getRulesets(message.object)); + } else if (message.type == "set_ruleset_active_status") { + var ruleset = activeRulesets.getRulesets(message.object.tab_id)[message.object.name]; + ruleset.active = message.object.active; + sendResponse(true); + } else if (message.type == "add_new_rule") { + addNewRule(message.object, function() { + sendResponse(true); + }); + return true; + } else if (message.type == "update_state") { + updateState(); + } else if (message.type == "remove_rule") { + removeRule(message.object); + } +}); diff --git a/chromium/popup.js b/chromium/popup.js index 6289e8fb06ba..12f6f1254163 100644 --- a/chromium/popup.js +++ b/chromium/popup.js @@ -1,10 +1,8 @@ "use strict"; -var backgroundPage = chrome.extension.getBackgroundPage(); var stableRules = null; var unstableRules = null; var hostReg = /.*\/\/[^$/]*\//; -var storage = backgroundPage.storage; function e(id) { return document.getElementById(id); @@ -15,18 +13,27 @@ function e(id) { * @param checkbox checkbox being clicked * @param ruleset the ruleset tied tot he checkbox */ -function toggleRuleLine(checkbox, ruleset) { - ruleset.active = checkbox.checked; - - if (ruleset.active != ruleset.default_state) { - localStorage[ruleset.name] = ruleset.active; - } else { - delete localStorage[ruleset.name]; - // purge the name from the cache so that this unchecking is persistent. - backgroundPage.all_rules.ruleCache.delete(ruleset.name); - } - // Now reload the selected tab of the current window. - chrome.tabs.reload(); +function toggleRuleLine(checkbox, ruleset, tab_id) { + var ruleset_active = checkbox.checked; + var set_ruleset = { + active: ruleset_active, + name: ruleset.name, + tab_id: tab_id + }; + + sendMessage("set_ruleset_active_status", set_ruleset, function(){ + + if (ruleset_active != ruleset.default_state) { + localStorage[ruleset.name] = ruleset_active; + } else { + delete localStorage[ruleset.name]; + // purge the name from the cache so that this unchecking is persistent. + sendMessage("delete_from_ruleset_cache", ruleset.name); + } + + // Now reload the selected tab of the current window. + chrome.tabs.reload(); + }); } /** @@ -50,7 +57,7 @@ function appendRuleLineToListDiv(ruleset, list_div) { checkbox.setAttribute("checked", ""); } checkbox.onchange = function(ev) { - toggleRuleLine(checkbox, ruleset); + toggleRuleLine(checkbox, ruleset, tab_id); }; label.appendChild(checkbox); @@ -85,7 +92,7 @@ function appendRuleLineToListDiv(ruleset, list_div) { line.appendChild(remove); remove.addEventListener("click", function(){ - backgroundPage.removeRule(ruleset); + sendMessage("remove_rule", ruleset); list_div.removeChild(line); }); } @@ -99,29 +106,36 @@ function appendRuleLineToListDiv(ruleset, list_div) { // Change the UI to reflect extension enabled/disabled function updateEnabledDisabledUI() { - document.getElementById('onoffswitch').checked = backgroundPage.isExtensionEnabled; - // Hide or show the rules sections - if (backgroundPage.isExtensionEnabled) { - document.body.className = "" - } else { - document.body.className = "disabled" - } - backgroundPage.updateState(); + sendMessage("get_is_extension_enabled", null, function(enabled){ + document.getElementById('onoffswitch').checked = enabled; + // Hide or show the rules sections + if (enabled) { + document.body.className = "" + } else { + document.body.className = "disabled" + } + sendMessage("update_state"); + }); } // Toggle extension enabled/disabled status function toggleEnabledDisabled() { - if (backgroundPage.isExtensionEnabled) { - // User wants to disable us - backgroundPage.isExtensionEnabled = false; - } else { - // User wants to enable us - backgroundPage.isExtensionEnabled = true; + var extension_toggle_effect = function(){ + updateEnabledDisabledUI(); + // The extension state changed, so reload this tab. + chrome.tabs.reload(); + window.close(); } - updateEnabledDisabledUI(); - // The extension state changed, so reload this tab. - chrome.tabs.reload(); - window.close(); + + sendMessage("get_is_extension_enabled", null, function(enabled){ + if (enabled) { + // User wants to disable us + sendMessage("set_is_extension_enabled", false, extension_toggle_effect); + } else { + // User wants to enable us + sendMessage("set_is_extension_enabled", true, extension_toggle_effect); + } + }); } /** @@ -130,21 +144,22 @@ function toggleEnabledDisabled() { */ function gotTab(tabArray) { var activeTab = tabArray[0]; - var rulesets = backgroundPage.activeRulesets.getRulesets(activeTab.id); - for (var r in rulesets) { - var listDiv = stableRules; - if (!rulesets[r].default_state) { - listDiv = unstableRules; + sendMessage("get_active_rulesets", activeTab.id, function(rulesets){ + for (var r in rulesets) { + var listDiv = stableRules; + if (!rulesets[r].default_state) { + listDiv = unstableRules; + } + appendRuleLineToListDiv(rulesets[r], listDiv); + listDiv.style.position = "static"; + listDiv.style.visibility = "visible"; } - appendRuleLineToListDiv(rulesets[r], listDiv); - listDiv.style.position = "static"; - listDiv.style.visibility = "visible"; - } - // Only show the "Add a rule" link if we're on an HTTPS page - if (/^https:/.test(activeTab.url)) { - show(e("add-rule-link")); - } + // Only show the "Add a rule" link if we're on an HTTPS page + if (/^https:/.test(activeTab.url)) { + show(e("add-rule-link")); + } + }); } /** @@ -223,7 +238,7 @@ function addManualRule() { redirectTo : e("new-rule-redirect").value, urlMatcher : e("new-rule-regex").value }; - backgroundPage.addNewRule(params, function() { + sendMessage("add_new_rule", params, function() { location.reload(); }); }); @@ -252,11 +267,20 @@ function toggleHttpNowhere() { function getOption_(opt, defaultOpt, callback) { var details = {}; details[opt] = defaultOpt; - return storage.get(details, callback); + sendMessage("get_option", details, callback); } function setOption_(opt, value) { var details = {}; details[opt] = value; - return storage.set(details); + sendMessage("set_option", details); +} + +function sendMessage(type, object, callback) { + var packet = {}; + packet.type = type; + if(object){ + packet.object = object; + } + chrome.runtime.sendMessage(packet, callback); } From 2948c3dfdbec5dcfd0cc16592b94f8f8a739d338 Mon Sep 17 00:00:00 2001 From: William Budington Date: Wed, 24 May 2017 16:40:20 -0700 Subject: [PATCH 06/11] Do not try to display image if we're not in Chrome browser --- chromium/popup.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/chromium/popup.js b/chromium/popup.js index 12f6f1254163..645728e51624 100644 --- a/chromium/popup.js +++ b/chromium/popup.js @@ -72,11 +72,14 @@ function appendRuleLineToListDiv(ruleset, list_div) { break; } } - var xhr = new XMLHttpRequest(); - try { - xhr.open("GET", favicon.src, true); - label.appendChild(favicon); - } catch (e) {} + + if (navigator.userAgent.match("Chrome")) { + var xhr = new XMLHttpRequest(); + try { + xhr.open("GET", favicon.src, true); + label.appendChild(favicon); + } catch (e) {} + } // label text var text = document.createElement("span"); From 00dd74cd57e3cc3e40858051e9cb7ae638506b96 Mon Sep 17 00:00:00 2001 From: William Budington Date: Wed, 24 May 2017 16:48:10 -0700 Subject: [PATCH 07/11] Create an additional lookup method for favicons. --- chromium/background.js | 30 ++++++++++++++++++++++-------- chromium/popup.js | 12 +++++++++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/chromium/background.js b/chromium/background.js index a7cdbba109bf..e29b0ec7453a 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -181,6 +181,7 @@ var removeRule = function(ruleset) { * */ function AppliedRulesets() { this.active_tab_rules = {}; + this.active_tab_hostnames = {}; var that = this; if (chrome.tabs) { @@ -192,12 +193,8 @@ function AppliedRulesets() { AppliedRulesets.prototype = { addRulesetToTab: function(tabId, ruleset) { - if (tabId in this.active_tab_rules) { - this.active_tab_rules[tabId][ruleset.name] = ruleset; - } else { - this.active_tab_rules[tabId] = {}; - this.active_tab_rules[tabId][ruleset.name] = ruleset; - } + this.active_tab_rules[tabId] = this.active_tab_rules[tabId] || {}; + this.active_tab_rules[tabId][ruleset.name] = ruleset; }, getRulesets: function(tabId) { @@ -207,8 +204,21 @@ AppliedRulesets.prototype = { return null; }, + addHostnameToTab: function(tabId, ruleset_name, hostname) { + this.active_tab_hostnames[tabId] = this.active_tab_hostnames[tabId] || {}; + this.active_tab_hostnames[tabId][ruleset_name] = hostname; + }, + + getHostnames: function(tabId) { + if (tabId in this.active_tab_hostnames) { + return this.active_tab_hostnames[tabId]; + } + return null; + }, + removeTab: function(tabId) { delete this.active_tab_rules[tabId]; + delete this.active_tab_hostnames[tabId]; } }; @@ -292,6 +302,7 @@ function onBeforeRequest(details) { for (let ruleset of potentiallyApplicable) { activeRulesets.addRulesetToTab(details.tabId, ruleset); + activeRulesets.addHostnameToTab(details.tabId, ruleset.name, uri.hostname); if (ruleset.active && !newuristr) { newuristr = ruleset.apply(canonical_url); } @@ -645,8 +656,11 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ sendResponse(isExtensionEnabled); } else if (message.type == "delete_from_ruleset_cache") { all_rules.ruleCache.delete(message.object); - } else if (message.type == "get_active_rulesets") { - sendResponse(activeRulesets.getRulesets(message.object)); + } else if (message.type == "get_active_rulesets_and_hostnames") { + sendResponse({ + rulesets: activeRulesets.getRulesets(message.object), + hostnames: activeRulesets.getHostnames(message.object) + }); } else if (message.type == "set_ruleset_active_status") { var ruleset = activeRulesets.getRulesets(message.object.tab_id)[message.object.name]; ruleset.active = message.object.active; diff --git a/chromium/popup.js b/chromium/popup.js index 645728e51624..faa889c2dd7f 100644 --- a/chromium/popup.js +++ b/chromium/popup.js @@ -41,7 +41,7 @@ function toggleRuleLine(checkbox, ruleset, tab_id) { * @param ruleset the ruleset to build the line for * @returns {*} */ -function appendRuleLineToListDiv(ruleset, list_div) { +function appendRuleLineToListDiv(ruleset, hostnames, tab_id, list_div) { // parent block for line var line = document.createElement("div"); @@ -72,6 +72,9 @@ function appendRuleLineToListDiv(ruleset, list_div) { break; } } + if (favicon.src == "chrome://favicon/") { + favicon.src += "https://" + hostnames[ruleset.name]; + } if (navigator.userAgent.match("Chrome")) { var xhr = new XMLHttpRequest(); @@ -148,13 +151,16 @@ function toggleEnabledDisabled() { function gotTab(tabArray) { var activeTab = tabArray[0]; - sendMessage("get_active_rulesets", activeTab.id, function(rulesets){ + sendMessage("get_active_rulesets_and_hostnames", activeTab.id, function(rulesets_and_hostnames){ + var rulesets = rulesets_and_hostnames.rulesets; + var hostnames = rulesets_and_hostnames.hostnames; + for (var r in rulesets) { var listDiv = stableRules; if (!rulesets[r].default_state) { listDiv = unstableRules; } - appendRuleLineToListDiv(rulesets[r], listDiv); + appendRuleLineToListDiv(rulesets[r], hostnames, activeTab.id, listDiv); listDiv.style.position = "static"; listDiv.style.visibility = "visible"; } From aba46a83b92ca9567b6930489303166ad5bd0a42 Mon Sep 17 00:00:00 2001 From: William Budington Date: Thu, 8 Jun 2017 17:36:19 -0700 Subject: [PATCH 08/11] Add spacing between checkbox and ruleset name in popup --- chromium/popup.css | 1 + 1 file changed, 1 insertion(+) diff --git a/chromium/popup.css b/chromium/popup.css index a817a04648d3..82c3dbb35b7e 100644 --- a/chromium/popup.css +++ b/chromium/popup.css @@ -69,6 +69,7 @@ section.rules { /* Override display attribute of text labels in widgets.css. */ .rule span { display: inline !important; + margin-left: 0.6em; } body { From 1993ef39a131e17193959530b56173ba4b03576e Mon Sep 17 00:00:00 2001 From: William Budington Date: Wed, 17 May 2017 21:21:31 -0700 Subject: [PATCH 09/11] Firefox: Removing SDK extension tests and generalizing selenium tests to support FF --- .gitmodules | 3 - addon-sdk | 1 - install-dev-dependencies.sh | 19 +++- test/chromium.sh | 2 +- test/chromium/script.py | 73 -------------- test/firefox.sh | 29 +----- test/firefox/README.md | 67 ++----------- test/firefox/lib/main.js | 0 test/firefox/package.json | 9 -- test/firefox/test/test-httpse-installed.js | 38 ------- test/firefox/test/test-main.js | 12 --- .../test_profile_skeleton/extensions.ini | 7 -- test/firefox/test_profile_skeleton/prefs.js | 11 --- test/script.py | 98 +++++++++++++++++++ 14 files changed, 126 insertions(+), 243 deletions(-) delete mode 160000 addon-sdk delete mode 100644 test/chromium/script.py delete mode 100644 test/firefox/lib/main.js delete mode 100644 test/firefox/package.json delete mode 100644 test/firefox/test/test-httpse-installed.js delete mode 100644 test/firefox/test/test-main.js delete mode 100644 test/firefox/test_profile_skeleton/extensions.ini create mode 100644 test/script.py diff --git a/.gitmodules b/.gitmodules index 8cebe79c8fff..049bbbed911c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "addon-sdk"] - path = addon-sdk - url = https://github.com/mozilla/addon-sdk.git [submodule "translations"] path = translations url = https://git.torproject.org/translation.git diff --git a/addon-sdk b/addon-sdk deleted file mode 160000 index 12f7d53e8b5f..000000000000 --- a/addon-sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 12f7d53e8b5fc015a15fa4a30fa588e81e9e9b2e diff --git a/install-dev-dependencies.sh b/install-dev-dependencies.sh index d933b579cb41..9ce7446491be 100755 --- a/install-dev-dependencies.sh +++ b/install-dev-dependencies.sh @@ -20,7 +20,15 @@ if type apt-get >/dev/null ; then # In Debian, `python-` is assumed to be python 2.7, no need to specify - dkg $SUDO_SHIM apt-get install libxml2-dev libxml2-utils libxslt1-dev \ python-dev $BROWSERS zip sqlite3 python-pip libcurl4-openssl-dev xvfb \ - libssl-dev git $CHROMEDRIVER + libssl-dev git curl $CHROMEDRIVER + if ! type geckodriver >/dev/null; then + curl -LO "https://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-linux64.tar.gz" + tar -zxvf "geckodriver-v0.16.1-linux64.tar.gz" + rm -f "geckodriver-v0.16.1-linux64.tar.gz" + $SUDO_SHIM mv geckodriver /usr/bin/geckodriver + $SUDO_SHIM chown root /usr/bin/geckodriver + $SUDO_SHIM chmod 755 /usr/bin/geckodriver + fi elif type brew >/dev/null ; then brew list python &>/dev/null || brew install python brew install libxml2 gnu-sed chromedriver @@ -42,9 +50,16 @@ elif type dnf >/dev/null ; then rm -f "chromedriver_linux$ARCH.zip" $SUDO_SHIM mv chromedriver /usr/bin/chromedriver $SUDO_SHIM chown root /usr/bin/chromedriver - $SUDO_SHIM chmod +x /usr/bin/chromedriver $SUDO_SHIM chmod 755 /usr/bin/chromedriver fi + if ! type geckodriver >/dev/null; then + curl -LO "https://github.com/mozilla/geckodriver/releases/download/v0.16.1/geckodriver-v0.16.1-macos.tar.gz" + tar -zxvf "geckodriver-v0.16.1-macos.tar.gz" + rm -f "geckodriver-v0.16.1-macos.tar.gz" + $SUDO_SHIM mv geckodriver /usr/bin/geckodriver + $SUDO_SHIM chown root /usr/bin/geckodriver + $SUDO_SHIM chmod 755 /usr/bin/geckodriver + fi # This is needed for Firefox on some systems. See here for more information: # https://github.com/EFForg/https-everywhere/pull/5584#issuecomment-238655443 if [ ! -f /var/lib/dbus/machine-id ]; then diff --git a/test/chromium.sh b/test/chromium.sh index e03696cf881e..29fdc3110dea 100755 --- a/test/chromium.sh +++ b/test/chromium.sh @@ -39,5 +39,5 @@ else ./makecrx.sh echo "running tests" CRX_NAME="`ls -tr pkg/*.crx | tail -1`" - $XVFB_RUN python2.7 test/chromium/script.py $CRX_NAME + $XVFB_RUN python2.7 test/script.py Chrome $CRX_NAME fi diff --git a/test/chromium/script.py b/test/chromium/script.py deleted file mode 100644 index ff76d6d0fc2c..000000000000 --- a/test/chromium/script.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python2.7 -# -# Run Chromium tests for HTTPS Everywhere -# -# This script may be executed as `python script.py [directory of CRX]` -# -# The script is compatible with Python 2. Python 3 is not tested. -# Selenium, WebDriver and Google Chrome (or Chromium) must be installed -# in order for the script to run successfully. A desktop version -# of linux is required for the script to run correctly as well. -# Otherwise, use pyvirtualdisplay. - -import sys, os, platform -from selenium import webdriver -from selenium.common.exceptions import WebDriverException - -class bcolors: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' - - -chromeOps = webdriver.ChromeOptions() -chromeOps.add_extension(sys.argv[1]) -if os.getuid() == 0: - chromeOps.add_argument("--no-sandbox") - -# Find the path to chromedriver -chromedriver_path = "chromedriver" -if sys.platform.startswith("linux"): - if 'Ubuntu' in platform.linux_distribution(): - chromedriver_path = "/usr/lib/chromium-browser/chromedriver" - elif 'debian' in platform.linux_distribution(): - #Debian is lowercase when platform.linux_distribution() is used. - #This is not a mistake. - chromedriver_path = "/usr/lib/chromium/chromedriver" - -try: - # First argument is optional, if not specified will search path. - driver = webdriver.Chrome(chromedriver_path, chrome_options=chromeOps) -except WebDriverException as e: - error = e.__str__() - - if "executable needs to be in PATH" in e.__str__(): - print "ChromeDriver isn't installed. Check test/chromium/README.md " \ - "for instructions on how to install ChromeDriver" - - sys.exit(2) - else: - raise e - -print '' - -driver.get('http://libssh.org/robots.txt') - -test_failed = False -if driver.current_url.startswith('https'): - print bcolors.OKGREEN + "Chromium: HTTP to HTTPS redirection successful" + bcolors.ENDC -elif driver.current_url.startswith('http'): - print bcolors.FAIL + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC - test_failed = True - -print '' - -driver.quit() - -if test_failed: - sys.exit(1) diff --git a/test/firefox.sh b/test/firefox.sh index 0ff398cf1b81..9e97b00db7de 100755 --- a/test/firefox.sh +++ b/test/firefox.sh @@ -14,9 +14,6 @@ fi source utils/mktemp.sh -# dummy Jetpack addon that contains tests -TEST_ADDON_PATH=./test/firefox/ - # We'll create a Firefox profile here and install HTTPS Everywhere into it. PROFILE_DIRECTORY="$(mktemp -d)" trap 'rm -r "$PROFILE_DIRECTORY"' EXIT @@ -38,10 +35,6 @@ die() { exit 1 } -if [ ! -f "addon-sdk/bin/activate" ]; then - die "Addon SDK not available. Run git submodule update." -fi - if [ ! -d "$HTTPSE_INSTALL_DIRECTORY" ]; then die "Firefox profile does not have HTTPS Everywhere installed" fi @@ -51,17 +44,6 @@ if [ -z "$XVFB_RUN" -a -n "$(which xvfb-run)" ]; then XVFB_RUN=xvfb-run fi -# Activate the Firefox Addon SDK. -pushd addon-sdk -source bin/activate -popd - -if ! type cfx > /dev/null; then - die "Addon SDK failed to activiate." -fi - -pushd $TEST_ADDON_PATH - # If you just want to run Firefox with the latest code: if [ "$1" == "--justrun" ]; then echo "running firefox" @@ -73,14 +55,11 @@ if [ "$1" == "--justrun" ]; then fi else echo "running tests" + + PATH=/home/user/geckodriver:$PATH if [ -n "$FIREFOX" ]; then - $XVFB_RUN cfx test -b $FIREFOX --profiledir="$PROFILE_DIRECTORY" --verbose + $XVFB_RUN python2.7 test/script.py Firefox "$PROFILE_DIRECTORY" $FIREFOX else - $XVFB_RUN cfx test --profiledir="$PROFILE_DIRECTORY" --verbose + $XVFB_RUN python2.7 test/script.py Firefox "$PROFILE_DIRECTORY" fi fi - -popd - -shasum=$(openssl sha -sha256 "$XPI_NAME") -echo -e "Git commit `git rev-parse HEAD`\n$shasum" diff --git a/test/firefox/README.md b/test/firefox/README.md index b503f2bb36b8..07f393098200 100644 --- a/test/firefox/README.md +++ b/test/firefox/README.md @@ -1,62 +1,7 @@ -# Tests for HTTPS Everywhere +# Requirements -## Prerequisites -* Latest release of the Firefox Add-On SDK as a submodule: - git submodule update - -# Running - bash test.sh - -To add tests, put them in `./https-everywhere-tests/tests`. - -# Manual tests - -These are test cases to execute manually before a release, and we should -implement them as automated tests: - -# Firefox -- Visit a site that triggers a ruleset (e.g., Reddit.com). Verify counter appears on HTTPS - Everywhere icon. -- Click HTTPS Everywhere icon menu, click 'show counter'. Verify counter - disappears. Verify checkmark disappears from menu item. -- Click HTTPS Everywhere icon, verify ruleset shows up in green. -- Click ruleset. -- Reopen HTTPS Everywhere icon menu, verify ruleset shows up in grey. -- Reload HTTP version of the site, ensure it doesn't get rewritten now that the - ruleset is disabled. -- Click HTTP Everywhere icon, click ruleset again. -- Reopen HTTPS Everywhere icon menu, verify ruleset shows up in green. -- Right-click on a rule, click 'View XML source.' Verify it opens up a dialog - box and shows the rule source. -- Click HTTPS Everywhere icon menu, click 'Block all HTTP requests'. Verify icon - turns red. -- Visit an HTTP site known to not have a rewrite rule. http://amazon.com is a - good example. Verify page does not load. -- Visit an HTTPS site that contains passive mixed content that is not rewritten - to HTTPS. https://jacob.hoffman-andrews.com/passive-mixed-content.html is a - good example. Verify the passive mixed content (e.g., image) does not load. -- Click icon menu, click 'About HTTPS Everywhere.' Verify dialog opens. -- Click icon menu, click 'SSL Observatory Preferences.' Verify dialog opens. -- Click icon menu, click 'Disable HTTPS Everywhere.' Verify icon turns grey. -- Visit a site that would normally trigger a ruleset. Verify it is not rewritten - to HTTPS. -- Click icon menu, click 'Enable HTTPS Everywhere.' Verify icon turns blue. - Verify page reloads and is rewritten to HTTPS. -- Look at log output, look for errors. Make sure certificates are being -submitted to SSL Observatory -- Tools > Web Developer > Browser Toolbox > Console. Check for errors. -- TODO: Test translations? - -# Chromium - -- Visit a site that triggers a ruleset (e.g., Reddit.com). Verify counter appears - on HTTPS Everywhere icon. -- Click HTTPS Everywhere icon menu. Verify it contains appropriate ruleset. -- Disable ruleset. -- Visit HTTP version of the site again. Verify it does not get redirected to - HTTPS. -- Re-enable ruleset. -- Visit HTTP version of the site again. Verify it does get redirected. -- Visit site that does not have a ruleset. From icon menu, click 'Add this - site', and complete site-adding process. -- Reload the site. Verify it gets redirected to HTTPS. +- Python 2.7 +- Selenium + - Install Selenium as a python package using ```pip install selenium```, or run install-dev-dependencies.sh and it will do the job +- GeckoDriver + - Manually download GeckoDriver from https://github.com/mozilla/geckodriver/releases. Extract the executable to /usr/bin/, so that the pasted executable's full path becomes /usr/bin/geckodriver. diff --git a/test/firefox/lib/main.js b/test/firefox/lib/main.js deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/firefox/package.json b/test/firefox/package.json deleted file mode 100644 index 90d35bce79ee..000000000000 --- a/test/firefox/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "https-everywhere-tests", - "title": "https-everywhere-tests", - "id": "jid1-we5BQOfc6skSMg", - "description": "a basic add-on", - "author": "", - "license": "MPL 2.0", - "version": "0.1" -} diff --git a/test/firefox/test/test-httpse-installed.js b/test/firefox/test/test-httpse-installed.js deleted file mode 100644 index be2fe9709d54..000000000000 --- a/test/firefox/test/test-httpse-installed.js +++ /dev/null @@ -1,38 +0,0 @@ -// Test that HTTPS Everywhere component is installed and accessible - -const { Cc, Ci } = require("chrome"); -var tabs = require("sdk/tabs"); - -let HTTPSEverywhere = Cc["@eff.org/https-everywhere;1"] - .getService(Ci.nsISupports) - .wrappedJSObject; - -exports["test httpse installed"] = function(assert) { - assert.equal(typeof HTTPSEverywhere, "object", - "Test that HTTPSEverywhere is defined"); - assert.equal(typeof HTTPSEverywhere.observe, "function", - "Test that HTTPSEverywhere.observe is a function"); -}; - -exports["test httpse potentiallyApplicableRulesets"] = function(assert) { - let HTTPSRules = HTTPSEverywhere.https_rules; - assert.deepEqual(HTTPSRules.potentiallyApplicableRulesets("www.wikia.com").length, - 1, - "Test that HTTPSE finds one applicable rule for www.wikia.com"); -} - -exports["test sample ruleset"] = function(assert, done) { - tabs.open({ - url: "http://www.freerangekitten.com/", - onOpen: function(tab) { - tab.on('load', function(tab) { - assert.equal(tab.url, "https://www.freerangekitten.com/", - "Test that URLs are rewritten to HTTPS."); - tab.close(); - done(); - }); - } - }); -} - -require("sdk/test").run(exports); diff --git a/test/firefox/test/test-main.js b/test/firefox/test/test-main.js deleted file mode 100644 index 147f98adfafe..000000000000 --- a/test/firefox/test/test-main.js +++ /dev/null @@ -1,12 +0,0 @@ -var main = require("./main"); - -exports["test main"] = function(assert) { - assert.pass("Unit test running!"); -}; - -exports["test main async"] = function(assert, done) { - assert.pass("async Unit test running!"); - done(); -}; - -require("sdk/test").run(exports); diff --git a/test/firefox/test_profile_skeleton/extensions.ini b/test/firefox/test_profile_skeleton/extensions.ini deleted file mode 100644 index a0ca1c2d30e8..000000000000 --- a/test/firefox/test_profile_skeleton/extensions.ini +++ /dev/null @@ -1,7 +0,0 @@ -[ExtensionDirs] -Extension0=/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/ubufox@ubuntu.com -Extension1=/usr/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/{2e1445b0-2682-11e1-bfc2-0800200c9a66} -Extension2=/usr/lib/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}/online-accounts@lists.launchpad.net - -[ThemeDirs] -Extension0=/usr/lib/firefox/browser/extensions/{972ce4c6-7e08-4474-a285-3208198ce6fd} diff --git a/test/firefox/test_profile_skeleton/prefs.js b/test/firefox/test_profile_skeleton/prefs.js index 42b3f0a7ec01..d1c0e37d53b0 100644 --- a/test/firefox/test_profile_skeleton/prefs.js +++ b/test/firefox/test_profile_skeleton/prefs.js @@ -1,20 +1,9 @@ -// Submit SSL Observatory reports. -user_pref("extensions.https_everywhere._observatory.enabled", true); -// Don't show any popups that might get in the way of testing. -user_pref("extensions.https_everywhere._observatory.popup_shown", true); -user_pref("extensions.https_everywhere.toolbar_hint_shown", true); -// Show all logs. -user_pref("extensions.https_everywhere.LogLevel", 0); -user_pref("extensions.https_everywhere.log_to_stdout", true); // Make it quicker to make manual config changes. user_pref("general.warnOnAboutConfig", false); // Minimize unnecessary requests. user_pref("browser.safebrowsing.enabled", false); user_pref("browser.safebrowsing.malware.enabled", false); // These two preferences allow debugging the extension -// using Tools > Web Developer > Browser Toolbox -// (Note: Since this is not an SDK extension, you can't use the Addon -// Debugger, but the Browser Toolbox is just about as good). user_pref("devtools.chrome.enabled", true); user_pref("devtools.debugger.remote-enabled", true); // Disable signature requirement so we can run testing addons diff --git a/test/script.py b/test/script.py new file mode 100644 index 000000000000..7d0867a395d0 --- /dev/null +++ b/test/script.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python2.7 +# +# Run Chromium tests for HTTPS Everywhere +# +# This script may be executed as `python script.py [directory of CRX]` +# +# The script is compatible with Python 2. Python 3 is not tested. +# Selenium, WebDriver and Google Chrome (or Chromium) must be installed +# in order for the script to run successfully. A desktop version +# of linux is required for the script to run correctly as well. +# Otherwise, use pyvirtualdisplay. + +import sys, os, platform, time +from selenium import webdriver +from selenium.common.exceptions import WebDriverException +from selenium.webdriver.firefox.firefox_binary import FirefoxBinary + +class bcolors: + HEADER = '\033[95m' + OKBLUE = '\033[94m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + + +if sys.argv[1] == "Chrome": + chromeOps = webdriver.ChromeOptions() + chromeOps.add_extension(sys.argv[2]) + if os.getuid() == 0: + chromeOps.add_argument("--no-sandbox") + + # Find the path to chromedriver + chromedriver_path = "chromedriver" + if sys.platform.startswith("linux"): + if 'Ubuntu' in platform.linux_distribution(): + chromedriver_path = "/usr/lib/chromium-browser/chromedriver" + elif 'debian' in platform.linux_distribution(): + #Debian is lowercase when platform.linux_distribution() is used. + #This is not a mistake. + chromedriver_path = "/usr/lib/chromium/chromedriver" + + try: + # First argument is optional, if not specified will search path. + driver = webdriver.Chrome(chromedriver_path, chrome_options=chromeOps) + except WebDriverException as e: + error = e.__str__() + + if "executable needs to be in PATH" in e.__str__(): + print "ChromeDriver isn't installed. Check test/chromium/README.md " \ + "for instructions on how to install ChromeDriver" + + sys.exit(2) + else: + raise e + +if sys.argv[1] == "Firefox": + fp = webdriver.FirefoxProfile(sys.argv[2]) + try: + if len(sys.argv) == 4: + binary = FirefoxBinary(sys.argv[3]) + driver = webdriver.Firefox(fp, firefox_binary=binary, log_path=os.devnull) + else: + driver = webdriver.Firefox(fp, log_path=os.devnull) + # Allow the extension time to load + except WebDriverException as e: + error = e.__str__() + + if "executable needs to be in PATH" in e.__str__(): + print "GeckoDriver isn't installed. Check test/firefox/README.md " \ + "for instructions on how to install GeckoDriver" + + sys.exit(2) + else: + raise e + + + time.sleep(1) + +print '' + +driver.get('http://freerangekitten.com') + +test_failed = False +if driver.current_url.startswith('https'): + print bcolors.OKGREEN + sys.argv[1] + ": HTTP to HTTPS redirection successful" + bcolors.ENDC +elif driver.current_url.startswith('http'): + print bcolors.FAIL + sys.argv[1] + "Chromium: HTTP to HTTPS redirection failed" + bcolors.ENDC + test_failed = True + +print '' + +driver.quit() + +if test_failed: + sys.exit(1) From fdd933fe0f46759ad3a68bf04a18597164531ee1 Mon Sep 17 00:00:00 2001 From: William Budington Date: Tue, 8 Aug 2017 14:32:36 -0700 Subject: [PATCH 10/11] Adding options UI for the ability to import settings. Chrome 55+ is required due to use of async functions. --- chromium/.eslintrc.json | 3 ++ chromium/background.js | 60 ++++++++++++++++++++++++++++++++++++++++ chromium/manifest.json | 5 +++- chromium/options.css | 17 ++++++++++++ chromium/options.html | 22 +++++++++++++++ chromium/options.js | 28 +++++++++++++++++++ chromium/popup.html | 2 ++ chromium/popup.js | 19 ------------- chromium/send-message.js | 8 ++++++ chromium/translation.js | 11 ++++++++ 10 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 chromium/options.css create mode 100644 chromium/options.html create mode 100644 chromium/options.js create mode 100644 chromium/send-message.js create mode 100644 chromium/translation.js diff --git a/chromium/.eslintrc.json b/chromium/.eslintrc.json index 772b09843098..97b53825ae30 100644 --- a/chromium/.eslintrc.json +++ b/chromium/.eslintrc.json @@ -1,4 +1,7 @@ { + "parserOptions": { + "ecmaVersion": 2017 + }, "env": { "browser": true, "commonjs": true, diff --git a/chromium/background.js b/chromium/background.js index e29b0ec7453a..874a15577023 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -31,6 +31,15 @@ storage.get({enableMixedRulesets: false}, function(item) { all_rules.addFromXml(loadExtensionFile('rules/default.rulesets', 'xml')); }); +// Load in the legacy custom rulesets, if any +storage.get({legacy_custom_rulesets: false}, item => { + if(item.legacy_custom_rulesets){ + for(let legacy_custom_ruleset of item.legacy_custom_rulesets){ + all_rules.addFromXml((new DOMParser()).parseFromString(legacy_custom_ruleset, 'text/xml')); + } + } +}); + var USER_RULE_KEY = 'userRules'; // Records which tabId's are active in the HTTPS Switch Planner (see // devtools-panel.js). @@ -674,5 +683,56 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ updateState(); } else if (message.type == "remove_rule") { removeRule(message.object); + } else if (message.type == "import_settings") { + import_settings(message.object).then(() => { + sendResponse(true); + }); } }); + +/** + * Enable switch planner for specific tab + * @param settings the settings object + */ +async function import_settings(settings){ + if(settings.changed){ + // Load custom rulesets and add to storage + await new Promise(resolve => { + for(let ruleset of settings.custom_rulesets){ + all_rules.addFromXml((new DOMParser()).parseFromString(ruleset, 'text/xml')); + } + storage.set({"legacy_custom_rulesets": settings.custom_rulesets}, item => { + resolve(item); + }); + }); + + // Load all the ruleset toggles into memory and store + let rule_toggle_promises = []; + for(let ruleset_name in settings.rule_toggle){ + localStorage[ruleset_name] = settings.rule_toggle[ruleset_name]; + + rule_toggle_promises.push((ruleset_name, ruleset_active => { + return new Promise(resolve => { + for(let host in all_rules.targets){ + for(let ruleset of all_rules.targets[host]){ + if(ruleset.name == ruleset_name){ + ruleset.active = ruleset_active; + resolve(true); + return; + } + } + } + resolve(false); + }) + })(ruleset_name, settings.rule_toggle[ruleset_name])); + } + await Promise.all(rule_toggle_promises); + + all_rules.ruleCache = new Map(); + + // Set/store globals + storage.set({'httpNowhere': settings.prefs.http_nowhere_enabled}); + storage.set({'showCounter': settings.prefs.show_counter}); + isExtensionEnabled = settings.prefs.global_enabled; + } +} diff --git a/chromium/manifest.json b/chromium/manifest.json index 35bd1f555e50..a5eb7afe51e3 100644 --- a/chromium/manifest.json +++ b/chromium/manifest.json @@ -15,6 +15,9 @@ "incognito-cache-clearing.js" ] }, + "options_ui": { + "page": "options.html" + }, "browser_action": { "default_icon": { "38": "icons/icon-active-38.png" @@ -32,7 +35,7 @@ }, "incognito": "spanning", "manifest_version": 2, - "minimum_chrome_version": "52", + "minimum_chrome_version": "55", "name": "__MSG_about_ext_name__", "permissions": [ "webNavigation", diff --git a/chromium/options.css b/chromium/options.css new file mode 100644 index 000000000000..1e9f0418e2b9 --- /dev/null +++ b/chromium/options.css @@ -0,0 +1,17 @@ +.section-header{ + margin-bottom: 10px; +} + +.section-header-span{ + border-bottom: 1px solid #ccc; + font-size: 15px; +} + +#import{ + margin-bottom: 10px; + float: right; +} + +#import-confirmed{ + display: none; +} diff --git a/chromium/options.html b/chromium/options.html new file mode 100644 index 000000000000..3a7ae116aa33 --- /dev/null +++ b/chromium/options.html @@ -0,0 +1,22 @@ + + + + + + + + + + +
+ +
+
+
+ +
+ +
+ + + diff --git a/chromium/options.js b/chromium/options.js new file mode 100644 index 000000000000..d979c504e0f2 --- /dev/null +++ b/chromium/options.js @@ -0,0 +1,28 @@ +document.addEventListener("DOMContentLoaded", () => { + + let json_data; + let import_button = document.querySelector("#import"); + + function import_json(e) { + e.preventDefault(); + + let settings = JSON.parse(json_data); + sendMessage("import_settings", settings, resp => { + document.querySelector("#import-confirmed").style.display = "block"; + document.querySelector("form").style.display = "none"; + }); + } + + document.querySelector("#import-settings").addEventListener("change", event => { + const file = event.target.files[0]; + const reader = new FileReader(); + reader.onload = event => { + json_data = event.target.result; + import_button.disabled = false; + }; + + reader.readAsText(file); + }); + + document.querySelector("form").addEventListener("submit", import_json); +}); diff --git a/chromium/popup.html b/chromium/popup.html index 2a400c5a7bd0..b6c92d4cf855 100644 --- a/chromium/popup.html +++ b/chromium/popup.html @@ -9,6 +9,8 @@ + + diff --git a/chromium/popup.js b/chromium/popup.js index faa889c2dd7f..a0d744df4a5d 100644 --- a/chromium/popup.js +++ b/chromium/popup.js @@ -197,16 +197,6 @@ document.addEventListener("DOMContentLoaded", function () { httpNowhereCheckbox.setAttribute('checked', ''); } }); - - // auto-translate all elements with i18n attributes - var elem = document.querySelectorAll("[i18n]"); - for (let el of elem) { - el.innerHTML = chrome.i18n.getMessage(el.getAttribute("i18n")); - } - - // other translations - e("aboutTitle").setAttribute("title", chrome.i18n.getMessage("about_title")); - e("add-rule-link").addEventListener("click", addManualRule); }); @@ -284,12 +274,3 @@ function setOption_(opt, value) { details[opt] = value; sendMessage("set_option", details); } - -function sendMessage(type, object, callback) { - var packet = {}; - packet.type = type; - if(object){ - packet.object = object; - } - chrome.runtime.sendMessage(packet, callback); -} diff --git a/chromium/send-message.js b/chromium/send-message.js new file mode 100644 index 000000000000..2ed895523d79 --- /dev/null +++ b/chromium/send-message.js @@ -0,0 +1,8 @@ +function sendMessage(type, object, callback) { + var packet = {}; + packet.type = type; + if(object){ + packet.object = object; + } + chrome.runtime.sendMessage(packet, callback); +} diff --git a/chromium/translation.js b/chromium/translation.js new file mode 100644 index 000000000000..61ae5ff14808 --- /dev/null +++ b/chromium/translation.js @@ -0,0 +1,11 @@ +document.addEventListener("DOMContentLoaded", function () { + // auto-translate all elements with i18n attributes + var elem = document.querySelectorAll("[i18n]"); + for (let el of elem) { + el.innerHTML = chrome.i18n.getMessage(el.getAttribute("i18n")); + } + + // other translations + e("aboutTitle").setAttribute("title", chrome.i18n.getMessage("about_title")); + e("add-rule-link").addEventListener("click", addManualRule); +}); From 48d8d3eed5a39740db50fa2827bcd8032d87dd0d Mon Sep 17 00:00:00 2001 From: William Budington Date: Tue, 8 Aug 2017 14:34:21 -0700 Subject: [PATCH 11/11] Converting the XPCOM extension to an Embedded WebExtension for settings migration --- chromium/background.js | 5 + makexpi.sh | 21 +- src/bootstrap.js | 111 ++ src/chrome/content/about.js | 14 - src/chrome/content/about.xul | 70 -- src/chrome/content/code/AndroidUI.jsm | 260 ----- src/chrome/content/code/ApplicableList.js | 279 ----- src/chrome/content/code/Cookie.js | 150 --- src/chrome/content/code/HTTPS.js | 330 ------ src/chrome/content/code/HTTPSRules.js | 780 ------------- src/chrome/content/code/IOUtil.js | 267 ----- src/chrome/content/code/NSS.js | 489 -------- src/chrome/content/code/Root-CAs.js | 348 ------ src/chrome/content/code/X509ChainWhitelist.js | 1007 ----------------- src/chrome/content/code/commonOCSP.json | 289 ----- src/chrome/content/code/sha256.js | 249 ---- src/chrome/content/meta-preferences.xul | 30 - src/chrome/content/observatory-popup.xul | 61 - .../content/observatory-preferences.xul | 115 -- src/chrome/content/observatory-warning.xul | 49 - src/chrome/content/observatory-xul.js | 208 ---- src/chrome/content/toolbar_button.js | 441 -------- src/chrome/content/toolbar_button.xul | 86 -- src/chrome/content/toolbar_button_binding.xml | 33 - src/chrome/skin/cross.png | Bin 261 -> 0 bytes src/chrome/skin/https-everywhere-banner.png | 1 - src/chrome/skin/https-everywhere.css | 78 -- src/chrome/skin/icon-active-128.png | 1 - src/chrome/skin/icon-active-16.png | 1 - src/chrome/skin/icon-active-24.png | 1 - src/chrome/skin/icon-active-38.png | 1 - src/chrome/skin/icon-blocking-16.png | 1 - src/chrome/skin/icon-blocking-24.png | 1 - src/chrome/skin/icon-blocking-38.png | 1 - src/chrome/skin/icon-disabled-16.png | 1 - src/chrome/skin/icon-disabled-24.png | 1 - src/chrome/skin/icon-disabled-38.png | 1 - src/chrome/skin/icon-inactive-16.png | 1 - src/chrome/skin/icon-inactive-24.png | 1 - src/chrome/skin/icon-inactive-38.png | 1 - src/chrome/skin/loop.png | Bin 364 -> 0 bytes src/chrome/skin/tick-moot.png | Bin 335 -> 0 bytes src/chrome/skin/tick.png | Bin 348 -> 0 bytes src/components/https-everywhere.js | 832 -------------- src/components/ssl-observatory.js | 979 ---------------- src/install.rdf | 12 +- 46 files changed, 141 insertions(+), 7466 deletions(-) create mode 100644 src/bootstrap.js delete mode 100644 src/chrome/content/about.js delete mode 100644 src/chrome/content/about.xul delete mode 100644 src/chrome/content/code/AndroidUI.jsm delete mode 100644 src/chrome/content/code/ApplicableList.js delete mode 100644 src/chrome/content/code/Cookie.js delete mode 100644 src/chrome/content/code/HTTPS.js delete mode 100644 src/chrome/content/code/HTTPSRules.js delete mode 100644 src/chrome/content/code/IOUtil.js delete mode 100644 src/chrome/content/code/NSS.js delete mode 100644 src/chrome/content/code/Root-CAs.js delete mode 100644 src/chrome/content/code/X509ChainWhitelist.js delete mode 100644 src/chrome/content/code/commonOCSP.json delete mode 100644 src/chrome/content/code/sha256.js delete mode 100644 src/chrome/content/meta-preferences.xul delete mode 100644 src/chrome/content/observatory-popup.xul delete mode 100644 src/chrome/content/observatory-preferences.xul delete mode 100644 src/chrome/content/observatory-warning.xul delete mode 100644 src/chrome/content/observatory-xul.js delete mode 100644 src/chrome/content/toolbar_button.js delete mode 100644 src/chrome/content/toolbar_button.xul delete mode 100644 src/chrome/content/toolbar_button_binding.xml delete mode 100644 src/chrome/skin/cross.png delete mode 120000 src/chrome/skin/https-everywhere-banner.png delete mode 100644 src/chrome/skin/https-everywhere.css delete mode 120000 src/chrome/skin/icon-active-128.png delete mode 120000 src/chrome/skin/icon-active-16.png delete mode 120000 src/chrome/skin/icon-active-24.png delete mode 120000 src/chrome/skin/icon-active-38.png delete mode 120000 src/chrome/skin/icon-blocking-16.png delete mode 120000 src/chrome/skin/icon-blocking-24.png delete mode 120000 src/chrome/skin/icon-blocking-38.png delete mode 120000 src/chrome/skin/icon-disabled-16.png delete mode 120000 src/chrome/skin/icon-disabled-24.png delete mode 120000 src/chrome/skin/icon-disabled-38.png delete mode 120000 src/chrome/skin/icon-inactive-16.png delete mode 120000 src/chrome/skin/icon-inactive-24.png delete mode 120000 src/chrome/skin/icon-inactive-38.png delete mode 100644 src/chrome/skin/loop.png delete mode 100644 src/chrome/skin/tick-moot.png delete mode 100644 src/chrome/skin/tick.png delete mode 100644 src/components/https-everywhere.js delete mode 100644 src/components/ssl-observatory.js diff --git a/chromium/background.js b/chromium/background.js index 874a15577023..e1181275a7fc 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -690,6 +690,11 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ } }); +// Send a message to the embedded webextension bootstrap.js to get settings to import +chrome.runtime.sendMessage("import-legacy-data", function(settings){ + import_settings(settings); +}); + /** * Enable switch planner for specific tab * @param settings the settings object diff --git a/makexpi.sh b/makexpi.sh index 02f5e915b63d..e22f762136bf 100755 --- a/makexpi.sh +++ b/makexpi.sh @@ -84,7 +84,6 @@ die() { } bash utils/validate.sh -cp pkg/rulesets.json src/chrome/content/rulesets.json # The name/version of the XPI we're building comes from src/install.rdf XPI_NAME="pkg/$APP_NAME-`grep em:version src/install.rdf | sed -e 's/[<>]/ /g' | cut -f3`" @@ -101,7 +100,25 @@ fi # Prepare packages suitable for uploading to EFF and AMO, respectively. [ -d pkg ] || mkdir pkg rsync -aL --delete --delete-excluded --exclude /chrome/content/rules src/ pkg/xpi-eff -cp -a translations/* pkg/xpi-eff/chrome/locale/ + +# The next lines are for embedded WebExtensions, and can be deleted after the full transition to WebExtensions +[ -d pkg/xpi-eff/webextension ] || mkdir pkg/xpi-eff/webextension +rsync -aL --delete chromium/ pkg/xpi-eff/webextension/ + +mkdir pkg/xpi-eff/webextension/_locales/ +python2.7 utils/chromium-translations.py translations/ pkg/xpi-eff/webextension/_locales/ +python2.7 utils/chromium-translations.py src/chrome/locale/ pkg/xpi-eff/webextension/_locales/ + +do_not_ship="*.py *.xml icon.jpg" +rm -f pkg/xpi-eff/webextension/$do_not_ship +rm -rf pkg/xpi-eff/chrome/content/rulesets.json +rm -rf pkg/xpi-eff/chrome/locale + +mkdir pkg/xpi-eff/webextension/rules/ +. ./utils/merge-rulesets.sh || exit 1 + +cp src/$RULESETS pkg/xpi-eff/webextension/rules/default.rulesets + rsync -a --delete pkg/xpi-eff/ pkg/xpi-amo # The AMO version of the package cannot contain the updateKey or updateURL tags. # Also, it has a different id than the eff-hosted version, because Firefox now diff --git a/src/bootstrap.js b/src/bootstrap.js new file mode 100644 index 000000000000..0822bb5b5580 --- /dev/null +++ b/src/bootstrap.js @@ -0,0 +1,111 @@ +"use strict"; + +const CI = Components.interfaces; +const CC = Components.classes; + +function get_prefs(branch_name){ + let o_prefs = CC["@mozilla.org/preferences-service;1"] + .getService(CI.nsIPrefService); + let o_branch = o_prefs.getBranch(branch_name); + return o_branch; +} + +function get_custom_rulesets_array(){ + var loc = "ProfD"; // profile directory + var dir = + CC["@mozilla.org/file/directory_service;1"] + .getService(CI.nsIProperties) + .get(loc, CI.nsILocalFile) + .clone(); + dir.append("HTTPSEverywhereUserRules"); + // Check for existence, if not, create. + if (!dir.exists()) { + return []; + } + + var entries = dir.directoryEntries; + var files = []; + while(entries.hasMoreElements()) { + var entry = entries.getNext(); + entry.QueryInterface(CI.nsIFile); + files.push(entry); + } + + let file_data = [] + for(let file of files){ + var data = ""; + var fstream = CC["@mozilla.org/network/file-input-stream;1"] + .createInstance(CI.nsIFileInputStream); + var sstream = CC["@mozilla.org/scriptableinputstream;1"] + .createInstance(CI.nsIScriptableInputStream); + fstream.init(file, -1, 0, 0); + sstream.init(fstream); + + var str = sstream.read(4096); + while (str.length > 0) { + data += str; + str = sstream.read(4096); + } + + sstream.close(); + fstream.close(); + file_data.push(data); + } + + return file_data; +} + +function startup({webExtension}) { + webExtension.startup().then(api => { + const {browser} = api; + browser.runtime.onMessage.addListener((msg, sender, sendReply) => { + if (msg == "import-legacy-data") { + let globals = get_prefs("extensions.https_everywhere."); + let prefs_array = globals.getChildList("", {}); + if(~prefs_array.indexOf("webextensions-migrated") ? !globals.getBoolPref("webextensions-migrated") : true){ + let rules = get_prefs("extensions.https_everywhere.rule_toggle."); + + let changed = false; + + let prefs = { + http_nowhere_enabled: ~prefs_array.indexOf("http_nowhere.enabled") ? globals.getBoolPref("http_nowhere.enabled") : false, + global_enabled: ~prefs_array.indexOf("globalEnabled") ? globals.getBoolPref("globalEnabled") : true, + show_counter: ~prefs_array.indexOf("show_counter") ? globals.getBoolPref("show_counter") : true + }; + + if(prefs.http_nowhere_enabled == true || + prefs.global_enabled == false || + prefs.show_counter == true + ){ + changed = true; + } + + let rule_toggle = {} + for(let rule_toggle_key of rules.getChildList("", {})){ + rule_toggle[rule_toggle_key] = rules.getBoolPref(rule_toggle_key); + changed = true; + } + + let custom_rulesets = get_custom_rulesets_array(); + if(custom_rulesets.length > 0){ + changed = true; + } + + sendReply({ + prefs: prefs, + rule_toggle: rule_toggle, + custom_rulesets: custom_rulesets, + changed: changed + }); + + globals.setBoolPref("webextensions-migrated", true); + } else { + sendReply({changed: false}); + } + } + }); + }); +} + +function shutdown(data) { +} diff --git a/src/chrome/content/about.js b/src/chrome/content/about.js deleted file mode 100644 index 7a37815f1454..000000000000 --- a/src/chrome/content/about.js +++ /dev/null @@ -1,14 +0,0 @@ -const CC = Components.classes; - -function window_opener(uri) { - // we don't use window.open, because we need to work around TorButton's state control - if(typeof gBrowser == "undefined"){ - var window = CC["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); - var browserWindow = window.getMostRecentWindow("navigator:browser").getBrowser(); - var newTab = browserWindow.addTab(uri, null, null); - browserWindow.selectedTab = newTab; - - } - else - gBrowser.selectedTab = gBrowser.addTab(uri); -} diff --git a/src/chrome/content/about.xul b/src/chrome/content/about.xul deleted file mode 100644 index 05ac898f1b4e..000000000000 --- a/src/chrome/content/about.xul +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - -