mirror of https://github.com/gorhill/uBlock.git
this fixes #249
This commit is contained in:
parent
2fee965257
commit
17838883da
|
@ -89,7 +89,7 @@ return {
|
|||
firstUpdateAfter: 5 * oneMinute,
|
||||
nextUpdateAfter: 7 * oneHour,
|
||||
|
||||
selfieMagic: 'imktayytaizj',
|
||||
selfieMagic: 'clegcrcjvuzg',
|
||||
selfieAfter: 7 * oneMinute,
|
||||
|
||||
pageStores: {},
|
||||
|
|
|
@ -54,14 +54,15 @@ const ThirdParty = 2 << 2;
|
|||
|
||||
const AnyType = 1 << 4;
|
||||
var typeNameToTypeValue = {
|
||||
'stylesheet': 2 << 4,
|
||||
'image': 3 << 4,
|
||||
'object': 4 << 4,
|
||||
'script': 5 << 4,
|
||||
'xmlhttprequest': 6 << 4,
|
||||
'sub_frame': 7 << 4,
|
||||
'other': 8 << 4,
|
||||
'popup': 9 << 4
|
||||
'stylesheet': 2 << 4,
|
||||
'image': 3 << 4,
|
||||
'object': 4 << 4,
|
||||
'script': 5 << 4,
|
||||
'xmlhttprequest': 6 << 4,
|
||||
'sub_frame': 7 << 4,
|
||||
'other': 8 << 4,
|
||||
'inline-script': 14 << 4,
|
||||
'popup': 15 << 4
|
||||
};
|
||||
|
||||
const BlockAnyTypeAnyParty = BlockAction | AnyType | AnyParty;
|
||||
|
@ -1066,6 +1067,7 @@ FilterParser.prototype.toNormalizedType = {
|
|||
'xmlhttprequest': 'xmlhttprequest',
|
||||
'subdocument': 'sub_frame',
|
||||
'other': 'other',
|
||||
'inline-script': 'inline-script',
|
||||
'popup': 'popup'
|
||||
};
|
||||
|
||||
|
@ -1095,12 +1097,19 @@ FilterParser.prototype.parseOptType = function(raw, not) {
|
|||
var type = this.toNormalizedType[raw];
|
||||
if ( not ) {
|
||||
for ( var k in typeNameToTypeValue ) {
|
||||
if ( k === type ) { continue; }
|
||||
if ( typeNameToTypeValue.hasOwnProperty(k) === false ) {
|
||||
continue;
|
||||
}
|
||||
if ( k === type ) {
|
||||
continue;
|
||||
}
|
||||
// https://github.com/gorhill/uBlock/issues/121
|
||||
// `popup` is a special type, it cannot be set for filters intended
|
||||
// for real net request types. The test is safe since there is no
|
||||
// such thing as a filter using `~popup`.
|
||||
if ( k === 'popup' ) { continue; }
|
||||
if ( typeNameToTypeValue[k] > typeNameToTypeValue['other'] ) {
|
||||
continue;
|
||||
}
|
||||
this.types.push(typeNameToTypeValue[k]);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -279,6 +279,52 @@ var cr410382Workaround = function(details) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
// To handle `inline-script`.
|
||||
|
||||
var onHeadersReceived = function(details) {
|
||||
// Only root document.
|
||||
if ( details.parentFrameId !== -1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not interfere with behind-the-scene requests.
|
||||
var tabId = details.tabId;
|
||||
if ( tabId < 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Lookup the page store associated with this tab id.
|
||||
var µb = µBlock;
|
||||
var pageStore = µb.pageStoreFromTabId(tabId);
|
||||
if ( !pageStore ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var result = '';
|
||||
if ( pageStore.getNetFilteringSwitch() ) {
|
||||
result = µb.netFilteringEngine.matchStringExactType(pageStore, details.url, 'inline-script');
|
||||
}
|
||||
|
||||
// Not blocked?
|
||||
if ( result === '' || result.slice(0, 2) === '@@' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Blocked
|
||||
pageStore.perLoadBlockedRequestCount++;
|
||||
µb.localSettings.blockedRequestCount++;
|
||||
µb.updateBadgeAsync(tabId);
|
||||
|
||||
details.responseHeaders.push({
|
||||
'name': 'Content-Security-Policy',
|
||||
'value': "script-src *"
|
||||
});
|
||||
|
||||
return { 'responseHeaders': details.responseHeaders };
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var headerValue = function(headers, name) {
|
||||
var i = headers.length;
|
||||
while ( i-- ) {
|
||||
|
@ -338,6 +384,20 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
|
|||
[ "blocking", "requestHeaders" ]
|
||||
);
|
||||
|
||||
chrome.webRequest.onHeadersReceived.addListener(
|
||||
onHeadersReceived,
|
||||
{
|
||||
"urls": [
|
||||
"http://*/*",
|
||||
"https://*/*",
|
||||
],
|
||||
"types": [
|
||||
"main_frame"
|
||||
]
|
||||
},
|
||||
[ "blocking", "responseHeaders" ]
|
||||
);
|
||||
|
||||
console.log('µBlock> Beginning to intercept net requests at %s', (new Date()).toISOString());
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue