Skip to content

Commit 19f8b30

Browse files
committed
New network filter option: to=[list of domain names]
Related discussion: - uBlockOrigin/uBlock-issues#2412 (comment) The new option is `to=` and the value is a list of domain list with similar syntax as `domain=` option. Entity-based syntax is supported, and also negated hostname. The main motivation is to give uBO's static network filtering engine with an equivalent of DNR's `requestDomains` and `excludedRequestDomains`. Essentially `to=` is a superset of `denyallow=`, but for now I decided against deprecating `denyallow=`, which still does not support entity- based syntax and for which negated domains are not allowed. This commit also introduces the `from=` option, which is just an alias for the `domain=` option. The logger will render network filters using the `from=` version.
1 parent 84aa217 commit 19f8b30

File tree

3 files changed

+460
-343
lines changed

3 files changed

+460
-343
lines changed

src/js/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ const µBlock = { // jshint ignore:line
176176

177177
// Read-only
178178
systemSettings: {
179-
compiledMagic: 51, // Increase when compiled format changes
180-
selfieMagic: 51, // Increase when selfie format changes
179+
compiledMagic: 52, // Increase when compiled format changes
180+
selfieMagic: 52, // Increase when selfie format changes
181181
},
182182

183183
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501

src/js/static-filtering-parser.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,11 +2348,11 @@ const OPTTokenCsp = 8;
23482348
const OPTTokenCss = 9;
23492349
const OPTTokenDenyAllow = 10;
23502350
const OPTTokenDoc = 11;
2351-
const OPTTokenDomain = 12;
2352-
const OPTTokenEhide = 13;
2353-
const OPTTokenEmpty = 14;
2354-
const OPTTokenFont = 15;
2355-
const OPTTokenFrame = 16;
2351+
const OPTTokenEhide = 12;
2352+
const OPTTokenEmpty = 13;
2353+
const OPTTokenFont = 14;
2354+
const OPTTokenFrame = 15;
2355+
const OPTTokenFrom = 16;
23562356
const OPTTokenGenericblock = 17;
23572357
const OPTTokenGhide = 18;
23582358
const OPTTokenHeader = 19;
@@ -2374,11 +2374,12 @@ const OPTTokenRedirectRule = 34;
23742374
const OPTTokenRemoveparam = 35;
23752375
const OPTTokenScript = 36;
23762376
const OPTTokenShide = 37;
2377-
const OPTTokenXhr = 38;
2378-
const OPTTokenWebrtc = 39;
2379-
const OPTTokenWebsocket = 40;
2380-
const OPTTokenMethod = 41;
2381-
const OPTTokenCount = 42;
2377+
const OPTTokenTo = 38;
2378+
const OPTTokenXhr = 39;
2379+
const OPTTokenWebrtc = 40;
2380+
const OPTTokenWebsocket = 41;
2381+
const OPTTokenMethod = 42;
2382+
const OPTTokenCount = 43;
23822383

23832384
//const OPTPerOptionMask = 0x0000ff00;
23842385
const OPTCanNegate = 1 << 8;
@@ -2449,12 +2450,14 @@ Parser.prototype.OPTTokenAll = OPTTokenAll;
24492450
Parser.prototype.OPTTokenBadfilter = OPTTokenBadfilter;
24502451
Parser.prototype.OPTTokenCname = OPTTokenCname;
24512452
Parser.prototype.OPTTokenCsp = OPTTokenCsp;
2453+
Parser.prototype.OPTTokenCss = OPTTokenCss;
24522454
Parser.prototype.OPTTokenDenyAllow = OPTTokenDenyAllow;
24532455
Parser.prototype.OPTTokenDoc = OPTTokenDoc;
2454-
Parser.prototype.OPTTokenDomain = OPTTokenDomain;
24552456
Parser.prototype.OPTTokenEhide = OPTTokenEhide;
24562457
Parser.prototype.OPTTokenEmpty = OPTTokenEmpty;
24572458
Parser.prototype.OPTTokenFont = OPTTokenFont;
2459+
Parser.prototype.OPTTokenFrame = OPTTokenFrame;
2460+
Parser.prototype.OPTTokenFrom = OPTTokenFrom;
24582461
Parser.prototype.OPTTokenGenericblock = OPTTokenGenericblock;
24592462
Parser.prototype.OPTTokenGhide = OPTTokenGhide;
24602463
Parser.prototype.OPTTokenHeader = OPTTokenHeader;
@@ -2477,8 +2480,7 @@ Parser.prototype.OPTTokenRedirect = OPTTokenRedirect;
24772480
Parser.prototype.OPTTokenRedirectRule = OPTTokenRedirectRule;
24782481
Parser.prototype.OPTTokenScript = OPTTokenScript;
24792482
Parser.prototype.OPTTokenShide = OPTTokenShide;
2480-
Parser.prototype.OPTTokenCss = OPTTokenCss;
2481-
Parser.prototype.OPTTokenFrame = OPTTokenFrame;
2483+
Parser.prototype.OPTTokenTo = OPTTokenTo;
24822484
Parser.prototype.OPTTokenXhr = OPTTokenXhr;
24832485
Parser.prototype.OPTTokenWebrtc = OPTTokenWebrtc;
24842486
Parser.prototype.OPTTokenWebsocket = OPTTokenWebsocket;
@@ -2512,12 +2514,13 @@ const netOptionTokenDescriptors = new Map([
25122514
[ 'denyallow', OPTTokenDenyAllow | OPTMustAssign | OPTDomainList | OPTNeedDomainOpt | OPTNonCspableType ],
25132515
[ 'doc', OPTTokenDoc | OPTNetworkType | OPTCanNegate | OPTModifiableType | OPTRedirectableType ],
25142516
/* synonym */ [ 'document', OPTTokenDoc | OPTNetworkType | OPTCanNegate | OPTModifiableType | OPTRedirectableType ],
2515-
[ 'domain', OPTTokenDomain | OPTMustAssign | OPTDomainList ],
25162517
[ 'ehide', OPTTokenEhide | OPTNonNetworkType | OPTNonCspableType | OPTNonRedirectableType ],
25172518
/* synonym */ [ 'elemhide', OPTTokenEhide | OPTNonNetworkType | OPTNonCspableType | OPTNonRedirectableType ],
25182519
[ 'empty', OPTTokenEmpty | OPTBlockOnly | OPTModifierType ],
25192520
[ 'frame', OPTTokenFrame | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTRedirectableType ],
25202521
/* synonym */ [ 'subdocument', OPTTokenFrame | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTRedirectableType ],
2522+
[ 'from', OPTTokenFrom | OPTMustAssign | OPTDomainList ],
2523+
/* synonym */ [ 'domain', OPTTokenFrom | OPTMustAssign | OPTDomainList ],
25212524
[ 'font', OPTTokenFont | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTNonCspableType ],
25222525
[ 'genericblock', OPTTokenGenericblock | OPTNotSupported ],
25232526
[ 'ghide', OPTTokenGhide | OPTNonNetworkType | OPTNonCspableType | OPTNonRedirectableType ],
@@ -2547,6 +2550,7 @@ const netOptionTokenDescriptors = new Map([
25472550
[ 'script', OPTTokenScript | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTRedirectableType | OPTNonCspableType ],
25482551
[ 'shide', OPTTokenShide | OPTNonNetworkType | OPTNonCspableType | OPTNonRedirectableType ],
25492552
/* synonym */ [ 'specifichide', OPTTokenShide | OPTNonNetworkType | OPTNonCspableType | OPTNonRedirectableType ],
2553+
[ 'to', OPTTokenTo | OPTMustAssign | OPTDomainList ],
25502554
[ 'xhr', OPTTokenXhr | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTRedirectableType | OPTNonCspableType ],
25512555
/* synonym */ [ 'xmlhttprequest', OPTTokenXhr | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTRedirectableType | OPTNonCspableType ],
25522556
[ 'webrtc', OPTTokenWebrtc | OPTNotSupported ],
@@ -2572,7 +2576,8 @@ Parser.netOptionTokenIds = new Map([
25722576
[ 'denyallow', OPTTokenDenyAllow ],
25732577
[ 'doc', OPTTokenDoc ],
25742578
/* synonym */ [ 'document', OPTTokenDoc ],
2575-
[ 'domain', OPTTokenDomain ],
2579+
[ 'from', OPTTokenFrom ],
2580+
/* synonym */ [ 'domain', OPTTokenFrom ],
25762581
[ 'ehide', OPTTokenEhide ],
25772582
/* synonym */ [ 'elemhide', OPTTokenEhide ],
25782583
[ 'empty', OPTTokenEmpty ],
@@ -2625,11 +2630,11 @@ Parser.netOptionTokenNames = new Map([
26252630
[ OPTTokenCss, 'stylesheet' ],
26262631
[ OPTTokenDenyAllow, 'denyallow' ],
26272632
[ OPTTokenDoc, 'document' ],
2628-
[ OPTTokenDomain, 'domain' ],
26292633
[ OPTTokenEhide, 'elemhide' ],
26302634
[ OPTTokenEmpty, 'empty' ],
26312635
[ OPTTokenFrame, 'subdocument' ],
26322636
[ OPTTokenFont, 'font' ],
2637+
[ OPTTokenFrom, 'from' ],
26332638
[ OPTTokenGenericblock, 'genericblock' ],
26342639
[ OPTTokenGhide, 'generichide' ],
26352640
[ OPTTokenHeader, 'header' ],
@@ -2652,6 +2657,7 @@ Parser.netOptionTokenNames = new Map([
26522657
[ OPTTokenRedirectRule, 'redirect-rule' ],
26532658
[ OPTTokenScript, 'script' ],
26542659
[ OPTTokenShide, 'specifichide' ],
2660+
[ OPTTokenTo, 'to' ],
26552661
[ OPTTokenXhr, 'xmlhttprequest' ],
26562662
[ OPTTokenWebrtc, 'webrtc' ],
26572663
[ OPTTokenWebsocket, 'websocket' ],
@@ -2802,7 +2808,7 @@ const NetOptionsIterator = class {
28022808
if ( this.interactive && hasBits(descriptor, OPTDomainList) ) {
28032809
this.parser.analyzeDomainList(
28042810
lval + 3, i, BITPipe,
2805-
tokenId === OPTTokenDomain ? 0b1010 : 0b0000
2811+
tokenId === OPTTokenDenyAllow ? 0b0000 : 0b1010
28062812
);
28072813
}
28082814
} else {
@@ -2825,7 +2831,7 @@ const NetOptionsIterator = class {
28252831
// `denyallow=` option requires `domain=` option.
28262832
{
28272833
const i = this.tokenPos[OPTTokenDenyAllow];
2828-
if ( i !== -1 && this.tokenPos[OPTTokenDomain] === -1 ) {
2834+
if ( i !== -1 && this.tokenPos[OPTTokenFrom] === -1 ) {
28292835
optSlices[i] = OPTTokenInvalid;
28302836
if ( this.interactive ) {
28312837
this.parser.errorSlices(optSlices[i+1], optSlices[i+5]);

0 commit comments

Comments
 (0)