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

Side by Side Diff: lib/filterClasses.js

Issue 29321478: Issue 2738 - Make RegExpFilter.matches() take a bit mask instead of content type string (Closed)
Patch Set: Created July 9, 2015, 1:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 this.sitekeySource = null; 618 this.sitekeySource = null;
619 } 619 }
620 620
621 Object.defineProperty(this, "sitekeys", {value: sitekeys, enumerable: true}) ; 621 Object.defineProperty(this, "sitekeys", {value: sitekeys, enumerable: true}) ;
622 return this.sitekeys; 622 return this.sitekeys;
623 }, 623 },
624 624
625 /** 625 /**
626 * Tests whether the URL matches this filter 626 * Tests whether the URL matches this filter
627 * @param {String} location URL to be tested 627 * @param {String} location URL to be tested
628 * @param {String} contentType content type identifier of the URL 628 * @param {String} typeMask bitmask of content / request types to match
629 * @param {String} docDomain domain name of the document that loads the URL 629 * @param {String} docDomain domain name of the document that loads the URL
630 * @param {Boolean} thirdParty should be true if the URL is a third-party requ est 630 * @param {Boolean} thirdParty should be true if the URL is a third-party requ est
631 * @param {String} sitekey public key provided by the document 631 * @param {String} sitekey public key provided by the document
632 * @return {Boolean} true in case of a match 632 * @return {Boolean} true in case of a match
633 */ 633 */
634 matches: function(location, contentType, docDomain, thirdParty, sitekey) 634 matches: function(location, typeMask, docDomain, thirdParty, sitekey)
635 { 635 {
636 if ((RegExpFilter.typeMap[contentType] & this.contentType) != 0 && 636 if ((this.contentType & typeMask) != 0 &&
Sebastian Noack 2015/07/09 15:36:44 Note that |!= 0| is unneeded here.
kzar 2015/07/12 13:59:39 Done.
637 (this.thirdParty == null || this.thirdParty == thirdParty) && 637 (this.thirdParty == null || this.thirdParty == thirdParty) &&
638 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location)) 638 this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
639 { 639 {
640 return true; 640 return true;
641 } 641 }
642 642
643 return false; 643 return false;
644 } 644 }
645 }; 645 };
646 646
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 BACKGROUND: 4, // Backwards compat, same as IMAGE 754 BACKGROUND: 4, // Backwards compat, same as IMAGE
755 755
756 POPUP: 0x10000000, 756 POPUP: 0x10000000,
757 ELEMHIDE: 0x40000000 757 ELEMHIDE: 0x40000000
758 }; 758 };
759 759
760 // DOCUMENT, ELEMHIDE, POPUP options shouldn't be there by default 760 // DOCUMENT, ELEMHIDE, POPUP options shouldn't be there by default
761 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | RegExpFi lter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP); 761 RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | RegExpFi lter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP);
762 762
763 /** 763 /**
764 * Creates a content / request type mask from a content type string or
765 * array of content type strings.
766 * @param {String} [contentType] content / request type string(s)
767 */
768 RegExpFilter.toTypeMask = function (contentType)
Sebastian Noack 2015/07/09 15:36:44 I feel that this function just adds unneeded compl
kzar 2015/07/09 17:44:18 I've got to say I agree with you here, the few tim
Wladimir Palant 2015/07/10 21:07:00 Not really sure this is a good idea but well - let
kzar 2015/07/12 13:59:39 Done.
769 {
770 if (typeof contentType == "string")
771 return RegExpFilter.typeMap[contentType];
772
773 var mask = 0;
774 for (let type of contentType)
775 mask |= RegExpFilter.typeMap[type];
776 return mask;
777 };
778
779 /**
764 * Class for blocking filters 780 * Class for blocking filters
765 * @param {String} text see Filter() 781 * @param {String} text see Filter()
766 * @param {String} regexpSource see RegExpFilter() 782 * @param {String} regexpSource see RegExpFilter()
767 * @param {Number} contentType see RegExpFilter() 783 * @param {Number} contentType see RegExpFilter()
768 * @param {Boolean} matchCase see RegExpFilter() 784 * @param {Boolean} matchCase see RegExpFilter()
769 * @param {String} domains see RegExpFilter() 785 * @param {String} domains see RegExpFilter()
770 * @param {Boolean} thirdParty see RegExpFilter() 786 * @param {Boolean} thirdParty see RegExpFilter()
771 * @param {String} sitekeys see RegExpFilter() 787 * @param {String} sitekeys see RegExpFilter()
772 * @param {Boolean} collapse defines whether the filter should collapse blocked content, can be null 788 * @param {Boolean} collapse defines whether the filter should collapse blocked content, can be null
773 * @constructor 789 * @constructor
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 // several times on Safari, due to WebKit bug 132872 1037 // several times on Safari, due to WebKit bug 132872
1022 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); 1038 let prop = Object.getOwnPropertyDescriptor(this, "regexpString");
1023 if (prop) 1039 if (prop)
1024 return prop.value; 1040 return prop.value;
1025 1041
1026 let regexp = Filter.toRegExp(this.regexpSource); 1042 let regexp = Filter.toRegExp(this.regexpSource);
1027 Object.defineProperty(this, "regexpString", {value: regexp}); 1043 Object.defineProperty(this, "regexpString", {value: regexp});
1028 return regexp; 1044 return regexp;
1029 } 1045 }
1030 }; 1046 };
OLDNEW
« lib/contentPolicy.js ('K') | « lib/contentPolicy.js ('k') | lib/matcher.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld