From 7dbab77ef08d86d8ca0219fa47d7fc54312d0ed9 Mon Sep 17 00:00:00 2001 From: William Budington Date: Wed, 24 May 2017 16:48:10 -0700 Subject: [PATCH 1/9] 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 9fbfe7648ec3be6586ff16e62fb20abe7a2f5c28 Mon Sep 17 00:00:00 2001 From: William Budington Date: Thu, 8 Jun 2017 17:36:19 -0700 Subject: [PATCH 2/9] 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 28f49a128070da231c919131a28c9294e9b60bbf Mon Sep 17 00:00:00 2001 From: William Budington Date: Wed, 17 May 2017 21:21:31 -0700 Subject: [PATCH 3/9] 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/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/script.py | 97 +++++++++++++++++++ 12 files changed, 119 insertions(+), 171 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/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/script.py b/test/script.py new file mode 100644 index 000000000000..ec53abd71554 --- /dev/null +++ b/test/script.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python2.7 +# +# Run Selenium 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) + 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 + + # Allow the extension time to load + 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] + ": HTTP to HTTPS redirection failed" + bcolors.ENDC + test_failed = True + +print '' + +driver.quit() + +if test_failed: + sys.exit(1) From 9283142d461cc8d61cddad0370181f0c3215b89b Mon Sep 17 00:00:00 2001 From: William Budington Date: Tue, 8 Aug 2017 14:32:36 -0700 Subject: [PATCH 4/9] 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 | 45 ++++++++++++++++++++++++++++++++++++++++ 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, 140 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..f70491fe899f 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -31,6 +31,14 @@ storage.get({enableMixedRulesets: false}, function(item) { all_rules.addFromXml(loadExtensionFile('rules/default.rulesets', 'xml')); }); +// Load in the legacy custom rulesets, if any +function load_legacy_custom_rulesets(legacy_custom_rulesets){ + for(let legacy_custom_ruleset of legacy_custom_rulesets){ + all_rules.addFromXml((new DOMParser()).parseFromString(legacy_custom_ruleset, 'text/xml')); + } +} +storage.get({legacy_custom_rulesets: []}, item => load_legacy_custom_rulesets(item.legacy_custom_rulesets)); + var USER_RULE_KEY = 'userRules'; // Records which tabId's are active in the HTTPS Switch Planner (see // devtools-panel.js). @@ -674,5 +682,42 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ updateState(); } else if (message.type == "remove_rule") { removeRule(message.object); + } else if (message.type == "import_settings") { + // This is used when importing settings from the options ui + import_settings(message.object).then(() => { + sendResponse(true); + }); } }); + +/** + * Import extension settings (custom rulesets, ruleset toggles, globals) from an object + * @param settings the settings object + */ +async function import_settings(settings){ + if(settings.changed){ + // Load custom rulesets and add to storage + await new Promise(resolve => { + storage.set({"legacy_custom_rulesets": settings.custom_rulesets}, resolve); + }); + load_legacy_custom_rulesets(settings.custom_rulesets); + + // 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]; + } + all_rules = new RuleSets(localStorage); + + // Set/store globals + await new Promise(resolve => { + storage.set({'httpNowhere': settings.prefs.http_nowhere_enabled}, resolve); + }); + await new Promise(resolve => { + storage.set({'showCounter': settings.prefs.show_counter}, resolve); + }); + await new Promise(resolve => { + storage.set({'globalEnabled': settings.prefs.global_enabled}, resolve); + }); + } +} 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 bd23706a625c2f68ee7766c44065e7a8c4bcb3aa Mon Sep 17 00:00:00 2001 From: William Budington Date: Tue, 8 Aug 2017 14:34:21 -0700 Subject: [PATCH 5/9] Converting the XPCOM extension to an Embedded WebExtension for settings migration --- chromium/background.js | 3 + makexpi.sh | 22 +- src/bootstrap.js | 118 ++ 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, 147 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 f70491fe899f..7b522cd9e5a7 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -690,6 +690,9 @@ 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", import_settings); + /** * Import extension settings (custom rulesets, ruleset toggles, globals) from an object * @param settings the settings object diff --git a/makexpi.sh b/makexpi.sh index 02f5e915b63d..c367f0f89ac0 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,26 @@ 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/ + +# START: 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 +# END + 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..57f89e3969e8 --- /dev/null +++ b/src/bootstrap.js @@ -0,0 +1,118 @@ +"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."); + if(!pref_retrieve_bool_with_default(globals, "webextension-migrated", false)){ + let changed = false; + + let prefs = { + http_nowhere_enabled: pref_retrieve_bool_with_default(globals, "http_nowhere.enabled", false), + global_enabled: pref_retrieve_bool_with_default(globals, "globalEnabled", true), + show_counter: pref_retrieve_bool_with_default(globals, "show_counter", true) + }; + + if(prefs.http_nowhere_enabled == true || + prefs.global_enabled == false || + prefs.show_counter == true + ){ + changed = true; + } + + let rule_toggle = {} + let rules = get_prefs("extensions.https_everywhere.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 pref_retrieve_bool_with_default(pref_branch, element, default_value){ + const pref_array = pref_branch.getChildList("", {}); + + if(pref_array.indexOf(element) !== -1){ + return pref_branch.getBoolPref(element); + } + return default_value; +} + +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 @@ - - - - - - - - -