@@ -59,6 +59,46 @@ function popupToggleMenu(aWindow) {
5959 * rule list dynamically.
6060 */
6161
62+ var popupInfo = {
63+ rules : [ ] ,
64+ ruleItems : [ ] ,
65+ ruleStatus : [ ] ,
66+ alist : null ,
67+ getApplicableList : function ( ) {
68+ var domWin = aWindow . BrowserApp . selectedTab . window ;
69+ if ( ! ( domWin instanceof CI . nsIDOMWindow ) ) {
70+ aWindow . console . log ( 'something went wrong getting top window' ) ;
71+ return null ;
72+ }
73+ return HTTPSEverywhere . getExpando ( domWin , "applicable_rules" , null ) ;
74+ } ,
75+ fill : function ( ) {
76+ this . clear ( ) ;
77+ this . alist = this . getApplicableList ( ) ;
78+ //aWindow.console.log("applicable list: "+JSON.stringify(this.alist));
79+ for ( var activeRule in this . alist . active ) {
80+ if ( this . alist . active . hasOwnProperty ( activeRule ) ) {
81+ this . ruleItems . push ( { label : activeRule , selected : true } ) ;
82+ this . ruleStatus . push ( true ) ;
83+ this . rules . push ( this . alist . active [ activeRule ] ) ;
84+ }
85+ }
86+ for ( var inactiveRule in this . alist . inactive ) {
87+ if ( this . alist . inactive . hasOwnProperty ( inactiveRule ) ) {
88+ this . ruleItems . push ( { label : inactiveRule } ) ;
89+ this . ruleStatus . push ( false ) ;
90+ this . rules . push ( this . alist . inactive [ inactiveRule ] ) ;
91+ }
92+ }
93+ } ,
94+ clear : function ( ) {
95+ this . rules = [ ] ;
96+ this . ruleItems = [ ] ;
97+ this . ruleStatus = [ ] ;
98+ this . alist = { } ;
99+ }
100+ } ;
101+
62102var urlbarOptions = {
63103
64104 title : "HTTPS Everywhere" ,
@@ -67,21 +107,28 @@ var urlbarOptions = {
67107
68108 clickCallback : function ( ) {
69109
70- var popupInfo = getPopupInfo ( ) ;
110+ popupInfo . fill ( ) ;
71111
72112 rulesPrompt . setMultiChoiceItems ( popupInfo . ruleItems ) ;
73113
74114 rulesPrompt . show ( function ( data ) {
75- if ( data . button === - 1 ) { return null ; }
76- for ( var i = 0 ; i < data . button . length ; i ++ ) {
77- if ( popupInfo . ruleStatus [ i ] !== data . button [ i ] ) {
115+ var db = data . button ;
116+ if ( db === - 1 ) { return null ; } // user didn't click the accept button
117+ if ( popupInfo . rules . length !== db . length ) {
118+ // Why does db sometimes have an extra entry that doesn't correspond
119+ // to any of the ruleItems? No idea, but let's log it.
120+ aWindow . console . log ( "popupInfo length not same as button response" ) ;
121+ aWindow . console . log ( JSON . stringify ( popupInfo . rules ) ) ;
122+ aWindow . console . log ( JSON . stringify ( db ) ) ;
123+ }
124+ for ( var i = 0 ; i < popupInfo . rules . length ; i ++ ) {
125+ if ( popupInfo . ruleStatus [ i ] !== db [ i ] ) {
78126 aWindow . console . log ( "toggling: " + JSON . stringify ( popupInfo . rules [ i ] ) ) ;
79127 popupInfo . rules [ i ] . toggle ( ) ;
80- } else {
81- aWindow . console . log ( "skipping: " + JSON . stringify ( popupInfo . rules [ i ] ) ) ;
82128 }
83129 }
84130 reloadTab ( ) ;
131+ return null ;
85132 } ) ;
86133 }
87134} ;
@@ -93,38 +140,6 @@ var rulesPrompt = new Prompt({
93140 buttons : [ "Apply changes" ]
94141} ) ;
95142
96- function getApplicableList ( ) {
97- var domWin = aWindow . content . document . defaultView . top ;
98- if ( ! ( domWin instanceof CI . nsIDOMWindow ) ) {
99- aWindow . console . log ( 'something went wrong getting top window' ) ;
100- return null ;
101- }
102- return HTTPSEverywhere . getExpando ( domWin , "applicable_rules" , null ) ;
103- }
104-
105- // Show active/inactive rules in the popup
106- function getPopupInfo ( ) {
107- var ruleItems = [ ] ;
108- var rules = [ ] ;
109- var ruleStatus = [ ] ;
110- var alist = getApplicableList ( ) ;
111- for ( var activeRule in alist . active ) {
112- if ( alist . active . hasOwnProperty ( activeRule ) ) {
113- ruleItems . push ( { label : activeRule , selected : true } ) ;
114- ruleStatus . push ( true ) ;
115- rules . push ( alist . active [ activeRule ] ) ;
116- }
117- }
118- for ( var inactiveRule in alist . inactive ) {
119- if ( alist . inactive . hasOwnProperty ( inactiveRule ) ) {
120- ruleItems . push ( { label : inactiveRule } ) ;
121- ruleStatus . push ( false ) ;
122- rules . push ( alist . inactive [ inactiveRule ] ) ;
123- }
124- }
125- return { ruleItems : ruleItems , rules : rules , ruleStatus : ruleStatus } ;
126- }
127-
128143function reloadTab ( ) {
129144 // There seems to be no API to do this directly?
130145 aWindow . BrowserApp . selectedTab . window . location . reload ( ) ;
@@ -139,5 +154,8 @@ function toggleEnabledState(){
139154var FennecUI = {
140155 init : function ( ) {
141156 loadIntoWindow ( ) ;
157+ } ,
158+ shutdown : function ( ) {
159+ unloadFromWindow ( ) ;
142160 }
143161} ;
0 commit comments