mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-11 17:41:03 +01:00
code review: avoid redundant PSL selfie
This commit is contained in:
parent
79b4706746
commit
4d8974fe80
3 changed files with 32 additions and 44 deletions
|
@ -132,8 +132,8 @@ var µBlock = (function() { // jshint ignore:line
|
|||
|
||||
// read-only
|
||||
systemSettings: {
|
||||
compiledMagic: 'puuijtkfpspv',
|
||||
selfieMagic: 'tuqilngsxkwo'
|
||||
compiledMagic: 1,
|
||||
selfieMagic: 1
|
||||
},
|
||||
|
||||
restoreBackupSettings: {
|
||||
|
@ -177,11 +177,7 @@ var µBlock = (function() { // jshint ignore:line
|
|||
epickerZap: false,
|
||||
epickerEprom: null,
|
||||
|
||||
scriptlets: {
|
||||
},
|
||||
|
||||
// so that I don't have to care for last comma
|
||||
dummy: 0
|
||||
scriptlets: {},
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
Home: https://github.com/gorhill/uBlock
|
||||
*/
|
||||
|
||||
/* global publicSuffixList */
|
||||
|
||||
'use strict';
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -95,7 +93,12 @@ var onAllReady = function() {
|
|||
// - PSL
|
||||
|
||||
var onPSLReady = function() {
|
||||
µb.loadFilterLists(onAllReady);
|
||||
µb.selfieManager.load(function(valid) {
|
||||
if ( valid === true ) {
|
||||
return onAllReady();
|
||||
}
|
||||
µb.loadFilterLists(onAllReady);
|
||||
});
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -161,31 +164,6 @@ var onVersionReady = function(lastVersion) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
var onSelfieReady = function(selfie) {
|
||||
if (
|
||||
selfie instanceof Object === false ||
|
||||
selfie.magic !== µb.systemSettings.selfieMagic
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if ( publicSuffixList.fromSelfie(selfie.publicSuffixList) !== true ) {
|
||||
return false;
|
||||
}
|
||||
if ( selfie.redirectEngine === undefined ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
µb.availableFilterLists = selfie.availableFilterLists;
|
||||
µb.staticNetFilteringEngine.fromSelfie(selfie.staticNetFilteringEngine);
|
||||
µb.redirectEngine.fromSelfie(selfie.redirectEngine);
|
||||
µb.staticExtFilteringEngine.fromSelfie(selfie.staticExtFilteringEngine);
|
||||
µb.loadRedirectResources();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/226
|
||||
// Whitelist in memory.
|
||||
// Whitelist parser needs PSL to be ready.
|
||||
|
@ -243,7 +221,7 @@ var onSystemSettingsReady = function(fetched) {
|
|||
if ( mustSaveSystemSettings ) {
|
||||
fetched.selfie = null;
|
||||
µb.selfieManager.destroy();
|
||||
vAPI.storage.set(µb.systemSettings, µb.noopFunc);
|
||||
vAPI.storage.set(µb.systemSettings);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -261,13 +239,8 @@ var onFirstFetchReady = function(fetched) {
|
|||
onNetWhitelistReady(fetched.netWhitelist);
|
||||
onVersionReady(fetched.version);
|
||||
|
||||
// If we have a selfie, skip loading PSL, filter lists
|
||||
vAPI.cacheStorage.get('selfie', function(bin) {
|
||||
if ( bin instanceof Object && onSelfieReady(bin.selfie) ) {
|
||||
return onAllReady();
|
||||
}
|
||||
µb.loadPublicSuffixList(onPSLReady);
|
||||
});
|
||||
µb.loadPublicSuffixList(onPSLReady);
|
||||
µb.loadRedirectResources();
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -1001,7 +1001,6 @@
|
|||
timer = null;
|
||||
var selfie = {
|
||||
magic: this.systemSettings.selfieMagic,
|
||||
publicSuffixList: publicSuffixList.toSelfie(),
|
||||
availableFilterLists: this.availableFilterLists,
|
||||
staticNetFilteringEngine: this.staticNetFilteringEngine.toSelfie(),
|
||||
redirectEngine: this.redirectEngine.toSelfie(),
|
||||
|
@ -1010,6 +1009,25 @@
|
|||
vAPI.cacheStorage.set({ selfie: selfie });
|
||||
}.bind(µBlock);
|
||||
|
||||
var load = function(callback) {
|
||||
vAPI.cacheStorage.get('selfie', function(bin) {
|
||||
var µb = µBlock;
|
||||
if (
|
||||
bin instanceof Object === false ||
|
||||
bin.selfie instanceof Object === false ||
|
||||
bin.selfie.magic !== µb.systemSettings.selfieMagic ||
|
||||
bin.selfie.redirectEngine === undefined
|
||||
) {
|
||||
return callback(false);
|
||||
}
|
||||
µb.availableFilterLists = bin.selfie.availableFilterLists;
|
||||
µb.staticNetFilteringEngine.fromSelfie(bin.selfie.staticNetFilteringEngine);
|
||||
µb.redirectEngine.fromSelfie(bin.selfie.redirectEngine);
|
||||
µb.staticExtFilteringEngine.fromSelfie(bin.selfie.staticExtFilteringEngine);
|
||||
callback(true);
|
||||
});
|
||||
};
|
||||
|
||||
var destroy = function() {
|
||||
if ( timer !== null ) {
|
||||
clearTimeout(timer);
|
||||
|
@ -1020,6 +1038,7 @@
|
|||
}.bind(µBlock);
|
||||
|
||||
return {
|
||||
load: load,
|
||||
destroy: destroy
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue