mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-01 08:39:37 +02:00
this should fix #1276
This commit is contained in:
parent
264b15f319
commit
1f345b585f
@ -834,37 +834,34 @@ vAPI.net.registerListeners = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var normalizeRequestDetails = function(details) {
|
var normalizeRequestDetails = function(details) {
|
||||||
µburi.set(details.url);
|
|
||||||
|
|
||||||
details.tabId = details.tabId.toString();
|
details.tabId = details.tabId.toString();
|
||||||
details.hostname = µburi.hostnameFromURI(details.url);
|
|
||||||
|
|
||||||
// The rest of the function code is to normalize type
|
// The rest of the function code is to normalize type
|
||||||
if ( details.type !== 'other' ) {
|
if ( details.type !== 'other' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tail = µburi.path.slice(-6);
|
var path = µburi.pathFromURI(details.url);
|
||||||
var pos = tail.lastIndexOf('.');
|
var pos = path.indexOf('.', path.length - 6);
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/862
|
// https://github.com/chrisaljoudi/uBlock/issues/862
|
||||||
// If no transposition possible, transpose to `object` as per
|
// If no transposition possible, transpose to `object` as per
|
||||||
// Chromium bug 410382 (see below)
|
// Chromium bug 410382 (see below)
|
||||||
if ( pos !== -1 ) {
|
if ( pos !== -1 ) {
|
||||||
var ext = tail.slice(pos) + '.';
|
var needle = path.slice(pos) + '.';
|
||||||
if ( '.eot.ttf.otf.svg.woff.woff2.'.indexOf(ext) !== -1 ) {
|
if ( '.eot.ttf.otf.svg.woff.woff2.'.indexOf(needle) !== -1 ) {
|
||||||
details.type = 'font';
|
details.type = 'font';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( '.mp3.mp4.webm.'.indexOf(ext) !== -1 ) {
|
if ( '.mp3.mp4.webm.'.indexOf(needle) !== -1 ) {
|
||||||
details.type = 'media';
|
details.type = 'media';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still need this because often behind-the-scene requests are wrongly
|
// Still need this because often behind-the-scene requests are wrongly
|
||||||
// categorized as 'other'
|
// categorized as 'other'
|
||||||
if ( '.ico.png.gif.jpg.jpeg.webp.'.indexOf(ext) !== -1 ) {
|
if ( '.ico.png.gif.jpg.jpeg.webp.'.indexOf(needle) !== -1 ) {
|
||||||
details.type = 'image';
|
details.type = 'image';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2022,15 +2022,8 @@ var httpObserver = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/966
|
|
||||||
var hostname = URI.asciiHost;
|
|
||||||
if ( hostname.endsWith('.') ) {
|
|
||||||
hostname = hostname.slice(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = this.onBeforeRequest({
|
var result = this.onBeforeRequest({
|
||||||
frameId: details.frameId,
|
frameId: details.frameId,
|
||||||
hostname: hostname,
|
|
||||||
parentFrameId: details.parentFrameId,
|
parentFrameId: details.parentFrameId,
|
||||||
tabId: details.tabId,
|
tabId: details.tabId,
|
||||||
type: type,
|
type: type,
|
||||||
@ -2084,14 +2077,7 @@ var httpObserver = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/966
|
|
||||||
var hostname = URI.asciiHost;
|
|
||||||
if ( hostname.endsWith('.') ) {
|
|
||||||
hostname = hostname.slice(0, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = this.onHeadersReceived({
|
var result = this.onHeadersReceived({
|
||||||
hostname: hostname,
|
|
||||||
parentFrameId: channelData[1],
|
parentFrameId: channelData[1],
|
||||||
responseHeaders: responseHeaders,
|
responseHeaders: responseHeaders,
|
||||||
tabId: channelData[2],
|
tabId: channelData[2],
|
||||||
|
@ -38,9 +38,6 @@ var exports = {};
|
|||||||
// Intercept and filter web requests.
|
// Intercept and filter web requests.
|
||||||
|
|
||||||
var onBeforeRequest = function(details) {
|
var onBeforeRequest = function(details) {
|
||||||
//console.debug('µBlock.webRequest/onBeforeRequest(): "%s": %o', details.url, details);
|
|
||||||
//console.debug('µBlock.webRequest/onBeforeRequest(): "type=%s, id=%d, parent id=%d, url=%s', details.type, details.frameId, details.parentFrameId, details.url);
|
|
||||||
|
|
||||||
// Special handling for root document.
|
// Special handling for root document.
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/1001
|
// https://github.com/chrisaljoudi/uBlock/issues/1001
|
||||||
// This must be executed regardless of whether the request is
|
// This must be executed regardless of whether the request is
|
||||||
@ -84,7 +81,7 @@ var onBeforeRequest = function(details) {
|
|||||||
// Setup context and evaluate
|
// Setup context and evaluate
|
||||||
var requestURL = details.url;
|
var requestURL = details.url;
|
||||||
requestContext.requestURL = requestURL;
|
requestContext.requestURL = requestURL;
|
||||||
requestContext.requestHostname = details.hostname;
|
requestContext.requestHostname = µb.URI.hostnameFromURI(requestURL);
|
||||||
requestContext.requestType = requestType;
|
requestContext.requestType = requestType;
|
||||||
|
|
||||||
var result = pageStore.filterRequest(requestContext);
|
var result = pageStore.filterRequest(requestContext);
|
||||||
@ -107,8 +104,6 @@ var onBeforeRequest = function(details) {
|
|||||||
|
|
||||||
// Not blocked
|
// Not blocked
|
||||||
if ( µb.isAllowResult(result) ) {
|
if ( µb.isAllowResult(result) ) {
|
||||||
//console.debug('traffic.js > onBeforeRequest(): ALLOW "%s" (%o) because "%s"', details.url, details, result);
|
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/114
|
// https://github.com/chrisaljoudi/uBlock/issues/114
|
||||||
frameId = details.frameId;
|
frameId = details.frameId;
|
||||||
if ( frameId > 0 ) {
|
if ( frameId > 0 ) {
|
||||||
@ -123,7 +118,6 @@ var onBeforeRequest = function(details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Blocked
|
// Blocked
|
||||||
//console.debug('traffic.js > onBeforeRequest(): BLOCK "%s" (%o) because "%s"', details.url, details, result);
|
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/905#issuecomment-76543649
|
// https://github.com/chrisaljoudi/uBlock/issues/905#issuecomment-76543649
|
||||||
// No point updating the badge if it's not being displayed.
|
// No point updating the badge if it's not being displayed.
|
||||||
@ -165,8 +159,9 @@ var onBeforeRootFrameRequest = function(details) {
|
|||||||
// https://github.com/chrisaljoudi/uBlock/issues/1001
|
// https://github.com/chrisaljoudi/uBlock/issues/1001
|
||||||
// This must be executed regardless of whether the request is
|
// This must be executed regardless of whether the request is
|
||||||
// behind-the-scene
|
// behind-the-scene
|
||||||
var requestHostname = details.hostname;
|
var µburi = µb.URI;
|
||||||
var requestDomain = µb.URI.domainFromHostname(requestHostname) || requestHostname;
|
var requestHostname = µburi.hostnameFromURI(requestURL);
|
||||||
|
var requestDomain = µburi.domainFromHostname(requestHostname) || requestHostname;
|
||||||
var context = {
|
var context = {
|
||||||
rootHostname: requestHostname,
|
rootHostname: requestHostname,
|
||||||
rootDomain: requestDomain,
|
rootDomain: requestDomain,
|
||||||
@ -286,8 +281,6 @@ var toBlockDocResult = function(url, hostname, result) {
|
|||||||
// Intercept and filter behind-the-scene requests.
|
// Intercept and filter behind-the-scene requests.
|
||||||
|
|
||||||
var onBeforeBehindTheSceneRequest = function(details) {
|
var onBeforeBehindTheSceneRequest = function(details) {
|
||||||
//console.debug('traffic.js > onBeforeBehindTheSceneRequest(): "%s": %o', details.url, details);
|
|
||||||
|
|
||||||
var µb = µBlock;
|
var µb = µBlock;
|
||||||
var pageStore = µb.pageStoreFromTabId(vAPI.noTabId);
|
var pageStore = µb.pageStoreFromTabId(vAPI.noTabId);
|
||||||
if ( !pageStore ) {
|
if ( !pageStore ) {
|
||||||
@ -295,8 +288,9 @@ var onBeforeBehindTheSceneRequest = function(details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var context = pageStore.createContextFromPage();
|
var context = pageStore.createContextFromPage();
|
||||||
context.requestURL = details.url;
|
var requestURL = details.url;
|
||||||
context.requestHostname = details.hostname;
|
context.requestURL = requestURL;
|
||||||
|
context.requestHostname = µb.URI.hostnameFromURI(requestURL);
|
||||||
context.requestType = details.type;
|
context.requestType = details.type;
|
||||||
|
|
||||||
// Blocking behind-the-scene requests can break a lot of stuff: prevent
|
// Blocking behind-the-scene requests can break a lot of stuff: prevent
|
||||||
@ -316,7 +310,7 @@ var onBeforeBehindTheSceneRequest = function(details) {
|
|||||||
'net',
|
'net',
|
||||||
result,
|
result,
|
||||||
details.type,
|
details.type,
|
||||||
details.url,
|
requestURL,
|
||||||
context.rootHostname,
|
context.rootHostname,
|
||||||
context.rootHostname
|
context.rootHostname
|
||||||
);
|
);
|
||||||
@ -324,13 +318,10 @@ var onBeforeBehindTheSceneRequest = function(details) {
|
|||||||
|
|
||||||
// Not blocked
|
// Not blocked
|
||||||
if ( µb.isAllowResult(result) ) {
|
if ( µb.isAllowResult(result) ) {
|
||||||
//console.debug('traffic.js > onBeforeBehindTheSceneRequest(): ALLOW "%s" (%o) because "%s"', details.url, details, result);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blocked
|
// Blocked
|
||||||
//console.debug('traffic.js > onBeforeBehindTheSceneRequest(): BLOCK "%s" (%o) because "%s"', details.url, details, result);
|
|
||||||
|
|
||||||
return { 'cancel': true };
|
return { 'cancel': true };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -367,8 +358,9 @@ var onHeadersReceived = function(details) {
|
|||||||
var onRootFrameHeadersReceived = function(details) {
|
var onRootFrameHeadersReceived = function(details) {
|
||||||
var µb = µBlock;
|
var µb = µBlock;
|
||||||
var tabId = details.tabId;
|
var tabId = details.tabId;
|
||||||
|
var requestURL = details.url;
|
||||||
|
|
||||||
µb.tabContextManager.push(tabId, details.url);
|
µb.tabContextManager.push(tabId, requestURL);
|
||||||
|
|
||||||
// Lookup the page store associated with this tab id.
|
// Lookup the page store associated with this tab id.
|
||||||
var pageStore = µb.pageStoreFromTabId(tabId);
|
var pageStore = µb.pageStoreFromTabId(tabId);
|
||||||
@ -378,8 +370,8 @@ var onRootFrameHeadersReceived = function(details) {
|
|||||||
// I can't think of how pageStore could be null at this point.
|
// I can't think of how pageStore could be null at this point.
|
||||||
|
|
||||||
var context = pageStore.createContextFromPage();
|
var context = pageStore.createContextFromPage();
|
||||||
context.requestURL = details.url;
|
context.requestURL = requestURL;
|
||||||
context.requestHostname = details.hostname;
|
context.requestHostname = µb.URI.hostnameFromURI(requestURL);
|
||||||
context.requestType = 'inline-script';
|
context.requestType = 'inline-script';
|
||||||
|
|
||||||
var result = pageStore.filterRequestNoCache(context);
|
var result = pageStore.filterRequestNoCache(context);
|
||||||
@ -392,7 +384,7 @@ var onRootFrameHeadersReceived = function(details) {
|
|||||||
'net',
|
'net',
|
||||||
result,
|
result,
|
||||||
'inline-script',
|
'inline-script',
|
||||||
details.url,
|
requestURL,
|
||||||
context.rootHostname,
|
context.rootHostname,
|
||||||
context.pageHostname
|
context.pageHostname
|
||||||
);
|
);
|
||||||
@ -423,8 +415,9 @@ var onFrameHeadersReceived = function(details) {
|
|||||||
// Frame id of frame request is their own id, while the request is made
|
// Frame id of frame request is their own id, while the request is made
|
||||||
// in the context of the parent.
|
// in the context of the parent.
|
||||||
var context = pageStore.createContextFromFrameId(details.parentFrameId);
|
var context = pageStore.createContextFromFrameId(details.parentFrameId);
|
||||||
context.requestURL = details.url;
|
var requestURL = details.url;
|
||||||
context.requestHostname = details.hostname;
|
context.requestURL = requestURL;
|
||||||
|
context.requestHostname = µb.URI.hostnameFromURI(requestURL);
|
||||||
context.requestType = 'inline-script';
|
context.requestType = 'inline-script';
|
||||||
|
|
||||||
var result = pageStore.filterRequestNoCache(context);
|
var result = pageStore.filterRequestNoCache(context);
|
||||||
@ -437,7 +430,7 @@ var onFrameHeadersReceived = function(details) {
|
|||||||
'net',
|
'net',
|
||||||
result,
|
result,
|
||||||
'inline-script',
|
'inline-script',
|
||||||
details.url,
|
requestURL,
|
||||||
context.rootHostname,
|
context.rootHostname,
|
||||||
context.pageHostname
|
context.pageHostname
|
||||||
);
|
);
|
||||||
|
@ -50,6 +50,7 @@ var reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
|
|||||||
var reSchemeFromURI = /^[^:\/?#]+:/;
|
var reSchemeFromURI = /^[^:\/?#]+:/;
|
||||||
var reAuthorityFromURI = /^(?:[^:\/?#]+:)?(\/\/[^\/?#]+)/;
|
var reAuthorityFromURI = /^(?:[^:\/?#]+:)?(\/\/[^\/?#]+)/;
|
||||||
var reCommonHostnameFromURL = /^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//;
|
var reCommonHostnameFromURL = /^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//;
|
||||||
|
var rePathFromURI = /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?([^?#]*)/;
|
||||||
|
|
||||||
// These are to parse authority field, not parsed by above official regex
|
// These are to parse authority field, not parsed by above official regex
|
||||||
// IPv6 is seen as an exception: a non-compatible IPv6 is first tried, and
|
// IPv6 is seen as an exception: a non-compatible IPv6 is first tried, and
|
||||||
@ -303,6 +304,13 @@ var psl = publicSuffixList;
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
URI.pathFromURI = function(uri) {
|
||||||
|
var matches = rePathFromURI.exec(uri);
|
||||||
|
return matches !== null ? matches[1] : '';
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// Trying to alleviate the worries of looking up too often the domain name from
|
// Trying to alleviate the worries of looking up too often the domain name from
|
||||||
// a hostname. With a cache, uBlock benefits given that it deals with a
|
// a hostname. With a cache, uBlock benefits given that it deals with a
|
||||||
// specific set of hostnames within a narrow time span -- in other words, I
|
// specific set of hostnames within a narrow time span -- in other words, I
|
||||||
|
Loading…
Reference in New Issue
Block a user