@@ -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
205229function 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
315340function 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
323359function open_in_tab ( url ) {
0 commit comments