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

Side by Side Diff: src/plugin/PluginFilter.cpp

Issue 4912420225024000: Issue #1234 - Convert strings associated with URL's (Closed)
Patch Set: Created Jan. 5, 2015, 4:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginFilter.h" 3 #include "PluginFilter.h"
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #include "PluginClient.h" 5 #include "PluginClient.h"
6 #include "PluginClientFactory.h" 6 #include "PluginClientFactory.h"
7 #include "PluginMutex.h" 7 #include "PluginMutex.h"
8 #include "PluginSettings.h" 8 #include "PluginSettings.h"
9 #include "PluginSystem.h" 9 #include "PluginSystem.h"
10 #include "PluginClass.h" 10 #include "PluginClass.h"
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (!id.IsEmpty()) 558 if (!id.IsEmpty())
559 { 559 {
560 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = 560 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum =
561 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id)); 561 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id));
562 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++) 562 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++)
563 { 563 {
564 if (idIt->second.IsMatchFilterElementHide(pEl)) 564 if (idIt->second.IsMatchFilterElementHide(pEl))
565 { 565 {
566 #ifdef ENABLE_DEBUG_RESULT 566 #ifdef ENABLE_DEBUG_RESULT
567 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second .m_filterText) 567 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second .m_filterText)
568 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText); 568 CPluginDebug::DebugResultHiding(tagCString, L"id:" + id, idIt->secon d.m_filterText);
569 #endif 569 #endif
570 return true; 570 return true;
571 } 571 }
572 } 572 }
573 573
574 // Search general id 574 // Search general id
575 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); 575 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id));
576 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++) 576 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++)
577 { 577 {
578 if (idIt->second.IsMatchFilterElementHide(pEl)) 578 if (idIt->second.IsMatchFilterElementHide(pEl))
579 { 579 {
580 #ifdef ENABLE_DEBUG_RESULT 580 #ifdef ENABLE_DEBUG_RESULT
581 DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m _filterText) 581 DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m _filterText)
582 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText); 582 CPluginDebug::DebugResultHiding(tagCString, L"id:" + id, idIt->secon d.m_filterText);
583 #endif 583 #endif
584 return true; 584 return true;
585 } 585 }
586 } 586 }
587 } 587 }
588 588
589 // Search tag/className filters 589 // Search tag/className filters
590 if (!classNames.IsEmpty()) 590 if (!classNames.IsEmpty())
591 { 591 {
592 int pos = 0; 592 int pos = 0;
593 CString className = classNames.Tokenize(L" \t\n\r", pos); 593 CString className = classNames.Tokenize(L" \t\n\r", pos);
594 while (pos >= 0) 594 while (pos >= 0)
595 { 595 {
596 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum = 596 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum =
597 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e)); 597 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e));
598 598
599 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++classIt) 599 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++classIt)
600 { 600 {
601 if (classIt->second.IsMatchFilterElementHide(pEl)) 601 if (classIt->second.IsMatchFilterElementHide(pEl))
602 { 602 {
603 #ifdef ENABLE_DEBUG_RESULT 603 #ifdef ENABLE_DEBUG_RESULT
604 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt ->second.m_filterText) 604 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt ->second.m_filterText)
605 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText); 605 CPluginDebug::DebugResultHiding(tagCString, L"class:" + className, classIt->second.m_filterText);
606 #endif 606 #endif
607 return true; 607 return true;
608 } 608 }
609 } 609 }
610 610
611 // Search general class name 611 // Search general class name
612 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName)); 612 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName));
613 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++ classIt) 613 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++ classIt)
614 { 614 {
615 if (classIt->second.IsMatchFilterElementHide(pEl)) 615 if (classIt->second.IsMatchFilterElementHide(pEl))
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } 698 }
699 699
700 m_elementHideTags.clear(); 700 m_elementHideTags.clear();
701 m_elementHideTagsId.clear(); 701 m_elementHideTagsId.clear();
702 m_elementHideTagsClass.clear(); 702 m_elementHideTagsClass.clear();
703 } 703 }
704 } 704 }
705 705
706 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const 706 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const
707 { 707 {
708 CString srcCString = to_CString(src); 708 std::wstring srcTrimmed = TrimString(src);
709 709
710 // We should not block the empty string, so all filtering does not make sense 710 // We should not block the empty string, so all filtering does not make sense
711 // Therefore we just return 711 // Therefore we just return
712 if (srcCString.Trim().IsEmpty()) 712 if (srcTrimmed.empty())
713 { 713 {
714 return false; 714 return false;
715 } 715 }
716
717 CPluginSettings* settings = CPluginSettings::GetInstance(); 716 CPluginSettings* settings = CPluginSettings::GetInstance();
718 717
719 CString type; 718 CString type;
720 if (addDebug) 719 if (addDebug)
721 { 720 {
722 type = "OTHER"; 721 type = "OTHER";
723 722
724 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); 723 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType );
725 if (it != m_contentMapText.end()) 724 if (it != m_contentMapText.end())
726 { 725 {
727 type = it->second; 726 type = it->second;
728 } 727 }
729 } 728 }
730 729
731 CPluginClient* client = CPluginClient::GetInstance(); 730 CPluginClient* client = CPluginClient::GetInstance();
732 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain)) 731 if (client->Matches(srcTrimmed, to_wstring(type), domain))
733 { 732 {
734 if (addDebug) 733 if (addDebug)
735 { 734 {
736 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") 735 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES")
737 736
738 #ifdef ENABLE_DEBUG_RESULT 737 #ifdef ENABLE_DEBUG_RESULT
739 CPluginDebug::DebugResultBlocking(type, srcCString, domain); 738 CPluginDebug::DebugResultBlocking(type, srcTrimmed, domain);
740 #endif 739 #endif
741 } 740 }
742 return true; 741 return true;
743 } 742 }
744 #ifdef ENABLE_DEBUG_RESULT 743 #ifdef ENABLE_DEBUG_RESULT
745 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); 744 CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain);
746 #endif 745 #endif
747 return false; 746 return false;
748 } 747 }
OLDNEW

Powered by Google App Engine
This is Rietveld