@@ -7,8 +7,10 @@ var HTTPSEverywhere = CC["@eff.org/https-everywhere;1"]
77
88CU . import ( "resource://gre/modules/Prompt.jsm" ) ;
99
10- var menuId ;
11- var urlbarId ;
10+ var menuToggleId ;
11+ var menuParentId ;
12+ var menuRulesId ;
13+ var menuDefaultsId ;
1214var aWindow = getWindow ( ) ;
1315
1416
@@ -21,12 +23,7 @@ function loadIntoWindow() {
2123 return ;
2224 }
2325 var enabled = HTTPSEverywhere . prefs . getBoolPref ( "globalEnabled" ) ;
24- addToggleItemToMenu ( enabled ) ;
25- if ( enabled ) {
26- urlbarId = aWindow . NativeWindow . pageactions . add ( urlbarOptions ) ;
27- } else if ( urlbarId ) {
28- aWindow . NativeWindow . pageactions . remove ( urlbarId ) ;
29- }
26+ addMenuItems ( enabled ) ;
3027
3128 // When navigating away from a page, we want to clear the applicable list for
3229 // that page. There are a few different APIs to do this, but this is the one
@@ -43,8 +40,7 @@ function unloadFromWindow() {
4340 if ( ! aWindow ) {
4441 return ;
4542 }
46- aWindow . NativeWindow . menu . remove ( menuId ) ;
47- aWindow . NativeWindow . pageactions . remove ( urlbarId ) ;
43+ aWindow . NativeWindow . menu . remove ( menuParentId ) ;
4844}
4945
5046
@@ -53,13 +49,72 @@ function unloadFromWindow() {
5349 */
5450
5551function addToggleItemToMenu ( enabled ) {
56- if ( menuId ) { aWindow . NativeWindow . menu . remove ( menuId ) ; }
57- var menuLabel = enabled ? "HTTPS Everywhere (on)" : "HTTPS Everywhere (off)" ;
58- menuId = aWindow . NativeWindow . menu . add ( menuLabel , null , function ( ) {
59- popupToggleMenu ( aWindow , enabled ) ;
52+ if ( menuToggleId ) { aWindow . NativeWindow . menu . remove ( menuToggleId ) ; }
53+ var menuLabel = enabled ? "Disable" : "Enable" ;
54+ menuToggleId = aWindow . NativeWindow . menu . add ( {
55+ name : menuLabel ,
56+ callback : function ( ) {
57+ popupToggleMenu ( aWindow , enabled ) ;
58+ } ,
59+ parent : menuParentId
6060 } ) ;
6161}
6262
63+ function addRulesItemToMenu ( enabled ) {
64+ if ( menuRulesId ) { aWindow . NativeWindow . menu . remove ( menuRulesId ) ; }
65+
66+ if ( enabled ) {
67+ menuRulesId = aWindow . NativeWindow . menu . add ( {
68+ name : "Enable/disable rules" ,
69+ callback : function ( ) {
70+ popupInfo . fill ( ) ;
71+ rulesPrompt . setMultiChoiceItems ( popupInfo . ruleItems ) ;
72+ rulesPrompt . show ( function ( data ) {
73+ var db = data . button ;
74+ if ( db === - 1 ) { return null ; } // user didn't click the accept button
75+
76+ for ( var i = 0 ; i < popupInfo . rules . length ; i ++ ) {
77+ var ruleOn = popupInfo . ruleStatus [ i ] ;
78+ var ruleChecked = ( data . list . indexOf ( i ) == - 1 ? false : true ) ;
79+ if ( ruleOn !== ruleChecked ) {
80+ HTTPSEverywhere . log ( 4 , "toggling: " + JSON . stringify ( popupInfo . rules [ i ] ) ) ;
81+ popupInfo . rules [ i ] . toggle ( ) ;
82+ }
83+ }
84+ reloadTab ( ) ;
85+ return null ;
86+ } ) ;
87+ } ,
88+ parent : menuParentId
89+ } ) ;
90+ }
91+ }
92+
93+ function addDefaultsItemToMenu ( enabled ) {
94+ if ( menuDefaultsId ) { aWindow . NativeWindow . menu . remove ( menuDefaultsId ) ; }
95+
96+ if ( enabled ) {
97+ menuDefaultsId = aWindow . NativeWindow . menu . add ( {
98+ name : "Reset to Defaults" ,
99+ callback : function ( ) {
100+ popupResetDefaultsMenu ( aWindow ) ;
101+ } ,
102+ parent : menuParentId
103+ } ) ;
104+ }
105+ }
106+
107+ function addMenuItems ( enabled ) {
108+ if ( ! menuParentId ) {
109+ menuParentId = aWindow . NativeWindow . menu . add ( {
110+ name : "HTTPS Everywhere" ,
111+ } ) ;
112+ }
113+ addToggleItemToMenu ( enabled ) ;
114+ addRulesItemToMenu ( enabled ) ;
115+ addDefaultsItemToMenu ( enabled ) ;
116+ }
117+
63118function popupToggleMenu ( aWindow , enabled ) {
64119 var buttons = [
65120 {
@@ -69,7 +124,8 @@ function popupToggleMenu(aWindow, enabled) {
69124 var msg = enabled ? "HTTPS Everywhere disabled!" : "HTTPS Everywhere enabled!" ;
70125 aWindow . NativeWindow . toast . show ( msg , "short" ) ;
71126 return true ;
72- }
127+ } ,
128+ positive : true
73129 } , {
74130 label : "No" ,
75131 callback : function ( ) { return false ; }
@@ -134,39 +190,6 @@ var popupInfo = {
134190 }
135191} ;
136192
137- var urlbarOptions = {
138-
139- title : "HTTPS Everywhere" ,
140-
141- icon : "chrome://https-everywhere/skin/icon-active-128.png" ,
142-
143- clickCallback : function ( ) {
144- popupInfo . fill ( ) ;
145- rulesPrompt . setMultiChoiceItems ( popupInfo . ruleItems ) ;
146- rulesPrompt . show ( function ( data ) {
147- var db = data . button ;
148- if ( db === - 1 ) { return null ; } // user didn't click the accept button
149- if ( popupInfo . rules . length !== db . length ) {
150- // Why does db sometimes have an extra entry that doesn't correspond
151- // to any of the ruleItems? No idea, but let's log it.
152- HTTPSEverywhere . log ( 5 , "Got length mismatch between popupInfo.ruleItems and data.button" ) ;
153- HTTPSEverywhere . log ( 4 , "Applicable rules: " + JSON . stringify ( popupInfo . rules ) ) ;
154- HTTPSEverywhere . log ( 4 , "data.button: " + JSON . stringify ( db ) ) ;
155- }
156- for ( var i = 0 ; i < popupInfo . rules . length ; i ++ ) {
157- if ( popupInfo . ruleStatus [ i ] !== db [ i ] ) {
158- HTTPSEverywhere . log ( 4 , "toggling: " + JSON . stringify ( popupInfo . rules [ i ] ) ) ;
159- popupInfo . rules [ i ] . toggle ( ) ;
160- }
161- }
162- reloadTab ( ) ;
163- return null ;
164- } ) ;
165- } ,
166-
167- longClickCallback : function ( ) { popupResetDefaultsMenu ( aWindow ) ; }
168- } ;
169-
170193var rulesPrompt = new Prompt ( {
171194 window : aWindow ,
172195 title : "Enable/disable rules" ,
@@ -182,7 +205,8 @@ function popupResetDefaultsMenu(aWindow) {
182205 var msg = "Default rules reset." ;
183206 aWindow . NativeWindow . toast . show ( msg , "short" ) ;
184207 return true ;
185- }
208+ } ,
209+ positive : true
186210 } , {
187211 label : "No" ,
188212 callback : function ( ) { return false ; }
0 commit comments