| LEFT | RIGHT |
| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 */ | 43 */ |
| 44 text: null, | 44 text: null, |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Filter subscriptions the filter belongs to | 47 * Filter subscriptions the filter belongs to |
| 48 * @type Subscription[] | 48 * @type Subscription[] |
| 49 */ | 49 */ |
| 50 subscriptions: null, | 50 subscriptions: null, |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Filter type as a string, e.g. "blocking". |
| 54 * @type String |
| 55 */ |
| 56 get type() |
| 57 { |
| 58 throw new Error("Please define filter type in the subclass"); |
| 59 }, |
| 60 |
| 61 /** |
| 53 * Serializes the filter to an array of strings for writing out on the disk. | 62 * Serializes the filter to an array of strings for writing out on the disk. |
| 54 * @param {string[]} buffer buffer to push the serialization results into | 63 * @param {string[]} buffer buffer to push the serialization results into |
| 55 */ | 64 */ |
| 56 serialize: function(buffer) | 65 serialize: function(buffer) |
| 57 { | 66 { |
| 58 buffer.push("[Filter]"); | 67 buffer.push("[Filter]"); |
| 59 buffer.push("text=" + this.text); | 68 buffer.push("text=" + this.text); |
| 60 }, | 69 }, |
| 61 | 70 |
| 62 toString: function() | 71 toString: function() |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Filter.call(this, text); | 208 Filter.call(this, text); |
| 200 | 209 |
| 201 this.reason = reason; | 210 this.reason = reason; |
| 202 } | 211 } |
| 203 exports.InvalidFilter = InvalidFilter; | 212 exports.InvalidFilter = InvalidFilter; |
| 204 | 213 |
| 205 InvalidFilter.prototype = | 214 InvalidFilter.prototype = |
| 206 { | 215 { |
| 207 __proto__: Filter.prototype, | 216 __proto__: Filter.prototype, |
| 208 | 217 |
| 218 type: "invalid", |
| 219 |
| 209 /** | 220 /** |
| 210 * Reason why this filter is invalid | 221 * Reason why this filter is invalid |
| 211 * @type String | 222 * @type String |
| 212 */ | 223 */ |
| 213 reason: null, | 224 reason: null, |
| 214 | 225 |
| 215 /** | 226 /** |
| 216 * See Filter.serialize() | 227 * See Filter.serialize() |
| 217 */ | 228 */ |
| 218 serialize: function(buffer) {} | 229 serialize: function(buffer) {} |
| 219 }; | 230 }; |
| 220 | 231 |
| 221 /** | 232 /** |
| 222 * Class for comments | 233 * Class for comments |
| 223 * @param {String} text see Filter() | 234 * @param {String} text see Filter() |
| 224 * @constructor | 235 * @constructor |
| 225 * @augments Filter | 236 * @augments Filter |
| 226 */ | 237 */ |
| 227 function CommentFilter(text) | 238 function CommentFilter(text) |
| 228 { | 239 { |
| 229 Filter.call(this, text); | 240 Filter.call(this, text); |
| 230 } | 241 } |
| 231 exports.CommentFilter = CommentFilter; | 242 exports.CommentFilter = CommentFilter; |
| 232 | 243 |
| 233 CommentFilter.prototype = | 244 CommentFilter.prototype = |
| 234 { | 245 { |
| 235 __proto__: Filter.prototype, | 246 __proto__: Filter.prototype, |
| 247 |
| 248 type: "comment", |
| 236 | 249 |
| 237 /** | 250 /** |
| 238 * See Filter.serialize() | 251 * See Filter.serialize() |
| 239 */ | 252 */ |
| 240 serialize: function(buffer) {} | 253 serialize: function(buffer) {} |
| 241 }; | 254 }; |
| 242 | 255 |
| 243 /** | 256 /** |
| 244 * Abstract base class for filters that can get hits | 257 * Abstract base class for filters that can get hits |
| 245 * @param {String} text see Filter() | 258 * @param {String} text see Filter() |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 481 |
| 469 if (this.ignoreTrailingDot) | 482 if (this.ignoreTrailingDot) |
| 470 docDomain = docDomain.replace(/\.+$/, ""); | 483 docDomain = docDomain.replace(/\.+$/, ""); |
| 471 docDomain = docDomain.toUpperCase(); | 484 docDomain = docDomain.toUpperCase(); |
| 472 | 485 |
| 473 for (let domain in this.domains) | 486 for (let domain in this.domains) |
| 474 if (this.domains[domain] && domain != docDomain && (domain.length <= docDo
main.length || domain.indexOf("." + docDomain) != domain.length - docDomain.leng
th - 1)) | 487 if (this.domains[domain] && domain != docDomain && (domain.length <= docDo
main.length || domain.indexOf("." + docDomain) != domain.length - docDomain.leng
th - 1)) |
| 475 return false; | 488 return false; |
| 476 | 489 |
| 477 return true; | 490 return true; |
| 491 }, |
| 492 |
| 493 /** |
| 494 * Checks whether this filter is generic or specific |
| 495 */ |
| 496 isGeneric: function() /**Boolean*/ |
| 497 { |
| 498 return !(this.sitekeys && this.sitekeys.length) && |
| 499 (!this.domains || this.domains[""]); |
| 478 }, | 500 }, |
| 479 | 501 |
| 480 /** | 502 /** |
| 481 * See Filter.serialize() | 503 * See Filter.serialize() |
| 482 */ | 504 */ |
| 483 serialize: function(buffer) | 505 serialize: function(buffer) |
| 484 { | 506 { |
| 485 if (this._disabled || this._hitCount || this._lastHit) | 507 if (this._disabled || this._hitCount || this._lastHit) |
| 486 { | 508 { |
| 487 Filter.prototype.serialize.call(this, buffer); | 509 Filter.prototype.serialize.call(this, buffer); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 PING: 1, | 769 PING: 1, |
| 748 XMLHTTPREQUEST: 2048, | 770 XMLHTTPREQUEST: 2048, |
| 749 OBJECT_SUBREQUEST: 4096, | 771 OBJECT_SUBREQUEST: 4096, |
| 750 DTD: 1, | 772 DTD: 1, |
| 751 MEDIA: 16384, | 773 MEDIA: 16384, |
| 752 FONT: 32768, | 774 FONT: 32768, |
| 753 | 775 |
| 754 BACKGROUND: 4, // Backwards compat, same as IMAGE | 776 BACKGROUND: 4, // Backwards compat, same as IMAGE |
| 755 | 777 |
| 756 POPUP: 0x10000000, | 778 POPUP: 0x10000000, |
| 757 ELEMHIDE: 0x40000000 | 779 GENERICBLOCK: 0x20000000, |
| 758 }; | 780 ELEMHIDE: 0x40000000, |
| 759 | 781 GENERICHIDE: 0x80000000 |
| 760 // DOCUMENT, ELEMHIDE, POPUP options shouldn't be there by default | 782 }; |
| 761 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | RegExpFi
lter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP); | 783 |
| 784 // DOCUMENT, ELEMHIDE, POPUP, GENERICHIDE and GENERICBLOCK options shouldn't |
| 785 // be there by default |
| 786 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | |
| 787 RegExpFilter.typeMap.ELEMHIDE | |
| 788 RegExpFilter.typeMap.POPUP | |
| 789 RegExpFilter.typeMap.GENERICHIDE | |
| 790 RegExpFilter.typeMap.GENERICBLOCK); |
| 762 | 791 |
| 763 /** | 792 /** |
| 764 * Class for blocking filters | 793 * Class for blocking filters |
| 765 * @param {String} text see Filter() | 794 * @param {String} text see Filter() |
| 766 * @param {String} regexpSource see RegExpFilter() | 795 * @param {String} regexpSource see RegExpFilter() |
| 767 * @param {Number} contentType see RegExpFilter() | 796 * @param {Number} contentType see RegExpFilter() |
| 768 * @param {Boolean} matchCase see RegExpFilter() | 797 * @param {Boolean} matchCase see RegExpFilter() |
| 769 * @param {String} domains see RegExpFilter() | 798 * @param {String} domains see RegExpFilter() |
| 770 * @param {Boolean} thirdParty see RegExpFilter() | 799 * @param {Boolean} thirdParty see RegExpFilter() |
| 771 * @param {String} sitekeys see RegExpFilter() | 800 * @param {String} sitekeys see RegExpFilter() |
| 772 * @param {Boolean} collapse defines whether the filter should collapse blocked
content, can be null | 801 * @param {Boolean} collapse defines whether the filter should collapse blocked
content, can be null |
| 773 * @constructor | 802 * @constructor |
| 774 * @augments RegExpFilter | 803 * @augments RegExpFilter |
| 775 */ | 804 */ |
| 776 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thi
rdParty, sitekeys, collapse) | 805 function BlockingFilter(text, regexpSource, contentType, matchCase, domains, thi
rdParty, sitekeys, collapse) |
| 777 { | 806 { |
| 778 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); | 807 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); |
| 779 | 808 |
| 780 this.collapse = collapse; | 809 this.collapse = collapse; |
| 781 } | 810 } |
| 782 exports.BlockingFilter = BlockingFilter; | 811 exports.BlockingFilter = BlockingFilter; |
| 783 | 812 |
| 784 BlockingFilter.prototype = | 813 BlockingFilter.prototype = |
| 785 { | 814 { |
| 786 __proto__: RegExpFilter.prototype, | 815 __proto__: RegExpFilter.prototype, |
| 787 | 816 |
| 817 type: "blocking", |
| 818 |
| 788 /** | 819 /** |
| 789 * Defines whether the filter should collapse blocked content. Can be null (us
e the global preference). | 820 * Defines whether the filter should collapse blocked content. Can be null (us
e the global preference). |
| 790 * @type Boolean | 821 * @type Boolean |
| 791 */ | 822 */ |
| 792 collapse: null | 823 collapse: null |
| 793 }; | 824 }; |
| 794 | 825 |
| 795 /** | 826 /** |
| 796 * Class for whitelist filters | 827 * Class for whitelist filters |
| 797 * @param {String} text see Filter() | 828 * @param {String} text see Filter() |
| 798 * @param {String} regexpSource see RegExpFilter() | 829 * @param {String} regexpSource see RegExpFilter() |
| 799 * @param {Number} contentType see RegExpFilter() | 830 * @param {Number} contentType see RegExpFilter() |
| 800 * @param {Boolean} matchCase see RegExpFilter() | 831 * @param {Boolean} matchCase see RegExpFilter() |
| 801 * @param {String} domains see RegExpFilter() | 832 * @param {String} domains see RegExpFilter() |
| 802 * @param {Boolean} thirdParty see RegExpFilter() | 833 * @param {Boolean} thirdParty see RegExpFilter() |
| 803 * @param {String} sitekeys see RegExpFilter() | 834 * @param {String} sitekeys see RegExpFilter() |
| 804 * @constructor | 835 * @constructor |
| 805 * @augments RegExpFilter | 836 * @augments RegExpFilter |
| 806 */ | 837 */ |
| 807 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
irdParty, sitekeys) | 838 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
irdParty, sitekeys) |
| 808 { | 839 { |
| 809 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); | 840 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); |
| 810 } | 841 } |
| 811 exports.WhitelistFilter = WhitelistFilter; | 842 exports.WhitelistFilter = WhitelistFilter; |
| 812 | 843 |
| 813 WhitelistFilter.prototype = | 844 WhitelistFilter.prototype = |
| 814 { | 845 { |
| 815 __proto__: RegExpFilter.prototype | 846 __proto__: RegExpFilter.prototype, |
| 847 |
| 848 type: "whitelist" |
| 816 }; | 849 }; |
| 817 | 850 |
| 818 /** | 851 /** |
| 819 * Base class for element hiding filters | 852 * Base class for element hiding filters |
| 820 * @param {String} text see Filter() | 853 * @param {String} text see Filter() |
| 821 * @param {String} [domains] Host names or domains the filter should be restrict
ed to | 854 * @param {String} [domains] Host names or domains the filter should be restrict
ed to |
| 822 * @param {String} selector CSS selector for the HTML elements that should be
hidden | 855 * @param {String} selector CSS selector for the HTML elements that should be
hidden |
| 823 * @constructor | 856 * @constructor |
| 824 * @augments ActiveFilter | 857 * @augments ActiveFilter |
| 825 */ | 858 */ |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 * @augments ElemHideBase | 970 * @augments ElemHideBase |
| 938 */ | 971 */ |
| 939 function ElemHideFilter(text, domains, selector) | 972 function ElemHideFilter(text, domains, selector) |
| 940 { | 973 { |
| 941 ElemHideBase.call(this, text, domains, selector); | 974 ElemHideBase.call(this, text, domains, selector); |
| 942 } | 975 } |
| 943 exports.ElemHideFilter = ElemHideFilter; | 976 exports.ElemHideFilter = ElemHideFilter; |
| 944 | 977 |
| 945 ElemHideFilter.prototype = | 978 ElemHideFilter.prototype = |
| 946 { | 979 { |
| 947 __proto__: ElemHideBase.prototype | 980 __proto__: ElemHideBase.prototype, |
| 981 |
| 982 type: "elemhide" |
| 948 }; | 983 }; |
| 949 | 984 |
| 950 /** | 985 /** |
| 951 * Class for element hiding exceptions | 986 * Class for element hiding exceptions |
| 952 * @param {String} text see Filter() | 987 * @param {String} text see Filter() |
| 953 * @param {String} domains see ElemHideBase() | 988 * @param {String} domains see ElemHideBase() |
| 954 * @param {String} selector see ElemHideBase() | 989 * @param {String} selector see ElemHideBase() |
| 955 * @constructor | 990 * @constructor |
| 956 * @augments ElemHideBase | 991 * @augments ElemHideBase |
| 957 */ | 992 */ |
| 958 function ElemHideException(text, domains, selector) | 993 function ElemHideException(text, domains, selector) |
| 959 { | 994 { |
| 960 ElemHideBase.call(this, text, domains, selector); | 995 ElemHideBase.call(this, text, domains, selector); |
| 961 } | 996 } |
| 962 exports.ElemHideException = ElemHideException; | 997 exports.ElemHideException = ElemHideException; |
| 963 | 998 |
| 964 ElemHideException.prototype = | 999 ElemHideException.prototype = |
| 965 { | 1000 { |
| 966 __proto__: ElemHideBase.prototype | 1001 __proto__: ElemHideBase.prototype, |
| 1002 |
| 1003 type: "elemhideexception" |
| 967 }; | 1004 }; |
| 968 | 1005 |
| 969 /** | 1006 /** |
| 970 * Class for CSS property filters | 1007 * Class for CSS property filters |
| 971 * @param {String} text see Filter() | 1008 * @param {String} text see Filter() |
| 972 * @param {String} domains see ElemHideBase() | 1009 * @param {String} domains see ElemHideBase() |
| 973 * @param {String} selector see ElemHideBase() | 1010 * @param {String} selector see ElemHideBase() |
| 974 * @param {String} regexpSource see CSSPropertyFilter.regexpSource | 1011 * @param {String} regexpSource see CSSPropertyFilter.regexpSource |
| 975 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix | 1012 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix |
| 976 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix | 1013 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix |
| 977 * @constructor | 1014 * @constructor |
| 978 * @augments ElemHideBase | 1015 * @augments ElemHideBase |
| 979 */ | 1016 */ |
| 980 function CSSPropertyFilter(text, domains, selector, regexpSource, | 1017 function CSSPropertyFilter(text, domains, selector, regexpSource, |
| 981 selectorPrefix, selectorSuffix) | 1018 selectorPrefix, selectorSuffix) |
| 982 { | 1019 { |
| 983 ElemHideBase.call(this, text, domains, selector); | 1020 ElemHideBase.call(this, text, domains, selector); |
| 984 | 1021 |
| 985 this.regexpSource = regexpSource; | 1022 this.regexpSource = regexpSource; |
| 986 this.selectorPrefix = selectorPrefix; | 1023 this.selectorPrefix = selectorPrefix; |
| 987 this.selectorSuffix = selectorSuffix; | 1024 this.selectorSuffix = selectorSuffix; |
| 988 } | 1025 } |
| 989 exports.CSSPropertyFilter = CSSPropertyFilter; | 1026 exports.CSSPropertyFilter = CSSPropertyFilter; |
| 990 | 1027 |
| 991 CSSPropertyFilter.prototype = | 1028 CSSPropertyFilter.prototype = |
| 992 { | 1029 { |
| 993 __proto__: ElemHideBase.prototype, | 1030 __proto__: ElemHideBase.prototype, |
| 994 | 1031 |
| 1032 type: "cssproperty", |
| 1033 |
| 995 /** | 1034 /** |
| 996 * Expression from which a regular expression should be generated for matching | 1035 * Expression from which a regular expression should be generated for matching |
| 997 * CSS properties - for delayed creation of the regexpString property | 1036 * CSS properties - for delayed creation of the regexpString property |
| 998 * @type String | 1037 * @type String |
| 999 */ | 1038 */ |
| 1000 regexpSource: null, | 1039 regexpSource: null, |
| 1001 /** | 1040 /** |
| 1002 * Substring of CSS selector before properties for the HTML elements that | 1041 * Substring of CSS selector before properties for the HTML elements that |
| 1003 * should be hidden | 1042 * should be hidden |
| 1004 * @type String | 1043 * @type String |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1022 // several times on Safari, due to WebKit bug 132872 | 1061 // several times on Safari, due to WebKit bug 132872 |
| 1023 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); | 1062 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); |
| 1024 if (prop) | 1063 if (prop) |
| 1025 return prop.value; | 1064 return prop.value; |
| 1026 | 1065 |
| 1027 let regexp = Filter.toRegExp(this.regexpSource); | 1066 let regexp = Filter.toRegExp(this.regexpSource); |
| 1028 Object.defineProperty(this, "regexpString", {value: regexp}); | 1067 Object.defineProperty(this, "regexpString", {value: regexp}); |
| 1029 return regexp; | 1068 return regexp; |
| 1030 } | 1069 } |
| 1031 }; | 1070 }; |
| LEFT | RIGHT |