Skip to content

Commit 3b0777f

Browse files
committed
Merge pull request EFForg#379 from EFForg/http-nowhere
Add toggle mode for HTTP Nowhere
2 parents d92f041 + 8eaafa8 commit 3b0777f

File tree

8 files changed

+186
-87
lines changed

8 files changed

+186
-87
lines changed

src/chrome/content/code/HTTPS.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,23 @@ const HTTPS = {
3030
httpsForcedExceptions: null,
3131
httpsRewrite: null,
3232

33-
replaceChannel: function(applicable_list, channel) {
33+
replaceChannel: function(applicable_list, channel, httpNowhereEnabled) {
3434
var blob = HTTPSRules.rewrittenURI(applicable_list, channel.URI.clone());
35-
if (null == blob) return false; // no rewrite
35+
if (blob === null) {
36+
// Abort insecure requests if HTTP Nowhere is on
37+
if (httpNowhereEnabled && channel.URI.schemeIs("http")) {
38+
IOUtil.abort(channel);
39+
}
40+
return false; // no rewrite
41+
}
3642
var uri = blob.newuri;
3743
if (!uri) this.log(WARN, "OH NO BAD ARGH\nARGH");
3844

45+
// Abort downgrading if HTTP Nowhere is on
46+
if (httpNowhereEnabled && uri.schemeIs("http")) {
47+
IOUtil.abort(channel);
48+
}
49+
3950
var c2 = channel.QueryInterface(CI.nsIHttpChannel);
4051
this.log(DBUG, channel.URI.spec+": Redirection limit is " + c2.redirectionLimit);
4152
// XXX This used to be (c2.redirectionLimit == 1), but that's very

src/chrome/content/toolbar_button.js

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ httpsEverywhere.toolbarButton = {
3737
*/
3838
COUNTER_PREF: "extensions.https_everywhere.show_counter",
3939

40+
/**
41+
* Name of preference for whether HTTP Nowhere is on.
42+
*/
43+
HTTP_NOWHERE_PREF: "extensions.https_everywhere.http_nowhere.enabled",
44+
4045
/**
4146
* Used to determine if a hint has been previously shown.
4247
* TODO: Probably extraneous, look into removing
@@ -53,14 +58,22 @@ httpsEverywhere.toolbarButton = {
5358

5459
var tb = httpsEverywhere.toolbarButton;
5560

56-
// make sure icon is proper color during init
57-
tb.changeIcon();
58-
5961
// make sure the checkbox for showing counter is properly set
6062
var showCounter = tb.shouldShowCounter();
6163
var counterItem = document.getElementById('https-everywhere-counter-item');
6264
counterItem.setAttribute('checked', showCounter ? 'true' : 'false');
6365

66+
// make sure UI for HTTP Nowhere mode is properly set
67+
var httpNowhereItem = document.getElementById('http-nowhere-item');
68+
var showHttpNowhere = tb.shouldShowHttpNowhere();
69+
var toolbarbutton = document.getElementById('https-everywhere-button');
70+
httpNowhereItem.setAttribute('checked', showHttpNowhere ? 'true' : 'false');
71+
toolbarbutton.setAttribute('http_nowhere',
72+
showHttpNowhere ? 'true' : 'false');
73+
74+
// make sure UI is set depending on whether HTTPS-E is enabled
75+
toggleEnabledUI();
76+
6477
// show ruleset counter when a tab is changed
6578
tb.updateRulesetsApplied();
6679
gBrowser.tabContainer.addEventListener(
@@ -119,20 +132,6 @@ httpsEverywhere.toolbarButton = {
119132
gBrowser.removeEventListener("DOMContentLoaded", tb.handleShowHint, true);
120133
},
121134

122-
/**
123-
* Changes HTTPS Everywhere toolbar icon based on whether HTTPS Everywhere
124-
* is enabled or disabled.
125-
*/
126-
changeIcon: function() {
127-
var enabled = HTTPSEverywhere.prefs.getBoolPref("globalEnabled");
128-
129-
var toolbarbutton = document.getElementById('https-everywhere-button');
130-
if (enabled) {
131-
toolbarbutton.setAttribute('status', 'enabled');
132-
} else {
133-
toolbarbutton.setAttribute('status', 'disabled');
134-
}
135-
},
136135

137136
/**
138137
* Update the rulesets applied counter for the current tab.
@@ -186,6 +185,17 @@ httpsEverywhere.toolbarButton = {
186185
return !prefExists || sp.getBoolPref(tb.COUNTER_PREF);
187186
},
188187

188+
/**
189+
* Gets whether to show HTTP Nowhere UI.
190+
*
191+
* @return {boolean}
192+
*/
193+
shouldShowHttpNowhere: function() {
194+
var tb = httpsEverywhere.toolbarButton;
195+
var sp = Services.prefs;
196+
return sp.getBoolPref(tb.HTTP_NOWHERE_PREF);
197+
},
198+
189199
/**
190200
* Toggles the user's preference for displaying the rulesets applied counter
191201
* and updates the UI.
@@ -198,8 +208,22 @@ httpsEverywhere.toolbarButton = {
198208
sp.setBoolPref(tb.COUNTER_PREF, !showCounter);
199209

200210
tb.updateRulesetsApplied();
201-
}
211+
},
212+
213+
/**
214+
* Toggles whether HTTP Nowhere mode is active, updates the toolbar icon.
215+
*/
216+
toggleHttpNowhere: function() {
217+
HTTPSEverywhere.toggleHttpNowhere();
218+
var tb = httpsEverywhere.toolbarButton;
219+
var showHttpNowhere = tb.shouldShowHttpNowhere();
202220

221+
// Change icon color to red if HTTP nowhere is enabled
222+
var toolbarbutton = document.getElementById('https-everywhere-button');
223+
toolbarbutton.setAttribute('http_nowhere',
224+
showHttpNowhere ? 'true' : 'false');
225+
reload_window();
226+
}
203227
};
204228

205229
function https_everywhere_load() {
@@ -307,17 +331,29 @@ function reload_window() {
307331
HTTPSEverywhere.log(WARN,"failed to get webNav");
308332
return null;
309333
}
310-
// This choice of flags comes from NoScript's quickReload function; not sure
311-
// if it's optimal
312-
webNav.reload(webNav.LOAD_FLAGS_CHARSET_CHANGE);
334+
// The choice of LOAD_FLAGS_CHARSET_CHANGE comes from NoScript's quickReload
335+
// function; not sure if it's optimal
336+
let flags = webNav.LOAD_FLAGS_BYPASS_CACHE & webNav.LOAD_FLAGS_CHARSET_CHANGE;
337+
webNav.reload(flags);
313338
}
314339

315340
function toggleEnabledState(){
316341
HTTPSEverywhere.toggleEnabledState();
317-
reload_window();
342+
reload_window();
343+
toggleEnabledUI();
344+
}
345+
346+
function toggleEnabledUI() {
347+
// Add/remove menu items depending on whether HTTPS-E is enabled
348+
var items = document.querySelectorAll(".hide-on-disable");
349+
var enabled = HTTPSEverywhere.prefs.getBoolPref("globalEnabled");
350+
for (let i = 0; i < items.length; i++) {
351+
items[i].hidden = !enabled;
352+
}
318353

319354
// Change icon depending on enabled state
320-
httpsEverywhere.toolbarButton.changeIcon();
355+
var toolbarbutton = document.getElementById('https-everywhere-button');
356+
toolbarbutton.setAttribute('status', enabled ? 'enabled' : 'disabled');
321357
}
322358

323359
function open_in_tab(url) {

src/chrome/content/toolbar_button.xul

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@
4242

4343
<menupopup id="https-everywhere-context" onpopupshowing="show_applicable_list(this)">
4444
<!-- entries will be written here by ApplicableList.populate_menu() -->
45-
<menuseparator />
45+
<menuseparator class="hide-on-disable"/>
46+
<menuitem type="checkbox" id="http-nowhere-item" label="Block all HTTP requests"
47+
oncommand="httpsEverywhere.toolbarButton.toggleHttpNowhere()" class="hide-on-disable"/>
48+
<menuseparator class="hide-on-disable"/>
4649
<menuitem type="checkbox" id="https-everywhere-counter-item" label="&https-everywhere.menu.showCounter;"
47-
oncommand="httpsEverywhere.toolbarButton.toggleShowCounter()" />
50+
oncommand="httpsEverywhere.toolbarButton.toggleShowCounter()" class="hide-on-disable"/>
4851
<menuseparator />
4952
<menuitem label="&https-everywhere.menu.observatory;" command="https-everywhere-menuitem-observatory" />
5053
<menuitem label="&https-everywhere.menu.about;" command="https-everywhere-menuitem-about" />
724 Bytes
Loading
1.21 KB
Loading

src/chrome/skin/https-everywhere.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ toolbar #https-everywhere-button > .https-everywhere-button {
1616
}
1717

1818
/* Use CSS attribute selector for changing icon */
19+
#https-everywhere-button[http_nowhere="true"] > .https-everywhere-button {
20+
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-24-red.png");
21+
}
1922
#https-everywhere-button[status="disabled"] > .https-everywhere-button {
2023
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-24-gray.png");
2124
}
22-
25+
toolbar[iconsize="small"] #https-everywhere-button[http_nowhere="true"] > .https-everywhere-button {
26+
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-16-red.png");
27+
}
2328
toolbar[iconsize="small"] #https-everywhere-button[status="disabled"] > .https-everywhere-button {
2429
list-style-image: url("chrome://https-everywhere/skin/https-everywhere-16-gray.png");
2530
}

0 commit comments

Comments
 (0)