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/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 408389fb02d0..e1181275a7fc 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). @@ -61,12 +70,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 +119,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; @@ -174,21 +190,20 @@ var removeRule = function(ruleset) { * */ function AppliedRulesets() { this.active_tab_rules = {}; + this.active_tab_hostnames = {}; 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 = { 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) { @@ -198,8 +213,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]; } }; @@ -283,6 +311,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); } @@ -618,3 +647,97 @@ 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_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; + 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); + } else if (message.type == "import_settings") { + import_settings(message.object).then(() => { + sendResponse(true); + }); + } +}); + +// 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 + */ +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/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); +} diff --git a/chromium/manifest.json b/chromium/manifest.json index a3d91a79311c..a5eb7afe51e3 100644 --- a/chromium/manifest.json +++ b/chromium/manifest.json @@ -1,7 +1,11 @@ { - "author": { - "email": "eff.software.projects@gmail.com" - }, + "applications": { + "gecko": { + "id": "https-everywhere-eff@eff.org", + "update_url": "https://www.eff.org/files/https-everywhere-updates.json" + } + }, + "author": "eff.software.projects@gmail.com", "background": { "scripts": [ "rules.js", @@ -11,6 +15,9 @@ "incognito-cache-clearing.js" ] }, + "options_ui": { + "page": "options.html" + }, "browser_action": { "default_icon": { "38": "icons/icon-active-38.png" @@ -28,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.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 { 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 6289e8fb06ba..a0d744df4a5d 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(); + }); } /** @@ -34,7 +41,7 @@ function toggleRuleLine(checkbox, ruleset) { * @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"); @@ -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); @@ -65,11 +72,17 @@ function appendRuleLineToListDiv(ruleset, list_div) { break; } } - var xhr = new XMLHttpRequest(); - try { - xhr.open("GET", favicon.src, true); - label.appendChild(favicon); - } catch (e) {} + if (favicon.src == "chrome://favicon/") { + favicon.src += "https://" + hostnames[ruleset.name]; + } + + 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"); @@ -85,7 +98,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 +112,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 +150,25 @@ 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_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], hostnames, activeTab.id, 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")); + } + }); } /** @@ -173,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); }); @@ -223,7 +237,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 +266,11 @@ 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); } 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/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; 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); +}); 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/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 @@ - - - - - - - - -