@@ -31,14 +31,18 @@ if(versionChecker.compare(appInfo.version, "23.0a1") >= 0) {
3131
3232ruleset_counter = 0 ;
3333function RuleSet ( name , xmlName , match_rule , default_off , platform ) {
34+ if ( xmlName == "WordPress.xml" || xmlName == "Github.xml" ) {
35+ this . log ( NOTE , "RuleSet( name=" + name + ", xmlName=" + xmlName + ", match_rule=" + match_rule + ", default_off=" + default_off + ", platform=" + platform + " )" ) ;
36+ }
37+
3438 this . id = "httpseR" + ruleset_counter ;
3539 ruleset_counter += 1 ;
3640 this . on_by_default = true ;
3741 this . name = name ;
3842 this . xmlName = xmlName ;
3943 //this.ruleset_match = match_rule;
4044 this . notes = "" ;
41- if ( match_rule ) this . ruleset_match_c = new RegExp ( match_rule )
45+ if ( match_rule ) this . ruleset_match_c = new RegExp ( match_rule ) ;
4246 else this . ruleset_match_c = null ;
4347 if ( default_off ) {
4448 // Perhaps problematically, this currently ignores the actual content of
@@ -56,15 +60,15 @@ function RuleSet(name, xmlName, match_rule, default_off, platform) {
5660 this . rules = [ ] ;
5761 this . exclusions = [ ] ;
5862 this . cookierules = [ ] ;
59- this . prefs = HTTPSEverywhere . instance . prefs ;
63+
64+ this . rule_toggle_prefs = HTTPSEverywhere . instance . rule_toggle_prefs ;
65+
6066 try {
6167 // if this pref exists, use it
62- this . active = this . prefs . getBoolPref ( name ) ;
63- } catch ( e ) {
64- // if not, create it
65- this . log ( DBUG , "Creating new pref " + name ) ;
68+ this . active = this . rule_toggle_prefs . getBoolPref ( name ) ;
69+ } catch ( e ) {
70+ // if not, use the default
6671 this . active = this . on_by_default ;
67- this . prefs . setBoolPref ( name , this . on_by_default ) ;
6872 }
6973}
7074
@@ -101,34 +105,34 @@ RuleSet.prototype = {
101105 https_everywhereLog ( level , msg ) ;
102106 } ,
103107
104- wouldMatch : function ( hypothetical_uri , alist ) {
105- // return true if this ruleset would match the uri, assuming it were http
106- // used for judging moot / inactive rulesets
107- // alist is optional
108-
109- // if the ruleset is already somewhere in this applicable list, we don't
110- // care about hypothetical wouldMatch questions
111- if ( alist && ( this . name in alist . all ) ) return false ;
112-
113- this . log ( DBUG , "Would " + this . name + " match " + hypothetical_uri . spec +
114- "? serial " + ( alist && alist . serial ) ) ;
115-
116- var uri = hypothetical_uri . clone ( ) ;
117- if ( uri . scheme == "https" ) uri . scheme = "http" ;
118- var urispec = uri . spec ;
119-
120- if ( this . ruleset_match_c && ! this . ruleset_match_c . test ( urispec ) )
121- return false ;
122-
123- for ( i = 0 ; i < this . exclusions . length ; ++ i )
124- if ( this . exclusions [ i ] . pattern_c . test ( urispec ) ) return false ;
125-
126- for ( i = 0 ; i < this . rules . length ; ++ i )
127- if ( this . rules [ i ] . from_c . test ( urispec ) ) return true ;
128- return false ;
129- } ,
130-
131- transformURI : function ( uri ) {
108+ wouldMatch : function ( hypothetical_uri , alist ) {
109+ // return true if this ruleset would match the uri, assuming it were http
110+ // used for judging moot / inactive rulesets
111+ // alist is optional
112+
113+ // if the ruleset is already somewhere in this applicable list, we don't
114+ // care about hypothetical wouldMatch questions
115+ if ( alist && ( this . name in alist . all ) ) return false ;
116+
117+ this . log ( DBUG , "Would " + this . name + " match " + hypothetical_uri . spec +
118+ "? serial " + ( alist && alist . serial ) ) ;
119+
120+ var uri = hypothetical_uri . clone ( ) ;
121+ if ( uri . scheme == "https" ) uri . scheme = "http" ;
122+ var urispec = uri . spec ;
123+
124+ if ( this . ruleset_match_c && ! this . ruleset_match_c . test ( urispec ) )
125+ return false ;
126+
127+ for ( i = 0 ; i < this . exclusions . length ; ++ i )
128+ if ( this . exclusions [ i ] . pattern_c . test ( urispec ) ) return false ;
129+
130+ for ( i = 0 ; i < this . rules . length ; ++ i )
131+ if ( this . rules [ i ] . from_c . test ( urispec ) ) return true ;
132+ return false ;
133+ } ,
134+
135+ transformURI : function ( uri ) {
132136 // If no rule applies, return null; if a rule would have applied but was
133137 // inactive, return 0; otherwise, return a fresh uri instance
134138 // for the target
@@ -145,19 +149,28 @@ RuleSet.prototype = {
145149
146150 enable : function ( ) {
147151 // Enable us.
148- this . prefs . setBoolPref ( this . name , true ) ;
152+ this . rule_toggle_prefs . setBoolPref ( this . name , true ) ;
149153 this . active = true ;
150154 } ,
151155
152156 disable : function ( ) {
153157 // Disable us.
154- this . prefs . setBoolPref ( this . name , false ) ;
158+ this . rule_toggle_prefs . setBoolPref ( this . name , false ) ;
155159 this . active = false ;
156160 } ,
157161
158162 toggle : function ( ) {
159163 this . active = ! this . active ;
160- this . prefs . setBoolPref ( this . name , this . active ) ;
164+ this . rule_toggle_prefs . setBoolPref ( this . name , this . active ) ;
165+ } ,
166+
167+ clear : function ( ) {
168+ try {
169+ this . rule_toggle_prefs . clearUserPref ( this . name ) ;
170+ } catch ( e ) {
171+ // this ruleset has never been toggled
172+ }
173+ this . active = this . on_by_default ;
161174 }
162175} ;
163176
@@ -432,8 +445,7 @@ const HTTPSRules = {
432445 // Callable from within the prefs UI and also for cleaning up buggy
433446 // configurations...
434447 for ( var i in this . rulesets ) {
435- if ( this . rulesets [ i ] . on_by_default ) this . rulesets [ i ] . enable ( ) ;
436- else this . rulesets [ i ] . disable ( ) ;
448+ this . rulesets [ i ] . clear ( ) ;
437449 }
438450 } ,
439451
@@ -539,7 +551,7 @@ const HTTPSRules = {
539551 intoList . push ( fromList [ i ] ) ;
540552 } ,
541553
542- potentiallyApplicableRulesets : function ( host ) {
554+ potentiallyApplicableRulesets : function ( host ) {
543555 // Return a list of rulesets that declare targets matching this host
544556 var i , tmp , t ;
545557 var results = this . global_rulesets . slice ( 0 ) ; // copy global_rulesets
0 commit comments