diff options
author | gorhill <rhill@raymondhill.net> | 2014-08-24 20:52:34 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2014-08-24 20:52:34 -0400 |
commit | 9b40ec937f19ca3e6ab9b0deaa0a9a80babf859e (patch) | |
tree | a51d02a0d3a7488a1032215c3af3b08fc403b74c /js | |
parent | c5fd6bc02492aeb653edaee4189eba275627d59e (diff) | |
download | uBlock-9b40ec937f19ca3e6ab9b0deaa0a9a80babf859e.zip uBlock-9b40ec937f19ca3e6ab9b0deaa0a9a80babf859e.tar.gz uBlock-9b40ec937f19ca3e6ab9b0deaa0a9a80babf859e.tar.bz2 |
this fixes #180, also code changes re #148
Diffstat (limited to 'js')
-rw-r--r-- | js/assets.js | 74 | ||||
-rw-r--r-- | js/background.js | 11 | ||||
-rw-r--r-- | js/storage.js | 106 | ||||
-rw-r--r-- | js/ublock.js | 2 |
4 files changed, 103 insertions, 90 deletions
diff --git a/js/assets.js b/js/assets.js index ad6876a..9e154ad 100644 --- a/js/assets.js +++ b/js/assets.js @@ -254,51 +254,6 @@ var getRepoMetadata = function(callback) { lastRepoMetaTimestamp = Date.now(); - // https://github.com/gorhill/uBlock/issues/84 - // First try to load from the actual home server of a third-party. - var parseHomeURLs = function(text) { - var entries = repoMetadata.entries; - var urlPairs = text.split(/\n\n+/); - var i = urlPairs.length; - var pair, pos, k, v; - while ( i-- ) { - pair = urlPairs[i]; - pos = pair.indexOf('\n'); - if ( pos === -1 ) { - continue; - } - k = 'assets/thirdparties/' + pair.slice(0, pos).trim(); - v = pair.slice(pos).trim(); - if ( k === '' || v === '' ) { - continue; - } - if ( entries[k] === undefined ) { - entries[k] = new AssetEntry(); - } - entries[k].homeURL = v; - } - while ( callback = repoMetadata.waiting.pop() ) { - callback(repoMetadata); - } - }; - - var pathToHomeURLs = 'assets/ublock/thirdparty-lists.txt'; - - var onLocalHomeURLsLoaded = function(details) { - parseHomeURLs(details.content); - }; - - var onRepoHomeURLsLoaded = function(details) { - var entries = repoMetadata.entries; - var entry = entries[pathToHomeURLs]; - if ( YaMD5.hashStr(details.content) !== entry.repoChecksum ) { - entry.repoChecksum = entry.localChecksum; - readLocalFile(pathToHomeURLs, onLocalHomeURLsLoaded); - return; - } - cachedAssetsManager.save(pathToHomeURLs, details.content, onLocalHomeURLsLoaded); - }; - var localChecksums; var repoChecksums; @@ -330,11 +285,8 @@ var getRepoMetadata = function(callback) { updateLocalChecksums(); } // Fetch and store homeURL associations - entry = entries[pathToHomeURLs]; - if ( entry.localChecksum !== entry.repoChecksum ) { - readRepoFile(pathToHomeURLs, onRepoHomeURLsLoaded); - } else { - readLocalFile(pathToHomeURLs, onLocalHomeURLsLoaded); + while ( callback = repoMetadata.waiting.pop() ) { + callback(repoMetadata); } }; @@ -894,12 +846,6 @@ exports.put = function(path, content, callback) { /******************************************************************************/ -exports.purge = function(pattern, before) { - cachedAssetsManager.remove(pattern, before); -}; - -/******************************************************************************/ - exports.metadata = function(callback) { var out = {}; @@ -959,6 +905,22 @@ exports.metadata = function(callback) { /******************************************************************************/ +exports.setHomeURL = function(path, homeURL) { + var entry = repoMetadata[path]; + if ( entry === undefined ) { + entry = repoMetadata[path] = new AssetEntry(); + } + entry.homeURL = homeURL; +}; + +/******************************************************************************/ + +exports.purge = function(pattern, before) { + cachedAssetsManager.remove(pattern, before); +}; + +/******************************************************************************/ + exports.purgeAll = function(callback) { var onMetaDataReady = function(entries) { var out = {}; diff --git a/js/background.js b/js/background.js index 64b1975..ef52d70 100644 --- a/js/background.js +++ b/js/background.js @@ -44,10 +44,15 @@ return { logBlockedRequests: false, logAllowedRequests: false, parseAllABPHideFilters: true, - netExceptionList: {}, // TODO: remove once all users are up to date - netWhitelist: '', showIconBadge: true }, + + // https://github.com/gorhill/uBlock/issues/180 + // Whitelist directives need to be loaded once the PSL is available + netExceptionList: {}, // TODO: remove once all users are up to date + netWhitelist: {}, + netWhitelistModifyTime: 0, + localSettings: { blockedRequestCount: 0, allowedRequestCount: 0 @@ -81,8 +86,6 @@ return { remoteBlacklists: { }, - netWhitelist: {}, - netWhitelistModifyTime: 0, pageStores: {}, storageQuota: chrome.storage.local.QUOTA_BYTES, diff --git a/js/storage.js b/js/storage.js index 71004b9..be6bf56 100644 --- a/js/storage.js +++ b/js/storage.js @@ -72,6 +72,31 @@ µBlock.loadUserSettings = function(callback) { var settingsLoaded = function(store) { + µBlock.userSettings = store; + if ( typeof callback === 'function' ) { + callback(); + } + }; + + chrome.storage.local.get(this.userSettings, settingsLoaded); +}; + +/******************************************************************************/ + +µBlock.saveWhitelist = function() { + var bin = { + 'netWhitelist': this.stringFromWhitelist(this.netWhitelist) + }; + chrome.storage.local.set(bin, function() { + µBlock.getBytesInUse(); + }); + this.netWhitelistModifyTime = Date.now(); +}; + +/******************************************************************************/ + +µBlock.loadWhitelist = function(callback) { + var onWhitelistLoaded = function(store) { var µb = µBlock; // Backward compatibility after fix to #5 // TODO: remove once all users are up to date with latest version. @@ -82,28 +107,21 @@ chrome.storage.local.set({ 'netWhitelist': store.netWhitelist }); } } - delete store.netExceptionList; chrome.storage.local.remove('netExceptionList'); } - µb.userSettings = store; µb.netWhitelist = µb.whitelistFromString(store.netWhitelist); µb.netWhitelistModifyTime = Date.now(); - callback(); + if ( typeof callback === 'function' ) { + callback(); + } }; - chrome.storage.local.get(this.userSettings, settingsLoaded); -}; - -/******************************************************************************/ - -µBlock.saveWhitelist = function() { - this.userSettings.netWhitelist = this.stringFromWhitelist(this.netWhitelist); - var bin = { 'netWhitelist': this.userSettings.netWhitelist }; - chrome.storage.local.set(bin, function() { - µBlock.getBytesInUse(); - }); - this.netWhitelistModifyTime = Date.now(); + var bin = { + 'netWhitelist': '', + 'netExceptionList': '' + }; + chrome.storage.local.get(bin, onWhitelistLoaded); }; /******************************************************************************/ @@ -145,25 +163,32 @@ µBlock.getAvailableLists = function(callback) { var availableLists = {}; + var redirections = {}; // selected lists var onSelectedListsLoaded = function(store) { + var µb = µBlock; var lists = store.remoteBlacklists; var locations = Object.keys(lists); - var location; + var oldLocation, newLocation; + var availableEntry, storedEntry; - while ( location = locations.pop() ) { - if ( !availableLists[location] ) { + while ( oldLocation = locations.pop() ) { + newLocation = redirections[oldLocation] || oldLocation; + availableEntry = availableLists[newLocation]; + if ( availableEntry === undefined ) { continue; } - // https://github.com/gorhill/httpswitchboard/issues/218 - // Transfer potentially existing list title into restored list data. - if ( lists[location].title !== availableLists[location].title ) { - lists[location].title = availableLists[location].title; + storedEntry = lists[oldLocation]; + availableEntry.off = storedEntry.off || false; + µb.assets.setHomeURL(newLocation, availableEntry.homeURL); + if ( storedEntry.entryCount !== undefined ) { + availableEntry.entryCount = storedEntry.entryCount; + } + if ( storedEntry.entryUsedCount !== undefined ) { + availableEntry.entryUsedCount = storedEntry.entryUsedCount; } - availableLists[location] = lists[location]; } - callback(availableLists); }; @@ -175,11 +200,17 @@ } catch (e) { locations = {}; } + var entry; for ( location in locations ) { if ( locations.hasOwnProperty(location) === false ) { continue; } - availableLists['assets/thirdparties/' + location] = locations[location]; + entry = locations[location]; + availableLists['assets/thirdparties/' + location] = entry; + if ( entry.old !== undefined ) { + redirections[entry.old] = location; + delete entry.old; + } } // Now get user's selection of lists @@ -423,13 +454,16 @@ /******************************************************************************/ -µBlock.loadPublicSuffixList = function() { +µBlock.loadPublicSuffixList = function(callback) { var applyPublicSuffixList = function(details) { // TODO: Not getting proper suffix list is a bit serious, I think // the extension should be force-restarted if it occurs.. if ( !details.error ) { publicSuffixList.parse(details.content, punycode.toASCII); } + if ( typeof callback === 'function' ) { + callback(); + } }; this.assets.get( 'assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat', @@ -458,9 +492,23 @@ // Load all µBlock.load = function() { + var µb = this; + + // User whitelist directives and filters need the Public Suffix List to be + // available -- because the way they are stored internally. + var onPSLReady = function() { + µb.loadWhitelist(); + µb.loadUbiquitousBlacklists(); + }; + + // Public Suffix List loader needs the user settings need to be available + // because we need to know whether to auto-update the list or not. + var onUserSettingsReady = function() { + µb.assets.autoUpdate = µb.userSettings.autoUpdate || true; + µb.loadPublicSuffixList(onPSLReady); + }; + this.loadUserSettings(onUserSettingsReady); + this.loadLocalSettings(); - // User settings need to be available for this because we need - // µBlock.userSettings.externalLists - this.loadUserSettings(this.loadUpdatableAssets.bind(this)); this.getBytesInUse(); }; diff --git a/js/ublock.js b/js/ublock.js index cce9aa5..fe158ba 100644 --- a/js/ublock.js +++ b/js/ublock.js @@ -34,7 +34,7 @@ domain = this.URI.domainFromHostname(keyHostname); } if ( !domain ) { - return false; + return true; } var exceptions = this.netWhitelist[domain]; |