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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29333474: Issue 4125 - [emscripten] Convert filter classes to C++ (Closed)
Left Patch Set: Minor improvements Created Feb. 6, 2016, 8:29 a.m.
Right Patch Set: Addressed comments from Patch Set 28 Created March 21, 2017, 10:04 a.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 | « compiled/traceInit.cpp ('k') | lib/filterClassesNew.js » ('j') | 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-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Definition of Filter class and its subclasses. 19 * @fileOverview Definition of Filter class and its subclasses.
20 */ 20 */
21 21
22 "use strict"; 22 "use strict";
23 23
24 let {FilterNotifier} = require("filterNotifier"); 24 let {FilterNotifier} = require("filterNotifier");
25 let {Utils} = require("utils");
26 25
27 /** 26 /**
28 * Abstract base class for filters 27 * Abstract base class for filters
29 * 28 *
30 * @param {String} text string representation of the filter 29 * @param {String} text string representation of the filter
31 * @constructor 30 * @constructor
32 */ 31 */
33 function Filter(text) 32 function Filter(text)
34 { 33 {
35 this.text = text; 34 this.text = text;
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 this.sitekeySource = null; 641 this.sitekeySource = null;
643 } 642 }
644 643
645 Object.defineProperty(this, "sitekeys", {value: sitekeys, enumerable: true}) ; 644 Object.defineProperty(this, "sitekeys", {value: sitekeys, enumerable: true}) ;
646 return this.sitekeys; 645 return this.sitekeys;
647 }, 646 },
648 647
649 /** 648 /**
650 * Tests whether the URL matches this filter 649 * Tests whether the URL matches this filter
651 * @param {String} location URL to be tested 650 * @param {String} location URL to be tested
652 * @param {String} typeMask bitmask of content / request types to match 651 * @param {number} typeMask bitmask of content / request types to match
653 * @param {String} docDomain domain name of the document that loads the URL 652 * @param {String} docDomain domain name of the document that loads the URL
654 * @param {Boolean} thirdParty should be true if the URL is a third-party requ est 653 * @param {Boolean} thirdParty should be true if the URL is a third-party requ est
655 * @param {String} sitekey public key provided by the document 654 * @param {String} sitekey public key provided by the document
656 * @return {Boolean} true in case of a match 655 * @return {Boolean} true in case of a match
657 */ 656 */
658 matches: function(location, typeMask, docDomain, thirdParty, sitekey) 657 matches: function(location, typeMask, docDomain, thirdParty, sitekey)
659 { 658 {
660 if (this.contentType & typeMask && 659 if (this.contentType & typeMask &&
661 (this.thirdParty == null || this.thirdParty == thirdParty) && 660 (this.thirdParty == null || this.thirdParty == thirdParty) &&
662 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) 661 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 thirdParty = true; 731 thirdParty = true;
733 else if (option == "~THIRD_PARTY") 732 else if (option == "~THIRD_PARTY")
734 thirdParty = false; 733 thirdParty = false;
735 else if (option == "COLLAPSE") 734 else if (option == "COLLAPSE")
736 collapse = true; 735 collapse = true;
737 else if (option == "~COLLAPSE") 736 else if (option == "~COLLAPSE")
738 collapse = false; 737 collapse = false;
739 else if (option == "SITEKEY" && typeof value != "undefined") 738 else if (option == "SITEKEY" && typeof value != "undefined")
740 sitekeys = value; 739 sitekeys = value;
741 else 740 else
742 return new InvalidFilter(origText, "Unknown option " + option.toLowerCas e()); 741 return new InvalidFilter(origText, "filter_unknown_option");
743 } 742 }
744 } 743 }
745 744
746 try 745 try
747 { 746 {
748 if (blocking) 747 if (blocking)
749 return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse); 748 return new BlockingFilter(origText, text, contentType, matchCase, domains, thirdParty, sitekeys, collapse);
750 else 749 else
751 return new WhitelistFilter(origText, text, contentType, matchCase, domains , thirdParty, sitekeys); 750 return new WhitelistFilter(origText, text, contentType, matchCase, domains , thirdParty, sitekeys);
752 } 751 }
753 catch (e) 752 catch (e)
754 { 753 {
755 return new InvalidFilter(origText, e); 754 return new InvalidFilter(origText, "filter_invalid_regexp");
756 } 755 }
757 }; 756 };
758 757
759 /** 758 /**
760 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks 759 * Maps type strings like "SCRIPT" or "OBJECT" to bit masks
761 */ 760 */
762 RegExpFilter.typeMap = { 761 RegExpFilter.typeMap = {
763 OTHER: 1, 762 OTHER: 1,
764 SCRIPT: 2, 763 SCRIPT: 2,
765 IMAGE: 4, 764 IMAGE: 4,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 rule = rule.substr(1, rule.length - 2); 921 rule = rule.substr(1, rule.length - 2);
923 let separatorPos = rule.indexOf("="); 922 let separatorPos = rule.indexOf("=");
924 if (separatorPos > 0) 923 if (separatorPos > 0)
925 { 924 {
926 rule = rule.replace(/=/, '="') + '"'; 925 rule = rule.replace(/=/, '="') + '"';
927 additional += "[" + rule + "]"; 926 additional += "[" + rule + "]";
928 } 927 }
929 else 928 else
930 { 929 {
931 if (id) 930 if (id)
932 return new InvalidFilter(text, Utils.getString("filter_elemhide_dupl icate_id")); 931 return new InvalidFilter(text, "filter_elemhide_duplicate_id");
933 932
934 id = rule; 933 id = rule;
935 } 934 }
936 } 935 }
937 } 936 }
938 937
939 if (id) 938 if (id)
940 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional; 939 selector = tagName + "." + id + additional + "," + tagName + "#" + id + ad ditional;
941 else if (tagName || additional) 940 else if (tagName || additional)
942 selector = tagName + additional; 941 selector = tagName + additional;
943 else 942 else
944 return new InvalidFilter(text, Utils.getString("filter_elemhide_nocriteria ")); 943 return new InvalidFilter(text, "filter_elemhide_nocriteria");
945 } 944 }
946 945
947 if (isException) 946 if (isException)
948 return new ElemHideException(text, domain, selector); 947 return new ElemHideException(text, domain, selector);
949 948
950 let match = Filter.csspropertyRegExp.exec(selector); 949 let match = Filter.csspropertyRegExp.exec(selector);
951 if (match) 950 if (match)
952 { 951 {
953 // CSS property filters are inefficient so we need to make sure that 952 // CSS property filters are inefficient so we need to make sure that
954 // they're only applied if they specify active domains 953 // they're only applied if they specify active domains
955 if (!/,[^~][^,.]*\.[^,]/.test("," + domain)) 954 if (!/,[^~][^,.]*\.[^,]/.test("," + domain))
956 return new InvalidFilter(text, Utils.getString("filter_cssproperty_nodomai n")); 955 return new InvalidFilter(text, "filter_cssproperty_nodomain");
957 956
958 return new CSSPropertyFilter(text, domain, selector, match[2], 957 return new CSSPropertyFilter(text, domain, selector, match[2],
959 selector.substr(0, match.index), 958 selector.substr(0, match.index),
960 selector.substr(match.index + match[0].length)); 959 selector.substr(match.index + match[0].length));
961 } 960 }
962 961
963 return new ElemHideFilter(text, domain, selector); 962 return new ElemHideFilter(text, domain, selector);
964 }; 963 };
965 964
966 /** 965 /**
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 // several times on Safari, due to WebKit bug 132872 1062 // several times on Safari, due to WebKit bug 132872
1064 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); 1063 let prop = Object.getOwnPropertyDescriptor(this, "regexpString");
1065 if (prop) 1064 if (prop)
1066 return prop.value; 1065 return prop.value;
1067 1066
1068 let regexp = Filter.toRegExp(this.regexpSource); 1067 let regexp = Filter.toRegExp(this.regexpSource);
1069 Object.defineProperty(this, "regexpString", {value: regexp}); 1068 Object.defineProperty(this, "regexpString", {value: regexp});
1070 return regexp; 1069 return regexp;
1071 } 1070 }
1072 }; 1071 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld