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

Delta Between Two Patch Sets: src/plugin/PluginFilter.cpp

Issue 6299667012780032: Issues #696,1231,1264,1265 - Improve handling in PassthroughApp (Closed)
Left Patch Set: Created Sept. 19, 2014, 2:41 p.m.
Right Patch Set: rebase Created Oct. 17, 2014, 12:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/AdblockPlusDomTraverser.cpp ('k') | src/plugin/PluginTabBase.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginFilter.h" 3 #include "PluginFilter.h"
4
5 #if (defined PRODUCT_ADBLOCKPLUS)
6 #include "PluginSettings.h" 4 #include "PluginSettings.h"
7 #include "PluginClient.h" 5 #include "PluginClient.h"
8 #include "PluginClientFactory.h" 6 #include "PluginClientFactory.h"
9 #endif
10
11 #include "PluginMutex.h" 7 #include "PluginMutex.h"
12 #include "PluginSettings.h" 8 #include "PluginSettings.h"
13 #include "PluginSystem.h" 9 #include "PluginSystem.h"
14 #include "PluginClass.h" 10 #include "PluginClass.h"
15 #include "mlang.h" 11 #include "mlang.h"
16 12
17 #include "..\shared\CriticalSection.h" 13 #include "..\shared\CriticalSection.h"
18 14
19 15
20 // The filters are described at http://adblockplus.org/en/filters 16 // The filters are described at http://adblockplus.org/en/filters
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 std::pair<CString, CFilterElementHide> pair = std::make_pair(filter->m _tag, *filter); 494 std::pair<CString, CFilterElementHide> pair = std::make_pair(filter->m _tag, *filter);
499 m_elementHideTags.insert(pair); 495 m_elementHideTags.insert(pair);
500 } 496 }
501 } 497 }
502 } while (separatorChar != '\0'); 498 } while (separatorChar != '\0');
503 } 499 }
504 500
505 return true; 501 return true;
506 } 502 }
507 503
508 bool CPluginFilter::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent) const 504 bool CPluginFilter::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::wstring& domain, const std::wstring& indent) const
509 { 505 {
506 CString tagCString = to_CString(tag);
507
510 CString id; 508 CString id;
511 CComBSTR bstrId; 509 CComBSTR bstrId;
512 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) 510 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
513 { 511 {
514 id = bstrId; 512 id = bstrId;
515 } 513 }
516 514
517 CString classNames; 515 CString classNames;
518 CComBSTR bstrClassNames; 516 CComBSTR bstrClassNames;
519 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames) 517 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames)
520 { 518 {
521 classNames = bstrClassNames; 519 classNames = bstrClassNames;
522 } 520 }
523 521
524 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); 522 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
525 { 523 {
526 CString domainTest = domain;
527
528 // Search tag/id filters 524 // Search tag/id filters
529 if (!id.IsEmpty()) 525 if (!id.IsEmpty())
530 { 526 {
531 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = 527 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum =
532 m_elementHideTagsId.equal_range(std::make_pair(tag, id)); 528 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id));
533 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++) 529 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++)
534 { 530 {
535 if (idIt->second.IsMatchFilterElementHide(pEl)) 531 if (idIt->second.IsMatchFilterElementHide(pEl))
536 { 532 {
537 #ifdef ENABLE_DEBUG_RESULT 533 #ifdef ENABLE_DEBUG_RESULT
538 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second .m_filterText) 534 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second .m_filterText)
539 CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filt erText); 535 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText);
540 #endif 536 #endif
541 return true; 537 return true;
542 } 538 }
543 } 539 }
544 540
545 // Search general id 541 // Search general id
546 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); 542 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id));
547 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++) 543 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++)
548 { 544 {
549 if (idIt->second.IsMatchFilterElementHide(pEl)) 545 if (idIt->second.IsMatchFilterElementHide(pEl))
550 { 546 {
551 #ifdef ENABLE_DEBUG_RESULT 547 #ifdef ENABLE_DEBUG_RESULT
552 DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m _filterText) 548 DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m _filterText)
553 CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filt erText); 549 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText);
554 #endif 550 #endif
555 return true; 551 return true;
556 } 552 }
557 } 553 }
558 } 554 }
559 555
560 // Search tag/className filters 556 // Search tag/className filters
561 if (!classNames.IsEmpty()) 557 if (!classNames.IsEmpty())
562 { 558 {
563 int pos = 0; 559 int pos = 0;
564 CString className = classNames.Tokenize(L" \t\n\r", pos); 560 CString className = classNames.Tokenize(L" \t\n\r", pos);
565 while (pos >= 0) 561 while (pos >= 0)
566 { 562 {
567 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum = 563 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum =
568 m_elementHideTagsClass.equal_range(std::make_pair(tag, className)); 564 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e));
569 565
570 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++classIt) 566 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++classIt)
571 { 567 {
572 if (classIt->second.IsMatchFilterElementHide(pEl)) 568 if (classIt->second.IsMatchFilterElementHide(pEl))
573 { 569 {
574 #ifdef ENABLE_DEBUG_RESULT 570 #ifdef ENABLE_DEBUG_RESULT
575 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt ->second.m_filterText) 571 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt ->second.m_filterText)
576 CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt ->second.m_filterText); 572 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText);
577 #endif 573 #endif
578 return true; 574 return true;
579 } 575 }
580 } 576 }
581 577
582 // Search general class name 578 // Search general class name
583 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName)); 579 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName));
584 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++ classIt) 580 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++ classIt)
585 { 581 {
586 if (classIt->second.IsMatchFilterElementHide(pEl)) 582 if (classIt->second.IsMatchFilterElementHide(pEl))
587 { 583 {
588 #ifdef ENABLE_DEBUG_RESULT 584 #ifdef ENABLE_DEBUG_RESULT
589 DEBUG_HIDE_EL(indent + "HideEl::Found (?/class) filter:" + classIt-> second.m_filterText) 585 DEBUG_HIDE_EL(indent + "HideEl::Found (?/class) filter:" + classIt-> second.m_filterText)
590 CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt ->second.m_filterText); 586 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText);
591 #endif 587 #endif
592 return true; 588 return true;
593 } 589 }
594 } 590 }
595 591
596 // Next class name 592 // Next class name
597 className = classNames.Tokenize(L" \t\n\r", pos); 593 className = classNames.Tokenize(L" \t\n\r", pos);
598 } 594 }
599 } 595 }
600 596
601 // Search tag filters 597 // Search tag filters
602 std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::co nst_iterator> tagItEnum 598 std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::co nst_iterator> tagItEnum
603 = m_elementHideTags.equal_range(tag); 599 = m_elementHideTags.equal_range(tagCString);
604 for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt ! = tagItEnum.second; ++ tagIt) 600 for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt ! = tagItEnum.second; ++ tagIt)
605 { 601 {
606 if (tagIt->second.IsMatchFilterElementHide(pEl)) 602 if (tagIt->second.IsMatchFilterElementHide(pEl))
607 { 603 {
608 #ifdef ENABLE_DEBUG_RESULT 604 #ifdef ENABLE_DEBUG_RESULT
609 DEBUG_HIDE_EL(indent + "HideEl::Found (tag) filter:" + tagIt->second.m_f ilterText) 605 DEBUG_HIDE_EL(indent + "HideEl::Found (tag) filter:" + tagIt->second.m_f ilterText)
610 CPluginDebug::DebugResultHiding(tag, "-", tagIt->second.m_filterText); 606 CPluginDebug::DebugResultHiding(tagCString, "-", tagIt->second.m_filte rText);
611 #endif 607 #endif
612 return true; 608 return true;
613 } 609 }
614 } 610 }
615 } 611 }
616 612
617 return false; 613 return false;
618 } 614 }
619 615
620 bool CPluginFilter::LoadHideFilters(std::vector<std::wstring> filters) 616 bool CPluginFilter::LoadHideFilters(std::vector<std::wstring> filters)
621 { 617 {
622
623 ClearFilters(); 618 ClearFilters();
624
625 bool isRead = false; 619 bool isRead = false;
626
627 #ifdef PRODUCT_ADBLOCKPLUS
628 CPluginClient* client = CPluginClient::GetInstance(); 620 CPluginClient* client = CPluginClient::GetInstance();
629 #endif
630 621
631 // Parse hide string 622 // Parse hide string
632 int pos = 0; 623 int pos = 0;
633
634 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); 624 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
635 { 625 {
636 for (std::vector<std::wstring>::iterator it = filters.begin(); it < filters. end(); ++it) 626 for (std::vector<std::wstring>::iterator it = filters.begin(); it < filters. end(); ++it)
637 { 627 {
638 CString filter((*it).c_str()); 628 CString filter((*it).c_str());
639 // If the line is not commented out 629 // If the line is not commented out
640 if (!filter.Trim().IsEmpty() && filter.GetAt(0) != '!' && filter.GetAt(0) != '[') 630 if (!filter.Trim().IsEmpty() && filter.GetAt(0) != '!' && filter.GetAt(0) != '[')
641 { 631 {
642 int filterType = 0; 632 int filterType = 0;
643 633
(...skipping 29 matching lines...) Expand all
673 } 663 }
674 m_filterMapDefault[i].clear(); 664 m_filterMapDefault[i].clear();
675 } 665 }
676 666
677 m_elementHideTags.clear(); 667 m_elementHideTags.clear();
678 m_elementHideTagsId.clear(); 668 m_elementHideTagsId.clear();
679 m_elementHideTagsClass.clear(); 669 m_elementHideTagsClass.clear();
680 } 670 }
681 } 671 }
682 672
683 bool CPluginFilter::ShouldBlock(CString src, int contentType, const CString& dom ain, bool addDebug) const 673 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const
684 { 674 {
675 CString srcCString = to_CString(src);
676
685 // We should not block the empty string, so all filtering does not make sense 677 // We should not block the empty string, so all filtering does not make sense
686 // Therefore we just return 678 // Therefore we just return
687 if (src.Trim().IsEmpty()) 679 if (srcCString.Trim().IsEmpty())
688 { 680 {
689 return false; 681 return false;
690 } 682 }
691 683
692 CPluginSettings* settings = CPluginSettings::GetInstance(); 684 CPluginSettings* settings = CPluginSettings::GetInstance();
693 685
694 CString type; 686 CString type;
695 if (addDebug) 687 if (addDebug)
696 { 688 {
697 type = "OTHER"; 689 type = "OTHER";
698 690
699 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); 691 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType );
700 if (it != m_contentMapText.end()) 692 if (it != m_contentMapText.end())
701 { 693 {
702 type = it->second; 694 type = it->second;
703 } 695 }
704 } 696 }
705 697
706 CPluginClient* client = CPluginClient::GetInstance(); 698 CPluginClient* client = CPluginClient::GetInstance();
707 if (client->Matches(std::wstring(src), std::wstring(type), std::wstring(domain ))) 699 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain))
708 { 700 {
709 if (addDebug) 701 if (addDebug)
710 { 702 {
711 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") 703 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES")
712 704
713 #ifdef ENABLE_DEBUG_RESULT 705 #ifdef ENABLE_DEBUG_RESULT
714 CPluginDebug::DebugResultBlocking(type, src, domain); 706 CPluginDebug::DebugResultBlocking(type, srcCString, domain);
715 #endif 707 #endif
716 } 708 }
717 return true; 709 return true;
718 } 710 }
719 #ifdef ENABLE_DEBUG_RESULT 711 #ifdef ENABLE_DEBUG_RESULT
720 CPluginDebug::DebugResultIgnoring(type, src, domain); 712 CPluginDebug::DebugResultIgnoring(type, src, domain);
721 #endif 713 #endif
722 return false; 714 return false;
723 } 715 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld