Left: | ||
Right: |
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 m_isMatchCase = filter.m_isMatchCase; | 268 m_isMatchCase = filter.m_isMatchCase; |
268 m_isFromStart = filter.m_isFromStart; | 269 m_isFromStart = filter.m_isFromStart; |
269 m_isFromEnd = filter.m_isFromEnd; | 270 m_isFromEnd = filter.m_isFromEnd; |
270 | 271 |
271 m_filterText = filter.m_filterText; | 272 m_filterText = filter.m_filterText; |
272 | 273 |
273 m_hitCount = filter.m_hitCount; | 274 m_hitCount = filter.m_hitCount; |
274 } | 275 } |
275 | 276 |
276 | 277 |
277 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), m_isThirdParty (false), m_contentType(CFilter::contentTypeAny), | 278 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), |
279 m_isThirdParty(false), m_contentType(AdblockPlus::FilterEngine::ContentType::C ONTENT_TYPE_OTHER), | |
278 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) | 280 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) |
279 { | 281 { |
280 } | 282 } |
281 | 283 |
282 | 284 |
283 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const | 285 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const |
284 { | 286 { |
285 HRESULT hr; | 287 HRESULT hr; |
286 | 288 |
287 if (!m_tagId.IsEmpty()) | 289 if (!m_tagId.IsEmpty()) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 } | 454 } |
453 | 455 |
454 | 456 |
455 | 457 |
456 // ============================================================================ | 458 // ============================================================================ |
457 // CPluginFilter | 459 // CPluginFilter |
458 // ============================================================================ | 460 // ============================================================================ |
459 | 461 |
460 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) | 462 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) |
461 { | 463 { |
462 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; | 464 ClearFilters(); |
463 m_contentMapText[CFilter::contentTypeObject] = "OBJECT"; | |
464 m_contentMapText[CFilter::contentTypeObjectSubrequest] = "OBJECT_SUBREQUEST"; | |
465 m_contentMapText[CFilter::contentTypeImage] = "IMAGE"; | |
466 m_contentMapText[CFilter::contentTypeScript] = "SCRIPT"; | |
467 m_contentMapText[CFilter::contentTypeOther] = "OTHER"; | |
468 m_contentMapText[CFilter::contentTypeUnknown] = "OTHER"; | |
469 m_contentMapText[CFilter::contentTypeSubdocument] = "SUBDOCUMENT"; | |
470 m_contentMapText[CFilter::contentTypeStyleSheet] = "STYLESHEET"; | |
471 m_contentMapText[CFilter::contentTypeXmlHttpRequest] = "XMLHTTPREQUEST"; | |
472 | |
473 ClearFilters(); | |
474 } | 465 } |
475 | 466 |
476 | 467 |
477 bool CPluginFilter::AddFilterElementHide(CString filterText) | 468 bool CPluginFilter::AddFilterElementHide(CString filterText) |
478 { | 469 { |
479 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); | 470 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); |
480 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 471 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
481 { | 472 { |
482 CString filterString = filterText; | 473 CString filterString = filterText; |
483 // Create filter descriptor | 474 // Create filter descriptor |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 } | 691 } |
701 m_filterMapDefault[i].clear(); | 692 m_filterMapDefault[i].clear(); |
702 } | 693 } |
703 | 694 |
704 m_elementHideTags.clear(); | 695 m_elementHideTags.clear(); |
705 m_elementHideTagsId.clear(); | 696 m_elementHideTagsId.clear(); |
706 m_elementHideTagsClass.clear(); | 697 m_elementHideTagsClass.clear(); |
707 } | 698 } |
708 } | 699 } |
709 | 700 |
710 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const | 701 bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngi ne::ContentType contentType, const std::wstring& domain, bool addDebug) const |
711 { | 702 { |
712 CString srcCString = to_CString(src); | 703 CString srcCString = to_CString(src); |
713 | 704 |
714 // We should not block the empty string, so all filtering does not make sense | 705 // We should not block the empty string, so all filtering does not make sense |
715 // Therefore we just return | 706 // Therefore we just return |
716 if (srcCString.Trim().IsEmpty()) | 707 if (srcCString.Trim().IsEmpty()) |
717 { | 708 { |
718 return false; | 709 return false; |
719 } | 710 } |
720 | 711 |
721 CPluginSettings* settings = CPluginSettings::GetInstance(); | 712 CPluginSettings* settings = CPluginSettings::GetInstance(); |
722 | 713 |
723 CString type; | 714 CPluginClient* client = CPluginClient::GetInstance(); |
715 bool result = client->Matches(to_wstring(srcCString), contentType, domain); | |
Eric
2014/12/30 16:56:08
ToWstring
| |
716 | |
717 #ifdef ENABLE_DEBUG_RESULT | |
724 if (addDebug) | 718 if (addDebug) |
725 { | 719 { |
726 type = "OTHER"; | 720 std::wstring type = ToUtf16String(ContentTypeToString(contentType)); |
727 | 721 if (result) |
728 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); | |
729 if (it != m_contentMapText.end()) | |
730 { | 722 { |
731 type = it->second; | 723 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES"); |
724 CPluginDebug::DebugResultBlocking(to_CString(type), srcCString, domain); | |
Eric
2014/12/30 16:56:08
ToCString
| |
725 } | |
726 else | |
727 { | |
728 CPluginDebug::DebugResultIgnoring(to_CString(type), srcCString, domain); | |
Eric
2014/12/30 16:56:08
ToCString
| |
732 } | 729 } |
733 } | 730 } |
734 | |
735 CPluginClient* client = CPluginClient::GetInstance(); | |
736 if (client->Matches(to_wstring(srcCString), to_wstring(type), domain)) | |
737 { | |
738 if (addDebug) | |
739 { | |
740 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") | |
741 | |
742 #ifdef ENABLE_DEBUG_RESULT | |
743 CPluginDebug::DebugResultBlocking(type, srcCString, domain); | |
744 #endif | 731 #endif |
745 } | 732 return result; |
746 return true; | |
747 } | |
748 #ifdef ENABLE_DEBUG_RESULT | |
749 CPluginDebug::DebugResultIgnoring(type, srcCString, domain); | |
750 #endif | |
751 return false; | |
752 } | 733 } |
OLD | NEW |