|
1 | 1 | var EXPORTED_SYMBOLS = ["FennecUI"]; |
2 | 2 |
|
| 3 | +const CC = Components.classes; |
| 4 | +const CI = Components.interfaces; |
| 5 | +const CU = Components.utils; |
| 6 | + |
| 7 | +var HTTPSEverywhere = CC["@eff.org/https-everywhere;1"] |
| 8 | + .getService(CI.nsISupports).wrappedJSObject; |
| 9 | + |
| 10 | +CU.import("resource://gre/modules/Prompt.jsm"); |
| 11 | + |
3 | 12 | var menuId; |
4 | 13 | var urlbarId; |
5 | 14 | var aWindow = getWindow(); |
6 | 15 |
|
7 | 16 | function getWindow() { |
8 | | - return Components.classes['@mozilla.org/appshell/window-mediator;1'] |
9 | | - .getService(Components.interfaces.nsIWindowMediator) |
| 17 | + return CC['@mozilla.org/appshell/window-mediator;1'] |
| 18 | + .getService(CI.nsIWindowMediator) |
10 | 19 | .getMostRecentWindow('navigator:browser'); |
11 | 20 | } |
12 | 21 |
|
@@ -44,14 +53,62 @@ function popupToggleMenu(aWindow) { |
44 | 53 | aWindow.NativeWindow.doorhanger.show("Would you like to turn off HTTPS Everywhere?", "doorhanger-test", buttons); |
45 | 54 | } |
46 | 55 |
|
| 56 | +/* |
| 57 | + * The HTTPS Everywhere icon in the URL bar shows a menu of rules that the |
| 58 | + * user can activate/deactivate. Here's some code to create it and update the |
| 59 | + * rule list dynamically. |
| 60 | + */ |
| 61 | + |
47 | 62 | var urlbarOptions = { |
48 | 63 | title: "HTTPS Everywhere", |
49 | 64 | icon: "chrome://https-everywhere/skin/https-everywhere-128.png", |
50 | | - clickCallback: function() {return;} |
| 65 | + clickCallback: function() { |
| 66 | + rulesPrompt.setMultiChoiceItems(ruleItems); |
| 67 | + rulesPrompt.show(function(data) { |
| 68 | + aWindow.alert(JSON.stringify(getApplicableList())); |
| 69 | + }) |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +// The prompt that shows up when someone clicks on the icon |
| 74 | +var rulesPrompt = new Prompt({ |
| 75 | + window: aWindow, |
| 76 | + title: "Enable/disable rules" |
| 77 | +}); |
| 78 | + |
| 79 | +// Rulesets to show in the list |
| 80 | +var ruleItems = [ |
| 81 | + { label: "rule 1" }, |
| 82 | + { label: "rule 2", disabled: true }, |
| 83 | + { label: "rule 3", selected: true } |
| 84 | +]; |
| 85 | + |
| 86 | +function getApplicableList() { |
| 87 | + var domWin = getWindow().content.document.defaultView.top; |
| 88 | + if (!(domWin instanceof CI.nsIDOMWindow)) { |
| 89 | + aWindow.console.log('something went wrong getting top window'); |
| 90 | + return null; |
| 91 | + } |
| 92 | + var alist = HTTPSEverywhere.getExpando(domWin,"applicable_rules", null); |
| 93 | + return alist.all; |
| 94 | +} |
| 95 | + |
| 96 | +function toggleRule(rule_id) { |
| 97 | + // toggle the rule state |
| 98 | + HTTPSEverywhere.https_rules.rulesetsByID[rule_id].toggle(); |
| 99 | + reloadTab(); |
51 | 100 | } |
52 | 101 |
|
| 102 | +function reloadTab() { return; } |
| 103 | + |
| 104 | +function toggleEnabledState(){ |
| 105 | + HTTPSEverywhere.toggleEnabledState(); |
| 106 | + reloadTab(); |
| 107 | +} |
| 108 | + |
| 109 | +// Here's the external API to this UI module |
53 | 110 | var FennecUI = { |
54 | 111 | init: function() { |
55 | 112 | loadIntoWindow(); |
56 | 113 | } |
57 | | -} |
| 114 | +}; |
0 commit comments