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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/filterClasses.js
diff --git a/lib/filterClasses.js b/lib/filterClasses.js
index 6bc6f29fdbf938c2d3b9a811bff24f9d85020ae0..90a79ec17c8bdc8e51524c18c318174b270a59c0 100644
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -625,15 +625,15 @@ RegExpFilter.prototype =
/**
* Tests whether the URL matches this filter
* @param {String} location URL to be tested
- * @param {String} contentType content type identifier of the URL
+ * @param {String} typeMask bitmask of content / request types to match
* @param {String} docDomain domain name of the document that loads the URL
* @param {Boolean} thirdParty should be true if the URL is a third-party request
* @param {String} sitekey public key provided by the document
* @return {Boolean} true in case of a match
*/
- matches: function(location, contentType, docDomain, thirdParty, sitekey)
+ matches: function(location, typeMask, docDomain, thirdParty, sitekey)
{
- if ((RegExpFilter.typeMap[contentType] & this.contentType) != 0 &&
+ 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.
(this.thirdParty == null || this.thirdParty == thirdParty) &&
this.isActiveOnDomain(docDomain, sitekey) && this.regexp.test(location))
{
@@ -761,6 +761,22 @@ RegExpFilter.typeMap = {
RegExpFilter.prototype.contentType &= ~(RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP);
/**
+ * Creates a content / request type mask from a content type string or
+ * array of content type strings.
+ * @param {String} [contentType] content / request type string(s)
+ */
+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.
+{
+ if (typeof contentType == "string")
+ return RegExpFilter.typeMap[contentType];
+
+ var mask = 0;
+ for (let type of contentType)
+ mask |= RegExpFilter.typeMap[type];
+ return mask;
+};
+
+/**
* Class for blocking filters
* @param {String} text see Filter()
* @param {String} regexpSource see RegExpFilter()
« 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