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: Rebased Created Oct. 21, 2014, 6:26 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
« no previous file with comments | « src/plugin/PluginDomTraverserBase.h ('k') | src/plugin/PluginTabBase.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (!id.IsEmpty()) 525 if (!id.IsEmpty())
526 { 526 {
527 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = 527 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum =
528 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id)); 528 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id));
529 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 ++)
530 { 530 {
531 if (idIt->second.IsMatchFilterElementHide(pEl)) 531 if (idIt->second.IsMatchFilterElementHide(pEl))
532 { 532 {
533 #ifdef ENABLE_DEBUG_RESULT 533 #ifdef ENABLE_DEBUG_RESULT
534 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)
535 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText); 535 CPluginDebug::DebugResultHiding(tagCString, L"id:" + id, idIt->secon d.m_filterText);
536 #endif 536 #endif
537 return true; 537 return true;
538 } 538 }
539 } 539 }
540 540
541 // Search general id 541 // Search general id
542 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); 542 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id));
543 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 ++)
544 { 544 {
545 if (idIt->second.IsMatchFilterElementHide(pEl)) 545 if (idIt->second.IsMatchFilterElementHide(pEl))
546 { 546 {
547 #ifdef ENABLE_DEBUG_RESULT 547 #ifdef ENABLE_DEBUG_RESULT
548 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)
549 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText); 549 CPluginDebug::DebugResultHiding(tagCString, L"id:" + id, idIt->secon d.m_filterText);
550 #endif 550 #endif
551 return true; 551 return true;
552 } 552 }
553 } 553 }
554 } 554 }
555 555
556 // Search tag/className filters 556 // Search tag/className filters
557 if (!classNames.IsEmpty()) 557 if (!classNames.IsEmpty())
558 { 558 {
559 int pos = 0; 559 int pos = 0;
560 CString className = classNames.Tokenize(L" \t\n\r", pos); 560 CString className = classNames.Tokenize(L" \t\n\r", pos);
561 while (pos >= 0) 561 while (pos >= 0)
562 { 562 {
563 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum = 563 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum =
564 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e)); 564 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e));
565 565
566 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)
567 { 567 {
568 if (classIt->second.IsMatchFilterElementHide(pEl)) 568 if (classIt->second.IsMatchFilterElementHide(pEl))
569 { 569 {
570 #ifdef ENABLE_DEBUG_RESULT 570 #ifdef ENABLE_DEBUG_RESULT
571 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)
572 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText); 572 CPluginDebug::DebugResultHiding(tagCString, L"class:" + className, classIt->second.m_filterText);
573 #endif 573 #endif
574 return true; 574 return true;
575 } 575 }
576 } 576 }
577 577
578 // Search general class name 578 // Search general class name
579 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName)); 579 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName));
580 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)
581 { 581 {
582 if (classIt->second.IsMatchFilterElementHide(pEl)) 582 if (classIt->second.IsMatchFilterElementHide(pEl))
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 665 }
666 666
667 m_elementHideTags.clear(); 667 m_elementHideTags.clear();
668 m_elementHideTagsId.clear(); 668 m_elementHideTagsId.clear();
669 m_elementHideTagsClass.clear(); 669 m_elementHideTagsClass.clear();
670 } 670 }
671 } 671 }
672 672
673 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const 673 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const
674 { 674 {
675 CString srcCString = to_CString(src); 675 CString srcCString = ToCString(src);
676 srcCString.Trim();
Oleksandr 2015/01/05 11:55:40 We have TrimString function in shared/Utils.h for
Eric 2015/01/05 16:18:26 Done.
677 std::wstring srcTrimmed = ToWstring(srcCString);
676 678
677 // We should not block the empty string, so all filtering does not make sense 679 // We should not block the empty string, so all filtering does not make sense
678 // Therefore we just return 680 // Therefore we just return
679 if (srcCString.Trim().IsEmpty()) 681 if (srcTrimmed.empty())
680 { 682 {
681 return false; 683 return false;
682 } 684 }
683
684 CPluginSettings* settings = CPluginSettings::GetInstance(); 685 CPluginSettings* settings = CPluginSettings::GetInstance();
685 686
686 CString type; 687 CString type;
687 if (addDebug) 688 if (addDebug)
688 { 689 {
689 type = "OTHER"; 690 type = "OTHER";
690 691
691 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); 692 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType );
692 if (it != m_contentMapText.end()) 693 if (it != m_contentMapText.end())
693 { 694 {
694 type = it->second; 695 type = it->second;
695 } 696 }
696 } 697 }
697 698
698 CPluginClient* client = CPluginClient::GetInstance(); 699 CPluginClient* client = CPluginClient::GetInstance();
699 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain)) 700 if (client->Matches(srcTrimmed, to_wstring(type), domain))
700 { 701 {
701 if (addDebug) 702 if (addDebug)
702 { 703 {
703 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") 704 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES")
704 705
705 #ifdef ENABLE_DEBUG_RESULT 706 #ifdef ENABLE_DEBUG_RESULT
706 CPluginDebug::DebugResultBlocking(type, srcCString, domain); 707 CPluginDebug::DebugResultBlocking(type, srcTrimmed, domain);
707 #endif 708 #endif
708 } 709 }
709 return true; 710 return true;
710 } 711 }
711 #ifdef ENABLE_DEBUG_RESULT 712 #ifdef ENABLE_DEBUG_RESULT
712 CPluginDebug::DebugResultIgnoring(type, src, domain); 713 CPluginDebug::DebugResultIgnoring(type, src, domain);
713 #endif 714 #endif
714 return false; 715 return false;
715 } 716 }
OLDNEW
« no previous file with comments | « src/plugin/PluginDomTraverserBase.h ('k') | src/plugin/PluginTabBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld