mirror of https://github.com/gorhill/uBlock.git
Add concept of "really bad list" to badlists infrastructure
This commit adds concept of "really bad list" to the badlists infrastructure. Really bad lists won't be fetched from a remote server, while plain bad list will be fetched but won't be compiled. A really bad list is denoted by the `nofetch` token following the URL. Really bad lists can cause more serious issues such as causing undue launch delays because the remote server where a really bad list is hosted fails to respond properly and times out. Such an example of really bad list is hpHosts which original server no longer exist.
This commit is contained in:
parent
3d048c999e
commit
4150c17f4a
|
@ -171,7 +171,7 @@ const µBlock = (( ) => { // jshint ignore:line
|
|||
|
||||
selectedFilterLists: [],
|
||||
availableFilterLists: {},
|
||||
badLists: new Set(),
|
||||
badLists: new Map(),
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/974
|
||||
// This can be used to defer filtering decision-making.
|
||||
|
|
|
@ -481,15 +481,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
let oldAvailableLists = {},
|
||||
newAvailableLists = {};
|
||||
|
||||
if ( this.badLists.size === 0 ) {
|
||||
const details = await this.assets.get('ublock-badlists');
|
||||
this.badLists = new Set(
|
||||
details.content.split(/\s*[\n\r]+\s*/).filter(a => {
|
||||
return a !== '' && a.startsWith('#') === false;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// User filter list.
|
||||
newAvailableLists[this.userFiltersPath] = {
|
||||
group: 'user',
|
||||
|
@ -538,12 +529,24 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
this.saveSelectedFilterLists([ listURL ], true);
|
||||
};
|
||||
|
||||
// Load previously saved available lists -- these contains data
|
||||
// computed at run-time, we will reuse this data if possible.
|
||||
const [ bin, entries ] = await Promise.all([
|
||||
const promises = [
|
||||
vAPI.storage.get('availableFilterLists'),
|
||||
this.assets.metadata(),
|
||||
]);
|
||||
this.badLists.size === 0 ? this.assets.get('ublock-badlists') : false,
|
||||
];
|
||||
|
||||
// Load previously saved available lists -- these contains data
|
||||
// computed at run-time, we will reuse this data if possible.
|
||||
const [ bin, entries, badlists ] = await Promise.all(promises);
|
||||
|
||||
if ( badlists instanceof Object ) {
|
||||
for ( const line of badlists.content.split(/\s*[\n\r]+\s*/) ) {
|
||||
if ( line === '' || line.startsWith('#') ) { continue; }
|
||||
const fields = line.split(/\s+/);
|
||||
const remove = fields.length === 2 && fields[1] === 'nofetch';
|
||||
this.badLists.set(fields[0], remove);
|
||||
}
|
||||
}
|
||||
|
||||
oldAvailableLists = bin && bin.availableFilterLists || {};
|
||||
|
||||
|
@ -725,6 +728,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
}
|
||||
}
|
||||
|
||||
// Skip downloading really bad lists.
|
||||
if ( this.badLists.get(assetKey) ) {
|
||||
return { assetKey, content: '' };
|
||||
}
|
||||
|
||||
const rawDetails = await this.assets.get(assetKey);
|
||||
// Compiling an empty string results in an empty string.
|
||||
if ( rawDetails.content === '' ) {
|
||||
|
@ -1331,11 +1339,14 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
|
||||
µBlock.assetObserver = function(topic, details) {
|
||||
// Do not update filter list if not in use.
|
||||
// Also, ignore really bad lists, i.e. those which should not even be
|
||||
// fetched from a remote server.
|
||||
if ( topic === 'before-asset-updated' ) {
|
||||
if ( details.type === 'filters' ) {
|
||||
if (
|
||||
this.availableFilterLists.hasOwnProperty(details.assetKey) === false ||
|
||||
this.selectedFilterLists.indexOf(details.assetKey) === -1
|
||||
this.selectedFilterLists.indexOf(details.assetKey) === -1 ||
|
||||
this.badLists.get(details.assetKey)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -1374,7 +1385,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||
this.compilePublicSuffixList(details.content);
|
||||
}
|
||||
} else if ( details.assetKey === 'ublock-badlists' ) {
|
||||
this.badLists = new Set();
|
||||
this.badLists = new Map();
|
||||
}
|
||||
vAPI.messaging.broadcast({
|
||||
what: 'assetUpdated',
|
||||
|
|
Loading…
Reference in New Issue