From 16a128dff0daa0c29b77e2811d39e59705216be9 Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 3 Jan 2016 13:58:25 -0500 Subject: [PATCH] this fixes #747 --- assets/checksums.txt | 2 +- assets/ublock/filter-lists.json | 27 ++++++++++++++++ src/js/background.js | 2 ++ src/js/start.js | 56 ++++++++++++++++++--------------- src/js/storage.js | 39 +++++++++++++++++++++-- 5 files changed, 98 insertions(+), 28 deletions(-) diff --git a/assets/checksums.txt b/assets/checksums.txt index 9865bf8fd..44dfe058b 100644 --- a/assets/checksums.txt +++ b/assets/checksums.txt @@ -6,7 +6,7 @@ 5baa90e2da7cd6a73edff2010557ee57 assets/ublock/redirect.txt 890e6b30c6a4cfd2ac5aa1bbe36d30fe assets/ublock/experimental.txt 40acd039d46d8e9dea7f63fd257d93bd assets/ublock/resources.txt -0a586f61b5bea73447c1bc1d46791c4c assets/ublock/filter-lists.json +9426bdf06d69f8d7493306ed135f6819 assets/ublock/filter-lists.json 50573388b525ede1a920cd4b4ee7fbf0 assets/thirdparties/easylist-downloads.adblockplus.org/easyprivacy.txt 61cc16cf02e034370f0f47bc17c46551 assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt 7f0443f3dcc9abfd47cfbc95ce824ddb assets/thirdparties/mirror1.malwaredomains.com/files/README.md diff --git a/assets/ublock/filter-lists.json b/assets/ublock/filter-lists.json index 314ab9ae1..99d8a131b 100644 --- a/assets/ublock/filter-lists.json +++ b/assets/ublock/filter-lists.json @@ -3,12 +3,14 @@ "off": true, "title": "ISL: Icelandic ABP List", "group": "regions", + "lang": "is", "supportURL": "http://adblock.gardar.net/" }, "https://adblock.dk/block.csv": { "off": true, "title": "DNK: Schacks Adblock Plus liste", "group": "regions", + "lang": "da", "supportURL": "https://henrik.schack.dk/adblock/" }, "https://dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt": { @@ -21,6 +23,7 @@ "off": true, "title": "RUS: RU AdList (Дополнительная региональная подписка)", "group": "regions", + "lang": "ru", "supportURL": "https://forums.lanik.us/viewforum.php?f=102" }, "https://easylist-downloads.adblockplus.org/bitblock.txt": { @@ -45,24 +48,28 @@ "off": true, "title": "CHN: EasyList China (中文)", "group": "regions", + "lang": "zh", "supportURL": "http://abpchina.org/forum/forum.php" }, "https://easylist-downloads.adblockplus.org/easylistdutch.txt": { "off": true, "title": "NLD: EasyList Dutch", "group": "regions", + "lang": "nl", "supportURL": "https://forums.lanik.us/viewforum.php?f=100" }, "https://easylist-downloads.adblockplus.org/easylistgermany.txt": { "off": true, "title": "DEU: EasyList Germany", "group": "regions", + "lang": "de", "supportURL": "https://forums.lanik.us/viewforum.php?f=90" }, "https://easylist-downloads.adblockplus.org/easylistitaly.txt": { "off": true, "title": "ITA: EasyList Italy", "group": "regions", + "lang": "it", "supportURL": "https://forums.lanik.us/viewforum.php?f=96" }, "easylist-downloads.adblockplus.org/easyprivacy.txt": { @@ -87,12 +94,14 @@ "off": true, "title": "FRA: EasyList Liste FR", "group": "regions", + "lang": "fr", "supportURL": "https://forums.lanik.us/viewforum.php?f=91" }, "https://notabug.org/latvian-list/adblock-latvian/raw/master/lists/latvian-list.txt": { "off": true, "title": "LVA: Latvian List", "group": "regions", + "lang": "lv", "supportURL": "https://notabug.org/latvian-list/adblock-latvian" }, "http://hosts-file.net/.%5Cad_servers.txt": { @@ -105,6 +114,7 @@ "off": true, "title": "EST: Eesti saitidele kohandatud filter", "group": "regions", + "lang": "et", "supportURL": "http://adblock.ee/" }, "https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt": { @@ -126,6 +136,7 @@ "off": true, "title": "POL: polskie filtry do Adblocka i uBlocka", "group": "regions", + "lang": "pl", "supportURL": "http://www.certyficate.it/adblock-ublock-polish-filters/" }, "https://easylist-downloads.adblockplus.org/antiadblockfilters.txt": { @@ -138,24 +149,28 @@ "off": true, "title": "FIN: Finnish Addition to Easylist", "group": "regions", + "lang": "fi", "supportURL": "http://www.juvander.fi/AdblockFinland" }, "https://raw.githubusercontent.com/gfmaster/adblock-korea-contrib/master/filter.txt": { "off": true, "title": "KOR: Korean Adblock List", "group": "regions", + "lang": "ko", "supportURL": "https://github.com/gfmaster/adblock-korea-contrib" }, "https://raw.githubusercontent.com/heradhis/indonesianadblockrules/master/subscriptions/abpindo.txt": { "off": true, "title": "IDN: ABPindo", "group": "regions", + "lang": "id", "supportURL": "https://github.com/heradhis/indonesianadblockrules" }, "https://raw.githubusercontent.com/k2jp/abp-japanese-filters/master/abpjf.txt": { "off": true, "title": "JPN: ABP Japanese filters (日本用フィルタ)", "group": "regions", + "lang": "ja", "supportURL": "https://github.com/k2jp/abp-japanese-filters" }, "https://raw.githubusercontent.com/liamja/Prebake/master/obtrusive.txt": { @@ -168,12 +183,14 @@ "off": true, "title": "KOR: YousList", "group": "regions", + "lang": "ko", "supportURL": "https://github.com/yous/YousList" }, "https://easylist-downloads.adblockplus.org/Liste_AR.txt": { "off": true, "title": "ara: Liste AR", "group": "regions", + "lang": "ar", "supportURL": "https://forums.lanik.us/viewforum.php?f=98" }, "https://liste-ar-adblock.googlecode.com/hg/Liste_AR.txt": { @@ -186,6 +203,7 @@ "off": true, "title": "LTU: Adblock Plus Lithuania", "group": "regions", + "lang": "lt", "supportURL": "http://margevicius.lt/easylist_lithuania/" }, "http://malwaredomains.lehigh.edu/files/immortal_domains.txt": { @@ -210,6 +228,7 @@ "off": true, "title": "ISR: EasyList Hebrew", "group": "regions", + "lang": "he", "supportURL": "https://github.com/AdBlockPlusIsrael/EasyListHebrew" }, "https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjxlist.txt": { @@ -229,12 +248,14 @@ "off": true, "title": "HUN: hufilter", "group": "regions", + "lang": "hu", "supportURL": "https://github.com/szpeter80/hufilter" }, "https://raw.githubusercontent.com/tomasko126/easylistczechandslovak/master/filters.txt": { "off": true, "title": "CZE, SVK: EasyList Czech and Slovak", "group": "regions", + "lang": "cs", "supportURL": "https://github.com/tomasko126/easylistczechandslovak" }, "http://someonewhocares.org/hosts/hosts": { @@ -253,6 +274,7 @@ "off": true, "title": "BGR: Bulgarian Adblock list", "group": "regions", + "lang": "bg", "supportURL": "http://stanev.org/abp/" }, "http://winhelp2002.mvps.org/hosts.txt": { @@ -283,6 +305,7 @@ "off": true, "title": "SWE: Fanboy's Swedish", "group": "regions", + "lang": "sv", "supportURL": "https://forums.lanik.us/" }, "https://www.fanboy.co.nz/r/fanboy-ultimate.txt": { @@ -295,12 +318,14 @@ "off": true, "title": "TUR: Adguard Turkish Filter", "group": "regions", + "lang": "tr", "supportURL": "http://forum.adguard.com/forumdisplay.php?51-Filter-Rules" }, "https://www.fanboy.co.nz/fanboy-vietnam.txt": { "off": true, "title": "VIE: Fanboy's Vietnamese", "group": "regions", + "lang": "vi", "supportURL": "https://forums.lanik.us/" }, "www.malwaredomainlist.com/hostslist/hosts.txt": { @@ -312,12 +337,14 @@ "off": true, "title": "GRC: Greek AdBlock Filter", "group": "regions", + "lang": "el", "supportURL": "https://github.com/kargig/greek-adblockplus-filter" }, "https://raw.githubusercontent.com/betterwebleon/slovenian-list/master/filters.txt": { "off": true, "title": "SVN: Slovenian List", "group": "regions", + "lang": "sl", "supportURL": "https://github.com/betterwebleon/slovenian-list" } } diff --git a/src/js/background.js b/src/js/background.js index 553bf9b2a..a18b28099 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -47,6 +47,8 @@ var defaultExternalLists = [ /******************************************************************************/ return { + firstInstall: false, + userSettings: { advancedUserEnabled: false, autoUpdate: true, diff --git a/src/js/start.js b/src/js/start.js index 87af69103..44fd3f085 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -76,6 +76,8 @@ var onAllReady = function() { //quickProfiler.stop(0); vAPI.onLoadAllCompleted(); + + µb.firstInstall = false; }; /******************************************************************************/ @@ -208,6 +210,9 @@ var onSystemSettingsReady = function(fetched) { /******************************************************************************/ var onFirstFetchReady = function(fetched) { + // https://github.com/gorhill/uBlock/issues/747 + µb.firstInstall = fetched.version === '0.0.0.0'; + // Order is important -- do not change: onSystemSettingsReady(fetched); fromFetch(µb.localSettings, fetched); @@ -250,34 +255,35 @@ var fromFetch = function(to, fetched) { /******************************************************************************/ -return function() { +var onAdminSettingsRestored = function() { + // Forbid remote fetching of assets + µb.assets.remoteFetchBarrier += 1; - var onAdminSettingsRestored = function() { - // Forbid remote fetching of assets - µb.assets.remoteFetchBarrier += 1; - - var fetchableProps = { - 'compiledMagic': '', - 'dynamicFilteringString': 'behind-the-scene * 3p noop\nbehind-the-scene * 3p-frame noop', - 'urlFilteringString': '', - 'hostnameSwitchesString': '', - 'lastRestoreFile': '', - 'lastRestoreTime': 0, - 'lastBackupFile': '', - 'lastBackupTime': 0, - 'netWhitelist': '', - 'selfie': null, - 'selfieMagic': '', - 'version': '0.0.0.0' - }; - - toFetch(µb.localSettings, fetchableProps); - toFetch(µb.userSettings, fetchableProps); - toFetch(µb.restoreBackupSettings, fetchableProps); - - vAPI.storage.get(fetchableProps, onFirstFetchReady); + var fetchableProps = { + 'compiledMagic': '', + 'dynamicFilteringString': 'behind-the-scene * 3p noop\nbehind-the-scene * 3p-frame noop', + 'urlFilteringString': '', + 'hostnameSwitchesString': '', + 'lastRestoreFile': '', + 'lastRestoreTime': 0, + 'lastBackupFile': '', + 'lastBackupTime': 0, + 'netWhitelist': '', + 'selfie': null, + 'selfieMagic': '', + 'version': '0.0.0.0' }; + toFetch(µb.localSettings, fetchableProps); + toFetch(µb.userSettings, fetchableProps); + toFetch(µb.restoreBackupSettings, fetchableProps); + + vAPI.storage.get(fetchableProps, onFirstFetchReady); +}; + +/******************************************************************************/ + +return function() { // https://github.com/gorhill/uBlock/issues/531 µb.restoreAdminSettings(onAdminSettingsRestored); }; diff --git a/src/js/storage.js b/src/js/storage.js index d55889d00..08152d1d8 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -269,6 +269,12 @@ availableEntry.title = storedEntry.title; } } + + // https://github.com/gorhill/uBlock/issues/747 + if ( µb.firstInstall ) { + µb.autoSelectFilterLists(availableLists); + } + callback(availableLists); }; @@ -338,6 +344,25 @@ /******************************************************************************/ +µBlock.autoSelectFilterLists = function(lists) { + var lang = self.navigator.language.slice(0, 2), + list; + for ( var path in lists ) { + if ( lists.hasOwnProperty(path) === false ) { + continue; + } + list = lists[path]; + if ( list.off !== true ) { + continue; + } + if ( list.lang === lang ) { + list.off = false; + } + } +}; + +/******************************************************************************/ + µBlock.createShortUniqueId = function(path) { var md5 = YaMD5.hashStr(path); return md5.slice(0, 4) + md5.slice(-4); @@ -347,7 +372,15 @@ /******************************************************************************/ +// This is used to be re-entrancy resistant. +µBlock.loadingFilterLists = false; + µBlock.loadFilterLists = function(callback) { + // Callers are expected to check this first. + if ( this.loadingFilterLists ) { + return; + } + this.loadingFilterLists = true; //quickProfiler.start('µBlock.loadFilterLists()'); @@ -377,6 +410,7 @@ callback(); µb.selfieManager.create(); + µb.loadingFilterLists = false; }; var applyCompiledFilters = function(path, compiled) { @@ -425,8 +459,7 @@ } filterlistsCount = toLoad.length; if ( filterlistsCount === 0 ) { - onDone(); - return; + return onDone(); } var i = toLoad.length; @@ -644,6 +677,8 @@ var µb = this; // We are just reloading the filter lists: we do not want assets to update. + // TODO: probably not needed anymore, since filter lists are now always + // loaded without update => see `µb.assets.remoteFetchBarrier`. this.assets.autoUpdate = false; var onFiltersReady = function() {