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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29321478: Issue 2738 - Make RegExpFilter.matches() take a bit mask instead of content type string (Closed)
Left Patch Set: Created July 9, 2015, 1:45 p.m.
Right Patch Set: Changed API as discussed and addressed feedback Created July 12, 2015, 1:55 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 | « lib/contentPolicy.js ('k') | lib/matcher.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-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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
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} typeMask bitmask of content / request types to match 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, typeMask, docDomain, thirdParty, sitekey) 634 matches: function(location, typeMask, docDomain, thirdParty, sitekey)
635 { 635 {
636 if ((this.contentType & typeMask) != 0 && 636 if (this.contentType & typeMask &&
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 /**
780 * Class for blocking filters 764 * Class for blocking filters
781 * @param {String} text see Filter() 765 * @param {String} text see Filter()
782 * @param {String} regexpSource see RegExpFilter() 766 * @param {String} regexpSource see RegExpFilter()
783 * @param {Number} contentType see RegExpFilter() 767 * @param {Number} contentType see RegExpFilter()
784 * @param {Boolean} matchCase see RegExpFilter() 768 * @param {Boolean} matchCase see RegExpFilter()
785 * @param {String} domains see RegExpFilter() 769 * @param {String} domains see RegExpFilter()
786 * @param {Boolean} thirdParty see RegExpFilter() 770 * @param {Boolean} thirdParty see RegExpFilter()
787 * @param {String} sitekeys see RegExpFilter() 771 * @param {String} sitekeys see RegExpFilter()
788 * @param {Boolean} collapse defines whether the filter should collapse blocked content, can be null 772 * @param {Boolean} collapse defines whether the filter should collapse blocked content, can be null
789 * @constructor 773 * @constructor
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 // several times on Safari, due to WebKit bug 132872 1021 // several times on Safari, due to WebKit bug 132872
1038 let prop = Object.getOwnPropertyDescriptor(this, "regexpString"); 1022 let prop = Object.getOwnPropertyDescriptor(this, "regexpString");
1039 if (prop) 1023 if (prop)
1040 return prop.value; 1024 return prop.value;
1041 1025
1042 let regexp = Filter.toRegExp(this.regexpSource); 1026 let regexp = Filter.toRegExp(this.regexpSource);
1043 Object.defineProperty(this, "regexpString", {value: regexp}); 1027 Object.defineProperty(this, "regexpString", {value: regexp});
1044 return regexp; 1028 return regexp;
1045 } 1029 }
1046 }; 1030 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld