@@ -19,14 +19,18 @@ function CookieRule(host, cookiename) {
1919localPlatformRegexp = new RegExp ( "(firefox|mixedcontent)" ) ;
2020ruleset_counter = 0 ;
2121function RuleSet ( name , xmlName , match_rule , default_off , platform ) {
22+ if ( xmlName == "WordPress.xml" || xmlName == "Github.xml" ) {
23+ this . log ( NOTE , "RuleSet( name=" + name + ", xmlName=" + xmlName + ", match_rule=" + match_rule + ", default_off=" + default_off + ", platform=" + platform + " )" ) ;
24+ }
25+
2226 this . id = "httpseR" + ruleset_counter ;
2327 ruleset_counter += 1 ;
2428 this . on_by_default = true ;
2529 this . name = name ;
2630 this . xmlName = xmlName ;
2731 //this.ruleset_match = match_rule;
2832 this . notes = "" ;
29- if ( match_rule ) this . ruleset_match_c = new RegExp ( match_rule )
33+ if ( match_rule ) this . ruleset_match_c = new RegExp ( match_rule ) ;
3034 else this . ruleset_match_c = null ;
3135 if ( default_off ) {
3236 // Perhaps problematically, this currently ignores the actual content of
@@ -44,15 +48,15 @@ function RuleSet(name, xmlName, match_rule, default_off, platform) {
4448 this . rules = [ ] ;
4549 this . exclusions = [ ] ;
4650 this . cookierules = [ ] ;
47- this . prefs = HTTPSEverywhere . instance . prefs ;
51+
52+ this . rule_toggle_prefs = HTTPSEverywhere . instance . rule_toggle_prefs ;
53+
4854 try {
4955 // if this pref exists, use it
50- this . active = this . prefs . getBoolPref ( name ) ;
51- } catch ( e ) {
52- // if not, create it
53- this . log ( DBUG , "Creating new pref " + name ) ;
56+ this . active = this . rule_toggle_prefs . getBoolPref ( name ) ;
57+ } catch ( e ) {
58+ // if not, use the default
5459 this . active = this . on_by_default ;
55- this . prefs . setBoolPref ( name , this . on_by_default ) ;
5660 }
5761}
5862
@@ -89,34 +93,34 @@ RuleSet.prototype = {
8993 https_everywhereLog ( level , msg ) ;
9094 } ,
9195
92- wouldMatch : function ( hypothetical_uri , alist ) {
93- // return true if this ruleset would match the uri, assuming it were http
94- // used for judging moot / inactive rulesets
95- // alist is optional
96-
97- // if the ruleset is already somewhere in this applicable list, we don't
98- // care about hypothetical wouldMatch questions
99- if ( alist && ( this . name in alist . all ) ) return false ;
100-
101- this . log ( DBUG , "Would " + this . name + " match " + hypothetical_uri . spec +
102- "? serial " + ( alist && alist . serial ) ) ;
103-
104- var uri = hypothetical_uri . clone ( ) ;
105- if ( uri . scheme == "https" ) uri . scheme = "http" ;
106- var urispec = uri . spec ;
107-
108- if ( this . ruleset_match_c && ! this . ruleset_match_c . test ( urispec ) )
109- return false ;
110-
111- for ( i = 0 ; i < this . exclusions . length ; ++ i )
112- if ( this . exclusions [ i ] . pattern_c . test ( urispec ) ) return false ;
113-
114- for ( i = 0 ; i < this . rules . length ; ++ i )
115- if ( this . rules [ i ] . from_c . test ( urispec ) ) return true ;
116- return false ;
117- } ,
118-
119- transformURI : function ( uri ) {
96+ wouldMatch : function ( hypothetical_uri , alist ) {
97+ // return true if this ruleset would match the uri, assuming it were http
98+ // used for judging moot / inactive rulesets
99+ // alist is optional
100+
101+ // if the ruleset is already somewhere in this applicable list, we don't
102+ // care about hypothetical wouldMatch questions
103+ if ( alist && ( this . name in alist . all ) ) return false ;
104+
105+ this . log ( DBUG , "Would " + this . name + " match " + hypothetical_uri . spec +
106+ "? serial " + ( alist && alist . serial ) ) ;
107+
108+ var uri = hypothetical_uri . clone ( ) ;
109+ if ( uri . scheme == "https" ) uri . scheme = "http" ;
110+ var urispec = uri . spec ;
111+
112+ if ( this . ruleset_match_c && ! this . ruleset_match_c . test ( urispec ) )
113+ return false ;
114+
115+ for ( i = 0 ; i < this . exclusions . length ; ++ i )
116+ if ( this . exclusions [ i ] . pattern_c . test ( urispec ) ) return false ;
117+
118+ for ( i = 0 ; i < this . rules . length ; ++ i )
119+ if ( this . rules [ i ] . from_c . test ( urispec ) ) return true ;
120+ return false ;
121+ } ,
122+
123+ transformURI : function ( uri ) {
120124 // If no rule applies, return null; if a rule would have applied but was
121125 // inactive, return 0; otherwise, return a fresh uri instance
122126 // for the target
@@ -135,19 +139,28 @@ RuleSet.prototype = {
135139
136140 enable : function ( ) {
137141 // Enable us.
138- this . prefs . setBoolPref ( this . name , true ) ;
142+ this . rule_toggle_prefs . setBoolPref ( this . name , true ) ;
139143 this . active = true ;
140144 } ,
141145
142146 disable : function ( ) {
143147 // Disable us.
144- this . prefs . setBoolPref ( this . name , false ) ;
148+ this . rule_toggle_prefs . setBoolPref ( this . name , false ) ;
145149 this . active = false ;
146150 } ,
147151
148152 toggle : function ( ) {
149153 this . active = ! this . active ;
150- this . prefs . setBoolPref ( this . name , this . active ) ;
154+ this . rule_toggle_prefs . setBoolPref ( this . name , this . active ) ;
155+ } ,
156+
157+ clear : function ( ) {
158+ try {
159+ this . rule_toggle_prefs . clearUserPref ( this . name ) ;
160+ } catch ( e ) {
161+ // this ruleset has never been toggled
162+ }
163+ this . active = this . on_by_default ;
151164 }
152165} ;
153166
@@ -464,8 +477,7 @@ const HTTPSRules = {
464477 // Callable from within the prefs UI and also for cleaning up buggy
465478 // configurations...
466479 for ( var i in this . rulesets ) {
467- if ( this . rulesets [ i ] . on_by_default ) this . rulesets [ i ] . enable ( ) ;
468- else this . rulesets [ i ] . disable ( ) ;
480+ this . rulesets [ i ] . clear ( ) ;
469481 }
470482 } ,
471483
@@ -563,7 +575,7 @@ const HTTPSRules = {
563575 } ,
564576
565577
566- potentiallyApplicableRulesets : function ( host ) {
578+ potentiallyApplicableRulesets : function ( host ) {
567579 // Return a list of rulesets that declare targets matching this host
568580 var i , tmp , t ;
569581 var results = this . global_rulesets ;
0 commit comments