Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rebase, rename to ScriptFilter, ignore element hiding exceptions Created May 23, 2018, 3:54 a.m.
Right Patch Set: Improve comment formatting Created July 11, 2018, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/filterListener.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 }; 78 };
79 79
80 /** 80 /**
81 * Cache for known filters, maps string representation to filter objects. 81 * Cache for known filters, maps string representation to filter objects.
82 * @type {Map.<string,Filter>} 82 * @type {Map.<string,Filter>}
83 */ 83 */
84 Filter.knownFilters = new Map(); 84 Filter.knownFilters = new Map();
85 85
86 /** 86 /**
87 * Regular expression that script filters should match 87 * Regular expression that content filters should match
88 * @type {RegExp} 88 * @type {RegExp}
89 */ 89 */
90 Filter.scriptRegExp = /^([^/*|@"!]*?)#([@?$])?#(.+)$/; 90 Filter.contentRegExp = /^([^/*|@"!]*?)#([@?$])?#(.+)$/;
91 /** 91 /**
92 * Regular expression that RegExp filters specified as RegExps should match 92 * Regular expression that RegExp filters specified as RegExps should match
93 * @type {RegExp} 93 * @type {RegExp}
94 */ 94 */
95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/;
96 /** 96 /**
97 * Regular expression that options on a RegExp filter should match 97 * Regular expression that options on a RegExp filter should match
98 * @type {RegExp} 98 * @type {RegExp}
99 */ 99 */
100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$/; 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,]+)?(?:,~?[\w-]+(?:=[^,]+)?)*)$/;
101 /** 101 /**
102 * Regular expression that matches an invalid Content Security Policy 102 * Regular expression that matches an invalid Content Security Policy
103 * @type {RegExp} 103 * @type {RegExp}
104 */ 104 */
105 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i; 105 Filter.invalidCSPRegExp = /(;|^) ?(base-uri|referrer|report-to|report-uri|upgrad e-insecure-requests)\b/i;
106 106
107 /** 107 /**
108 * Creates a filter of correct type from its text representation - does the 108 * Creates a filter of correct type from its text representation - does the
109 * basic parsing and calls the right constructor then. 109 * basic parsing and calls the right constructor then.
110 * 110 *
111 * @param {string} text as in Filter() 111 * @param {string} text as in Filter()
112 * @return {Filter} 112 * @return {Filter}
113 */ 113 */
114 Filter.fromText = function(text) 114 Filter.fromText = function(text)
115 { 115 {
116 let filter = Filter.knownFilters.get(text); 116 let filter = Filter.knownFilters.get(text);
117 if (filter) 117 if (filter)
118 return filter; 118 return filter;
119 119
120 let match = text.includes("#") ? Filter.scriptRegExp.exec(text) : null; 120 let match = text.includes("#") ? Filter.contentRegExp.exec(text) : null;
121 if (match) 121 if (match)
122 { 122 {
123 let propsMatch; 123 let propsMatch;
124 if (!match[2] && 124 if (!match[2] &&
125 (propsMatch = /\[-abp-properties=(["'])([^"']+)\1\]/.exec(match[3]))) 125 (propsMatch = /\[-abp-properties=(["'])([^"']+)\1\]/.exec(match[3])))
126 { 126 {
127 // This is legacy CSS properties syntax, convert to current syntax 127 // This is legacy CSS properties syntax, convert to current syntax
128 let prefix = match[3].substr(0, propsMatch.index); 128 let prefix = match[3].substr(0, propsMatch.index);
129 let expression = propsMatch[2]; 129 let expression = propsMatch[2];
130 let suffix = match[3].substr(propsMatch.index + propsMatch[0].length); 130 let suffix = match[3].substr(propsMatch.index + propsMatch[0].length);
131 return Filter.fromText(`${match[1]}#?#` + 131 return Filter.fromText(`${match[1]}#?#` +
132 `${prefix}:-abp-properties(${expression})${suffix}`); 132 `${prefix}:-abp-properties(${expression})${suffix}`);
133 } 133 }
134 134
135 if (match[2] == "$") 135 filter = ContentFilter.fromText(text, match[1], match[2], match[3]);
136 filter = new SnippetFilter(text, match[1], match[3]);
137 else
138 filter = ElemHideBase.fromText(text, match[1], match[2], match[3]);
139 } 136 }
140 else if (text[0] == "!") 137 else if (text[0] == "!")
141 filter = new CommentFilter(text); 138 filter = new CommentFilter(text);
142 else 139 else
143 filter = RegExpFilter.fromText(text); 140 filter = RegExpFilter.fromText(text);
144 141
145 Filter.knownFilters.set(filter.text, filter); 142 Filter.knownFilters.set(filter.text, filter);
146 return filter; 143 return filter;
147 }; 144 };
148 145
(...skipping 29 matching lines...) Expand all
178 if (!text) 175 if (!text)
179 return text; 176 return text;
180 177
181 // Remove line breaks, tabs etc 178 // Remove line breaks, tabs etc
182 text = text.replace(/[^\S ]+/g, ""); 179 text = text.replace(/[^\S ]+/g, "");
183 180
184 // Don't remove spaces inside comments 181 // Don't remove spaces inside comments
185 if (/^ *!/.test(text)) 182 if (/^ *!/.test(text))
186 return text.trim(); 183 return text.trim();
187 184
188 // Special treatment for script filters, right side is allowed to contain 185 // Special treatment for content filters, right side is allowed to contain
189 // spaces 186 // spaces
190 if (Filter.scriptRegExp.test(text)) 187 if (Filter.contentRegExp.test(text))
191 { 188 {
192 let [, domains, separator, script] = /^(.*?)(#[@?$]?#?)(.*)$/.exec(text); 189 let [, domains, separator, body] = /^(.*?)(#[@?$]?#?)(.*)$/.exec(text);
193 return domains.replace(/ +/g, "") + separator + script.trim(); 190 return domains.replace(/ +/g, "") + separator + body.trim();
194 } 191 }
195 192
196 // For most regexp filters we strip all spaces, but $csp filter options 193 // For most regexp filters we strip all spaces, but $csp filter options
197 // are allowed to contain single (non trailing) spaces. 194 // are allowed to contain single (non trailing) spaces.
198 let strippedText = text.replace(/ +/g, ""); 195 let strippedText = text.replace(/ +/g, "");
199 if (!strippedText.includes("$") || !/\bcsp=/i.test(strippedText)) 196 if (!strippedText.includes("$") || !/\bcsp=/i.test(strippedText))
200 return strippedText; 197 return strippedText;
201 198
202 let optionsMatch = Filter.optionsRegExp.exec(strippedText); 199 let optionsMatch = Filter.optionsRegExp.exec(strippedText);
203 if (!optionsMatch) 200 if (!optionsMatch)
(...skipping 30 matching lines...) Expand all
234 return beforeOptions + "$" + options.join(); 231 return beforeOptions + "$" + options.join();
235 }; 232 };
236 233
237 /** 234 /**
238 * @see filterToRegExp 235 * @see filterToRegExp
239 */ 236 */
240 Filter.toRegExp = filterToRegExp; 237 Filter.toRegExp = filterToRegExp;
241 238
242 /** 239 /**
243 * Class for invalid filters 240 * Class for invalid filters
244 * @param {string} text see Filter() 241 * @param {string} text see {@link Filter Filter()}
245 * @param {string} reason Reason why this filter is invalid 242 * @param {string} reason Reason why this filter is invalid
246 * @constructor 243 * @constructor
247 * @augments Filter 244 * @augments Filter
248 */ 245 */
249 function InvalidFilter(text, reason) 246 function InvalidFilter(text, reason)
250 { 247 {
251 Filter.call(this, text); 248 Filter.call(this, text);
252 249
253 this.reason = reason; 250 this.reason = reason;
254 } 251 }
(...skipping 10 matching lines...) Expand all
265 262
266 /** 263 /**
267 * See Filter.serialize() 264 * See Filter.serialize()
268 * @inheritdoc 265 * @inheritdoc
269 */ 266 */
270 serialize(buffer) {} 267 serialize(buffer) {}
271 }); 268 });
272 269
273 /** 270 /**
274 * Class for comments 271 * Class for comments
275 * @param {string} text see Filter() 272 * @param {string} text see {@link Filter Filter()}
276 * @constructor 273 * @constructor
277 * @augments Filter 274 * @augments Filter
278 */ 275 */
279 function CommentFilter(text) 276 function CommentFilter(text)
280 { 277 {
281 Filter.call(this, text); 278 Filter.call(this, text);
282 } 279 }
283 exports.CommentFilter = CommentFilter; 280 exports.CommentFilter = CommentFilter;
284 281
285 CommentFilter.prototype = extend(Filter, { 282 CommentFilter.prototype = extend(Filter, {
286 type: "comment", 283 type: "comment",
287 284
288 /** 285 /**
289 * See Filter.serialize() 286 * See Filter.serialize()
290 * @inheritdoc 287 * @inheritdoc
291 */ 288 */
292 serialize(buffer) {} 289 serialize(buffer) {}
293 }); 290 });
294 291
295 /** 292 /**
296 * Abstract base class for filters that can get hits 293 * Abstract base class for filters that can get hits
297 * @param {string} text 294 * @param {string} text
298 * see Filter() 295 * see {@link Filter Filter()}
299 * @param {string} [domains] 296 * @param {string} [domains]
300 * Domains that the filter is restricted to separated by domainSeparator 297 * Domains that the filter is restricted to separated by domainSeparator
301 * e.g. "foo.com|bar.com|~baz.com" 298 * e.g. "foo.com|bar.com|~baz.com"
302 * @constructor 299 * @constructor
303 * @augments Filter 300 * @augments Filter
304 */ 301 */
305 function ActiveFilter(text, domains) 302 function ActiveFilter(text, domains)
306 { 303 {
307 Filter.call(this, text); 304 Filter.call(this, text);
308 305
309 this.domainSource = domains; 306 if (domains)
307 this.domainSource = domains;
310 } 308 }
311 exports.ActiveFilter = ActiveFilter; 309 exports.ActiveFilter = ActiveFilter;
312 310
313 ActiveFilter.prototype = extend(Filter, { 311 ActiveFilter.prototype = extend(Filter, {
314 _disabled: false, 312 _disabled: false,
315 _hitCount: 0, 313 _hitCount: 0,
316 _lastHit: 0, 314 _lastHit: 0,
317 315
318 /** 316 /**
319 * Defines whether the filter is disabled 317 * Defines whether the filter is disabled
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 domainSource: null, 378 domainSource: null,
381 379
382 /** 380 /**
383 * Separator character used in domainSource property, must be 381 * Separator character used in domainSource property, must be
384 * overridden by subclasses 382 * overridden by subclasses
385 * @type {string} 383 * @type {string}
386 */ 384 */
387 domainSeparator: null, 385 domainSeparator: null,
388 386
389 /** 387 /**
390 * Determines whether the trailing dot in domain names isn't important and 388 * Determines whether domainSource is already lower-case,
391 * should be ignored, must be overridden by subclasses.
392 * @type {boolean}
393 */
394 ignoreTrailingDot: true,
395
396 /**
397 * Determines whether domainSource is already upper-case,
398 * can be overridden by subclasses. 389 * can be overridden by subclasses.
399 * @type {boolean} 390 * @type {boolean}
400 */ 391 */
401 domainSourceIsUpperCase: false, 392 domainSourceIsLowerCase: false,
402 393
403 /** 394 /**
404 * Map containing domains that this filter should match on/not match 395 * Map containing domains that this filter should match on/not match
405 * on or null if the filter should match on all domains 396 * on or null if the filter should match on all domains
406 * @type {?Map.<string,boolean>} 397 * @type {?Map.<string,boolean>}
407 */ 398 */
408 get domains() 399 get domains()
409 { 400 {
410 // Despite this property being cached, the getter is called 401 let prop = Object.getOwnPropertyDescriptor(this, "_domains");
411 // several times on Safari, due to WebKit bug 132872
412 let prop = Object.getOwnPropertyDescriptor(this, "domains");
413 if (prop) 402 if (prop)
414 return prop.value; 403 {
404 let {value} = prop;
405 return typeof value == "string" ?
406 new Map([[value, true], ["", false]]) : value;
407 }
415 408
416 let domains = null; 409 let domains = null;
417 410
418 if (this.domainSource) 411 if (this.domainSource)
419 { 412 {
420 let source = this.domainSource; 413 let source = this.domainSource;
421 if (!this.domainSourceIsUpperCase) 414 if (!this.domainSourceIsLowerCase)
422 { 415 {
423 // RegExpFilter already have uppercase domains 416 // RegExpFilter already have lowercase domains
424 source = source.toUpperCase(); 417 source = source.toLowerCase();
425 } 418 }
426 let list = source.split(this.domainSeparator); 419 let list = source.split(this.domainSeparator);
427 if (list.length == 1 && list[0][0] != "~") 420 if (list.length == 1 && list[0][0] != "~")
428 { 421 {
429 // Fast track for the common one-domain scenario 422 // Fast track for the common one-domain scenario
430 if (this.ignoreTrailingDot) 423 domains = list[0];
431 list[0] = list[0].replace(/\.+$/, "");
432 domains = new Map([["", false], [list[0], true]]);
433 } 424 }
434 else 425 else
435 { 426 {
436 let hasIncludes = false; 427 let hasIncludes = false;
437 for (let i = 0; i < list.length; i++) 428 for (let i = 0; i < list.length; i++)
438 { 429 {
439 let domain = list[i]; 430 let domain = list[i];
440 if (this.ignoreTrailingDot)
441 domain = domain.replace(/\.+$/, "");
442 if (domain == "") 431 if (domain == "")
443 continue; 432 continue;
444 433
445 let include; 434 let include;
446 if (domain[0] == "~") 435 if (domain[0] == "~")
447 { 436 {
448 include = false; 437 include = false;
449 domain = domain.substr(1); 438 domain = domain.substr(1);
450 } 439 }
451 else 440 else
452 { 441 {
453 include = true; 442 include = true;
454 hasIncludes = true; 443 hasIncludes = true;
455 } 444 }
456 445
457 if (!domains) 446 if (!domains)
458 domains = new Map(); 447 domains = new Map();
459 448
460 domains.set(domain, include); 449 domains.set(domain, include);
461 } 450 }
462 if (domains) 451 if (domains)
463 domains.set("", !hasIncludes); 452 domains.set("", !hasIncludes);
464 } 453 }
465 454
466 this.domainSource = null; 455 this.domainSource = null;
467 } 456 }
468 457
469 Object.defineProperty(this, "domains", {value: domains, enumerable: true}); 458 Object.defineProperty(this, "_domains", {value: domains});
470 return this.domains; 459 return this.domains;
471 }, 460 },
472 461
473 /** 462 /**
474 * Array containing public keys of websites that this filter should apply to 463 * Array containing public keys of websites that this filter should apply to
475 * @type {?string[]} 464 * @type {?string[]}
476 */ 465 */
477 sitekeys: null, 466 sitekeys: null,
478 467
479 /** 468 /**
(...skipping 15 matching lines...) Expand all
495 484
496 // If no domains are set the rule matches everywhere 485 // If no domains are set the rule matches everywhere
497 if (!this.domains) 486 if (!this.domains)
498 return true; 487 return true;
499 488
500 // If the document has no host name, match only if the filter 489 // If the document has no host name, match only if the filter
501 // isn't restricted to specific domains 490 // isn't restricted to specific domains
502 if (!docDomain) 491 if (!docDomain)
503 return this.domains.get(""); 492 return this.domains.get("");
504 493
505 if (this.ignoreTrailingDot) 494 docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
506 docDomain = docDomain.replace(/\.+$/, "");
507 docDomain = docDomain.toUpperCase();
508 495
509 while (true) 496 while (true)
510 { 497 {
511 let isDomainIncluded = this.domains.get(docDomain); 498 let isDomainIncluded = this.domains.get(docDomain);
512 if (typeof isDomainIncluded != "undefined") 499 if (typeof isDomainIncluded != "undefined")
513 return isDomainIncluded; 500 return isDomainIncluded;
514 501
515 let nextDot = docDomain.indexOf("."); 502 let nextDot = docDomain.indexOf(".");
516 if (nextDot < 0) 503 if (nextDot < 0)
517 break; 504 break;
518 docDomain = docDomain.substr(nextDot + 1); 505 docDomain = docDomain.substr(nextDot + 1);
519 } 506 }
520 return this.domains.get(""); 507 return this.domains.get("");
521 }, 508 },
522 509
523 /** 510 /**
524 * Checks whether this filter is active only on a domain and its subdomains. 511 * Checks whether this filter is active only on a domain and its subdomains.
525 * @param {string} docDomain 512 * @param {string} docDomain
526 * @return {boolean} 513 * @return {boolean}
527 */ 514 */
528 isActiveOnlyOnDomain(docDomain) 515 isActiveOnlyOnDomain(docDomain)
529 { 516 {
530 if (!docDomain || !this.domains || this.domains.get("")) 517 if (!docDomain || !this.domains || this.domains.get(""))
531 return false; 518 return false;
532 519
533 if (this.ignoreTrailingDot) 520 docDomain = docDomain.replace(/\.+$/, "").toLowerCase();
534 docDomain = docDomain.replace(/\.+$/, "");
535 docDomain = docDomain.toUpperCase();
536 521
537 for (let [domain, isIncluded] of this.domains) 522 for (let [domain, isIncluded] of this.domains)
538 { 523 {
539 if (isIncluded && domain != docDomain) 524 if (isIncluded && domain != docDomain)
540 { 525 {
541 if (domain.length <= docDomain.length) 526 if (domain.length <= docDomain.length)
542 return false; 527 return false;
543 528
544 if (!domain.endsWith("." + docDomain)) 529 if (!domain.endsWith("." + docDomain))
545 return false; 530 return false;
(...skipping 27 matching lines...) Expand all
573 if (this._hitCount) 558 if (this._hitCount)
574 buffer.push("hitCount=" + this._hitCount); 559 buffer.push("hitCount=" + this._hitCount);
575 if (this._lastHit) 560 if (this._lastHit)
576 buffer.push("lastHit=" + this._lastHit); 561 buffer.push("lastHit=" + this._lastHit);
577 } 562 }
578 } 563 }
579 }); 564 });
580 565
581 /** 566 /**
582 * Abstract base class for RegExp-based filters 567 * Abstract base class for RegExp-based filters
583 * @param {string} text see Filter() 568 * @param {string} text see {@link Filter Filter()}
584 * @param {string} regexpSource 569 * @param {string} regexpSource
585 * filter part that the regular expression should be build from 570 * filter part that the regular expression should be build from
586 * @param {number} [contentType] 571 * @param {number} [contentType]
587 * Content types the filter applies to, combination of values from 572 * Content types the filter applies to, combination of values from
588 * RegExpFilter.typeMap 573 * RegExpFilter.typeMap
589 * @param {boolean} [matchCase] 574 * @param {boolean} [matchCase]
590 * Defines whether the filter should distinguish between lower and upper case 575 * Defines whether the filter should distinguish between lower and upper case
591 * letters 576 * letters
592 * @param {string} [domains] 577 * @param {string} [domains]
593 * Domains that the filter is restricted to, e.g. "foo.com|bar.com|~baz.com" 578 * Domains that the filter is restricted to, e.g. "foo.com|bar.com|~baz.com"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 else 611 else
627 { 612 {
628 // No need to convert this filter to regular expression yet, do it on demand 613 // No need to convert this filter to regular expression yet, do it on demand
629 this.regexpSource = regexpSource; 614 this.regexpSource = regexpSource;
630 } 615 }
631 } 616 }
632 exports.RegExpFilter = RegExpFilter; 617 exports.RegExpFilter = RegExpFilter;
633 618
634 RegExpFilter.prototype = extend(ActiveFilter, { 619 RegExpFilter.prototype = extend(ActiveFilter, {
635 /** 620 /**
636 * @see ActiveFilter.domainSourceIsUpperCase 621 * @see ActiveFilter.domainSourceIsLowerCase
637 */ 622 */
638 domainSourceIsUpperCase: true, 623 domainSourceIsLowerCase: true,
639 624
640 /** 625 /**
641 * Number of filters contained, will always be 1 (required to 626 * Number of filters contained, will always be 1 (required to
642 * optimize Matcher). 627 * optimize Matcher).
643 * @type {number} 628 * @type {number}
644 */ 629 */
645 length: 1, 630 length: 1,
646 631
647 /** 632 /**
648 * @see ActiveFilter.domainSeparator 633 * @see ActiveFilter.domainSeparator
649 */ 634 */
650 domainSeparator: "|", 635 domainSeparator: "|",
651 636
652 /** 637 /**
653 * Expression from which a regular expression should be generated - 638 * Expression from which a regular expression should be generated -
654 * for delayed creation of the regexp property 639 * for delayed creation of the regexp property
655 * @type {string} 640 * @type {string}
656 */ 641 */
657 regexpSource: null, 642 regexpSource: null,
658 /** 643 /**
659 * Regular expression to be used when testing against this filter 644 * Regular expression to be used when testing against this filter
660 * @type {RegExp} 645 * @type {RegExp}
661 */ 646 */
662 get regexp() 647 get regexp()
663 { 648 {
664 // Despite this property being cached, the getter is called
665 // several times on Safari, due to WebKit bug 132872
666 let prop = Object.getOwnPropertyDescriptor(this, "regexp");
667 if (prop)
668 return prop.value;
669
670 let source = Filter.toRegExp(this.regexpSource); 649 let source = Filter.toRegExp(this.regexpSource);
671 let regexp = new RegExp(source, this.matchCase ? "" : "i"); 650 let regexp = new RegExp(source, this.matchCase ? "" : "i");
672 Object.defineProperty(this, "regexp", {value: regexp}); 651 Object.defineProperty(this, "regexp", {value: regexp});
652 this.regexpSource = null;
673 return regexp; 653 return regexp;
674 }, 654 },
675 /** 655 /**
676 * Content types the filter applies to, combination of values from 656 * Content types the filter applies to, combination of values from
677 * RegExpFilter.typeMap 657 * RegExpFilter.typeMap
678 * @type {number} 658 * @type {number}
679 */ 659 */
680 contentType: 0x7FFFFFFF, 660 contentType: 0x7FFFFFFF,
681 /** 661 /**
682 * Defines whether the filter should distinguish between lower and 662 * Defines whether the filter should distinguish between lower and
(...skipping 12 matching lines...) Expand all
695 * String that the sitekey property should be generated from 675 * String that the sitekey property should be generated from
696 * @type {?string} 676 * @type {?string}
697 */ 677 */
698 sitekeySource: null, 678 sitekeySource: null,
699 679
700 /** 680 /**
701 * @see ActiveFilter.sitekeys 681 * @see ActiveFilter.sitekeys
702 */ 682 */
703 get sitekeys() 683 get sitekeys()
704 { 684 {
705 // Despite this property being cached, the getter is called
706 // several times on Safari, due to WebKit bug 132872
707 let prop = Object.getOwnPropertyDescriptor(this, "sitekeys");
708 if (prop)
709 return prop.value;
710
711 let sitekeys = null; 685 let sitekeys = null;
712 686
713 if (this.sitekeySource) 687 if (this.sitekeySource)
714 { 688 {
715 sitekeys = this.sitekeySource.split("|"); 689 sitekeys = this.sitekeySource.split("|");
716 this.sitekeySource = null; 690 this.sitekeySource = null;
717 } 691 }
718 692
719 Object.defineProperty( 693 Object.defineProperty(
720 this, "sitekeys", {value: sitekeys, enumerable: true} 694 this, "sitekeys", {value: sitekeys, enumerable: true}
(...skipping 30 matching lines...) Expand all
751 725
752 /** 726 /**
753 * Creates a RegExp filter from its text representation 727 * Creates a RegExp filter from its text representation
754 * @param {string} text same as in Filter() 728 * @param {string} text same as in Filter()
755 * @return {Filter} 729 * @return {Filter}
756 */ 730 */
757 RegExpFilter.fromText = function(text) 731 RegExpFilter.fromText = function(text)
758 { 732 {
759 let blocking = true; 733 let blocking = true;
760 let origText = text; 734 let origText = text;
761 if (text.indexOf("@@") == 0) 735 if (text[0] == "@" && text[1] == "@")
762 { 736 {
763 blocking = false; 737 blocking = false;
764 text = text.substr(2); 738 text = text.substr(2);
765 } 739 }
766 740
767 let contentType = null; 741 let contentType = null;
768 let matchCase = null; 742 let matchCase = null;
769 let domains = null; 743 let domains = null;
770 let sitekeys = null; 744 let sitekeys = null;
771 let thirdParty = null; 745 let thirdParty = null;
772 let collapse = null; 746 let collapse = null;
773 let csp = null; 747 let csp = null;
774 let rewrite = null; 748 let rewrite = null;
775 let options; 749 let options;
776 let match = (text.indexOf("$") >= 0 ? Filter.optionsRegExp.exec(text) : null); 750 let match = text.includes("$") ? Filter.optionsRegExp.exec(text) : null;
777 if (match) 751 if (match)
778 { 752 {
779 options = match[1].split(","); 753 options = match[1].split(",");
780 text = match.input.substr(0, match.index); 754 text = match.input.substr(0, match.index);
781 for (let option of options) 755 for (let option of options)
782 { 756 {
783 let value = null; 757 let value = null;
784 let separatorIndex = option.indexOf("="); 758 let separatorIndex = option.indexOf("=");
785 if (separatorIndex >= 0) 759 if (separatorIndex >= 0)
786 { 760 {
787 value = option.substr(separatorIndex + 1); 761 value = option.substr(separatorIndex + 1);
788 option = option.substr(0, separatorIndex); 762 option = option.substr(0, separatorIndex);
789 } 763 }
790 option = option.replace(/-/, "_").toUpperCase(); 764
791 if (option in RegExpFilter.typeMap) 765 let inverse = option[0] == "~";
766 if (inverse)
767 option = option.substr(1);
768
769 let type = RegExpFilter.typeMap[option.replace(/-/, "_").toUpperCase()];
770 if (type)
792 { 771 {
793 if (contentType == null) 772 if (inverse)
794 contentType = 0; 773 {
795 contentType |= RegExpFilter.typeMap[option]; 774 if (contentType == null)
796 775 ({contentType} = RegExpFilter.prototype);
797 if (option == "CSP" && value) 776 contentType &= ~type;
798 csp = value; 777 }
778 else
779 {
780 contentType |= type;
781
782 if (type == RegExpFilter.typeMap.CSP && value)
783 csp = value;
784 }
799 } 785 }
800 else if (option[0] == "~" && option.substr(1) in RegExpFilter.typeMap) 786 else
801 { 787 {
802 if (contentType == null) 788 switch (option.toLowerCase())
803 ({contentType} = RegExpFilter.prototype); 789 {
804 contentType &= ~RegExpFilter.typeMap[option.substr(1)]; 790 case "match-case":
791 matchCase = !inverse;
792 break;
793 case "domain":
794 if (!value)
795 return new InvalidFilter(origText, "filter_unknown_option");
796 domains = value.toLowerCase();
797 break;
798 case "third-party":
799 thirdParty = !inverse;
800 break;
801 case "collapse":
802 collapse = !inverse;
803 break;
804 case "sitekey":
805 if (!value)
806 return new InvalidFilter(origText, "filter_unknown_option");
807 sitekeys = value.toUpperCase();
808 break;
809 case "rewrite":
810 if (!value)
811 return new InvalidFilter(origText, "filter_unknown_option");
812 rewrite = value;
813 break;
814 default:
815 return new InvalidFilter(origText, "filter_unknown_option");
816 }
805 } 817 }
806 else if (option == "MATCH_CASE") 818 }
807 matchCase = true; 819 }
808 else if (option == "~MATCH_CASE") 820
809 matchCase = false; 821 // For security reasons, never match $rewrite filters
810 else if (option == "DOMAIN" && value) 822 // against requests that might load any code to be executed.
811 domains = value.toUpperCase(); 823 if (rewrite != null)
812 else if (option == "THIRD_PARTY") 824 {
813 thirdParty = true; 825 if (contentType == null)
814 else if (option == "~THIRD_PARTY") 826 ({contentType} = RegExpFilter.prototype);
815 thirdParty = false; 827 contentType &= ~(RegExpFilter.typeMap.SCRIPT |
816 else if (option == "COLLAPSE") 828 RegExpFilter.typeMap.SUBDOCUMENT |
817 collapse = true; 829 RegExpFilter.typeMap.OBJECT |
818 else if (option == "~COLLAPSE") 830 RegExpFilter.typeMap.OBJECT_SUBREQUEST);
819 collapse = false;
820 else if (option == "SITEKEY" && value)
821 sitekeys = value.toUpperCase();
822 else if (option == "REWRITE" && value)
823 rewrite = value;
824 else
825 return new InvalidFilter(origText, "filter_unknown_option");
826 }
827 } 831 }
828 832
829 try 833 try
830 { 834 {
831 if (blocking) 835 if (blocking)
832 { 836 {
833 if (csp && Filter.invalidCSPRegExp.test(csp)) 837 if (csp && Filter.invalidCSPRegExp.test(csp))
834 return new InvalidFilter(origText, "filter_invalid_csp"); 838 return new InvalidFilter(origText, "filter_invalid_csp");
835 839
836 return new BlockingFilter(origText, text, contentType, matchCase, domains, 840 return new BlockingFilter(origText, text, contentType, matchCase, domains,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 // shouldn't be there by default 883 // shouldn't be there by default
880 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.CSP | 884 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.CSP |
881 RegExpFilter.typeMap.DOCUMENT | 885 RegExpFilter.typeMap.DOCUMENT |
882 RegExpFilter.typeMap.ELEMHIDE | 886 RegExpFilter.typeMap.ELEMHIDE |
883 RegExpFilter.typeMap.POPUP | 887 RegExpFilter.typeMap.POPUP |
884 RegExpFilter.typeMap.GENERICHIDE | 888 RegExpFilter.typeMap.GENERICHIDE |
885 RegExpFilter.typeMap.GENERICBLOCK); 889 RegExpFilter.typeMap.GENERICBLOCK);
886 890
887 /** 891 /**
888 * Class for blocking filters 892 * Class for blocking filters
889 * @param {string} text see Filter() 893 * @param {string} text see {@link Filter Filter()}
890 * @param {string} regexpSource see RegExpFilter() 894 * @param {string} regexpSource see {@link RegExpFilter RegExpFilter()}
891 * @param {number} [contentType] see RegExpFilter() 895 * @param {number} [contentType] see {@link RegExpFilter RegExpFilter()}
892 * @param {boolean} [matchCase] see RegExpFilter() 896 * @param {boolean} [matchCase] see {@link RegExpFilter RegExpFilter()}
893 * @param {string} [domains] see RegExpFilter() 897 * @param {string} [domains] see {@link RegExpFilter RegExpFilter()}
894 * @param {boolean} [thirdParty] see RegExpFilter() 898 * @param {boolean} [thirdParty] see {@link RegExpFilter RegExpFilter()}
895 * @param {string} [sitekeys] see RegExpFilter() 899 * @param {string} [sitekeys] see {@link RegExpFilter RegExpFilter()}
896 * @param {boolean} [collapse] 900 * @param {boolean} [collapse]
897 * defines whether the filter should collapse blocked content, can be null 901 * defines whether the filter should collapse blocked content, can be null
898 * @param {string} [csp] 902 * @param {string} [csp]
899 * Content Security Policy to inject when the filter matches 903 * Content Security Policy to inject when the filter matches
900 * @param {?string} [rewrite] 904 * @param {?string} [rewrite]
901 * The (optional) rule specifying how to rewrite the URL. See 905 * The (optional) rule specifying how to rewrite the URL. See
902 * BlockingFilter.prototype.rewrite. 906 * BlockingFilter.prototype.rewrite.
903 * @constructor 907 * @constructor
904 * @augments RegExpFilter 908 * @augments RegExpFilter
905 */ 909 */
906 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, 910 function BlockingFilter(text, regexpSource, contentType, matchCase, domains,
907 thirdParty, sitekeys, collapse, csp, rewrite) 911 thirdParty, sitekeys, collapse, csp, rewrite)
908 { 912 {
909 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, 913 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
910 thirdParty, sitekeys); 914 thirdParty, sitekeys);
911 915
912 this.collapse = collapse; 916 if (collapse != null)
913 this.csp = csp; 917 this.collapse = collapse;
914 this.rewrite = rewrite; 918
919 if (csp != null)
920 this.csp = csp;
921
922 if (rewrite != null)
923 this.rewrite = rewrite;
915 } 924 }
916 exports.BlockingFilter = BlockingFilter; 925 exports.BlockingFilter = BlockingFilter;
917 926
918 BlockingFilter.prototype = extend(RegExpFilter, { 927 BlockingFilter.prototype = extend(RegExpFilter, {
919 type: "blocking", 928 type: "blocking",
920 929
921 /** 930 /**
922 * Defines whether the filter should collapse blocked content. 931 * Defines whether the filter should collapse blocked content.
923 * Can be null (use the global preference). 932 * Can be null (use the global preference).
924 * @type {?boolean} 933 * @type {?boolean}
(...skipping 29 matching lines...) Expand all
954 catch (e) 963 catch (e)
955 { 964 {
956 } 965 }
957 966
958 return url; 967 return url;
959 } 968 }
960 }); 969 });
961 970
962 /** 971 /**
963 * Class for whitelist filters 972 * Class for whitelist filters
964 * @param {string} text see Filter() 973 * @param {string} text see {@link Filter Filter()}
965 * @param {string} regexpSource see RegExpFilter() 974 * @param {string} regexpSource see {@link RegExpFilter RegExpFilter()}
966 * @param {number} [contentType] see RegExpFilter() 975 * @param {number} [contentType] see {@link RegExpFilter RegExpFilter()}
967 * @param {boolean} [matchCase] see RegExpFilter() 976 * @param {boolean} [matchCase] see {@link RegExpFilter RegExpFilter()}
968 * @param {string} [domains] see RegExpFilter() 977 * @param {string} [domains] see {@link RegExpFilter RegExpFilter()}
969 * @param {boolean} [thirdParty] see RegExpFilter() 978 * @param {boolean} [thirdParty] see {@link RegExpFilter RegExpFilter()}
970 * @param {string} [sitekeys] see RegExpFilter() 979 * @param {string} [sitekeys] see {@link RegExpFilter RegExpFilter()}
971 * @constructor 980 * @constructor
972 * @augments RegExpFilter 981 * @augments RegExpFilter
973 */ 982 */
974 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, 983 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains,
975 thirdParty, sitekeys) 984 thirdParty, sitekeys)
976 { 985 {
977 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, 986 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains,
978 thirdParty, sitekeys); 987 thirdParty, sitekeys);
979 } 988 }
980 exports.WhitelistFilter = WhitelistFilter; 989 exports.WhitelistFilter = WhitelistFilter;
981 990
982 WhitelistFilter.prototype = extend(RegExpFilter, { 991 WhitelistFilter.prototype = extend(RegExpFilter, {
983 type: "whitelist" 992 type: "whitelist"
984 }); 993 });
985 994
986 /** 995 /**
987 * Base class for script filters 996 * Base class for content filters
988 * @param {string} text see Filter() 997 * @param {string} text see {@link Filter Filter()}
989 * @param {string} [domains] Host names or domains the filter should be 998 * @param {string} [domains] Host names or domains the filter should be
990 * restricted to 999 * restricted to
991 * @param {string} script Script that should be executed 1000 * @param {string} body The body of the filter
992 * @constructor 1001 * @constructor
993 * @augments ActiveFilter 1002 * @augments ActiveFilter
994 */ 1003 */
995 function ScriptFilter(text, domains, script) 1004 function ContentFilter(text, domains, body)
996 { 1005 {
997 ActiveFilter.call(this, text, domains || null); 1006 ActiveFilter.call(this, text, domains || null);
998 1007
999 if (domains) 1008 this.body = body;
1000 { 1009 }
1001 this.scriptDomains = domains.replace(/,~[^,]+/g, "") 1010 exports.ContentFilter = ContentFilter;
1002 .replace(/^~[^,]+,?/, "").toLowerCase(); 1011
1003 } 1012 ContentFilter.prototype = extend(ActiveFilter, {
1004
1005 this.script = script;
1006 }
1007 exports.ScriptFilter = ScriptFilter;
1008
1009 ScriptFilter.prototype = extend(ActiveFilter, {
1010 /** 1013 /**
1011 * @see ActiveFilter.domainSeparator 1014 * @see ActiveFilter.domainSeparator
1012 */ 1015 */
1013 domainSeparator: ",", 1016 domainSeparator: ",",
1014 1017
1015 /** 1018 /**
1016 * @see ActiveFilter.ignoreTrailingDot 1019 * The body of the filter
1017 */
1018 ignoreTrailingDot: false,
1019
1020 /**
1021 * Host names or domains the filter should be restricted to (can be null for
1022 * no restriction)
1023 * @type {?string}
1024 */
1025 scriptDomains: null,
1026
1027 /**
1028 * Script that should be executed
1029 * @type {string} 1020 * @type {string}
1030 */ 1021 */
1031 script: null 1022 body: null
1032 }); 1023 });
1033 1024
1034 /* 1025 /**
1035 * Base class for element hiding filters 1026 * Creates a content filter from a pre-parsed text representation
1036 * @param {string} text see Filter()
1037 * @param {string} [domains] see ScriptFilter()
1038 * @param {string} selector CSS selector for the HTML elements that should be
1039 * hidden
1040 * @constructor
1041 * @augments ScriptFilter
1042 */
1043 function ElemHideBase(text, domains, selector)
1044 {
1045 ScriptFilter.call(this, text, domains, selector);
1046
1047 // Braces are being escaped to prevent CSS rule injection.
1048 this.script = this.script.replace("{", "\\7B ").replace("}", "\\7D ");
1049 }
1050 exports.ElemHideBase = ElemHideBase;
1051
1052 ElemHideBase.prototype = extend(ScriptFilter, {
1053 /**
1054 * @see ScriptFilter.scriptDomains
1055 */
1056 get selectorDomains()
1057 {
1058 return this.scriptDomains;
1059 },
1060
1061 /**
1062 * CSS selector for the HTML elements that should be hidden
1063 * @type {string}
1064 */
1065 get selector()
1066 {
1067 return this.script;
1068 }
1069 });
1070
1071 /**
1072 * Creates an element hiding filter from a pre-parsed text representation
1073 * 1027 *
1074 * @param {string} text same as in Filter() 1028 * @param {string} text same as in Filter()
1075 * @param {string} [domains] 1029 * @param {string} [domains]
1076 * domains part of the text representation 1030 * domains part of the text representation
1077 * @param {string} [type] 1031 * @param {string} [type]
1078 * rule type, either empty or @ (exception) or ? (emulation rule) 1032 * rule type, either:
1079 * @param {string} selector raw CSS selector 1033 * <li>"" for an element hiding filter</li>
Manish Jethani 2018/07/11 13:04:26 Using just "-" doesn't work in the HTML version, b
kzar 2018/07/11 17:17:52 Acknowledged.
1034 * <li>"@" for an element hiding exception filter</li>
1035 * <li>"?" for an element hiding emulation filter</li>
1036 * <li>"$" for a snippet filter</li>
1037 * @param {string} body
1038 * body part of the text representation, either a CSS selector or a snippet
1039 * script
1080 * @return {ElemHideFilter|ElemHideException| 1040 * @return {ElemHideFilter|ElemHideException|
1081 * ElemHideEmulationFilter|InvalidFilter} 1041 * ElemHideEmulationFilter|SnippetFilter|InvalidFilter}
1082 */ 1042 */
1083 ElemHideBase.fromText = function(text, domains, type, selector) 1043 ContentFilter.fromText = function(text, domains, type, body)
1084 { 1044 {
1085 // We don't allow ElemHide filters which have any empty domains. 1045 // We don't allow content filters which have any empty domains.
1086 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that 1046 // Note: The ContentFilter.prototype.domainSeparator is duplicated here, if
1087 // changes this must be changed too. 1047 // that changes this must be changed too.
1088 if (domains && /(^|,)~?(,|$)/.test(domains)) 1048 if (domains && /(^|,)~?(,|$)/.test(domains))
1089 return new InvalidFilter(text, "filter_invalid_domain"); 1049 return new InvalidFilter(text, "filter_invalid_domain");
1090 1050
1091 if (type == "@") 1051 if (type == "@")
1092 return new ElemHideException(text, domains, selector); 1052 return new ElemHideException(text, domains, body);
1053
1054 if (type == "$")
1055 return new SnippetFilter(text, domains, body);
1093 1056
1094 if (type == "?") 1057 if (type == "?")
1095 { 1058 {
1096 // Element hiding emulation filters are inefficient so we need to make sure 1059 // Element hiding emulation filters are inefficient so we need to make sure
1097 // that they're only applied if they specify active domains 1060 // that they're only applied if they specify active domains
1098 if (!/,[^~][^,.]*\.[^,]/.test("," + domains)) 1061 if (!/,[^~][^,.]*\.[^,]/.test("," + domains))
1099 return new InvalidFilter(text, "filter_elemhideemulation_nodomain"); 1062 return new InvalidFilter(text, "filter_elemhideemulation_nodomain");
1100 1063
1101 return new ElemHideEmulationFilter(text, domains, selector); 1064 return new ElemHideEmulationFilter(text, domains, body);
1102 } 1065 }
1103 1066
1104 return new ElemHideFilter(text, domains, selector); 1067 return new ElemHideFilter(text, domains, body);
1105 }; 1068 };
1106 1069
1107 /** 1070 /**
1071 * Base class for element hiding filters
1072 * @param {string} text see {@link Filter Filter()}
1073 * @param {string} [domains] see {@link ContentFilter ContentFilter()}
1074 * @param {string} selector CSS selector for the HTML elements that should be
1075 * hidden
1076 * @constructor
1077 * @augments ContentFilter
1078 */
1079 function ElemHideBase(text, domains, selector)
1080 {
1081 ContentFilter.call(this, text, domains, selector);
1082 }
1083 exports.ElemHideBase = ElemHideBase;
1084
1085 ElemHideBase.prototype = extend(ContentFilter, {
1086 /**
1087 * CSS selector for the HTML elements that should be hidden
1088 * @type {string}
1089 */
1090 get selector()
1091 {
1092 // Braces are being escaped to prevent CSS rule injection.
1093 return this.body.replace("{", "\\7B ").replace("}", "\\7D ");
1094 }
1095 });
1096
1097 /**
1108 * Class for element hiding filters 1098 * Class for element hiding filters
1109 * @param {string} text see Filter() 1099 * @param {string} text see {@link Filter Filter()}
1110 * @param {string} [domains] see ElemHideBase() 1100 * @param {string} [domains] see {@link ElemHideBase ElemHideBase()}
1111 * @param {string} selector see ElemHideBase() 1101 * @param {string} selector see {@link ElemHideBase ElemHideBase()}
1112 * @constructor 1102 * @constructor
1113 * @augments ElemHideBase 1103 * @augments ElemHideBase
1114 */ 1104 */
1115 function ElemHideFilter(text, domains, selector) 1105 function ElemHideFilter(text, domains, selector)
1116 { 1106 {
1117 ElemHideBase.call(this, text, domains, selector); 1107 ElemHideBase.call(this, text, domains, selector);
1118 } 1108 }
1119 exports.ElemHideFilter = ElemHideFilter; 1109 exports.ElemHideFilter = ElemHideFilter;
1120 1110
1121 ElemHideFilter.prototype = extend(ElemHideBase, { 1111 ElemHideFilter.prototype = extend(ElemHideBase, {
1122 type: "elemhide" 1112 type: "elemhide"
1123 }); 1113 });
1124 1114
1125 /** 1115 /**
1126 * Class for element hiding exceptions 1116 * Class for element hiding exceptions
1127 * @param {string} text see Filter() 1117 * @param {string} text see {@link Filter Filter()}
1128 * @param {string} [domains] see ElemHideBase() 1118 * @param {string} [domains] see {@link ElemHideBase ElemHideBase()}
1129 * @param {string} selector see ElemHideBase() 1119 * @param {string} selector see {@link ElemHideBase ElemHideBase()}
1130 * @constructor 1120 * @constructor
1131 * @augments ElemHideBase 1121 * @augments ElemHideBase
1132 */ 1122 */
1133 function ElemHideException(text, domains, selector) 1123 function ElemHideException(text, domains, selector)
1134 { 1124 {
1135 ElemHideBase.call(this, text, domains, selector); 1125 ElemHideBase.call(this, text, domains, selector);
1136 } 1126 }
1137 exports.ElemHideException = ElemHideException; 1127 exports.ElemHideException = ElemHideException;
1138 1128
1139 ElemHideException.prototype = extend(ElemHideBase, { 1129 ElemHideException.prototype = extend(ElemHideBase, {
1140 type: "elemhideexception" 1130 type: "elemhideexception"
1141 }); 1131 });
1142 1132
1143 /** 1133 /**
1144 * Class for element hiding emulation filters 1134 * Class for element hiding emulation filters
1145 * @param {string} text see Filter() 1135 * @param {string} text see {@link Filter Filter()}
1146 * @param {string} domains see ElemHideBase() 1136 * @param {string} domains see {@link ElemHideBase ElemHideBase()}
1147 * @param {string} selector see ElemHideBase() 1137 * @param {string} selector see {@link ElemHideBase ElemHideBase()}
1148 * @constructor 1138 * @constructor
1149 * @augments ElemHideBase 1139 * @augments ElemHideBase
1150 */ 1140 */
1151 function ElemHideEmulationFilter(text, domains, selector) 1141 function ElemHideEmulationFilter(text, domains, selector)
1152 { 1142 {
1153 ElemHideBase.call(this, text, domains, selector); 1143 ElemHideBase.call(this, text, domains, selector);
1154 } 1144 }
1155 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1145 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1156 1146
1157 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1147 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1158 type: "elemhideemulation" 1148 type: "elemhideemulation"
1159 }); 1149 });
1160 1150
1161 /** 1151 /**
1162 * Class for snippet filters 1152 * Class for snippet filters
1163 * @param {string} text see Filter() 1153 * @param {string} text see Filter()
1164 * @param {string} [domains] see ScriptFilter() 1154 * @param {string} [domains] see ContentFilter()
1165 * @param {string} script Script that should be executed 1155 * @param {string} script Script that should be executed
1166 * @constructor 1156 * @constructor
1167 * @augments ScriptFilter 1157 * @augments ContentFilter
1168 */ 1158 */
1169 function SnippetFilter(text, domains, script) 1159 function SnippetFilter(text, domains, script)
1170 { 1160 {
1171 ScriptFilter.call(this, text, domains, script); 1161 ContentFilter.call(this, text, domains, script);
1172 } 1162 }
1173 exports.SnippetFilter = SnippetFilter; 1163 exports.SnippetFilter = SnippetFilter;
1174 1164
1175 SnippetFilter.prototype = extend(ScriptFilter, { 1165 SnippetFilter.prototype = extend(ContentFilter, {
1176 type: "snippet" 1166 type: "snippet",
1177 }); 1167
1168 /**
1169 * Script that should be executed
1170 * @type {string}
1171 */
1172 get script()
1173 {
1174 return this.body;
1175 }
1176 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld