Left: | ||
Right: |
OLD | NEW |
---|---|
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 { | 158 { |
159 if (filter.text in this.keywordByFilter) | 159 if (filter.text in this.keywordByFilter) |
160 return this.keywordByFilter[filter.text]; | 160 return this.keywordByFilter[filter.text]; |
161 else | 161 else |
162 return null; | 162 return null; |
163 }, | 163 }, |
164 | 164 |
165 /** | 165 /** |
166 * Checks whether the entries for a particular keyword match a URL | 166 * Checks whether the entries for a particular keyword match a URL |
167 */ | 167 */ |
168 _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdPar ty, sitekey) | 168 _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdPar ty, sitekey, specificOnly) |
169 { | 169 { |
170 let list = this.filterByKeyword[keyword]; | 170 let list = this.filterByKeyword[keyword]; |
171 for (let i = 0; i < list.length; i++) | 171 for (let i = 0; i < list.length; i++) |
172 { | 172 { |
173 let filter = list[i]; | 173 let filter = list[i]; |
174 if (filter.matches(location, contentType, docDomain, thirdParty, sitekey)) | 174 if (filter.matches(location, contentType, docDomain, thirdParty, sitekey) && |
Sebastian Noack
2015/03/12 11:36:21
Since the filter match is certainly the most expen
Sebastian Noack
2015/03/12 11:36:21
This is a very long chain of conditions. How about
kzar
2015/03/12 17:08:09
Done.
kzar
2015/03/12 17:08:09
Done.
| |
175 (!specificOnly || filter instanceof WhitelistFilter || | |
176 !(!filter.domains || filter.domains[""]))) | |
Sebastian Noack
2015/03/12 11:36:21
Isn't this the same as (filter.domains && !filter.
kzar
2015/03/12 17:08:09
Done.
| |
175 return filter; | 177 return filter; |
176 } | 178 } |
177 return null; | 179 return null; |
178 }, | 180 }, |
179 | 181 |
180 /** | 182 /** |
181 * Tests whether the URL matches any of the known filters | 183 * Tests whether the URL matches any of the known filters |
182 * @param {String} location URL to be tested | 184 * @param {String} location URL to be tested |
183 * @param {String} contentType content type identifier of the URL | 185 * @param {String} contentType content type identifier of the URL |
184 * @param {String} docDomain domain name of the document that loads the URL | 186 * @param {String} docDomain domain name of the document that loads the URL |
185 * @param {Boolean} thirdParty should be true if the URL is a third-party requ est | 187 * @param {Boolean} thirdParty should be true if the URL is a third-party requ est |
186 * @param {String} sitekey public key provided by the document | 188 * @param {String} sitekey public key provided by the document |
189 * @param {Boolean} specificOnly should be true if generic matches should be i gnored | |
187 * @return {RegExpFilter} matching filter or null | 190 * @return {RegExpFilter} matching filter or null |
188 */ | 191 */ |
189 matchesAny: function(location, contentType, docDomain, thirdParty, sitekey) | 192 matchesAny: function(location, contentType, docDomain, thirdParty, sitekey, sp ecificOnly) |
190 { | 193 { |
191 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); | 194 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
192 if (candidates === null) | 195 if (candidates === null) |
193 candidates = []; | 196 candidates = []; |
194 candidates.push(""); | 197 candidates.push(""); |
195 for (let i = 0, l = candidates.length; i < l; i++) | 198 for (let i = 0, l = candidates.length; i < l; i++) |
196 { | 199 { |
197 let substr = candidates[i]; | 200 let substr = candidates[i]; |
198 if (substr in this.filterByKeyword) | 201 if (substr in this.filterByKeyword) |
199 { | 202 { |
200 let result = this._checkEntryMatch(substr, location, contentType, docDom ain, thirdParty, sitekey); | 203 let result = this._checkEntryMatch(substr, location, contentType, docDom ain, thirdParty, sitekey, specificOnly); |
201 if (result) | 204 if (result) |
202 return result; | 205 return result; |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 return null; | 209 return null; |
207 } | 210 } |
208 }; | 211 }; |
209 | 212 |
210 /** | 213 /** |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 return !matcher.getKeywordForFilter(filter); | 343 return !matcher.getKeywordForFilter(filter); |
341 else | 344 else |
342 return !matcher.findKeyword(filter); | 345 return !matcher.findKeyword(filter); |
343 }, | 346 }, |
344 | 347 |
345 /** | 348 /** |
346 * Optimized filter matching testing both whitelist and blacklist matchers | 349 * Optimized filter matching testing both whitelist and blacklist matchers |
347 * simultaneously. For parameters see Matcher.matchesAny(). | 350 * simultaneously. For parameters see Matcher.matchesAny(). |
348 * @see Matcher#matchesAny | 351 * @see Matcher#matchesAny |
349 */ | 352 */ |
350 matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sit ekey) | 353 matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sit ekey, specificOnly) |
351 { | 354 { |
352 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); | 355 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
353 if (candidates === null) | 356 if (candidates === null) |
354 candidates = []; | 357 candidates = []; |
355 candidates.push(""); | 358 candidates.push(""); |
356 | 359 |
357 let blacklistHit = null; | 360 let blacklistHit = null; |
358 for (let i = 0, l = candidates.length; i < l; i++) | 361 for (let i = 0, l = candidates.length; i < l; i++) |
359 { | 362 { |
360 let substr = candidates[i]; | 363 let substr = candidates[i]; |
361 if (substr in this.whitelist.filterByKeyword) | 364 if (substr in this.whitelist.filterByKeyword) |
362 { | 365 { |
363 let result = this.whitelist._checkEntryMatch(substr, location, contentTy pe, docDomain, thirdParty, sitekey); | 366 let result = this.whitelist._checkEntryMatch(substr, location, contentTy pe, docDomain, thirdParty, sitekey); |
364 if (result) | 367 if (result) |
365 return result; | 368 return result; |
366 } | 369 } |
367 if (substr in this.blacklist.filterByKeyword && blacklistHit === null) | 370 if (substr in this.blacklist.filterByKeyword && blacklistHit === null) |
368 blacklistHit = this.blacklist._checkEntryMatch(substr, location, content Type, docDomain, thirdParty, sitekey); | 371 blacklistHit = this.blacklist._checkEntryMatch(substr, location, content Type, docDomain, thirdParty, sitekey, specificOnly); |
369 } | 372 } |
370 return blacklistHit; | 373 return blacklistHit; |
371 }, | 374 }, |
372 | 375 |
373 /** | 376 /** |
374 * @see Matcher#matchesAny | 377 * @see Matcher#matchesAny |
375 */ | 378 */ |
376 matchesAny: function(location, contentType, docDomain, thirdParty, sitekey) | 379 matchesAny: function(location, contentType, docDomain, thirdParty, sitekey, sp ecificOnly) |
377 { | 380 { |
378 let key = location + " " + contentType + " " + docDomain + " " + thirdParty + " " + sitekey; | 381 let key = location + " " + contentType + " " + docDomain + " " + thirdParty + " " + sitekey + " " + specificOnly; |
379 if (key in this.resultCache) | 382 if (key in this.resultCache) |
380 return this.resultCache[key]; | 383 return this.resultCache[key]; |
381 | 384 |
382 let result = this.matchesAnyInternal(location, contentType, docDomain, third Party, sitekey); | 385 let result = this.matchesAnyInternal(location, contentType, docDomain, third Party, sitekey, specificOnly); |
383 | 386 |
384 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) | 387 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) |
385 { | 388 { |
386 this.resultCache = Object.create(null); | 389 this.resultCache = Object.create(null); |
387 this.cacheEntries = 0; | 390 this.cacheEntries = 0; |
388 } | 391 } |
389 | 392 |
390 this.resultCache[key] = result; | 393 this.resultCache[key] = result; |
391 this.cacheEntries++; | 394 this.cacheEntries++; |
392 | 395 |
393 return result; | 396 return result; |
394 } | 397 } |
395 } | 398 } |
396 | 399 |
397 /** | 400 /** |
398 * Shared CombinedMatcher instance that should usually be used. | 401 * Shared CombinedMatcher instance that should usually be used. |
399 * @type CombinedMatcher | 402 * @type CombinedMatcher |
400 */ | 403 */ |
401 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); | 404 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); |
OLD | NEW |