LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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, docLocation, siteKey) | 168 _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdPar
ty, sitekey) |
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, docLocati
on, siteKey)) | 174 if (filter.matches(location, contentType, docDomain, thirdParty, sitekey)) |
175 return filter; | 175 return filter; |
176 } | 176 } |
177 return null; | 177 return null; |
178 }, | 178 }, |
179 | 179 |
180 /** | 180 /** |
181 * Tests whether the URL matches any of the known filters | 181 * Tests whether the URL matches any of the known filters |
182 * @param {String} location URL to be tested | 182 * @param {String} location URL to be tested |
183 * @param {String} contentType content type identifier of the URL | 183 * @param {String} contentType content type identifier of the URL |
184 * @param {String} docDomain domain name of the document that loads the URL | 184 * @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 | 185 * @param {Boolean} thirdParty should be true if the URL is a third-party requ
est |
186 * @param {String} docLocation location the document that loads the URL | 186 * @param {String} sitekey public key provided by the document |
187 * @param {String} siteKey public key provided by the document | |
188 * @return {RegExpFilter} matching filter or null | 187 * @return {RegExpFilter} matching filter or null |
189 */ | 188 */ |
190 matchesAny: function(location, contentType, docDomain, thirdParty, docLocation
, siteKey) | 189 matchesAny: function(location, contentType, docDomain, thirdParty, sitekey) |
191 { | 190 { |
192 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); | 191 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
193 if (candidates === null) | 192 if (candidates === null) |
194 candidates = []; | 193 candidates = []; |
195 candidates.push(""); | 194 candidates.push(""); |
196 for (let i = 0, l = candidates.length; i < l; i++) | 195 for (let i = 0, l = candidates.length; i < l; i++) |
197 { | 196 { |
198 let substr = candidates[i]; | 197 let substr = candidates[i]; |
199 if (substr in this.filterByKeyword) | 198 if (substr in this.filterByKeyword) |
200 { | 199 { |
201 let result = this._checkEntryMatch(substr, location, contentType, docDom
ain, thirdParty, docLocation, siteKey); | 200 let result = this._checkEntryMatch(substr, location, contentType, docDom
ain, thirdParty, sitekey); |
202 if (result) | 201 if (result) |
203 return result; | 202 return result; |
204 } | 203 } |
205 } | 204 } |
206 | 205 |
207 return null; | 206 return null; |
208 } | 207 } |
209 }; | 208 }; |
210 | 209 |
211 /** | 210 /** |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 return !matcher.getKeywordForFilter(filter); | 340 return !matcher.getKeywordForFilter(filter); |
342 else | 341 else |
343 return !matcher.findKeyword(filter); | 342 return !matcher.findKeyword(filter); |
344 }, | 343 }, |
345 | 344 |
346 /** | 345 /** |
347 * Optimized filter matching testing both whitelist and blacklist matchers | 346 * Optimized filter matching testing both whitelist and blacklist matchers |
348 * simultaneously. For parameters see Matcher.matchesAny(). | 347 * simultaneously. For parameters see Matcher.matchesAny(). |
349 * @see Matcher#matchesAny | 348 * @see Matcher#matchesAny |
350 */ | 349 */ |
351 matchesAnyInternal: function(location, contentType, docDomain, thirdParty, doc
Location, siteKey) | 350 matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sit
ekey) |
352 { | 351 { |
353 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); | 352 let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g); |
354 if (candidates === null) | 353 if (candidates === null) |
355 candidates = []; | 354 candidates = []; |
356 candidates.push(""); | 355 candidates.push(""); |
357 | 356 |
358 let blacklistHit = null; | 357 let blacklistHit = null; |
359 for (let i = 0, l = candidates.length; i < l; i++) | 358 for (let i = 0, l = candidates.length; i < l; i++) |
360 { | 359 { |
361 let substr = candidates[i]; | 360 let substr = candidates[i]; |
362 if (substr in this.whitelist.filterByKeyword) | 361 if (substr in this.whitelist.filterByKeyword) |
363 { | 362 { |
364 let result = this.whitelist._checkEntryMatch(substr, location, contentTy
pe, docDomain, thirdParty, docLocation, siteKey); | 363 let result = this.whitelist._checkEntryMatch(substr, location, contentTy
pe, docDomain, thirdParty, sitekey); |
365 if (result) | 364 if (result) |
366 return result; | 365 return result; |
367 } | 366 } |
368 if (substr in this.blacklist.filterByKeyword && blacklistHit === null) | 367 if (substr in this.blacklist.filterByKeyword && blacklistHit === null) |
369 blacklistHit = this.blacklist._checkEntryMatch(substr, location, content
Type, docDomain, thirdParty, docLocation, siteKey); | 368 blacklistHit = this.blacklist._checkEntryMatch(substr, location, content
Type, docDomain, thirdParty, sitekey); |
370 } | 369 } |
371 return blacklistHit; | 370 return blacklistHit; |
372 }, | 371 }, |
373 | 372 |
374 /** | 373 /** |
375 * @see Matcher#matchesAny | 374 * @see Matcher#matchesAny |
376 */ | 375 */ |
377 matchesAny: function(location, contentType, docDomain, thirdParty, docLocation
, siteKey) | 376 matchesAny: function(location, contentType, docDomain, thirdParty, sitekey) |
378 { | 377 { |
379 let key = location + " " + contentType + " " + docDomain + " " + thirdParty
+ " " + docLocation + " " + siteKey; | 378 let key = location + " " + contentType + " " + docDomain + " " + thirdParty
+ " " + sitekey; |
380 if (key in this.resultCache) | 379 if (key in this.resultCache) |
381 return this.resultCache[key]; | 380 return this.resultCache[key]; |
382 | 381 |
383 let result = this.matchesAnyInternal(location, contentType, docDomain, third
Party, docLocation, siteKey); | 382 let result = this.matchesAnyInternal(location, contentType, docDomain, third
Party, sitekey); |
384 | 383 |
385 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) | 384 if (this.cacheEntries >= CombinedMatcher.maxCacheEntries) |
386 { | 385 { |
387 this.resultCache = Object.create(null); | 386 this.resultCache = Object.create(null); |
388 this.cacheEntries = 0; | 387 this.cacheEntries = 0; |
389 } | 388 } |
390 | 389 |
391 this.resultCache[key] = result; | 390 this.resultCache[key] = result; |
392 this.cacheEntries++; | 391 this.cacheEntries++; |
393 | 392 |
394 return result; | 393 return result; |
395 } | 394 } |
396 } | 395 } |
397 | 396 |
398 /** | 397 /** |
399 * Shared CombinedMatcher instance that should usually be used. | 398 * Shared CombinedMatcher instance that should usually be used. |
400 * @type CombinedMatcher | 399 * @type CombinedMatcher |
401 */ | 400 */ |
402 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); | 401 let defaultMatcher = exports.defaultMatcher = new CombinedMatcher(); |
LEFT | RIGHT |