diff --git a/css/noop.css b/css/noop.css new file mode 100644 index 000000000..e69de29bb diff --git a/img/noop.png b/img/noop.png new file mode 100644 index 000000000..37c28e7fe Binary files /dev/null and b/img/noop.png differ diff --git a/js/abp-filters.js b/js/abp-filters.js index c1e9d238a..4f6eeda04 100644 --- a/js/abp-filters.js +++ b/js/abp-filters.js @@ -1376,7 +1376,7 @@ FilterContainer.prototype.match3rdPartyHostname = function(requestHostname) { /******************************************************************************/ -FilterContainer.prototype.matchString = function(pageStore, url, requestType, requestHostname) { +FilterContainer.prototype.matchString = function(pageDetails, url, requestType, requestHostname) { // adbProfiler.countUrl(); // https://github.com/gorhill/httpswitchboard/issues/239 @@ -1397,7 +1397,7 @@ FilterContainer.prototype.matchString = function(pageStore, url, requestType, re // This helps performance compared to testing against both classes of // filters in the same loop. - var pageDomain = pageStore.pageDomain || ''; + var pageDomain = pageDetails.pageDomain || ''; var party = requestHostname.slice(-pageDomain.length) === pageDomain ? FirstParty : ThirdParty; @@ -1405,9 +1405,6 @@ FilterContainer.prototype.matchString = function(pageStore, url, requestType, re var type = typeNameToTypeValue[requestType]; var categories = this.categories; - // This will be used by hostname-based filters - pageHostname = pageStore.pageHostname || ''; - // Test hostname-based block filters var bf = false; bf = this.matchAnyPartyHostname(requestHostname); @@ -1415,6 +1412,9 @@ FilterContainer.prototype.matchString = function(pageStore, url, requestType, re bf = this.match3rdPartyHostname(requestHostname); } + // This will be used by hostname-based filters + pageHostname = pageDetails.pageHostname || ''; + // Test against block filters if ( bf === false ) { this.bucket0 = categories[this.makeCategoryKey(BlockAnyTypeAnyParty)]; diff --git a/js/background.js b/js/background.js index cd414bc78..0ef8e0327 100644 --- a/js/background.js +++ b/js/background.js @@ -42,6 +42,7 @@ return { updateAssetsEvery: 5 * 24 * 60 * 60 * 1000, projectServerRoot: 'https://raw2.github.com/gorhill/ublock/master/', + userFiltersPath: 'assets/user/filters.txt', // list of remote blacklist locations remoteBlacklists: { @@ -59,8 +60,6 @@ return { // Power switch to disengage µBlock off: false, - userFiltersPath: 'assets/user/filters.txt', - storageQuota: chrome.storage.local.QUOTA_BYTES, storageUsed: 0, diff --git a/js/noop.js b/js/noop.js new file mode 100644 index 000000000..092bc2b04 --- /dev/null +++ b/js/noop.js @@ -0,0 +1 @@ +; diff --git a/js/traffic.js b/js/traffic.js index b931a48a0..f4d95ae30 100644 --- a/js/traffic.js +++ b/js/traffic.js @@ -30,31 +30,40 @@ /******************************************************************************/ +var typeToRedirectPathMap = { + 'stylesheet': chrome.runtime.getURL('css/noop.css'), + 'image': chrome.runtime.getURL('img/noop.png'), + 'script': chrome.runtime.getURL('js/noop.js'), + 'sub_frame': 'about:blank' +}; + +/******************************************************************************/ + // Intercept and filter web requests according to white and black lists. var onBeforeRequestHandler = function(details) { - var requestType = details.type; - // console.debug('onBeforeRequestHandler()> "%s": %o', details.url, details); // Do not block behind the scene requests. - if ( details.tabId < 0 ) { - return; - } - - // Never block root main doc. - if ( requestType === 'main_frame' && details.parentFrameId < 0 ) { + var tabId = details.tabId; + if ( tabId < 0 ) { return; } var µb = µBlock; + var requestType = details.type; + + // Never block root main doc. + if ( requestType === 'main_frame' && details.parentFrameId < 0 ) { + µb.bindTabToPageStats(tabId, details.url); + return; + } + var µburi = µb.URI; var requestURL = µburi.set(details.url).normalizedURI(); - var requestScheme = µburi.scheme; - var requestHostname = µburi.hostname; - var requestPath = µburi.path; // Ignore non-http schemes + var requestScheme = µburi.scheme; if ( requestScheme.indexOf('http') !== 0 ) { return; } @@ -64,6 +73,9 @@ var onBeforeRequestHandler = function(details) { return; } + var requestHostname = µburi.hostname; + var requestPath = µburi.path; + // rhill 2013-12-15: // Try to transpose generic `other` category into something more // meaningful. @@ -72,27 +84,29 @@ var onBeforeRequestHandler = function(details) { } // Lookup the page store associated with this tab id. - var pageStore = µb.pageStoreFromTabId(details.tabId) || {}; + var pageStore = µb.pageStoreFromTabId(tabId) || {}; var reason = false; if ( µb.getNetFilteringSwitch(pageStore.pageHostname) ) { reason = µb.abpFilters.matchString(pageStore, requestURL, requestType, requestHostname); } + // Record what happened. + if ( pageStore ) { + pageStore.recordRequest(requestType, requestURL, reason); + } - // Block using ABP filters? - pageStore.recordRequest(requestType, requestURL, reason); - - // whitelisted? + // Not blocked? if ( reason === false ) { return; } - // blacklisted + // Blocked // console.debug('onBeforeRequestHandler()> BLOCK "%s": %o', details.url, details); - // If it's a blacklisted frame, redirect to something harmless. - if ( requestType === 'sub_frame' ) { - return { 'redirectUrl': 'about:blank' }; + // Redirect to noop versions whenever possible. + var redirectPath = typeToRedirectPathMap[requestType]; + if ( redirectPath ) { + return { 'redirectUrl': redirectPath }; } return { 'cancel': true }; diff --git a/manifest.json b/manifest.json index 974e177cc..b9ff0dcf8 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extName__", "short_name": "µBlock", - "version": "0.1.0.5", + "version": "0.1.0.6", "description": "__MSG_extShortDesc__", "icons": { "16": "img/icon_16.png", @@ -48,5 +48,10 @@ "webRequestBlocking", "http://*/*", "https://*/*" + ], + "web_accessible_resources": [ + "css/noop.css", + "img/noop.png", + "js/noop.js" ] }