Skip to content

Commit fc51f3f

Browse files
committed
Add toolbar button for HTTP Nowhere
1 parent 07cdc46 commit fc51f3f

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

src/chrome/content/toolbar_button.js

Lines changed: 37 additions & 1 deletion
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
@@ -61,6 +66,14 @@ httpsEverywhere.toolbarButton = {
6166
var counterItem = document.getElementById('https-everywhere-counter-item');
6267
counterItem.setAttribute('checked', showCounter ? 'true' : 'false');
6368

69+
// make sure UI for HTTP Nowhere mode is properly set
70+
var httpNowhereItem = document.getElementById('http-nowhere-item');
71+
var showHttpNowhere = tb.shouldShowHttpNowhere();
72+
var toolbarbutton = document.getElementById('https-everywhere-button');
73+
httpNowhereItem.setAttribute('checked', showHttpNowhere ? 'true' : 'false');
74+
toolbarbutton.setAttribute('http_nowhere',
75+
showHttpNowhere ? 'true' : 'false');
76+
6477
// show ruleset counter when a tab is changed
6578
tb.updateRulesetsApplied();
6679
gBrowser.tabContainer.addEventListener(
@@ -186,6 +199,17 @@ httpsEverywhere.toolbarButton = {
186199
return !prefExists || sp.getBoolPref(tb.COUNTER_PREF);
187200
},
188201

202+
/**
203+
* Gets whether to show HTTP Nowhere UI.
204+
*
205+
* @return {boolean}
206+
*/
207+
shouldShowHttpNowhere: function() {
208+
var tb = httpsEverywhere.toolbarButton;
209+
var sp = Services.prefs;
210+
return sp.getBoolPref(tb.HTTP_NOWHERE_PREF);
211+
},
212+
189213
/**
190214
* Toggles the user's preference for displaying the rulesets applied counter
191215
* and updates the UI.
@@ -198,8 +222,20 @@ httpsEverywhere.toolbarButton = {
198222
sp.setBoolPref(tb.COUNTER_PREF, !showCounter);
199223

200224
tb.updateRulesetsApplied();
201-
}
225+
},
202226

227+
/**
228+
* Toggles whether HTTP Nowhere mode is active, updates the toolbar icon.
229+
*/
230+
toggleHttpNowhere: function() {
231+
var tb = httpsEverywhere.toolbarButton;
232+
HTTPSEverywhere.toggleHttpNowhere();
233+
var showHttpNowhere = tb.shouldShowHttpNowhere();
234+
var toolbarbutton = document.getElementById('https-everywhere-button');
235+
toolbarbutton.setAttribute('http_nowhere',
236+
showHttpNowhere ? 'true' : 'false');
237+
reload_window();
238+
}
203239
};
204240

205241
function https_everywhere_load() {

src/chrome/content/toolbar_button.xul

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<menupopup id="https-everywhere-context" onpopupshowing="show_applicable_list(this)">
4444
<!-- entries will be written here by ApplicableList.populate_menu() -->
4545
<menuseparator />
46+
<menuitem type="checkbox" id="http-nowhere-item" label="Turn on HTTP Nowhere"
47+
oncommand="httpsEverywhere.toolbarButton.toggleHttpNowhere()" />
48+
<menuseparator />
4649
<menuitem type="checkbox" id="https-everywhere-counter-item" label="&https-everywhere.menu.showCounter;"
4750
oncommand="httpsEverywhere.toolbarButton.toggleShowCounter()" />
4851
<menuseparator />

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
}

src/components/https-everywhere.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -804,17 +804,19 @@ HTTPSEverywhere.prototype = {
804804
let prefService = Services.prefs;
805805
let thisBranch =
806806
prefService.getBranch("extensions.https_everywhere.http_nowhere.");
807+
let networkBranch = prefService.getBranch("network.");
808+
let securityBranch = prefService.getBranch("security.");
807809

808810
// Proxy type. 0: none, 1: manual, 2: autoconfig by URL, 3: same as 0,
809811
// 4: autodetect proxy settings, 5: use system proxy settings (default)
810-
let PROXY_TYPE = "network.proxy.type";
812+
let PROXY_TYPE = "proxy.type";
811813
// HTTP proxy host
812-
let PROXY_HTTP = "network.proxy.http";
814+
let PROXY_HTTP = "proxy.http";
813815
// HTTP proxy port
814-
let PROXY_PORT = "network.proxy.http_port";
816+
let PROXY_PORT = "proxy.http_port";
815817

816818
// Whether cert is treated as invalid when OCSP connection fails
817-
let OCSP_REQUIRED = "security.ocsp.require";
819+
let OCSP_REQUIRED = "OCSP.require";
818820

819821
// Original settings
820822
let ORIG_PROXY_TYPE = "orig.proxy.type";
@@ -827,39 +829,39 @@ HTTPSEverywhere.prototype = {
827829
// Restore original proxy/OCSP settings. TODO: What if user manually edits
828830
// these while HTTP Nowhere is enabled?
829831
let origProxyType = thisBranch.getIntPref(ORIG_PROXY_TYPE);
830-
prefService.setIntPref(PROXY_TYPE, origProxyType);
832+
networkBranch.setIntPref(PROXY_TYPE, origProxyType);
831833

832834
let origProxyHttp = thisBranch.getCharPref(ORIG_PROXY_HTTP);
833-
prefService.setCharPref(PROXY_HTTP, origProxyHttp);
835+
networkBranch.setCharPref(PROXY_HTTP, origProxyHttp);
834836

835837
let origProxyPort = thisBranch.getIntPref(ORIG_PROXY_PORT);
836-
prefService.setIntPref(PROXY_PORT, origProxyPort);
838+
networkBranch.setIntPref(PROXY_PORT, origProxyPort);
837839

838840
let origOcspRequired = thisBranch.getBoolPref(ORIG_OCSP_REQUIRED);
839-
prefService.setBoolPref(OCSP_REQUIRED, origOcspRequired);
841+
securityBranch.setBoolPref(OCSP_REQUIRED, origOcspRequired);
840842

841843
thisBranch.setBoolPref("enabled", false);
842844
} else {
843845
// Save original proxy settings in HTTP Nowhere preferences branch.
844-
let origProxyType = prefService.getIntPref(PROXY_TYPE);
846+
let origProxyType = networkBranch.getIntPref(PROXY_TYPE);
845847
thisBranch.setIntPref(ORIG_PROXY_TYPE, origProxyType);
846848

847-
let origProxyHttp = prefService.getCharPref(PROXY_HTTP);
849+
let origProxyHttp = networkBranch.getCharPref(PROXY_HTTP);
848850
thisBranch.setCharPref(ORIG_PROXY_HTTP, origProxyHttp);
849851

850-
let origProxyPort = prefService.getIntPref(PROXY_PORT);
852+
let origProxyPort = networkBranch.getIntPref(PROXY_PORT);
851853
thisBranch.setIntPref(ORIG_PROXY_PORT, origProxyPort);
852854

853-
let origOcspRequired = prefService.getBoolPref(OCSP_REQUIRED);
855+
let origOcspRequired = securityBranch.getBoolPref(OCSP_REQUIRED);
854856
thisBranch.setBoolPref(ORIG_OCSP_REQUIRED, origOcspRequired);
855857

856858
// Set a null proxy for HTTP requests
857-
prefService.setIntPref(PROXY_TYPE, 1); // manual
858-
prefService.setCharPref(PROXY_HTTP, "localhost");
859-
prefService.setIntPref(PROXY_PORT, 4); // any arbitrary unused port
859+
networkBranch.setIntPref(PROXY_TYPE, 1); // manual
860+
networkBranch.setCharPref(PROXY_HTTP, "localhost");
861+
networkBranch.setIntPref(PROXY_PORT, 4); // any arbitrary unused port
860862

861863
// Disable OCSP enforcement
862-
thisBranch.setBoolPref(OCSP_REQUIRED, false);
864+
securityBranch.setBoolPref(OCSP_REQUIRED, false);
863865

864866
thisBranch.setBoolPref("enabled", true);
865867
}

src/defaults/preferences/preferences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pref("extensions.https_everywhere.enable_mixed_rulesets", false);
1818
// HTTP Nowhere preferences
1919
pref("extensions.https_everywhere.http_nowhere.enabled", false);
2020
pref("extensions.https_everywhere.http_nowhere.orig.proxy.type", 0);
21-
pref("extensions.https_everywhere.http_nowhere.orig.proxy.http", "");
21+
pref("extensions.https_everywhere.http_nowhere.orig.proxy.http", "none");
2222
pref("extensions.https_everywhere.http_nowhere.orig.proxy.http_port", 0);
2323
pref("extensions.https_everywhere.http_nowhere.orig.ocsp.required", false);
2424

0 commit comments

Comments
 (0)