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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 5730585574113280: Issue 2390 - Created filter class for CSS property filters (Closed)
Left Patch Set: Created May 6, 2015, 11:13 a.m.
Right Patch Set: Modified constructor signature Created June 8, 2015, 2:25 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 | « chrome/locale/en-US/global.properties ('k') | no next file » | 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-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
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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 let separatorPos = rule.indexOf("="); 887 let separatorPos = rule.indexOf("=");
897 if (separatorPos > 0) 888 if (separatorPos > 0)
898 { 889 {
899 rule = rule.replace(/=/, '="') + '"'; 890 rule = rule.replace(/=/, '="') + '"';
900 additional += "[" + rule + "]"; 891 additional += "[" + rule + "]";
901 } 892 }
902 else 893 else
903 { 894 {
904 if (id) 895 if (id)
905 return new InvalidFilter(text, Utils.getString("filter_elemhide_dupl icate_id")); 896 return new InvalidFilter(text, Utils.getString("filter_elemhide_dupl icate_id"));
906 else 897
907 id = rule; 898 id = rule;
908 } 899 }
909 } 900 }
910 } 901 }
911 902
912 if (id) 903 if (id)
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 }
910
919 if (isException) 911 if (isException)
920 return new ElemHideException(text, domain, selector); 912 return new ElemHideException(text, domain, selector);
921 else 913
922 { 914 let match = Filter.csspropertyRegExp.exec(selector);
923 if (Filter.csspropertyRegExp.test(selector)) 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))
Sebastian Noack 2015/05/06 13:07:48 This regex will allow "foo.." (note that this is e
Thomas Greiner 2015/05/06 15:33:07 While "foo.." might be equivalent to "foo" when us
928 return new InvalidFilter(text, Utils.getString("filter_cssproperty_nodom ain")); 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],
931 } 923 selector.substr(0, match.index),
932 924 selector.substr(match.index + match[0].length));
933 return new ElemHideFilter(text, domain, selector); 925 }
934 } 926
927 return new ElemHideFilter(text, domain, selector);
935 }; 928 };
936 929
937 /** 930 /**
938 * Class for element hiding filters 931 * Class for element hiding filters
939 * @param {String} text see Filter() 932 * @param {String} text see Filter()
940 * @param {String} domains see ElemHideBase() 933 * @param {String} domains see ElemHideBase()
941 * @param {String} selector see ElemHideBase() 934 * @param {String} selector see ElemHideBase()
942 * @constructor 935 * @constructor
943 * @augments ElemHideBase 936 * @augments ElemHideBase
944 */ 937 */
(...skipping 22 matching lines...) Expand all
967 } 960 }
968 exports.ElemHideException = ElemHideException; 961 exports.ElemHideException = ElemHideException;
969 962
970 ElemHideException.prototype = 963 ElemHideException.prototype =
971 { 964 {
972 __proto__: ElemHideBase.prototype 965 __proto__: ElemHideBase.prototype
973 }; 966 };
974 967
975 /** 968 /**
976 * Class for CSS property filters 969 * Class for CSS property filters
977 * @param {String} text see Filter() 970 * @param {String} text see Filter()
978 * @param {String} domains see ElemHideBase() 971 * @param {String} domains see ElemHideBase()
979 * @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
980 * @constructor 976 * @constructor
981 * @augments ElemHideBase 977 * @augments ElemHideBase
982 */ 978 */
983 function CSSPropertyFilter(text, domains, selector) 979 function CSSPropertyFilter(text, domains, selector, regexpSource,
980 selectorPrefix, selectorSuffix)
984 { 981 {
985 ElemHideBase.call(this, text, domains, selector); 982 ElemHideBase.call(this, text, domains, selector);
986 983
987 let properties; 984 this.regexpSource = regexpSource;
988 [properties, , this.regexpSource] = selector.match(Filter.csspropertyRegExp); 985 this.selectorPrefix = selectorPrefix;
989 [this.selectorPrefix, this.selectorSuffix] = selector.split(properties); 986 this.selectorSuffix = selectorSuffix;
990 } 987 }
991 exports.CSSPropertyFilter = CSSPropertyFilter; 988 exports.CSSPropertyFilter = CSSPropertyFilter;
992 989
993 CSSPropertyFilter.prototype = 990 CSSPropertyFilter.prototype =
994 { 991 {
995 __proto__: ElemHideBase.prototype, 992 __proto__: ElemHideBase.prototype,
996 993
997 /** 994 /**
998 * Expression from which a regular expression should be generated for matching 995 * Expression from which a regular expression should be generated for matching
999 * 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
1024 // several times on Safari, due to WebKit bug 132872 1021 // several times on Safari, due to WebKit bug 132872
1025 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); 1022 let prop = Object.getOwnPropertyDescriptor(this, "regexpString");
1026 if (prop) 1023 if (prop)
1027 return prop.value; 1024 return prop.value;
1028 1025
1029 let regexp = Filter.toRegExp(this.regexpSource); 1026 let regexp = Filter.toRegExp(this.regexpSource);
1030 Object.defineProperty(this, "regexpString", {value: regexp}); 1027 Object.defineProperty(this, "regexpString", {value: regexp});
1031 return regexp; 1028 return regexp;
1032 } 1029 }
1033 }; 1030 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld