@@ -228,21 +228,6 @@ HTTPSB.loadUbiquitousBlacklists = function() {
228228 var blacklistLoadCount ;
229229 var obsoleteBlacklists = [ ] ;
230230
231- var onMessageHandler = function ( details ) {
232- if ( ! details || ! details . what ) {
233- return ;
234- }
235- if ( details . what === 'mergeUbiquitousBlacklist' ) {
236- mergeBlacklist ( details ) ;
237- return ;
238- }
239- if ( details . what === 'listOfBlockListsLoaded' ) {
240- onListOfBlockListsLoaded ( details ) ;
241- return ;
242- }
243- } ;
244- chrome . runtime . onMessage . addListener ( onMessageHandler ) ;
245-
246231 var removeObsoleteBlacklistsHandler = function ( store ) {
247232 if ( ! store . remoteBlacklists ) {
248233 return ;
@@ -277,7 +262,6 @@ HTTPSB.loadUbiquitousBlacklists = function() {
277262 HTTPSB . abpFilters . freeze ( ) ;
278263 HTTPSB . abpHideFilters . freeze ( ) ;
279264 removeObsoleteBlacklists ( ) ;
280- chrome . runtime . onMessage . removeListener ( onMessageHandler ) ;
281265 chrome . runtime . sendMessage ( { what : 'loadUbiquitousBlacklistCompleted' } ) ;
282266 } ;
283267
@@ -320,7 +304,7 @@ HTTPSB.loadUbiquitousBlacklists = function() {
320304 blacklistLoadCount -= 1 ;
321305 continue ;
322306 }
323- httpsb . assets . get ( location , 'mergeUbiquitousBlacklist' ) ;
307+ httpsb . assets . get ( location , mergeBlacklist ) ;
324308 }
325309 } ;
326310
@@ -349,7 +333,7 @@ HTTPSB.loadUbiquitousBlacklists = function() {
349333 }
350334
351335 // Get new list of 3rd-party block lists.
352- this . assets . get ( 'assets/httpsb/ubiquitous-block-lists.json' , 'listOfBlockListsLoaded' ) ;
336+ this . assets . get ( 'assets/httpsb/ubiquitous-block-lists.json' , onListOfBlockListsLoaded ) ;
353337} ;
354338
355339/******************************************************************************/
@@ -502,61 +486,27 @@ HTTPSB.reloadPresetBlacklists = function(switches) {
502486/******************************************************************************/
503487
504488HTTPSB . loadPublicSuffixList = function ( ) {
505- var onMessage = function ( request ) {
506- if ( ! request || ! request . what ) {
507- return ;
508- }
509- if ( request . what === 'publicSuffixListLoaded' ) {
510- applyPublicSuffixList ( request ) ;
511- }
512- } ;
513489 var applyPublicSuffixList = function ( details ) {
490+ // TODO: Not getting proper suffix list is a bit serious, I think
491+ // the extension should be force-restarted if it occurs..
514492 if ( ! details . error ) {
515493 publicSuffixList . parse ( details . content , punycode . toASCII ) ;
516494 }
517- chrome . runtime . onMessage . removeListener ( onMessage ) ;
518495 } ;
519- chrome . runtime . onMessage . addListener ( onMessage ) ;
520496 this . assets . get (
521497 'assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat' ,
522- 'publicSuffixListLoaded'
498+ applyPublicSuffixList
523499 ) ;
524500} ;
525501
526502/******************************************************************************/
527503
528504// Load updatable assets
529505
530- HTTPSB . loadUpdatableAssets = function ( update ) {
531- var load = function ( httpsb ) {
532- httpsb . loadUbiquitousBlacklists ( ) ;
533- httpsb . loadPublicSuffixList ( ) ;
534- httpsb . reloadAllPresets ( ) ;
535- } ;
536-
537- if ( update !== true ) {
538- load ( this ) ;
539- return ;
540- }
541-
542- var assetsUpdated = function ( ) {
543- load ( HTTPSB ) ;
544- } ;
545-
546- var timestampLoaded = function ( store ) {
547- var httpsb = HTTPSB ;
548- var elapsed = Date . now ( ) ;
549- if ( typeof store . assetsUpdateTimestamp === 'number' ) {
550- elapsed -= store . assetsUpdateTimestamp ;
551- }
552- if ( elapsed < httpsb . updateAssetsEvery ) {
553- load ( httpsb ) ;
554- } else {
555- httpsb . assetUpdater . update ( null , assetsUpdated ) ;
556- }
557- } ;
558-
559- chrome . storage . local . get ( 'assetsUpdateTimestamp' , timestampLoaded ) ;
506+ HTTPSB . loadUpdatableAssets = function ( ) {
507+ this . loadUbiquitousBlacklists ( ) ;
508+ this . loadPublicSuffixList ( ) ;
509+ this . reloadAllPresets ( ) ;
560510} ;
561511
562512/******************************************************************************/
@@ -569,8 +519,8 @@ HTTPSB.load = function() {
569519 this . loadScopedRules ( ) ;
570520 this . loadUbiquitousWhitelists ( ) ;
571521
572- // updatable assets
573- this . loadUpdatableAssets ( true ) ;
522+ // load updatable assets -- after updating them if needed
523+ this . assetUpdater . update ( null , this . loadUpdatableAssets . bind ( this ) ) ;
574524
575525 this . getBytesInUse ( ) ;
576526} ;
0 commit comments