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

Add support for ping static filter option

Related issue:
- https://github.com/gorhill/uBlock/issues/1493

Documentation:
- https://help.eyeo.com/adblockplus/how-to-write-filters#type-options

Test page:
- https://testpages.adblockplus.org/en/filters/ping

Additionally, network requests of type `beacon` will
be mapped to `ping` by the static filtering engine.
This commit is contained in:
Raymond Hill 2019-09-22 09:11:55 -04:00
parent 22b390eb00
commit 010635acd6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 70 additions and 88 deletions

View File

@ -66,14 +66,6 @@
let type = details.type; let type = details.type;
// https://github.com/gorhill/uBlock/issues/1493
// Chromium 49+/WebExtensions support a new request type: `ping`,
// which is fired as a result of using `navigator.sendBeacon`.
if ( type === 'ping' ) {
details.type = 'beacon';
return;
}
if ( type === 'imageset' ) { if ( type === 'imageset' ) {
details.type = 'image'; details.type = 'image';
return; return;

View File

@ -72,14 +72,6 @@
const type = details.type; const type = details.type;
// https://github.com/gorhill/uBlock/issues/1493
// Chromium 49+/WebExtensions support a new request type: `ping`,
// which is fired as a result of using `navigator.sendBeacon`.
if ( type === 'ping' ) {
details.type = 'beacon';
return;
}
if ( type === 'imageset' ) { if ( type === 'imageset' ) {
details.type = 'image'; details.type = 'image';
return; return;

View File

@ -140,8 +140,8 @@ const µBlock = (( ) => { // jshint ignore:line
// Read-only // Read-only
systemSettings: { systemSettings: {
compiledMagic: 20, // Increase when compiled format changes compiledMagic: 21, // Increase when compiled format changes
selfieMagic: 20, // Increase when selfie format changes selfieMagic: 21, // Increase when selfie format changes
}, },
restoreBackupSettings: { restoreBackupSettings: {

View File

@ -1089,13 +1089,11 @@ const reloadTab = function(ev) {
const reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/; const reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
const reSchemeOnly = /^[\w-]+:$/; const reSchemeOnly = /^[\w-]+:$/;
const staticFilterTypes = { const staticFilterTypes = {
'beacon': 'other', 'beacon': 'ping',
'doc': 'document', 'doc': 'document',
'css': 'stylesheet', 'css': 'stylesheet',
'frame': 'subdocument', 'frame': 'subdocument',
'ping': 'other',
'object_subrequest': 'object', 'object_subrequest': 'object',
'xhr': 'xmlhttprequest'
}; };
const createdStaticFilters = {}; const createdStaticFilters = {};
@ -1182,7 +1180,7 @@ const reloadTab = function(ev) {
value = selectValue('select.static.origin'); value = selectValue('select.static.origin');
if ( value !== '' ) { if ( value !== '' ) {
if ( value === targetDomain ) { if ( value === targetDomain ) {
options.push('first-party'); options.push('1p');
} else { } else {
options.push('domain=' + value); options.push('domain=' + value);
} }

View File

@ -63,18 +63,20 @@ const typeNameToTypeValue = {
'font': 7 << 4, 'font': 7 << 4,
'media': 8 << 4, 'media': 8 << 4,
'websocket': 9 << 4, 'websocket': 9 << 4,
'other': 10 << 4, 'beacon': 10 << 4,
'popup': 11 << 4, // start of behavorial filtering 'ping': 10 << 4,
'popunder': 12 << 4, 'other': 11 << 4,
'main_frame': 13 << 4, // start of 1st-party-only behavorial filtering 'popup': 12 << 4, // start of behavorial filtering
'generichide': 14 << 4, 'popunder': 13 << 4,
'specifichide': 15 << 4, 'main_frame': 14 << 4, // start of 1st-party-only behavorial filtering
'inline-font': 16 << 4, 'generichide': 15 << 4,
'inline-script': 17 << 4, 'specifichide': 16 << 4,
'data': 18 << 4, // special: a generic data holder 'inline-font': 17 << 4,
'redirect': 19 << 4, 'inline-script': 18 << 4,
'webrtc': 20 << 4, 'data': 19 << 4, // special: a generic data holder
'unsupported': 21 << 4, 'redirect': 20 << 4,
'webrtc': 21 << 4,
'unsupported': 22 << 4,
}; };
const otherTypeBitValue = typeNameToTypeValue.other; const otherTypeBitValue = typeNameToTypeValue.other;
@ -106,18 +108,54 @@ const typeValueToTypeName = {
7: 'font', 7: 'font',
8: 'media', 8: 'media',
9: 'websocket', 9: 'websocket',
10: 'other', 10: 'ping',
11: 'popup', 11: 'other',
12: 'popunder', 12: 'popup',
13: 'document', 13: 'popunder',
14: 'generichide', 14: 'document',
15: 'specifichide', 15: 'generichide',
16: 'inline-font', 16: 'specifichide',
17: 'inline-script', 17: 'inline-font',
18: 'data', 18: 'inline-script',
19: 'redirect', 19: 'data',
20: 'webrtc', 20: 'redirect',
21: 'unsupported' 21: 'webrtc',
22: 'unsupported',
};
// https://github.com/gorhill/uBlock/issues/1493
// Transpose `ping` into `other` for now.
const toNormalizedType = {
'all': 'all',
'beacon': 'ping',
'css': 'stylesheet',
'data': 'data',
'doc': 'main_frame',
'document': 'main_frame',
'font': 'font',
'frame': 'sub_frame',
'genericblock': 'unsupported',
'generichide': 'generichide',
'ghide': 'generichide',
'image': 'image',
'inline-font': 'inline-font',
'inline-script': 'inline-script',
'media': 'media',
'object': 'object',
'object-subrequest': 'object',
'other': 'other',
'ping': 'ping',
'popunder': 'popunder',
'popup': 'popup',
'script': 'script',
'specifichide': 'specifichide',
'shide': 'specifichide',
'stylesheet': 'stylesheet',
'subdocument': 'sub_frame',
'xhr': 'xmlhttprequest',
'xmlhttprequest': 'xmlhttprequest',
'webrtc': 'unsupported',
'websocket': 'websocket',
}; };
const BlockImportant = BlockAction | Important; const BlockImportant = BlockAction | Important;
@ -239,9 +277,9 @@ const toLogDataInternal = function(categoryBits, tokenHash, filter) {
opts.push('important'); opts.push('important');
} }
if ( categoryBits & 0x008 ) { if ( categoryBits & 0x008 ) {
opts.push('third-party'); opts.push('3p');
} else if ( categoryBits & 0x004 ) { } else if ( categoryBits & 0x004 ) {
opts.push('first-party'); opts.push('1p');
} }
const type = categoryBits & 0x1F0; const type = categoryBits & 0x1F0;
if ( type !== 0 && type !== typeNameToTypeValue.data ) { if ( type !== 0 && type !== typeNameToTypeValue.data ) {
@ -1840,44 +1878,6 @@ const FilterParser = function() {
/******************************************************************************/ /******************************************************************************/
// https://github.com/gorhill/uBlock/issues/1493
// Transpose `ping` into `other` for now.
FilterParser.prototype.toNormalizedType = {
'all': 'all',
'beacon': 'other',
'css': 'stylesheet',
'data': 'data',
'doc': 'main_frame',
'document': 'main_frame',
'font': 'font',
'frame': 'sub_frame',
'genericblock': 'unsupported',
'generichide': 'generichide',
'ghide': 'generichide',
'image': 'image',
'inline-font': 'inline-font',
'inline-script': 'inline-script',
'media': 'media',
'object': 'object',
'object-subrequest': 'object',
'other': 'other',
'ping': 'other',
'popunder': 'popunder',
'popup': 'popup',
'script': 'script',
'specifichide': 'specifichide',
'shide': 'specifichide',
'stylesheet': 'stylesheet',
'subdocument': 'sub_frame',
'xhr': 'xmlhttprequest',
'xmlhttprequest': 'xmlhttprequest',
'webrtc': 'unsupported',
'websocket': 'websocket',
};
/******************************************************************************/
FilterParser.prototype.reset = function() { FilterParser.prototype.reset = function() {
this.action = BlockAction; this.action = BlockAction;
this.anchor = 0; this.anchor = 0;
@ -1919,7 +1919,7 @@ FilterParser.prototype.bitFromType = function(type) {
FilterParser.prototype.parseTypeOption = function(raw, not) { FilterParser.prototype.parseTypeOption = function(raw, not) {
const typeBit = raw !== 'all' const typeBit = raw !== 'all'
? this.bitFromType(this.toNormalizedType[raw]) ? this.bitFromType(toNormalizedType[raw])
: allTypesBits; : allTypesBits;
if ( not ) { if ( not ) {
@ -1978,7 +1978,7 @@ FilterParser.prototype.parseOptions = function(s) {
this.parsePartyOption(true, not); this.parsePartyOption(true, not);
continue; continue;
} }
if ( this.toNormalizedType.hasOwnProperty(opt) ) { if ( toNormalizedType.hasOwnProperty(opt) ) {
this.parseTypeOption(opt, not); this.parseTypeOption(opt, not);
continue; continue;
} }