1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

All third-party assets which are not enabled by default will no longer be

part of the package. The code here is to ensure a seamless transition from
local assets which have been converted to remote assets. The only side
effect to expect is that the selfie, if any, will be invalidated.
This commit is contained in:
gorhill 2015-08-18 13:15:58 -04:00
parent 9b4b998364
commit efccaf1416
4 changed files with 170 additions and 11 deletions

View File

@ -1,6 +1,6 @@
/*******************************************************************************
µBlock - a browser extension to block requests.
uBlock - a browser extension to block requests.
Copyright (C) 2014-2015 Raymond Hill
This program is free software: you can redistribute it and/or modify
@ -392,8 +392,14 @@ var getRepoMetadata = function(callback) {
continue;
}
entry = entries[path];
// If repo checksums could not be fetched, assume no change
if ( repoChecksums === '' ) {
// If repo checksums could not be fetched, assume no change.
// https://github.com/gorhill/uBlock/issues/602
// Added: if repo checksum is that of the empty string,
// assume no change
if (
repoChecksums === '' ||
entry.repoChecksum === 'd41d8cd98f00b204e9800998ecf8427e'
) {
entry.repoChecksum = entry.localChecksum;
}
if ( entry.repoChecksum !== '' || entry.localChecksum === '' ) {
@ -1042,6 +1048,33 @@ exports.rmrf = function() {
/******************************************************************************/
exports.rename = function(from, to, callback) {
var done = function() {
if ( typeof callback === 'function' ) {
callback();
}
};
var fromLoaded = function(details) {
cachedAssetsManager.remove(from);
cachedAssetsManager.save(to, details.content, callback);
done();
};
var toLoaded = function(details) {
// `to` already exists: do nothing
if ( details.content !== '' ) {
return done();
}
cachedAssetsManager.load(from, fromLoaded);
};
// If `to` content already exists, do nothing.
cachedAssetsManager.load(to, toLoaded);
};
/******************************************************************************/
exports.metadata = function(callback) {
var out = {};

View File

@ -1,7 +1,7 @@
/*******************************************************************************
uBlock - a browser extension to block requests.
Copyright (C) 2014 Raymond Hill
Copyright (C) 2014-2015 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,12 +22,12 @@
/* global vAPI */
/* exported µBlock */
'use strict';
/******************************************************************************/
var µBlock = (function() {
'use strict';
/******************************************************************************/
var oneSecond = 1000;
@ -94,7 +94,7 @@ return {
// read-only
systemSettings: {
compiledMagic: 'msgmqxreevdy',
selfieMagic: 'spqmeuaftfra'
selfieMagic: 'mnigwksyvgkv'
},
restoreBackupSettings: {
@ -139,7 +139,45 @@ return {
},
// current lists
remoteBlacklists: {
remoteBlacklists: {},
oldListToNewListMap: {
"assets/thirdparties/adblock.gardar.net/is.abp.txt": "http://adblock.gardar.net/is.abp.txt",
"assets/thirdparties/adblock.schack.dk/block.txt": "https://adblock.schack.dk/block.txt",
"assets/thirdparties/dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt": "https://dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/advblock.txt": "https://easylist-downloads.adblockplus.org/advblock.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/bitblock.txt": "https://easylist-downloads.adblockplus.org/bitblock.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/easylist_noelemhide.txt": "https://easylist-downloads.adblockplus.org/easylist_noelemhide.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/easylistchina.txt": "https://easylist-downloads.adblockplus.org/easylistchina.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/easylistdutch.txt": "https://easylist-downloads.adblockplus.org/easylistdutch.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/easylistgermany.txt": "https://easylist-downloads.adblockplus.org/easylistgermany.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/easylistitaly.txt": "https://easylist-downloads.adblockplus.org/easylistitaly.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/fanboy-annoyance.txt": "https://easylist-downloads.adblockplus.org/fanboy-annoyance.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/fanboy-social.txt": "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
"assets/thirdparties/easylist-downloads.adblockplus.org/liste_fr.txt": "https://easylist-downloads.adblockplus.org/liste_fr.txt",
"assets/thirdparties/gitorious.org/adblock-latvian/adblock-latvian/raw/master_lists/latvian-list.txt": "https://notabug.org/latvian-list/adblock-latvian/raw/master/lists/latvian-list.txt",
"assets/thirdparties/home.fredfiber.no/langsholt/adblock.txt": "http://home.fredfiber.no/langsholt/adblock.txt",
"assets/thirdparties/hosts-file.net/ad-servers": "http://hosts-file.net/.%5Cad_servers.txt",
"assets/thirdparties/http://www.certyficate.it/adblock/adblock.txt": "https://www.certyficate.it/adblock/adblock.txt",
"assets/thirdparties/liste-ar-adblock.googlecode.com/hg/Liste_AR.txt": "https://liste-ar-adblock.googlecode.com/hg/Liste_AR.txt",
"assets/thirdparties/margevicius.lt/easylistlithuania.txt": "http://margevicius.lt/easylistlithuania.txt",
"assets/thirdparties/mirror1.malwaredomains.com/files/immortal_domains.txt": "http://malwaredomains.lehigh.edu/files/immortal_domains.txt",
"assets/thirdparties/raw.githubusercontent.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt": "https://raw.githubusercontent.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt",
"assets/thirdparties/raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt": "https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt",
"assets/thirdparties/raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt": "https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt",
"assets/thirdparties/raw.githubusercontent.com/szpeter80/hufilter/master/hufilter.txt": "https://raw.githubusercontent.com/szpeter80/hufilter/master/hufilter.txt",
"assets/thirdparties/raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt": "https://raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt",
"assets/thirdparties/someonewhocares.org/hosts/hosts": "http://someonewhocares.org/hosts/hosts",
"assets/thirdparties/spam404bl.com/spam404scamlist.txt": "https://spam404bl.com/spam404scamlist.txt",
"assets/thirdparties/stanev.org/abp/adblock_bg.txt": "http://stanev.org/abp/adblock_bg.txt",
"assets/thirdparties/winhelp2002.mvps.org/hosts.txt": "http://winhelp2002.mvps.org/hosts.txt",
"assets/thirdparties/www.fanboy.co.nz/enhancedstats.txt": "https://www.fanboy.co.nz/enhancedstats.txt",
"assets/thirdparties/www.fanboy.co.nz/fanboy-antifacebook.txt": "https://www.fanboy.co.nz/fanboy-antifacebook.txt",
"assets/thirdparties/www.fanboy.co.nz/fanboy-korean.txt": "https://www.fanboy.co.nz/fanboy-korean.txt",
"assets/thirdparties/www.fanboy.co.nz/fanboy-swedish.txt": "https://www.fanboy.co.nz/fanboy-swedish.txt",
"assets/thirdparties/www.fanboy.co.nz/fanboy-ultimate.txt": "https://www.fanboy.co.nz/r/fanboy-ultimate.txt",
"assets/thirdparties/www.fanboy.co.nz/fanboy-vietnam.txt": "https://www.fanboy.co.nz/fanboy-vietnam.txt",
"assets/thirdparties/www.void.gr/kargig/void-gr-filters.txt": "https://www.void.gr/kargig/void-gr-filters.txt",
"assets/thirdparties/www.zoso.ro/pages/rolist.txt": ""
},
selfieAfter: 23 * oneMinute,

View File

@ -393,7 +393,6 @@ Matrix.prototype.evaluateCellZY = function(srcHostname, desHostname, type) {
}
// 3rd-party, any type
if ( this.evaluateCellZ(srcHostname, '*', '3p') !== 0 ) { return this; }
} else if ( type === 'script' ) {
// 1st party, specific type
if ( this.evaluateCellZ(srcHostname, '*', '1p-script') !== 0 ) { return this; }

View File

@ -147,7 +147,7 @@
// https://github.com/gorhill/uBlock/issues/63
// Get built-in block lists: this will help us determine whether a
// specific list must be included in the result.
this.assets.get('assets/ublock/filter-lists.json', onBuiltinListsLoaded);
this.loadAndPatchStockFilterLists(onBuiltinListsLoaded);
};
/******************************************************************************/
@ -327,7 +327,7 @@
}
// get built-in block lists.
this.assets.get('assets/ublock/filter-lists.json', onBuiltinListsLoaded);
this.loadAndPatchStockFilterLists(onBuiltinListsLoaded);
};
/******************************************************************************/
@ -899,3 +899,92 @@
return handler;
})();
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/602
// - Load and patch `filter-list.json`
// - Load and patch user's `remoteBlacklists`
// - Load and patch cached filter lists
// - Load and patch compiled filter lists
//
// Once enough time has passed to safely assume all uBlock Origin
// installations have been converted to the new stock filter lists, this code
// can be removed.
µBlock.patchFilterLists = function(filterLists) {
var modified = false;
var oldListKey, newListKey, listEntry;
for ( var listKey in filterLists ) {
if ( filterLists.hasOwnProperty(listKey) === false ) {
continue;
}
oldListKey = listKey;
if ( this.oldListToNewListMap.hasOwnProperty(oldListKey) === false ) {
oldListKey = 'assets/thirdparties/' + listKey;
if ( this.oldListToNewListMap.hasOwnProperty(oldListKey) === false ) {
continue;
}
}
newListKey = this.oldListToNewListMap[oldListKey];
if ( newListKey !== '' ) {
listEntry = filterLists[listKey];
listEntry.homeURL = undefined;
filterLists[newListKey] = listEntry;
}
delete filterLists[listKey];
modified = true;
}
return modified;
};
µBlock.loadAndPatchStockFilterLists = function(callback) {
var onStockListsLoaded = function(details) {
var µb = µBlock;
var stockLists;
try {
stockLists = JSON.parse(details.content);
} catch (e) {
stockLists = {};
}
// Migrate assets affected by the change to their new name.
var newListKey;
for ( var oldListKey in stockLists ) {
if ( stockLists.hasOwnProperty(oldListKey) === false ) {
continue;
}
oldListKey = 'assets/thirdparties/' + oldListKey;
if ( µb.oldListToNewListMap.hasOwnProperty(oldListKey) === false ) {
continue;
}
newListKey = µb.oldListToNewListMap[oldListKey];
// Remove cached and compiled list
if ( newListKey === '' ) {
continue;
}
// Rename cached and compiled list (important: compiled list first)
µb.assets.rename(µb.getCompiledFilterListPath(oldListKey),
µb.getCompiledFilterListPath(newListKey));
µb.assets.rename(oldListKey, newListKey);
}
µb.patchFilterLists(stockLists);
// Stock lists information cascades into
// - In-memory user's selected filter lists, so we need to patch this.
µb.patchFilterLists(µb.remoteBlacklists);
// Stock lists information cascades into
// - In-storage user's selected filter lists, so we need to patch this.
vAPI.storage.get('remoteBlacklists', function(bin) {
var userLists = bin.remoteBlacklists || {};
if ( µb.patchFilterLists(userLists) ) {
µb.keyvalSetOne('remoteBlacklists', userLists);
}
details.content = JSON.stringify(stockLists);
callback(details);
});
};
this.assets.get('assets/ublock/filter-lists.json', onStockListsLoaded);
};