From 971b7690860c677374cbe14ee64558b1bd174718 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Mon, 20 Oct 2014 02:25:28 +0200 Subject: https-everywhere updated to 4.0.2 --- .../chrome/content/code/AndroidUI.jsm | 226 +++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 data/extensions/https-everywhere@eff.org/chrome/content/code/AndroidUI.jsm (limited to 'data/extensions/https-everywhere@eff.org/chrome/content/code/AndroidUI.jsm') diff --git a/data/extensions/https-everywhere@eff.org/chrome/content/code/AndroidUI.jsm b/data/extensions/https-everywhere@eff.org/chrome/content/code/AndroidUI.jsm new file mode 100644 index 0000000..e476345 --- /dev/null +++ b/data/extensions/https-everywhere@eff.org/chrome/content/code/AndroidUI.jsm @@ -0,0 +1,226 @@ +const CC = Components.classes; +const CI = Components.interfaces; +const CU = Components.utils; + +var HTTPSEverywhere = CC["@eff.org/https-everywhere;1"] + .getService(CI.nsISupports).wrappedJSObject; + +CU.import("resource://gre/modules/Prompt.jsm"); + +var menuId; +var urlbarId; +var aWindow = getWindow(); + + +/* + * Setup/Teardown for the UI + */ + +function loadIntoWindow() { + if (!aWindow) { + return; + } + var enabled = HTTPSEverywhere.prefs.getBoolPref("globalEnabled"); + addToggleItemToMenu(enabled); + if (enabled) { + urlbarId = aWindow.NativeWindow.pageactions.add(urlbarOptions); + } else if (urlbarId) { + aWindow.NativeWindow.pageactions.remove(urlbarId); + } +} + +function unloadFromWindow() { + if (!aWindow) { + return; + } + aWindow.NativeWindow.menu.remove(menuId); + aWindow.NativeWindow.pageactions.remove(urlbarId); +} + + +/* + * Add a menu item to toggle HTTPS Everywhere + */ + +function addToggleItemToMenu(enabled) { + if (menuId) { aWindow.NativeWindow.menu.remove(menuId); } + var menuLabel = enabled ? "HTTPS Everywhere on" : "HTTPS Everywhere off"; + menuId = aWindow.NativeWindow.menu.add(menuLabel, null, function() { + popupToggleMenu(aWindow, enabled); + }); +} + +function popupToggleMenu(aWindow, enabled) { + var buttons = [ + { + label: "Yes", + callback: function() { + toggleEnabledState(); + var msg = enabled ? "HTTPS Everywhere disabled!" : "HTTPS Everywhere enabled!"; + aWindow.NativeWindow.toast.show(msg, "short"); + return true; + } + }, { + label: "No", + callback: function() { return false; } + } + ]; + var newState = enabled ? "off?" : "on?"; + aWindow.NativeWindow.doorhanger.show("Would you like to turn HTTPS Everywhere "+newState, + "doorhanger-toggle", buttons); +} + + +/* + * The HTTPS Everywhere icon in the URL bar shows a popup of rules that the + * user can activate/deactivate. On long click, reset all rules to defaults. + */ + +var popupInfo = { + rules: [], + ruleItems: [], + ruleStatus: [], + alist: null, + getApplicableList: function() { + var domWin = aWindow.BrowserApp.selectedTab.window; + return HTTPSEverywhere.getApplicableListForDOMWin(domWin); + }, + fill: function() { + this.clear(); + this.alist = this.getApplicableList(); + HTTPSEverywhere.log(4,"applicable list active: "+JSON.stringify(this.alist.active)); + HTTPSEverywhere.log(4,"applicable list inactive: "+JSON.stringify(this.alist.inactive)); + for (var rule in this.alist.all) { + if (this.alist.active.hasOwnProperty(rule)) { + // active rules are checked and toggleable + this.ruleItems.push({ label: rule, selected: true }); + this.ruleStatus.push(true); + this.rules.push(this.alist.active[rule]); + } else if (this.alist.moot.hasOwnProperty(rule)) { + // moot rules are checked and toggleable too + this.ruleItems.push({ label: rule, selected: true }); + this.ruleStatus.push(true); + this.rules.push(this.alist.moot[rule]); + } else if (this.alist.inactive.hasOwnProperty(rule)) { + // inactive rules are unchecked and toggleable + this.ruleItems.push({ label: rule }); + this.ruleStatus.push(false); + this.rules.push(this.alist.inactive[rule]); + } else if (this.alist.breaking.hasOwnProperty(rule)) { + // breaking rules are get a unicode clockwise arrow next to them + var ruleLabel = "\u21B7"+rule; + var isSelected = this.alist.breaking[rule].active; + this.ruleItems.push({ label: ruleLabel, selected: isSelected }); + this.ruleStatus.push(isSelected); + this.rules.push(this.alist.breaking[rule]); + } + } + }, + clear: function() { + this.rules = []; + this.ruleItems = []; + this.ruleStatus = []; + this.alist = {}; + } +}; + +var urlbarOptions = { + + title: "HTTPS Everywhere", + + icon: "chrome://https-everywhere/skin/https-everywhere-128.png", + + clickCallback: function() { + popupInfo.fill(); + rulesPrompt.setMultiChoiceItems(popupInfo.ruleItems); + rulesPrompt.show(function(data) { + var db = data.button; + if (db === -1) { return null; } // user didn't click the accept button + if (popupInfo.rules.length !== db.length) { + // Why does db sometimes have an extra entry that doesn't correspond + // to any of the ruleItems? No idea, but let's log it. + HTTPSEverywhere.log(5,"Got length mismatch between popupInfo.ruleItems and data.button"); + HTTPSEverywhere.log(4,"Applicable rules: "+JSON.stringify(popupInfo.rules)); + HTTPSEverywhere.log(4, "data.button: "+JSON.stringify(db)); + } + for (var i=0; i