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

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

Issue 5163396739629056: Issue #1234 - Remove CString from ShouldBlock(), IsElementHidden() declarations (Closed)
Patch Set: Created Sept. 30, 2014, 5:37 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/PluginFilter.h ('k') | src/plugin/PluginWbPassThrough.cpp » ('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 4
5 #if (defined PRODUCT_ADBLOCKPLUS) 5 #if (defined PRODUCT_ADBLOCKPLUS)
6 #include "PluginSettings.h" 6 #include "PluginSettings.h"
7 #include "PluginClient.h" 7 #include "PluginClient.h"
8 #include "PluginClientFactory.h" 8 #include "PluginClientFactory.h"
9 #endif 9 #endif
10 10
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 std::pair<CString, CFilterElementHide> pair = std::make_pair(filter->m _tag, *filter); 497 std::pair<CString, CFilterElementHide> pair = std::make_pair(filter->m _tag, *filter);
498 m_elementHideTags.insert(pair); 498 m_elementHideTags.insert(pair);
499 } 499 }
500 } 500 }
501 } while (separatorChar != '\0'); 501 } while (separatorChar != '\0');
502 } 502 }
503 503
504 return true; 504 return true;
505 } 505 }
506 506
507 bool CPluginFilter::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent) const 507 bool CPluginFilter::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::wstring& domain, const std::wstring& indent) const
508 { 508 {
509 CString tagCString = to_CString(tag);
510
509 CString id; 511 CString id;
510 CComBSTR bstrId; 512 CComBSTR bstrId;
511 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) 513 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId)
512 { 514 {
513 id = bstrId; 515 id = bstrId;
514 } 516 }
515 517
516 CString classNames; 518 CString classNames;
517 CComBSTR bstrClassNames; 519 CComBSTR bstrClassNames;
518 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames) 520 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames)
519 { 521 {
520 classNames = bstrClassNames; 522 classNames = bstrClassNames;
521 } 523 }
522 524
523 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); 525 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
524 { 526 {
525 CString domainTest = domain; 527 CString domainTest = to_CString(domain);
526 528
527 // Search tag/id filters 529 // Search tag/id filters
528 if (!id.IsEmpty()) 530 if (!id.IsEmpty())
529 { 531 {
530 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = 532 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum =
531 m_elementHideTagsId.equal_range(std::make_pair(tag, id)); 533 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id));
532 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++) 534 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++)
533 { 535 {
534 if (idIt->second.IsMatchFilterElementHide(pEl)) 536 if (idIt->second.IsMatchFilterElementHide(pEl))
535 { 537 {
536 #ifdef ENABLE_DEBUG_RESULT 538 #ifdef ENABLE_DEBUG_RESULT
537 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second .m_filterText) 539 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/id) filter:" + idIt->second .m_filterText)
538 CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filt erText); 540 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText);
539 #endif 541 #endif
540 return true; 542 return true;
541 } 543 }
542 } 544 }
543 545
544 // Search general id 546 // Search general id
545 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); 547 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id));
546 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++) 548 for (TFilterElementHideTagsNamed::const_iterator idIt = idItEnum.first; id It != idItEnum.second; idIt ++)
547 { 549 {
548 if (idIt->second.IsMatchFilterElementHide(pEl)) 550 if (idIt->second.IsMatchFilterElementHide(pEl))
549 { 551 {
550 #ifdef ENABLE_DEBUG_RESULT 552 #ifdef ENABLE_DEBUG_RESULT
551 DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m _filterText) 553 DEBUG_HIDE_EL(indent + "HideEl::Found (?/id) filter:" + idIt->second.m _filterText)
552 CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filt erText); 554 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText);
553 #endif 555 #endif
554 return true; 556 return true;
555 } 557 }
556 } 558 }
557 } 559 }
558 560
559 // Search tag/className filters 561 // Search tag/className filters
560 if (!classNames.IsEmpty()) 562 if (!classNames.IsEmpty())
561 { 563 {
562 int pos = 0; 564 int pos = 0;
563 CString className = classNames.Tokenize(L" \t\n\r", pos); 565 CString className = classNames.Tokenize(L" \t\n\r", pos);
564 while (pos >= 0) 566 while (pos >= 0)
565 { 567 {
566 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum = 568 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum =
567 m_elementHideTagsClass.equal_range(std::make_pair(tag, className)); 569 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e));
568 570
569 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++classIt) 571 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++classIt)
570 { 572 {
571 if (classIt->second.IsMatchFilterElementHide(pEl)) 573 if (classIt->second.IsMatchFilterElementHide(pEl))
572 { 574 {
573 #ifdef ENABLE_DEBUG_RESULT 575 #ifdef ENABLE_DEBUG_RESULT
574 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt ->second.m_filterText) 576 DEBUG_HIDE_EL(indent + "HideEl::Found (tag/class) filter:" + classIt ->second.m_filterText)
575 CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt ->second.m_filterText); 577 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText);
576 #endif 578 #endif
577 return true; 579 return true;
578 } 580 }
579 } 581 }
580 582
581 // Search general class name 583 // Search general class name
582 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName)); 584 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName));
583 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++ classIt) 585 for (TFilterElementHideTagsNamed::const_iterator classIt = classItEnum.f irst; classIt != classItEnum.second; ++ classIt)
584 { 586 {
585 if (classIt->second.IsMatchFilterElementHide(pEl)) 587 if (classIt->second.IsMatchFilterElementHide(pEl))
586 { 588 {
587 #ifdef ENABLE_DEBUG_RESULT 589 #ifdef ENABLE_DEBUG_RESULT
588 DEBUG_HIDE_EL(indent + "HideEl::Found (?/class) filter:" + classIt-> second.m_filterText) 590 DEBUG_HIDE_EL(indent + "HideEl::Found (?/class) filter:" + classIt-> second.m_filterText)
589 CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt ->second.m_filterText); 591 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText);
590 #endif 592 #endif
591 return true; 593 return true;
592 } 594 }
593 } 595 }
594 596
595 // Next class name 597 // Next class name
596 className = classNames.Tokenize(L" \t\n\r", pos); 598 className = classNames.Tokenize(L" \t\n\r", pos);
597 } 599 }
598 } 600 }
599 601
600 // Search tag filters 602 // Search tag filters
601 std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::co nst_iterator> tagItEnum 603 std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::co nst_iterator> tagItEnum
602 = m_elementHideTags.equal_range(tag); 604 = m_elementHideTags.equal_range(tagCString);
603 for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt ! = tagItEnum.second; ++ tagIt) 605 for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt ! = tagItEnum.second; ++ tagIt)
604 { 606 {
605 if (tagIt->second.IsMatchFilterElementHide(pEl)) 607 if (tagIt->second.IsMatchFilterElementHide(pEl))
606 { 608 {
607 #ifdef ENABLE_DEBUG_RESULT 609 #ifdef ENABLE_DEBUG_RESULT
608 DEBUG_HIDE_EL(indent + "HideEl::Found (tag) filter:" + tagIt->second.m_f ilterText) 610 DEBUG_HIDE_EL(indent + "HideEl::Found (tag) filter:" + tagIt->second.m_f ilterText)
609 CPluginDebug::DebugResultHiding(tag, "-", tagIt->second.m_filterText); 611 CPluginDebug::DebugResultHiding(tagCString, "-", tagIt->second.m_filte rText);
610 #endif 612 #endif
611 return true; 613 return true;
612 } 614 }
613 } 615 }
614 } 616 }
615 617
616 return false; 618 return false;
617 } 619 }
618 620
619 bool CPluginFilter::LoadHideFilters(std::vector<std::wstring> filters) 621 bool CPluginFilter::LoadHideFilters(std::vector<std::wstring> filters)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 } 674 }
673 m_filterMapDefault[i].clear(); 675 m_filterMapDefault[i].clear();
674 } 676 }
675 677
676 m_elementHideTags.clear(); 678 m_elementHideTags.clear();
677 m_elementHideTagsId.clear(); 679 m_elementHideTagsId.clear();
678 m_elementHideTagsClass.clear(); 680 m_elementHideTagsClass.clear();
679 } 681 }
680 } 682 }
681 683
682 bool CPluginFilter::ShouldBlock(CString src, int contentType, const CString& dom ain, bool addDebug) const 684 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const
683 { 685 {
686 CString srcCString = to_CString(src);
687
684 // We should not block the empty string, so all filtering does not make sense 688 // We should not block the empty string, so all filtering does not make sense
685 // Therefore we just return 689 // Therefore we just return
686 if (src.Trim().IsEmpty()) 690 if (srcCString.Trim().IsEmpty())
687 { 691 {
688 return false; 692 return false;
689 } 693 }
690 694
691 CPluginSettings* settings = CPluginSettings::GetInstance(); 695 CPluginSettings* settings = CPluginSettings::GetInstance();
692 696
693 CString type; 697 CString type;
694 if (addDebug) 698 if (addDebug)
695 { 699 {
696 type = "OTHER"; 700 type = "OTHER";
697 701
698 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); 702 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType );
699 if (it != m_contentMapText.end()) 703 if (it != m_contentMapText.end())
700 { 704 {
701 type = it->second; 705 type = it->second;
702 } 706 }
703 } 707 }
704 708
705 CPluginClient* client = CPluginClient::GetInstance(); 709 CPluginClient* client = CPluginClient::GetInstance();
706 if (client->Matches(std::wstring(src), std::wstring(type), std::wstring(domain ))) 710 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain))
707 { 711 {
708 if (addDebug) 712 if (addDebug)
709 { 713 {
710 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") 714 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES")
711 715
712 #ifdef ENABLE_DEBUG_RESULT 716 #ifdef ENABLE_DEBUG_RESULT
713 CPluginDebug::DebugResultBlocking(type, src, domain); 717 CPluginDebug::DebugResultBlocking(type, srcCString, to_CString(domain));
714 #endif 718 #endif
715 } 719 }
716 return true; 720 return true;
717 } 721 }
718 return false; 722 return false;
719 } 723 }
OLDNEW
« no previous file with comments | « src/plugin/PluginFilter.h ('k') | src/plugin/PluginWbPassThrough.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld