Left: | ||
Right: |
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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 collapse = true; | 712 collapse = true; |
713 else if (option == "~COLLAPSE") | 713 else if (option == "~COLLAPSE") |
714 collapse = false; | 714 collapse = false; |
715 else if (option == "SITEKEY" && typeof value != "undefined") | 715 else if (option == "SITEKEY" && typeof value != "undefined") |
716 sitekeys = value; | 716 sitekeys = value; |
717 else | 717 else |
718 return new InvalidFilter(origText, "Unknown option " + option.toLowerCas e()); | 718 return new InvalidFilter(origText, "Unknown option " + option.toLowerCas e()); |
719 } | 719 } |
720 } | 720 } |
721 | 721 |
722 if (!blocking && (contentType == null || (contentType & RegExpFilter.typeMap.D OCUMENT)) && | |
723 (!options || options.indexOf("DOCUMENT") < 0) && !/^\|?[\w\-]+:/.test(text )) | |
724 { | |
725 // Exception filters shouldn't apply to pages by default unless they start w ith a protocol name | |
726 if (contentType == null) | |
727 contentType = RegExpFilter.prototype.contentType; | |
728 contentType &= ~RegExpFilter.typeMap.DOCUMENT; | |
729 } | |
730 | |
731 try | 722 try |
732 { | 723 { |
733 if (blocking) | 724 if (blocking) |
734 return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse); | 725 return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse); |
735 else | 726 else |
736 return new WhitelistFilter(origText, text, contentType, matchCase, domains , thirdParty, sitekeys); | 727 return new WhitelistFilter(origText, text, contentType, matchCase, domains , thirdParty, sitekeys); |
737 } | 728 } |
738 catch (e) | 729 catch (e) |
739 { | 730 { |
740 return new InvalidFilter(origText, e); | 731 return new InvalidFilter(origText, e); |
(...skipping 18 matching lines...) Expand all Loading... | |
759 DTD: 1, | 750 DTD: 1, |
760 MEDIA: 16384, | 751 MEDIA: 16384, |
761 FONT: 32768, | 752 FONT: 32768, |
762 | 753 |
763 BACKGROUND: 4, // Backwards compat, same as IMAGE | 754 BACKGROUND: 4, // Backwards compat, same as IMAGE |
764 | 755 |
765 POPUP: 0x10000000, | 756 POPUP: 0x10000000, |
766 ELEMHIDE: 0x40000000 | 757 ELEMHIDE: 0x40000000 |
767 }; | 758 }; |
768 | 759 |
769 // ELEMHIDE, POPUP option shouldn't be there by default | 760 // DOCUMENT, ELEMHIDE, POPUP options shouldn't be there by default |
770 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.ELEMHIDE | RegExpFi lter.typeMap.POPUP); | 761 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | RegExpFi lter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP); |
771 | 762 |
772 /** | 763 /** |
773 * Class for blocking filters | 764 * Class for blocking filters |
774 * @param {String} text see Filter() | 765 * @param {String} text see Filter() |
775 * @param {String} regexpSource see RegExpFilter() | 766 * @param {String} regexpSource see RegExpFilter() |
776 * @param {Number} contentType see RegExpFilter() | 767 * @param {Number} contentType see RegExpFilter() |
777 * @param {Boolean} matchCase see RegExpFilter() | 768 * @param {Boolean} matchCase see RegExpFilter() |
778 * @param {String} domains see RegExpFilter() | 769 * @param {String} domains see RegExpFilter() |
779 * @param {Boolean} thirdParty see RegExpFilter() | 770 * @param {Boolean} thirdParty see RegExpFilter() |
780 * @param {String} sitekeys see RegExpFilter() | 771 * @param {String} sitekeys see RegExpFilter() |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; | 904 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; |
914 else if (tagName || additional) | 905 else if (tagName || additional) |
915 selector = tagName + additional; | 906 selector = tagName + additional; |
916 else | 907 else |
917 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocriteria ")); | 908 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocriteria ")); |
918 } | 909 } |
919 | 910 |
920 if (isException) | 911 if (isException) |
921 return new ElemHideException(text, domain, selector); | 912 return new ElemHideException(text, domain, selector); |
922 | 913 |
923 if (Filter.csspropertyRegExp.test(selector)) | 914 let match = Filter.csspropertyRegExp.exec(selector); |
Wladimir Palant
2015/06/05 22:08:59
How about actually storing the result of this sele
Thomas Greiner
2015/06/08 14:33:43
Done. I don't really mind either approach.
Note t
| |
915 if (match) | |
924 { | 916 { |
925 // CSS property filters are inefficient so we need to make sure that | 917 // CSS property filters are inefficient so we need to make sure that |
926 // they're only applied if they specify active domains | 918 // they're only applied if they specify active domains |
927 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) | 919 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) |
928 return new InvalidFilter(text, Utils.getString("filter_cssproperty_nodomai n")); | 920 return new InvalidFilter(text, Utils.getString("filter_cssproperty_nodomai n")); |
929 | 921 |
930 return new CSSPropertyFilter(text, domain, selector); | 922 return new CSSPropertyFilter(text, domain, selector, match[2], |
923 selector.substr(0, match.index), | |
924 selector.substr(match.index + match[0].length)); | |
931 } | 925 } |
932 | 926 |
933 return new ElemHideFilter(text, domain, selector); | 927 return new ElemHideFilter(text, domain, selector); |
934 }; | 928 }; |
935 | 929 |
936 /** | 930 /** |
937 * Class for element hiding filters | 931 * Class for element hiding filters |
938 * @param {String} text see Filter() | 932 * @param {String} text see Filter() |
939 * @param {String} domains see ElemHideBase() | 933 * @param {String} domains see ElemHideBase() |
940 * @param {String} selector see ElemHideBase() | 934 * @param {String} selector see ElemHideBase() |
(...skipping 25 matching lines...) Expand all Loading... | |
966 } | 960 } |
967 exports.ElemHideException = ElemHideException; | 961 exports.ElemHideException = ElemHideException; |
968 | 962 |
969 ElemHideException.prototype = | 963 ElemHideException.prototype = |
970 { | 964 { |
971 __proto__: ElemHideBase.prototype | 965 __proto__: ElemHideBase.prototype |
972 }; | 966 }; |
973 | 967 |
974 /** | 968 /** |
975 * Class for CSS property filters | 969 * Class for CSS property filters |
976 * @param {String} text see Filter() | 970 * @param {String} text see Filter() |
977 * @param {String} domains see ElemHideBase() | 971 * @param {String} domains see ElemHideBase() |
978 * @param {String} selector see ElemHideBase() | 972 * @param {String} selector see ElemHideBase() |
973 * @param {String} regexpSource see CSSPropertyFilter.regexpSource | |
974 * @param {String} selectorPrefix see CSSPropertyFilter.selectorPrefix | |
975 * @param {String} selectorSuffix see CSSPropertyFilter.selectorSuffix | |
979 * @constructor | 976 * @constructor |
980 * @augments ElemHideBase | 977 * @augments ElemHideBase |
981 */ | 978 */ |
982 function CSSPropertyFilter(text, domains, selector) | 979 function CSSPropertyFilter(text, domains, selector, regexpSource, |
980 selectorPrefix, selectorSuffix) | |
983 { | 981 { |
984 ElemHideBase.call(this, text, domains, selector); | 982 ElemHideBase.call(this, text, domains, selector); |
985 | 983 |
986 let properties; | 984 this.regexpSource = regexpSource; |
987 [properties, , this.regexpSource] = selector.match(Filter.csspropertyRegExp); | 985 this.selectorPrefix = selectorPrefix; |
988 [this.selectorPrefix, this.selectorSuffix] = selector.split(properties); | 986 this.selectorSuffix = selectorSuffix; |
989 } | 987 } |
990 exports.CSSPropertyFilter = CSSPropertyFilter; | 988 exports.CSSPropertyFilter = CSSPropertyFilter; |
991 | 989 |
992 CSSPropertyFilter.prototype = | 990 CSSPropertyFilter.prototype = |
993 { | 991 { |
994 __proto__: ElemHideBase.prototype, | 992 __proto__: ElemHideBase.prototype, |
995 | 993 |
996 /** | 994 /** |
997 * Expression from which a regular expression should be generated for matching | 995 * Expression from which a regular expression should be generated for matching |
998 * CSS properties - for delayed creation of the regexpString property | 996 * CSS properties - for delayed creation of the regexpString property |
(...skipping 24 matching lines...) Expand all Loading... | |
1023 // several times on Safari, due to WebKit bug 132872 | 1021 // several times on Safari, due to WebKit bug 132872 |
1024 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); | 1022 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); |
1025 if (prop) | 1023 if (prop) |
1026 return prop.value; | 1024 return prop.value; |
1027 | 1025 |
1028 let regexp = Filter.toRegExp(this.regexpSource); | 1026 let regexp = Filter.toRegExp(this.regexpSource); |
1029 Object.defineProperty(this, "regexpString", {value: regexp}); | 1027 Object.defineProperty(this, "regexpString", {value: regexp}); |
1030 return regexp; | 1028 return regexp; |
1031 } | 1029 } |
1032 }; | 1030 }; |
LEFT | RIGHT |