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-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, |
236 | 247 |
| 248 type: "comment", |
| 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() |
246 * @param {String} [domains] Domains that the filter is restricted to separated
by domainSeparator e.g. "foo.com|bar.com|~baz.com" | 259 * @param {String} [domains] Domains that the filter is restricted to separated
by domainSeparator e.g. "foo.com|bar.com|~baz.com" |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); | 807 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); |
795 | 808 |
796 this.collapse = collapse; | 809 this.collapse = collapse; |
797 } | 810 } |
798 exports.BlockingFilter = BlockingFilter; | 811 exports.BlockingFilter = BlockingFilter; |
799 | 812 |
800 BlockingFilter.prototype = | 813 BlockingFilter.prototype = |
801 { | 814 { |
802 __proto__: RegExpFilter.prototype, | 815 __proto__: RegExpFilter.prototype, |
803 | 816 |
| 817 type: "blocking", |
| 818 |
804 /** | 819 /** |
805 * 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). |
806 * @type Boolean | 821 * @type Boolean |
807 */ | 822 */ |
808 collapse: null | 823 collapse: null |
809 }; | 824 }; |
810 | 825 |
811 /** | 826 /** |
812 * Class for whitelist filters | 827 * Class for whitelist filters |
813 * @param {String} text see Filter() | 828 * @param {String} text see Filter() |
814 * @param {String} regexpSource see RegExpFilter() | 829 * @param {String} regexpSource see RegExpFilter() |
815 * @param {Number} contentType see RegExpFilter() | 830 * @param {Number} contentType see RegExpFilter() |
816 * @param {Boolean} matchCase see RegExpFilter() | 831 * @param {Boolean} matchCase see RegExpFilter() |
817 * @param {String} domains see RegExpFilter() | 832 * @param {String} domains see RegExpFilter() |
818 * @param {Boolean} thirdParty see RegExpFilter() | 833 * @param {Boolean} thirdParty see RegExpFilter() |
819 * @param {String} sitekeys see RegExpFilter() | 834 * @param {String} sitekeys see RegExpFilter() |
820 * @constructor | 835 * @constructor |
821 * @augments RegExpFilter | 836 * @augments RegExpFilter |
822 */ | 837 */ |
823 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
irdParty, sitekeys) | 838 function WhitelistFilter(text, regexpSource, contentType, matchCase, domains, th
irdParty, sitekeys) |
824 { | 839 { |
825 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); | 840 RegExpFilter.call(this, text, regexpSource, contentType, matchCase, domains, t
hirdParty, sitekeys); |
826 } | 841 } |
827 exports.WhitelistFilter = WhitelistFilter; | 842 exports.WhitelistFilter = WhitelistFilter; |
828 | 843 |
829 WhitelistFilter.prototype = | 844 WhitelistFilter.prototype = |
830 { | 845 { |
831 __proto__: RegExpFilter.prototype | 846 __proto__: RegExpFilter.prototype, |
| 847 |
| 848 type: "whitelist" |
832 }; | 849 }; |
833 | 850 |
834 /** | 851 /** |
835 * Base class for element hiding filters | 852 * Base class for element hiding filters |
836 * @param {String} text see Filter() | 853 * @param {String} text see Filter() |
837 * @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 |
838 * @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 |
839 * @constructor | 856 * @constructor |
840 * @augments ActiveFilter | 857 * @augments ActiveFilter |
841 */ | 858 */ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 * @augments ElemHideBase | 969 * @augments ElemHideBase |
953 */ | 970 */ |
954 function ElemHideFilter(text, domains, selector) | 971 function ElemHideFilter(text, domains, selector) |
955 { | 972 { |
956 ElemHideBase.call(this, text, domains, selector); | 973 ElemHideBase.call(this, text, domains, selector); |
957 } | 974 } |
958 exports.ElemHideFilter = ElemHideFilter; | 975 exports.ElemHideFilter = ElemHideFilter; |
959 | 976 |
960 ElemHideFilter.prototype = | 977 ElemHideFilter.prototype = |
961 { | 978 { |
962 __proto__: ElemHideBase.prototype | 979 __proto__: ElemHideBase.prototype, |
| 980 |
| 981 type: "elemhide" |
963 }; | 982 }; |
964 | 983 |
965 /** | 984 /** |
966 * Class for element hiding exceptions | 985 * Class for element hiding exceptions |
967 * @param {String} text see Filter() | 986 * @param {String} text see Filter() |
968 * @param {String} domains see ElemHideBase() | 987 * @param {String} domains see ElemHideBase() |
969 * @param {String} selector see ElemHideBase() | 988 * @param {String} selector see ElemHideBase() |
970 * @constructor | 989 * @constructor |
971 * @augments ElemHideBase | 990 * @augments ElemHideBase |
972 */ | 991 */ |
973 function ElemHideException(text, domains, selector) | 992 function ElemHideException(text, domains, selector) |
974 { | 993 { |
975 ElemHideBase.call(this, text, domains, selector); | 994 ElemHideBase.call(this, text, domains, selector); |
976 } | 995 } |
977 exports.ElemHideException = ElemHideException; | 996 exports.ElemHideException = ElemHideException; |
978 | 997 |
979 ElemHideException.prototype = | 998 ElemHideException.prototype = |
980 { | 999 { |
981 __proto__: ElemHideBase.prototype | 1000 __proto__: ElemHideBase.prototype, |
| 1001 |
| 1002 type: "elemhideexception" |
982 }; | 1003 }; |
983 | 1004 |
984 /** | 1005 /** |
985 * Class for CSS property filters | 1006 * Class for CSS property filters |
986 * @param {String} text see Filter() | 1007 * @param {String} text see Filter() |
987 * @param {String} domains see ElemHideBase() | 1008 * @param {String} domains see ElemHideBase() |
988 * @param {String} selector see ElemHideBase() | 1009 * @param {String} selector see ElemHideBase() |
989 * @param {String} regexpSource see CSSPropertyFilter.regexpSource | 1010 * @param {String} regexpSource see CSSPropertyFilter.regexpSource |
990 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix | 1011 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix |
991 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix | 1012 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix |
992 * @constructor | 1013 * @constructor |
993 * @augments ElemHideBase | 1014 * @augments ElemHideBase |
994 */ | 1015 */ |
995 function CSSPropertyFilter(text, domains, selector, regexpSource, | 1016 function CSSPropertyFilter(text, domains, selector, regexpSource, |
996 selectorPrefix, selectorSuffix) | 1017 selectorPrefix, selectorSuffix) |
997 { | 1018 { |
998 ElemHideBase.call(this, text, domains, selector); | 1019 ElemHideBase.call(this, text, domains, selector); |
999 | 1020 |
1000 this.regexpSource = regexpSource; | 1021 this.regexpSource = regexpSource; |
1001 this.selectorPrefix = selectorPrefix; | 1022 this.selectorPrefix = selectorPrefix; |
1002 this.selectorSuffix = selectorSuffix; | 1023 this.selectorSuffix = selectorSuffix; |
1003 } | 1024 } |
1004 exports.CSSPropertyFilter = CSSPropertyFilter; | 1025 exports.CSSPropertyFilter = CSSPropertyFilter; |
1005 | 1026 |
1006 CSSPropertyFilter.prototype = | 1027 CSSPropertyFilter.prototype = |
1007 { | 1028 { |
1008 __proto__: ElemHideBase.prototype, | 1029 __proto__: ElemHideBase.prototype, |
1009 | 1030 |
| 1031 type: "cssproperty", |
| 1032 |
1010 /** | 1033 /** |
1011 * Expression from which a regular expression should be generated for matching | 1034 * Expression from which a regular expression should be generated for matching |
1012 * CSS properties - for delayed creation of the regexpString property | 1035 * CSS properties - for delayed creation of the regexpString property |
1013 * @type String | 1036 * @type String |
1014 */ | 1037 */ |
1015 regexpSource: null, | 1038 regexpSource: null, |
1016 /** | 1039 /** |
1017 * Substring of CSS selector before properties for the HTML elements that | 1040 * Substring of CSS selector before properties for the HTML elements that |
1018 * should be hidden | 1041 * should be hidden |
1019 * @type String | 1042 * @type String |
(...skipping 17 matching lines...) Expand all Loading... |
1037 // several times on Safari, due to WebKit bug 132872 | 1060 // several times on Safari, due to WebKit bug 132872 |
1038 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); | 1061 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); |
1039 if (prop) | 1062 if (prop) |
1040 return prop.value; | 1063 return prop.value; |
1041 | 1064 |
1042 let regexp = Filter.toRegExp(this.regexpSource); | 1065 let regexp = Filter.toRegExp(this.regexpSource); |
1043 Object.defineProperty(this, "regexpString", {value: regexp}); | 1066 Object.defineProperty(this, "regexpString", {value: regexp}); |
1044 return regexp; | 1067 return regexp; |
1045 } | 1068 } |
1046 }; | 1069 }; |
OLD | NEW |