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