Skip to content

Commit 252d061

Browse files
committed
Working patch for issue 4060 (global enable/disable from toolbar). Will test a little bit more, then make a patch and submit to EFF tomorrow.
1 parent e175a5c commit 252d061

File tree

14 files changed

+130
-84
lines changed

14 files changed

+130
-84
lines changed

src/chrome/content/code/ApplicableList.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ ApplicableList.prototype = {
7272
HTTPSEverywhere.instance.https_rules.rewrittenURI(this, this.doc.baseURIObject);
7373
this.log(DBUG, "populating using alist #" + this.serial);
7474
this.document = document;
75+
76+
var https_everywhere = CC["@eff.org/https-everywhere;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
77+
var o_httpsprefs = https_everywhere.get_prefs();
7578

7679
// get the menu popup
7780
this.menupopup = menupopup;
@@ -82,10 +85,17 @@ ApplicableList.prototype = {
8285
}
8386

8487
// add global enable/disable toggle button
88+
var strings = document.getElementById("HttpsEverywhereStrings");
89+
8590
var enableLabel = document.createElement('menuitem');
86-
enableLabel.setAttribute('label', 'Enable / Disable HTTPS Everywhere');
87-
enableLabel.setAttribute('command', 'https-everywhere-menuitem-globalEnableToggle');
91+
var text = strings.getString("https-everywhere.menu.globalDisable");
92+
if(!o_httpsprefs.getBoolPref("globalEnabled"))
93+
text = strings.getString("https-everywhere.menu.globalEnable");
8894

95+
enableLabel.setAttribute('label', text);
96+
enableLabel.setAttribute('command', 'https-everywhere-menuitem-globalEnableToggle');
97+
this.prepend_child(enableLabel);
98+
8999
// add the label at the top
90100
var any_rules = false
91101
for (var x in this.all) {
@@ -135,9 +145,6 @@ ApplicableList.prototype = {
135145

136146
//Search for applicable rulesets for the host listed in the location bar
137147
var alist = HTTPSRules.potentiallyApplicableRulesets(fromHost);
138-
139-
https_everywhere = CC["@eff.org/https-everywhere;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
140-
o_httpsprefs = https_everywhere.get_prefs();
141148

142149
for (var i = 0 ; i < alist.length ; i++){
143150
//For each applicable rulset, determine active/inactive, and append to proper list.
@@ -158,22 +165,24 @@ ApplicableList.prototype = {
158165
for(var x in this.inactive)
159166
this.add_command(this.inactive[x]);
160167

161-
// add all the menu items
162-
for (var x in this.inactive)
163-
this.add_menuitem(this.inactive[x], 'inactive');
164-
// rules that are active for some uris are not really moot
165-
for (var x in this.moot)
166-
if (!(x in this.active))
167-
this.add_menuitem(this.moot[x], 'moot');
168-
// break once break everywhere
169-
for (var x in this.active)
170-
if (!(x in this.breaking))
171-
this.add_menuitem(this.active[x], 'active');
172-
for (var x in this.breaking)
173-
this.add_menuitem(this.breaking[x], 'breaking');
174-
175-
this.prepend_child(label);
176-
this.prepend_child(enableLabel);
168+
if(o_httpsprefs.getBoolPref("globalEnabled")){
169+
// add all the menu items
170+
for (var x in this.inactive)
171+
this.add_menuitem(this.inactive[x], 'inactive');
172+
// rules that are active for some uris are not really moot
173+
for (var x in this.moot)
174+
if (!(x in this.active))
175+
this.add_menuitem(this.moot[x], 'moot');
176+
// break once break everywhere
177+
for (var x in this.active)
178+
if (!(x in this.breaking))
179+
this.add_menuitem(this.active[x], 'active');
180+
for (var x in this.breaking)
181+
this.add_menuitem(this.breaking[x], 'breaking');
182+
183+
this.prepend_child(label);
184+
}
185+
177186
},
178187

179188
prepend_child: function(node) {

src/chrome/content/code/HTTPSRules.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,18 @@ const HTTPSRules = {
455455
},
456456

457457

458-
potentiallyApplicableRulesets: function(host) {
458+
potentiallyApplicableRulesets: function(host) {
459459
// Return a list of rulesets that declare targets matching this host
460460
var i, tmp, t;
461461
var results = this.global_rulesets;
462-
if (this.targets[host])
463-
results = results.concat(this.targets[host]);
462+
try{
463+
if (this.targets[host])
464+
results = results.concat(this.targets[host]);
465+
}
466+
catch(e){
467+
this.log(DBUG,"Couldn't check for ApplicableRulesets: " + e);
468+
return [];
469+
}
464470
// replace each portion of the domain with a * in turn
465471
var segmented = host.split(".");
466472
for (i = 0; i < segmented.length; ++i) {

src/chrome/content/toolbar_button.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,11 @@ function reload_window() {
102102
// This choice of flags comes from NoScript's quickReload function; not sure
103103
// if it's optimal
104104
webNav.reload(webNav.LOAD_FLAGS_CHARSET_CHANGE);
105-
106-
//The code below works fine for switching between HTTP/HTTPS when reload_window() is called.
107-
//However, reload_window() is also called for changing rulesets that do not affect page location (but rather content within a page)
108-
//Maybe add code to determine if a ruleset applies to the domain in the location bar, and reload to the proper scheme if so?
109-
/*
110-
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
111-
.getService(Components.interfaces.nsIIOService);
105+
}
112106

113-
var uri = gBrowser.getBrowserForDocument(gBrowser.contentDocument).currentURI;
114-
var newURI = "";
115-
116-
if(uri.scheme == "https")
117-
var newURI = uri.asciiSpec.replace("https://", "http://");
118-
else
119-
var newURI = uri.asciiSpec.replace("http://", "https://");
120-
121-
window.content.wrappedJSObject.location = newURI;
122-
*/
107+
function toggleEnabledState(){
108+
HTTPSEverywhere.toggleEnabledState();
109+
reload_window();
123110
}
124111

125112
function open_in_tab(url) {

src/chrome/content/toolbar_button.xul

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
<overlay id="https-everywhere-button-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
1010
<script type="application/x-javascript" src="chrome://https-everywhere/content/toolbar_button.js"/>
11+
12+
<stringbundleset id="stringbundleset">
13+
<stringbundle id="HttpsEverywhereStrings"
14+
src="chrome://https-everywhere/locale/https-everywhere.properties" />
15+
</stringbundleset>
1116

1217
<!-- this works in Firefox, we need a Seamonkey version too... -->
1318
<menupopup id="menu_ToolsPopup" onpopupshowing="stitch_context_menu()">
@@ -43,7 +48,7 @@
4348
</toolbarpalette>
4449
<commandset>
4550
<command id="https-everywhere-menuitem-globalEnableToggle"
46-
oncommand="HTTPSEverywhere.toggleEnabledState();" />
51+
oncommand="toggleEnabledState();" />
4752
<command id="https-everywhere-menuitem-preferences"
4853
oncommand="HTTPSEverywhere.chrome_opener('chrome://https-everywhere/content/preferences.xul');" />
4954
<command id="https-everywhere-menuitem-about"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https-everywhere.menu.globalEnable = Enable HTTPS Everywhere
2+
https-everywhere.menu.globalDisable = Disable HTTPS Everywhere

src/chrome/locale/en/https-everywhere.dtd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
<!ENTITY https-everywhere.menu.about "About HTTPS Everywhere">
1414
<!ENTITY https-everywhere.menu.observatory "SSL Observatory Preferences">
15+
<!ENTITY https-everywhere.menu.globalEnable "Enable HTTPS Everywhere">
16+
<!ENTITY https-everywhere.menu.globalDisable "Disable HTTPS Everywhere">
1517

1618
<!ENTITY https-everywhere.prefs.title "HTTPS Everywhere Preferences">
1719
<!ENTITY https-everywhere.prefs.enable_all "Enable All">
@@ -23,5 +25,4 @@
2325
<!ENTITY https-everywhere.prefs.list_caption "Which HTTPS redirection rules should apply?">
2426
<!ENTITY https-everywhere.prefs.enabled "Enabled">
2527
<!ENTITY https-everywhere.prefs.ruleset_howto "You can learn how to write your own rulesets (to add support for other web sites)">
26-
<!ENTITY https-everywhere.prefs.here_link "here">
27-
28+
<!ENTITY https-everywhere.prefs.here_link "here">
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https-everywhere.menu.globalEnable = Enable HTTPS Everywhere
2+
https-everywhere.menu.globalDisable = Disable HTTPS Everywhere
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https-everywhere.menu.globalEnable = Enable HTTPS Everywhere
2+
https-everywhere.menu.globalDisable = Disable HTTPS Everywhere
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https-everywhere.menu.globalEnable = Enable HTTPS Everywhere
2+
https-everywhere.menu.globalDisable = Disable HTTPS Everywhere
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
https-everywhere.menu.globalEnable = Enable HTTPS Everywhere
2+
https-everywhere.menu.globalDisable = Disable HTTPS Everywhere

0 commit comments

Comments
 (0)