@@ -324,7 +324,7 @@ const RuleWriter = {
324324 // Add this ruleset id into HTTPSRules.targets if it's not already there.
325325 // This should only happen for custom user rules. Built-in rules get
326326 // their ids preloaded into the targets map, and have their <target>
327- // tags stripped when the sqlite database is built.
327+ // tags stripped when the JSON database is built.
328328 var targets = xmlruleset . getElementsByTagName ( "target" ) ;
329329 for ( var i = 0 ; i < targets . length ; i ++ ) {
330330 var host = targets [ i ] . getAttribute ( "host" ) ;
@@ -392,29 +392,7 @@ const HTTPSRules = {
392392 var rulefiles = RuleWriter . enumerate ( RuleWriter . getCustomRuleDir ( ) ) ;
393393 this . scanRulefiles ( rulefiles ) ;
394394
395- // Initialize database connection.
396- var dbFile = new FileUtils . File ( RuleWriter . chromeToPath ( "chrome://https-everywhere/content/rulesets.sqlite" ) ) ;
397- var rulesetDBConn = Services . storage . openDatabase ( dbFile ) ;
398- this . queryForRuleset = rulesetDBConn . createStatement (
399- "select contents from rulesets where id = :id" ) ;
400-
401- // Preload the mapping of hostname target -> ruleset ID from DB.
402- // This is a little slow (287 ms on a Core2 Duo @ 2.2GHz with SSD),
403- // but is faster than loading all of the rulesets. If this becomes a
404- // bottleneck, change it to load in a background webworker, or load
405- // a smaller bloom filter instead.
406- var targetsQuery = rulesetDBConn . createStatement ( "select host, ruleset_id from targets" ) ;
407- this . log ( DBUG , "Loading targets..." ) ;
408- while ( targetsQuery . executeStep ( ) ) {
409- var host = targetsQuery . row . host ;
410- var id = targetsQuery . row . ruleset_id ;
411- if ( ! this . targets [ host ] ) {
412- this . targets [ host ] = [ id ] ;
413- } else {
414- this . targets [ host ] . push ( id ) ;
415- }
416- }
417- this . log ( DBUG , "Loading adding targets." ) ;
395+ this . loadTargets ( ) ;
418396 } catch ( e ) {
419397 this . log ( DBUG , "Rules Failed: " + e ) ;
420398 }
@@ -424,6 +402,13 @@ const HTTPSRules = {
424402 return ;
425403 } ,
426404
405+ loadTargets : function ( ) {
406+ var file = new FileUtils . File ( RuleWriter . chromeToPath ( "chrome://https-everywhere/content/rulesets.json" ) ) ;
407+ var rules = JSON . parse ( RuleWriter . read ( file ) ) ;
408+ this . targets = rules . targets ;
409+ this . rules_list = rules . rules_list ;
410+ } ,
411+
427412 checkMixedContentHandling : function ( ) {
428413 // Firefox 23+ blocks mixed content by default, so rulesets that create
429414 // mixed content situations should be disabled there
@@ -576,22 +561,8 @@ const HTTPSRules = {
576561 } ,
577562
578563 // Load a ruleset by numeric id, e.g. 234
579- // NOTE: This call runs synchronously, which can lock up the browser UI. Is
580- // there any way to fix that, given that we need to run blocking in the request
581- // flow? Perhaps we can preload all targets from the DB into memory at startup
582- // so we only hit the DB when we know there is something to be had.
583564 loadRulesetById : function ( ruleset_id ) {
584- this . queryForRuleset . params . id = ruleset_id ;
585-
586- try {
587- if ( this . queryForRuleset . executeStep ( ) ) {
588- RuleWriter . readFromString ( this . queryForRuleset . row . contents , this , ruleset_id ) ;
589- } else {
590- this . log ( WARN , "Couldn't find ruleset for id " + ruleset_id ) ;
591- }
592- } finally {
593- this . queryForRuleset . reset ( ) ;
594- }
565+ RuleWriter . readFromString ( this . rules_list [ ruleset_id ] , this , ruleset_id ) ;
595566 } ,
596567
597568 // Get all rulesets matching a given target, lazy-loading from DB as necessary.
0 commit comments