| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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 std::wstring& tag_wstring, IHTMLElemen t* pEl, const std::wstring& domain, const std::wstring& indent) const | 507 bool CPluginFilter::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl, const std::wstring& domain, const std::wstring& indent) const |
|
Felix Dahlke
2014/09/30 13:30:15
Since "CString tag" is temporary and "const std::w
Eric
2014/09/30 17:56:40
I was trying to minimize the number of changed lin
| |
| 508 { | 508 { |
| 509 CString tag = to_CString(tag_wstring); | 509 CString tagCString = to_CString(tag); |
| 510 | 510 |
| 511 CString id; | 511 CString id; |
| 512 CComBSTR bstrId; | 512 CComBSTR bstrId; |
| 513 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) | 513 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) |
| 514 { | 514 { |
| 515 id = bstrId; | 515 id = bstrId; |
| 516 } | 516 } |
| 517 | 517 |
| 518 CString classNames; | 518 CString classNames; |
| 519 CComBSTR bstrClassNames; | 519 CComBSTR bstrClassNames; |
| 520 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames) | 520 if (SUCCEEDED(pEl->get_className(&bstrClassNames)) && bstrClassNames) |
| 521 { | 521 { |
| 522 classNames = bstrClassNames; | 522 classNames = bstrClassNames; |
| 523 } | 523 } |
| 524 | 524 |
| 525 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 525 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| 526 { | 526 { |
| 527 CString domainTest = to_CString(domain); | 527 CString domainTest = to_CString(domain); |
| 528 | 528 |
| 529 // Search tag/id filters | 529 // Search tag/id filters |
| 530 if (!id.IsEmpty()) | 530 if (!id.IsEmpty()) |
| 531 { | 531 { |
| 532 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = | 532 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHideT agsNamed::const_iterator> idItEnum = |
| 533 m_elementHideTagsId.equal_range(std::make_pair(tag, id)); | 533 m_elementHideTagsId.equal_range(std::make_pair(tagCString, id)); |
| 534 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 ++) |
| 535 { | 535 { |
| 536 if (idIt->second.IsMatchFilterElementHide(pEl)) | 536 if (idIt->second.IsMatchFilterElementHide(pEl)) |
| 537 { | 537 { |
| 538 #ifdef ENABLE_DEBUG_RESULT | 538 #ifdef ENABLE_DEBUG_RESULT |
| 539 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) |
| 540 CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filt erText); | 540 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText); |
| 541 #endif | 541 #endif |
| 542 return true; | 542 return true; |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 // Search general id | 546 // Search general id |
| 547 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); | 547 idItEnum = m_elementHideTagsId.equal_range(std::make_pair("", id)); |
| 548 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 ++) |
| 549 { | 549 { |
| 550 if (idIt->second.IsMatchFilterElementHide(pEl)) | 550 if (idIt->second.IsMatchFilterElementHide(pEl)) |
| 551 { | 551 { |
| 552 #ifdef ENABLE_DEBUG_RESULT | 552 #ifdef ENABLE_DEBUG_RESULT |
| 553 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) |
| 554 CPluginDebug::DebugResultHiding(tag, "id:" + id, idIt->second.m_filt erText); | 554 CPluginDebug::DebugResultHiding(tagCString, "id:" + id, idIt->second .m_filterText); |
| 555 #endif | 555 #endif |
| 556 return true; | 556 return true; |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 // Search tag/className filters | 561 // Search tag/className filters |
| 562 if (!classNames.IsEmpty()) | 562 if (!classNames.IsEmpty()) |
| 563 { | 563 { |
| 564 int pos = 0; | 564 int pos = 0; |
| 565 CString className = classNames.Tokenize(L" \t\n\r", pos); | 565 CString className = classNames.Tokenize(L" \t\n\r", pos); |
| 566 while (pos >= 0) | 566 while (pos >= 0) |
| 567 { | 567 { |
| 568 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum = | 568 std::pair<TFilterElementHideTagsNamed::const_iterator, TFilterElementHid eTagsNamed::const_iterator> classItEnum = |
| 569 m_elementHideTagsClass.equal_range(std::make_pair(tag, className)); | 569 m_elementHideTagsClass.equal_range(std::make_pair(tagCString, classNam e)); |
| 570 | 570 |
| 571 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) |
| 572 { | 572 { |
| 573 if (classIt->second.IsMatchFilterElementHide(pEl)) | 573 if (classIt->second.IsMatchFilterElementHide(pEl)) |
| 574 { | 574 { |
| 575 #ifdef ENABLE_DEBUG_RESULT | 575 #ifdef ENABLE_DEBUG_RESULT |
| 576 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) |
| 577 CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt ->second.m_filterText); | 577 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText); |
| 578 #endif | 578 #endif |
| 579 return true; | 579 return true; |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 | 582 |
| 583 // Search general class name | 583 // Search general class name |
| 584 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName)); | 584 classItEnum = m_elementHideTagsClass.equal_range(std::make_pair("", clas sName)); |
| 585 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) |
| 586 { | 586 { |
| 587 if (classIt->second.IsMatchFilterElementHide(pEl)) | 587 if (classIt->second.IsMatchFilterElementHide(pEl)) |
| 588 { | 588 { |
| 589 #ifdef ENABLE_DEBUG_RESULT | 589 #ifdef ENABLE_DEBUG_RESULT |
| 590 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) |
| 591 CPluginDebug::DebugResultHiding(tag, "class:" + className, classIt ->second.m_filterText); | 591 CPluginDebug::DebugResultHiding(tagCString, "class:" + className, classIt->second.m_filterText); |
| 592 #endif | 592 #endif |
| 593 return true; | 593 return true; |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 | 596 |
| 597 // Next class name | 597 // Next class name |
| 598 className = classNames.Tokenize(L" \t\n\r", pos); | 598 className = classNames.Tokenize(L" \t\n\r", pos); |
| 599 } | 599 } |
| 600 } | 600 } |
| 601 | 601 |
| 602 // Search tag filters | 602 // Search tag filters |
| 603 std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::co nst_iterator> tagItEnum | 603 std::pair<TFilterElementHideTags::const_iterator, TFilterElementHideTags::co nst_iterator> tagItEnum |
| 604 = m_elementHideTags.equal_range(tag); | 604 = m_elementHideTags.equal_range(tagCString); |
| 605 for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt ! = tagItEnum.second; ++ tagIt) | 605 for (TFilterElementHideTags::const_iterator tagIt = tagItEnum.first; tagIt ! = tagItEnum.second; ++ tagIt) |
| 606 { | 606 { |
| 607 if (tagIt->second.IsMatchFilterElementHide(pEl)) | 607 if (tagIt->second.IsMatchFilterElementHide(pEl)) |
| 608 { | 608 { |
| 609 #ifdef ENABLE_DEBUG_RESULT | 609 #ifdef ENABLE_DEBUG_RESULT |
| 610 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) |
| 611 CPluginDebug::DebugResultHiding(tag, "-", tagIt->second.m_filterText); | 611 CPluginDebug::DebugResultHiding(tagCString, "-", tagIt->second.m_filte rText); |
| 612 #endif | 612 #endif |
| 613 return true; | 613 return true; |
| 614 } | 614 } |
| 615 } | 615 } |
| 616 } | 616 } |
| 617 | 617 |
| 618 return false; | 618 return false; |
| 619 } | 619 } |
| 620 | 620 |
| 621 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 Loading... | |
| 674 } | 674 } |
| 675 m_filterMapDefault[i].clear(); | 675 m_filterMapDefault[i].clear(); |
| 676 } | 676 } |
| 677 | 677 |
| 678 m_elementHideTags.clear(); | 678 m_elementHideTags.clear(); |
| 679 m_elementHideTagsId.clear(); | 679 m_elementHideTagsId.clear(); |
| 680 m_elementHideTagsClass.clear(); | 680 m_elementHideTagsClass.clear(); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 | 683 |
| 684 bool CPluginFilter::ShouldBlock(const std::wstring& src_wstring, int contentType , const std::wstring& domain_wstring, bool addDebug) const | 684 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const |
| 685 { | 685 { |
| 686 CString src = to_CString(src_wstring); | 686 CString srcCString = to_CString(src); |
| 687 CString domain = to_CString(domain_wstring); | |
| 688 | 687 |
| 689 // 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 |
| 690 // Therefore we just return | 689 // Therefore we just return |
| 691 if (src.Trim().IsEmpty()) | 690 if (srcCString.Trim().IsEmpty()) |
| 692 { | 691 { |
| 693 return false; | 692 return false; |
| 694 } | 693 } |
| 695 | 694 |
| 696 CPluginSettings* settings = CPluginSettings::GetInstance(); | 695 CPluginSettings* settings = CPluginSettings::GetInstance(); |
| 697 | 696 |
| 698 CString type; | 697 CString type; |
| 699 if (addDebug) | 698 if (addDebug) |
| 700 { | 699 { |
| 701 type = "OTHER"; | 700 type = "OTHER"; |
| 702 | 701 |
| 703 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); | 702 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); |
| 704 if (it != m_contentMapText.end()) | 703 if (it != m_contentMapText.end()) |
| 705 { | 704 { |
| 706 type = it->second; | 705 type = it->second; |
| 707 } | 706 } |
| 708 } | 707 } |
| 709 | 708 |
| 710 CPluginClient* client = CPluginClient::GetInstance(); | 709 CPluginClient* client = CPluginClient::GetInstance(); |
| 711 if (client->Matches(std::wstring(src), std::wstring(type), std::wstring(domain ))) | 710 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain)) |
| 712 { | 711 { |
| 713 if (addDebug) | 712 if (addDebug) |
| 714 { | 713 { |
| 715 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") | 714 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") |
| 716 | 715 |
| 717 #ifdef ENABLE_DEBUG_RESULT | 716 #ifdef ENABLE_DEBUG_RESULT |
| 718 CPluginDebug::DebugResultBlocking(type, src, domain); | 717 CPluginDebug::DebugResultBlocking(type, srcCString, to_CString(domain)); |
| 719 #endif | 718 #endif |
| 720 } | 719 } |
| 721 return true; | 720 return true; |
| 722 } | 721 } |
| 723 return false; | 722 return false; |
| 724 } | 723 } |
| LEFT | RIGHT |