| Index: lib/matcher.js |
| =================================================================== |
| --- a/lib/matcher.js |
| +++ b/lib/matcher.js |
| @@ -165,13 +165,13 @@ |
| /** |
| * Checks whether the entries for a particular keyword match a URL |
| */ |
| - _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdParty) |
| + _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdParty, sitekey) |
| { |
| let list = this.filterByKeyword[keyword]; |
| for (let i = 0; i < list.length; i++) |
| { |
| let filter = list[i]; |
| - if (filter.matches(location, contentType, docDomain, thirdParty)) |
| + if (filter.matches(location, contentType, docDomain, thirdParty, sitekey)) |
| return filter; |
| } |
| return null; |
| @@ -183,9 +183,10 @@ |
| * @param {String} contentType content type identifier of the URL |
| * @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 {RegExpFilter} matching filter or null |
| */ |
| - matchesAny: function(location, contentType, docDomain, thirdParty) |
| + matchesAny: function(location, contentType, docDomain, thirdParty, sitekey) |
| { |
| let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
| if (candidates === null) |
| @@ -196,7 +197,7 @@ |
| let substr = candidates[i]; |
| if (substr in this.filterByKeyword) |
| { |
| - let result = this._checkEntryMatch(substr, location, contentType, docDomain, thirdParty); |
| + let result = this._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey); |
| if (result) |
| return result; |
| } |
| @@ -215,7 +216,6 @@ |
| { |
| this.blacklist = new Matcher(); |
| this.whitelist = new Matcher(); |
| - this.keys = Object.create(null); |
| this.resultCache = Object.create(null); |
| } |
| exports.CombinedMatcher = CombinedMatcher; |
| @@ -241,12 +241,6 @@ |
| whitelist: null, |
| /** |
| - * Exception rules that are limited by public keys, mapped by the corresponding keys. |
| - * @type Object |
| - */ |
| - keys: null, |
| - |
| - /** |
| * Lookup table of previous matchesAny results |
| * @type Object |
| */ |
| @@ -265,7 +259,6 @@ |
| { |
| this.blacklist.clear(); |
| this.whitelist.clear(); |
| - this.keys = Object.create(null); |
| this.resultCache = Object.create(null); |
| this.cacheEntries = 0; |
| }, |
| @@ -276,15 +269,7 @@ |
| add: function(filter) |
| { |
| if (filter instanceof WhitelistFilter) |
| - { |
| - if (filter.siteKeys) |
| - { |
| - for (let i = 0; i < filter.siteKeys.length; i++) |
| - this.keys[filter.siteKeys[i]] = filter.text; |
| - } |
| - else |
| - this.whitelist.add(filter); |
| - } |
| + this.whitelist.add(filter); |
| else |
| this.blacklist.add(filter); |
| @@ -301,15 +286,7 @@ |
| remove: function(filter) |
| { |
| if (filter instanceof WhitelistFilter) |
| - { |
| - if (filter.siteKeys) |
| - { |
| - for (let i = 0; i < filter.siteKeys.length; i++) |
| - delete this.keys[filter.siteKeys[i]]; |
| - } |
| - else |
| - this.whitelist.remove(filter); |
| - } |
| + this.whitelist.remove(filter); |
| else |
| this.blacklist.remove(filter); |
| @@ -370,7 +347,7 @@ |
| * simultaneously. For parameters see Matcher.matchesAny(). |
| * @see Matcher#matchesAny |
| */ |
| - matchesAnyInternal: function(location, contentType, docDomain, thirdParty) |
| + matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sitekey) |
| { |
| let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
| if (candidates === null) |
| @@ -383,12 +360,12 @@ |
| let substr = candidates[i]; |
| if (substr in this.whitelist.filterByKeyword) |
| { |
| - let result = this.whitelist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty); |
| + let result = this.whitelist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey); |
| if (result) |
| return result; |
| } |
| if (substr in this.blacklist.filterByKeyword && blacklistHit === null) |
| - blacklistHit = this.blacklist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty); |
| + blacklistHit = this.blacklist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey); |
| } |
| return blacklistHit; |
| }, |
| @@ -396,13 +373,13 @@ |
| /** |
| * @see Matcher#matchesAny |
| */ |
| - matchesAny: function(location, contentType, docDomain, thirdParty) |
| + matchesAny: function(location, contentType, docDomain, thirdParty, sitekey) |
| { |
| - let key = location + " " + contentType + " " + docDomain + " " + thirdParty; |
| + let key = location + " " + contentType + " " + docDomain + " " + thirdParty + " " + sitekey; |
| if (key in this.resultCache) |
| return this.resultCache[key]; |
| - let result = this.matchesAnyInternal(location, contentType, docDomain, thirdParty); |
| + let result = this.matchesAnyInternal(location, contentType, docDomain, thirdParty, sitekey); |
| if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) |
| { |
| @@ -414,24 +391,6 @@ |
| this.cacheEntries++; |
| return result; |
| - }, |
| - |
| - /** |
| - * Looks up whether any filters match the given website key. |
| - */ |
| - matchesByKey: function(/**String*/ location, /**String*/ key, /**String*/ docDomain) |
| - { |
| - key = key.toUpperCase(); |
| - if (key in this.keys) |
| - { |
| - let filter = Filter.knownFilters[this.keys[key]]; |
| - if (filter && filter.matches(location, "DOCUMENT", docDomain, false)) |
| - return filter; |
| - else |
| - return null; |
| - } |
| - else |
| - return null; |
| } |
| } |