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

Side by Side Diff: lib/matcher.js

Issue 30018555: Issue 7311 - Split _checkEntryMatchByDomain() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 26, 2019, 9:29 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 (count == resultCount && candidate.length > resultLength)) 415 (count == resultCount && candidate.length > resultLength))
416 { 416 {
417 result = candidate; 417 result = candidate;
418 resultCount = count; 418 resultCount = count;
419 resultLength = candidate.length; 419 resultLength = candidate.length;
420 } 420 }
421 } 421 }
422 return result; 422 return result;
423 } 423 }
424 424
425 _matchFilterWithoutDomain(filter, location, typeMask, thirdParty, sitekey,
426 collection)
427 {
428 if (filter.matchesWithoutDomain(location, typeMask, thirdParty, sitekey))
429 {
430 if (!collection)
431 return filter;
432
433 collection.push(filter);
434 }
435
436 return null;
437 }
438
439 _matchFiltersByDomain(filtersByDomain, location, typeMask, docDomain,
440 thirdParty, sitekey, specificOnly, collection)
441 {
442 let excluded = new Set();
443
444 for (let suffix of domainSuffixes(docDomain ?
445 normalizeHostname(docDomain) : "",
446 !specificOnly))
447 {
448 let filters = filtersByDomain.get(suffix);
449 if (filters)
450 {
451 for (let [filter, include] of filters.entries())
452 {
453 if (!include)
454 {
455 excluded.add(filter);
456 }
457 else if ((excluded.size == 0 || !excluded.has(filter)) &&
458 this._matchFilterWithoutDomain(filter, location, typeMask,
459 thirdParty, sitekey,
460 collection))
461 {
462 return filter;
463 }
464 }
465 }
466 }
467
468 return null;
469 }
470
425 _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty, 471 _checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty,
426 sitekey, specificOnly, collection) 472 sitekey, specificOnly, collection)
427 { 473 {
428 let filters = this._simpleFiltersByKeyword.get(keyword); 474 let filters = this._simpleFiltersByKeyword.get(keyword);
429 if (filters) 475 if (filters)
430 { 476 {
431 let lowerCaseLocation = location.toLowerCase(); 477 let lowerCaseLocation = location.toLowerCase();
432 478
433 for (let filter of filters) 479 for (let filter of filters)
434 { 480 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 523
478 return null; 524 return null;
479 } 525 }
480 526
481 _checkEntryMatchByDomain(keyword, location, typeMask, docDomain, thirdParty, 527 _checkEntryMatchByDomain(keyword, location, typeMask, docDomain, thirdParty,
482 sitekey, specificOnly, collection) 528 sitekey, specificOnly, collection)
483 { 529 {
484 let filtersByDomain = this._filterDomainMapsByKeyword.get(keyword); 530 let filtersByDomain = this._filterDomainMapsByKeyword.get(keyword);
485 if (filtersByDomain) 531 if (filtersByDomain)
486 { 532 {
533 if (filtersByDomain instanceof Map)
534 {
535 return this._matchFiltersByDomain(filtersByDomain, location, typeMask,
536 docDomain, thirdParty, sitekey,
537 specificOnly, collection);
538 }
539
487 // Because of the memory optimization in the add function, most of the 540 // Because of the memory optimization in the add function, most of the
488 // time this will be a filter rather than a map. 541 // time this will be a filter rather than a map.
489 if (!(filtersByDomain instanceof Map)) 542 return this._matchFilterWithoutDomain(filtersByDomain, location,
490 { 543 typeMask, thirdParty, sitekey,
491 if (filtersByDomain.matchesWithoutDomain(location, typeMask, 544 collection);
492 thirdParty, sitekey))
493 {
494 if (!collection)
495 return filtersByDomain;
496
497 collection.push(filtersByDomain);
498 }
499
500 return null;
501 }
502
503 let excluded = new Set();
504
505 for (let suffix of domainSuffixes(docDomain ?
506 normalizeHostname(docDomain) : "",
507 !specificOnly))
508 {
509 let filters = filtersByDomain.get(suffix);
510 if (filters)
511 {
512 for (let [filter, include] of filters.entries())
513 {
514 if (!include)
515 {
516 excluded.add(filter);
517 }
518 else if ((excluded.size == 0 || !excluded.has(filter)) &&
519 filter.matchesWithoutDomain(location, typeMask,
520 thirdParty, sitekey))
521 {
522 if (!collection)
523 return filter;
524
525 collection.push(filter);
526 }
527 }
528 }
529 }
530 } 545 }
531 546
532 return null; 547 return null;
533 } 548 }
534 549
535 /** 550 /**
536 * Checks whether the entries for a particular keyword match a URL 551 * Checks whether the entries for a particular keyword match a URL
537 * @param {string} keyword 552 * @param {string} keyword
538 * @param {string} location 553 * @param {string} location
539 * @param {number} typeMask 554 * @param {number} typeMask
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 891
877 exports.CombinedMatcher = CombinedMatcher; 892 exports.CombinedMatcher = CombinedMatcher;
878 893
879 /** 894 /**
880 * Shared {@link CombinedMatcher} instance that should usually be used. 895 * Shared {@link CombinedMatcher} instance that should usually be used.
881 * @type {CombinedMatcher} 896 * @type {CombinedMatcher}
882 */ 897 */
883 let defaultMatcher = new CombinedMatcher(); 898 let defaultMatcher = new CombinedMatcher();
884 899
885 exports.defaultMatcher = defaultMatcher; 900 exports.defaultMatcher = defaultMatcher;
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld