1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 01:27:12 +02:00

this addresses #7, #11

This commit is contained in:
gorhill 2014-06-24 21:46:37 -04:00
parent a908f20fe6
commit 4d98233814
7 changed files with 47 additions and 28 deletions

0
css/noop.css Normal file
View File

BIN
img/noop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 B

View File

@ -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)];

View File

@ -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,

1
js/noop.js Normal file
View File

@ -0,0 +1 @@
;

View File

@ -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 };

View File

@ -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"
]
}