| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 { | 367 { |
| 368 let oldValue = this._lastHit; | 368 let oldValue = this._lastHit; |
| 369 this._lastHit = value; | 369 this._lastHit = value; |
| 370 FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue); | 370 FilterNotifier.triggerListeners("filter.lastHit", this, value, oldValue); |
| 371 } | 371 } |
| 372 return this._lastHit; | 372 return this._lastHit; |
| 373 }, | 373 }, |
| 374 | 374 |
| 375 /** | 375 /** |
| 376 * String that the domains property should be generated from | 376 * String that the domains property should be generated from |
| 377 * @type {string} | 377 * @type {?string} |
| 378 */ | 378 */ |
| 379 domainSource: null, | 379 domainSource: null, |
| 380 | 380 |
| 381 /** | 381 /** |
| 382 * Separator character used in domainSource property, must be | 382 * Separator character used in domainSource property, must be |
| 383 * overridden by subclasses | 383 * overridden by subclasses |
| 384 * @type {string} | 384 * @type {string} |
| 385 */ | 385 */ |
| 386 domainSeparator: null, | 386 domainSeparator: null, |
| 387 | 387 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 | 464 |
| 465 this.domainSource = null; | 465 this.domainSource = null; |
| 466 } | 466 } |
| 467 | 467 |
| 468 Object.defineProperty(this, "domains", {value: domains, enumerable: true}); | 468 Object.defineProperty(this, "domains", {value: domains, enumerable: true}); |
| 469 return this.domains; | 469 return this.domains; |
| 470 }, | 470 }, |
| 471 | 471 |
| 472 /** | 472 /** |
| 473 * Array containing public keys of websites that this filter should apply to | 473 * Array containing public keys of websites that this filter should apply to |
| 474 * @type {string[]} | 474 * @type {?string[]} |
| 475 */ | 475 */ |
| 476 sitekeys: null, | 476 sitekeys: null, |
| 477 | 477 |
| 478 /** | 478 /** |
| 479 * Checks whether this filter is active on a domain. | 479 * Checks whether this filter is active on a domain. |
| 480 * @param {string} docDomain domain name of the document that loads the URL | 480 * @param {string} [docDomain] domain name of the document that loads the URL |
| 481 * @param {string} [sitekey] public key provided by the document | 481 * @param {string} [sitekey] public key provided by the document |
| 482 * @return {boolean} true in case of the filter being active | 482 * @return {boolean} true in case of the filter being active |
| 483 */ | 483 */ |
| 484 isActiveOnDomain(docDomain, sitekey) | 484 isActiveOnDomain(docDomain, sitekey) |
| 485 { | 485 { |
| 486 // Sitekeys are case-sensitive so we shouldn't convert them to | 486 // Sitekeys are case-sensitive so we shouldn't convert them to |
| 487 // upper-case to avoid false positives here. Instead we need to | 487 // upper-case to avoid false positives here. Instead we need to |
| 488 // change the way filter options are parsed. | 488 // change the way filter options are parsed. |
| 489 if (this.sitekeys && | 489 if (this.sitekeys && |
| 490 (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) | 490 (!sitekey || this.sitekeys.indexOf(sitekey.toUpperCase()) < 0)) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 contentType: 0x7FFFFFFF, | 679 contentType: 0x7FFFFFFF, |
| 680 /** | 680 /** |
| 681 * Defines whether the filter should distinguish between lower and | 681 * Defines whether the filter should distinguish between lower and |
| 682 * upper case letters | 682 * upper case letters |
| 683 * @type {boolean} | 683 * @type {boolean} |
| 684 */ | 684 */ |
| 685 matchCase: false, | 685 matchCase: false, |
| 686 /** | 686 /** |
| 687 * Defines whether the filter should apply to third-party or | 687 * Defines whether the filter should apply to third-party or |
| 688 * first-party content only. Can be null (apply to all content). | 688 * first-party content only. Can be null (apply to all content). |
| 689 * @type {boolean} | 689 * @type {?boolean} |
| 690 */ | 690 */ |
| 691 thirdParty: null, | 691 thirdParty: null, |
| 692 | 692 |
| 693 /** | 693 /** |
| 694 * String that the sitekey property should be generated from | 694 * String that the sitekey property should be generated from |
| 695 * @type {string} | 695 * @type {?string} |
| 696 */ | 696 */ |
| 697 sitekeySource: null, | 697 sitekeySource: null, |
| 698 | 698 |
| 699 /** | 699 /** |
| 700 * Array containing public keys of websites that this filter should apply to | 700 * @see ActiveFilter.sitekeys |
|
Manish Jethani
2018/05/09 16:56:08
This may seem unrelated but I wanted to specify th
| |
| 701 * @type {string[]} | |
| 702 */ | 701 */ |
| 703 get sitekeys() | 702 get sitekeys() |
| 704 { | 703 { |
| 705 // Despite this property being cached, the getter is called | 704 // Despite this property being cached, the getter is called |
| 706 // several times on Safari, due to WebKit bug 132872 | 705 // several times on Safari, due to WebKit bug 132872 |
| 707 let prop = Object.getOwnPropertyDescriptor(this, "sitekeys"); | 706 let prop = Object.getOwnPropertyDescriptor(this, "sitekeys"); |
| 708 if (prop) | 707 if (prop) |
| 709 return prop.value; | 708 return prop.value; |
| 710 | 709 |
| 711 let sitekeys = null; | 710 let sitekeys = null; |
| 712 | 711 |
| 713 if (this.sitekeySource) | 712 if (this.sitekeySource) |
| 714 { | 713 { |
| 715 sitekeys = this.sitekeySource.split("|"); | 714 sitekeys = this.sitekeySource.split("|"); |
| 716 this.sitekeySource = null; | 715 this.sitekeySource = null; |
| 717 } | 716 } |
| 718 | 717 |
| 719 Object.defineProperty( | 718 Object.defineProperty( |
| 720 this, "sitekeys", {value: sitekeys, enumerable: true} | 719 this, "sitekeys", {value: sitekeys, enumerable: true} |
| 721 ); | 720 ); |
| 722 return this.sitekeys; | 721 return this.sitekeys; |
| 723 }, | 722 }, |
| 724 | 723 |
| 725 /** | 724 /** |
| 726 * Tests whether the URL matches this filter | 725 * Tests whether the URL matches this filter |
| 727 * @param {string} location URL to be tested | 726 * @param {string} location URL to be tested |
| 728 * @param {number} typeMask bitmask of content / request types to match | 727 * @param {number} typeMask bitmask of content / request types to match |
| 729 * @param {string} docDomain domain name of the document that loads the URL | 728 * @param {string} [docDomain] domain name of the document that loads the URL |
| 730 * @param {boolean} thirdParty should be true if the URL is a third-party | 729 * @param {boolean} [thirdParty] should be true if the URL is a third-party |
| 731 * request | 730 * request |
| 732 * @param {string} sitekey public key provided by the document | 731 * @param {string} [sitekey] public key provided by the document |
| 733 * @return {boolean} true in case of a match | 732 * @return {boolean} true in case of a match |
| 734 */ | 733 */ |
| 735 matches(location, typeMask, docDomain, thirdParty, sitekey) | 734 matches(location, typeMask, docDomain, thirdParty, sitekey) |
| 736 { | 735 { |
| 737 if (this.contentType & typeMask && | 736 if (this.contentType & typeMask && |
| 738 (this.thirdParty == null || this.thirdParty == thirdParty) && | 737 (this.thirdParty == null || this.thirdParty == thirdParty) && |
| 739 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) | 738 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) |
| 740 { | 739 { |
| 741 return true; | 740 return true; |
| 742 } | 741 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 RegExpFilter.typeMap.DOCUMENT | | 877 RegExpFilter.typeMap.DOCUMENT | |
| 879 RegExpFilter.typeMap.ELEMHIDE | | 878 RegExpFilter.typeMap.ELEMHIDE | |
| 880 RegExpFilter.typeMap.POPUP | | 879 RegExpFilter.typeMap.POPUP | |
| 881 RegExpFilter.typeMap.GENERICHIDE | | 880 RegExpFilter.typeMap.GENERICHIDE | |
| 882 RegExpFilter.typeMap.GENERICBLOCK); | 881 RegExpFilter.typeMap.GENERICBLOCK); |
| 883 | 882 |
| 884 /** | 883 /** |
| 885 * Class for blocking filters | 884 * Class for blocking filters |
| 886 * @param {string} text see Filter() | 885 * @param {string} text see Filter() |
| 887 * @param {string} regexpSource see RegExpFilter() | 886 * @param {string} regexpSource see RegExpFilter() |
| 888 * @param {number} contentType see RegExpFilter() | 887 * @param {number} [contentType] see RegExpFilter() |
| 889 * @param {boolean} matchCase see RegExpFilter() | 888 * @param {boolean} [matchCase] see RegExpFilter() |
| 890 * @param {string} domains see RegExpFilter() | 889 * @param {string} [domains] see RegExpFilter() |
| 891 * @param {boolean} thirdParty see RegExpFilter() | 890 * @param {boolean} [thirdParty] see RegExpFilter() |
| 892 * @param {string} sitekeys see RegExpFilter() | 891 * @param {string} [sitekeys] see RegExpFilter() |
| 893 * @param {boolean} collapse | 892 * @param {boolean} [collapse] |
| 894 * defines whether the filter should collapse blocked content, can be null | 893 * defines whether the filter should collapse blocked content, can be null |
| 895 * @param {string} [csp] | 894 * @param {string} [csp] |
| 896 * Content Security Policy to inject when the filter matches | 895 * Content Security Policy to inject when the filter matches |
| 897 * @constructor | 896 * @constructor |
| 898 * @augments RegExpFilter | 897 * @augments RegExpFilter |
| 899 */ | 898 */ |
| 900 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, | 899 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, |
| 901 thirdParty, sitekeys, collapse, csp) | 900 thirdParty, sitekeys, collapse, csp) |
| 902 { | 901 { |
| 903 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, | 902 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
| 904 thirdParty, sitekeys); | 903 thirdParty, sitekeys); |
| 905 | 904 |
| 906 this.collapse = collapse; | 905 this.collapse = collapse; |
| 907 this.csp = csp; | 906 this.csp = csp; |
| 908 } | 907 } |
| 909 exports.BlockingFilter = BlockingFilter; | 908 exports.BlockingFilter = BlockingFilter; |
| 910 | 909 |
| 911 BlockingFilter.prototype = extend(RegExpFilter, { | 910 BlockingFilter.prototype = extend(RegExpFilter, { |
| 912 type: "blocking", | 911 type: "blocking", |
| 913 | 912 |
| 914 /** | 913 /** |
| 915 * Defines whether the filter should collapse blocked content. | 914 * Defines whether the filter should collapse blocked content. |
| 916 * Can be null (use the global preference). | 915 * Can be null (use the global preference). |
| 917 * @type {boolean} | 916 * @type {?boolean} |
| 918 */ | 917 */ |
| 919 collapse: null, | 918 collapse: null, |
| 920 | 919 |
| 921 /** | 920 /** |
| 922 * Content Security Policy to inject for matching requests. | 921 * Content Security Policy to inject for matching requests. |
| 923 * @type {string} | 922 * @type {?string} |
| 924 */ | 923 */ |
| 925 csp: null | 924 csp: null |
| 926 }); | 925 }); |
| 927 | 926 |
| 928 /** | 927 /** |
| 929 * Class for whitelist filters | 928 * Class for whitelist filters |
| 930 * @param {string} text see Filter() | 929 * @param {string} text see Filter() |
| 931 * @param {string} regexpSource see RegExpFilter() | 930 * @param {string} regexpSource see RegExpFilter() |
| 932 * @param {number} contentType see RegExpFilter() | 931 * @param {number} [contentType] see RegExpFilter() |
| 933 * @param {boolean} matchCase see RegExpFilter() | 932 * @param {boolean} [matchCase] see RegExpFilter() |
| 934 * @param {string} domains see RegExpFilter() | 933 * @param {string} [domains] see RegExpFilter() |
| 935 * @param {boolean} thirdParty see RegExpFilter() | 934 * @param {boolean} [thirdParty] see RegExpFilter() |
| 936 * @param {string} sitekeys see RegExpFilter() | 935 * @param {string} [sitekeys] see RegExpFilter() |
| 937 * @constructor | 936 * @constructor |
| 938 * @augments RegExpFilter | 937 * @augments RegExpFilter |
| 939 */ | 938 */ |
| 940 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, | 939 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, |
| 941 thirdParty, sitekeys) | 940 thirdParty, sitekeys) |
| 942 { | 941 { |
| 943 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, | 942 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, |
| 944 thirdParty, sitekeys); | 943 thirdParty, sitekeys); |
| 945 } | 944 } |
| 946 exports.WhitelistFilter = WhitelistFilter; | 945 exports.WhitelistFilter = WhitelistFilter; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 domainSeparator: ",", | 980 domainSeparator: ",", |
| 982 | 981 |
| 983 /** | 982 /** |
| 984 * @see ActiveFilter.ignoreTrailingDot | 983 * @see ActiveFilter.ignoreTrailingDot |
| 985 */ | 984 */ |
| 986 ignoreTrailingDot: false, | 985 ignoreTrailingDot: false, |
| 987 | 986 |
| 988 /** | 987 /** |
| 989 * Host names or domains the filter should be restricted to (can be null for | 988 * Host names or domains the filter should be restricted to (can be null for |
| 990 * no restriction) | 989 * no restriction) |
| 991 * @type {string} | 990 * @type {?string} |
| 992 */ | 991 */ |
| 993 selectorDomains: null, | 992 selectorDomains: null, |
| 994 /** | 993 /** |
| 995 * CSS selector for the HTML elements that should be hidden | 994 * CSS selector for the HTML elements that should be hidden |
| 996 * @type {string} | 995 * @type {string} |
|
Manish Jethani
2018/05/09 16:56:08
Note that selector will always be non-null.
kzar
2018/05/10 11:06:25
I guess this is technically incorrect for the abst
Manish Jethani
2018/05/11 03:20:57
So ElemHideBase is an abstract class, we don't cre
Manish Jethani
2018/05/11 03:26:52
By the way there's a @abstract tag in JSDoc [1], b
| |
| 997 */ | 996 */ |
| 998 selector: null | 997 selector: null |
| 999 }); | 998 }); |
| 1000 | 999 |
| 1001 /** | 1000 /** |
| 1002 * Creates an element hiding filter from a pre-parsed text representation | 1001 * Creates an element hiding filter from a pre-parsed text representation |
| 1003 * | 1002 * |
| 1004 * @param {string} text same as in Filter() | 1003 * @param {string} text same as in Filter() |
| 1005 * @param {string?} domains | 1004 * @param {string} [domains] |
| 1006 * domains part of the text representation | 1005 * domains part of the text representation |
| 1007 * @param {string?} type | 1006 * @param {string} [type] |
| 1008 * rule type, either empty or @ (exception) or ? (emulation rule) | 1007 * rule type, either empty or @ (exception) or ? (emulation rule) |
| 1009 * @param {string} selector raw CSS selector | 1008 * @param {string} selector raw CSS selector |
| 1010 * @return {ElemHideFilter|ElemHideException| | 1009 * @return {ElemHideFilter|ElemHideException| |
| 1011 * ElemHideEmulationFilter|InvalidFilter} | 1010 * ElemHideEmulationFilter|InvalidFilter} |
| 1012 */ | 1011 */ |
| 1013 ElemHideBase.fromText = function(text, domains, type, selector) | 1012 ElemHideBase.fromText = function(text, domains, type, selector) |
| 1014 { | 1013 { |
| 1015 // We don't allow ElemHide filters which have any empty domains. | 1014 // We don't allow ElemHide filters which have any empty domains. |
| 1016 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that | 1015 // Note: The ElemHide.prototype.domainSeparator is duplicated here, if that |
| 1017 // changes this must be changed too. | 1016 // changes this must be changed too. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1030 | 1029 |
| 1031 return new ElemHideEmulationFilter(text, domains, selector); | 1030 return new ElemHideEmulationFilter(text, domains, selector); |
| 1032 } | 1031 } |
| 1033 | 1032 |
| 1034 return new ElemHideFilter(text, domains, selector); | 1033 return new ElemHideFilter(text, domains, selector); |
| 1035 }; | 1034 }; |
| 1036 | 1035 |
| 1037 /** | 1036 /** |
| 1038 * Class for element hiding filters | 1037 * Class for element hiding filters |
| 1039 * @param {string} text see Filter() | 1038 * @param {string} text see Filter() |
| 1040 * @param {string} domains see ElemHideBase() | 1039 * @param {string} [domains] see ElemHideBase() |
| 1041 * @param {string} selector see ElemHideBase() | 1040 * @param {string} selector see ElemHideBase() |
| 1042 * @constructor | 1041 * @constructor |
| 1043 * @augments ElemHideBase | 1042 * @augments ElemHideBase |
| 1044 */ | 1043 */ |
| 1045 function ElemHideFilter(text, domains, selector) | 1044 function ElemHideFilter(text, domains, selector) |
| 1046 { | 1045 { |
| 1047 ElemHideBase.call(this, text, domains, selector); | 1046 ElemHideBase.call(this, text, domains, selector); |
| 1048 } | 1047 } |
| 1049 exports.ElemHideFilter = ElemHideFilter; | 1048 exports.ElemHideFilter = ElemHideFilter; |
| 1050 | 1049 |
| 1051 ElemHideFilter.prototype = extend(ElemHideBase, { | 1050 ElemHideFilter.prototype = extend(ElemHideBase, { |
| 1052 type: "elemhide" | 1051 type: "elemhide" |
| 1053 }); | 1052 }); |
| 1054 | 1053 |
| 1055 /** | 1054 /** |
| 1056 * Class for element hiding exceptions | 1055 * Class for element hiding exceptions |
| 1057 * @param {string} text see Filter() | 1056 * @param {string} text see Filter() |
| 1058 * @param {string} domains see ElemHideBase() | 1057 * @param {string} [domains] see ElemHideBase() |
| 1059 * @param {string} selector see ElemHideBase() | 1058 * @param {string} selector see ElemHideBase() |
| 1060 * @constructor | 1059 * @constructor |
| 1061 * @augments ElemHideBase | 1060 * @augments ElemHideBase |
| 1062 */ | 1061 */ |
| 1063 function ElemHideException(text, domains, selector) | 1062 function ElemHideException(text, domains, selector) |
| 1064 { | 1063 { |
| 1065 ElemHideBase.call(this, text, domains, selector); | 1064 ElemHideBase.call(this, text, domains, selector); |
| 1066 } | 1065 } |
| 1067 exports.ElemHideException = ElemHideException; | 1066 exports.ElemHideException = ElemHideException; |
| 1068 | 1067 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1080 */ | 1079 */ |
| 1081 function ElemHideEmulationFilter(text, domains, selector) | 1080 function ElemHideEmulationFilter(text, domains, selector) |
| 1082 { | 1081 { |
| 1083 ElemHideBase.call(this, text, domains, selector); | 1082 ElemHideBase.call(this, text, domains, selector); |
| 1084 } | 1083 } |
| 1085 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; | 1084 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; |
| 1086 | 1085 |
| 1087 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { | 1086 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { |
| 1088 type: "elemhideemulation" | 1087 type: "elemhideemulation" |
| 1089 }); | 1088 }); |
| OLD | NEW |