| OLD | NEW |
| 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" |
| 11 #include "mlang.h" | 11 #include "mlang.h" |
| 12 | 12 |
| 13 #include "..\shared\CriticalSection.h" | 13 #include "..\shared\CriticalSection.h" |
| 14 #include "..\shared\Utils.h" | 14 #include "..\shared\Utils.h" |
| 15 #include "..\shared\ContentType.h" |
| 15 | 16 |
| 16 | 17 |
| 17 // The filters are described at http://adblockplus.org/en/filters | 18 // The filters are described at http://adblockplus.org/en/filters |
| 18 | 19 |
| 19 static CriticalSection s_criticalSectionFilterMap; | 20 static CriticalSection s_criticalSectionFilterMap; |
| 20 | 21 |
| 21 namespace | 22 namespace |
| 22 { | 23 { |
| 23 struct GetHtmlElementAttributeResult | 24 struct GetHtmlElementAttributeResult |
| 24 { | 25 { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 m_isMatchCase = filter.m_isMatchCase; | 265 m_isMatchCase = filter.m_isMatchCase; |
| 265 m_isFromStart = filter.m_isFromStart; | 266 m_isFromStart = filter.m_isFromStart; |
| 266 m_isFromEnd = filter.m_isFromEnd; | 267 m_isFromEnd = filter.m_isFromEnd; |
| 267 | 268 |
| 268 m_filterText = filter.m_filterText; | 269 m_filterText = filter.m_filterText; |
| 269 | 270 |
| 270 m_hitCount = filter.m_hitCount; | 271 m_hitCount = filter.m_hitCount; |
| 271 } | 272 } |
| 272 | 273 |
| 273 | 274 |
| 274 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), m_isThirdParty
(false), m_contentType(CFilter::contentTypeAny), | 275 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), |
| 276 m_isThirdParty(false), m_contentType(AdblockPlus::FilterEngine::ContentType::C
ONTENT_TYPE_OTHER), |
| 275 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) | 277 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) |
| 276 { | 278 { |
| 277 } | 279 } |
| 278 | 280 |
| 279 | 281 |
| 280 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const | 282 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const |
| 281 { | 283 { |
| 282 HRESULT hr; | 284 HRESULT hr; |
| 283 | 285 |
| 284 if (!m_tagId.IsEmpty()) | 286 if (!m_tagId.IsEmpty()) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 450 } |
| 449 | 451 |
| 450 | 452 |
| 451 | 453 |
| 452 // ============================================================================ | 454 // ============================================================================ |
| 453 // CPluginFilter | 455 // CPluginFilter |
| 454 // ============================================================================ | 456 // ============================================================================ |
| 455 | 457 |
| 456 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) | 458 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) |
| 457 { | 459 { |
| 458 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; | 460 ClearFilters(); |
| 459 m_contentMapText[CFilter::contentTypeObject] = "OBJECT"; | |
| 460 m_contentMapText[CFilter::contentTypeObjectSubrequest] = "OBJECT_SUBREQUEST"; | |
| 461 m_contentMapText[CFilter::contentTypeImage] = "IMAGE"; | |
| 462 m_contentMapText[CFilter::contentTypeScript] = "SCRIPT"; | |
| 463 m_contentMapText[CFilter::contentTypeOther] = "OTHER"; | |
| 464 m_contentMapText[CFilter::contentTypeUnknown] = "OTHER"; | |
| 465 m_contentMapText[CFilter::contentTypeSubdocument] = "SUBDOCUMENT"; | |
| 466 m_contentMapText[CFilter::contentTypeStyleSheet] = "STYLESHEET"; | |
| 467 m_contentMapText[CFilter::contentTypeXmlHttpRequest] = "XMLHTTPREQUEST"; | |
| 468 | |
| 469 ClearFilters(); | |
| 470 } | 461 } |
| 471 | 462 |
| 472 | 463 |
| 473 bool CPluginFilter::AddFilterElementHide(CString filterText) | 464 bool CPluginFilter::AddFilterElementHide(CString filterText) |
| 474 { | 465 { |
| 475 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); | 466 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); |
| 476 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 467 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| 477 { | 468 { |
| 478 CString filterString = filterText; | 469 CString filterString = filterText; |
| 479 // Create filter descriptor | 470 // Create filter descriptor |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 } | 520 } |
| 530 } | 521 } |
| 531 } while (separatorChar != '\0'); | 522 } while (separatorChar != '\0'); |
| 532 } | 523 } |
| 533 | 524 |
| 534 return true; | 525 return true; |
| 535 } | 526 } |
| 536 | 527 |
| 537 bool CPluginFilter::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl,
const std::wstring& domain, const std::wstring& indent) const | 528 bool CPluginFilter::IsElementHidden(const std::wstring& tag, IHTMLElement* pEl,
const std::wstring& domain, const std::wstring& indent) const |
| 538 { | 529 { |
| 539 CString tagCString = to_CString(tag); | 530 CString tagCString = ToCString(tag); |
| 540 | 531 |
| 541 CString id; | 532 CString id; |
| 542 CComBSTR bstrId; | 533 CComBSTR bstrId; |
| 543 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) | 534 if (SUCCEEDED(pEl->get_id(&bstrId)) && bstrId) |
| 544 { | 535 { |
| 545 id = bstrId; | 536 id = bstrId; |
| 546 } | 537 } |
| 547 | 538 |
| 548 CString classNames; | 539 CString classNames; |
| 549 CComBSTR bstrClassNames; | 540 CComBSTR bstrClassNames; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 } | 687 } |
| 697 m_filterMapDefault[i].clear(); | 688 m_filterMapDefault[i].clear(); |
| 698 } | 689 } |
| 699 | 690 |
| 700 m_elementHideTags.clear(); | 691 m_elementHideTags.clear(); |
| 701 m_elementHideTagsId.clear(); | 692 m_elementHideTagsId.clear(); |
| 702 m_elementHideTagsClass.clear(); | 693 m_elementHideTagsClass.clear(); |
| 703 } | 694 } |
| 704 } | 695 } |
| 705 | 696 |
| 706 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const
std::wstring& domain, bool addDebug) const | 697 bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngi
ne::ContentType contentType, const std::wstring& domain, bool addDebug) const |
| 707 { | 698 { |
| 708 CString srcCString = to_CString(src); | 699 CString srcCString = ToCString(src); |
| 709 | 700 |
| 710 // We should not block the empty string, so all filtering does not make sense | 701 // We should not block the empty string, so all filtering does not make sense |
| 711 // Therefore we just return | 702 // Therefore we just return |
| 712 if (srcCString.Trim().IsEmpty()) | 703 if (srcCString.Trim().IsEmpty()) |
| 713 { | 704 { |
| 714 return false; | 705 return false; |
| 715 } | 706 } |
| 716 | 707 |
| 717 CPluginSettings* settings = CPluginSettings::GetInstance(); | 708 CPluginSettings* settings = CPluginSettings::GetInstance(); |
| 718 | 709 |
| 719 CString type; | 710 CPluginClient* client = CPluginClient::GetInstance(); |
| 711 bool result = client->Matches(ToWstring(srcCString), contentType, domain); |
| 712 |
| 713 #ifdef ENABLE_DEBUG_RESULT |
| 720 if (addDebug) | 714 if (addDebug) |
| 721 { | 715 { |
| 722 type = "OTHER"; | 716 std::wstring type = ToUtf16String(ContentTypeToString(contentType)); |
| 723 | 717 if (result) |
| 724 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType
); | |
| 725 if (it != m_contentMapText.end()) | |
| 726 { | 718 { |
| 727 type = it->second; | 719 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES"); |
| 720 CPluginDebug::DebugResultBlocking(ToCString(type), srcCString, domain); |
| 721 } |
| 722 else |
| 723 { |
| 724 CPluginDebug::DebugResultIgnoring(ToCString(type), srcCString, domain); |
| 728 } | 725 } |
| 729 } | 726 } |
| 730 | |
| 731 CPluginClient* client = CPluginClient::GetInstance(); | |
| 732 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain)) | |
| 733 { | |
| 734 if (addDebug) | |
| 735 { | |
| 736 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") | |
| 737 | |
| 738 #ifdef ENABLE_DEBUG_RESULT | |
| 739 CPluginDebug::DebugResultBlocking(type, srcCString, domain); | |
| 740 #endif | 727 #endif |
| 741 } | 728 return result; |
| 742 return true; | |
| 743 } | |
| 744 #ifdef ENABLE_DEBUG_RESULT | |
| 745 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); | |
| 746 #endif | |
| 747 return false; | |
| 748 } | 729 } |
| OLD | NEW |