OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "PluginClient.h" | 22 #include "PluginClient.h" |
23 #include "PluginClientFactory.h" | 23 #include "PluginClientFactory.h" |
24 #include "PluginMutex.h" | 24 #include "PluginMutex.h" |
25 #include "PluginSettings.h" | 25 #include "PluginSettings.h" |
26 #include "PluginSystem.h" | 26 #include "PluginSystem.h" |
27 #include "PluginClass.h" | 27 #include "PluginClass.h" |
28 #include "mlang.h" | 28 #include "mlang.h" |
29 | 29 |
30 #include "..\shared\CriticalSection.h" | 30 #include "..\shared\CriticalSection.h" |
31 #include "..\shared\Utils.h" | 31 #include "..\shared\Utils.h" |
| 32 #include "..\shared\ContentType.h" |
32 | 33 |
33 | 34 |
34 // The filters are described at http://adblockplus.org/en/filters | 35 // The filters are described at http://adblockplus.org/en/filters |
35 | 36 |
36 static CriticalSection s_criticalSectionFilterMap; | 37 static CriticalSection s_criticalSectionFilterMap; |
37 | 38 |
38 namespace | 39 namespace |
39 { | 40 { |
40 struct GetHtmlElementAttributeResult | 41 struct GetHtmlElementAttributeResult |
41 { | 42 { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 m_isMatchCase = filter.m_isMatchCase; | 282 m_isMatchCase = filter.m_isMatchCase; |
282 m_isFromStart = filter.m_isFromStart; | 283 m_isFromStart = filter.m_isFromStart; |
283 m_isFromEnd = filter.m_isFromEnd; | 284 m_isFromEnd = filter.m_isFromEnd; |
284 | 285 |
285 m_filterText = filter.m_filterText; | 286 m_filterText = filter.m_filterText; |
286 | 287 |
287 m_hitCount = filter.m_hitCount; | 288 m_hitCount = filter.m_hitCount; |
288 } | 289 } |
289 | 290 |
290 | 291 |
291 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), m_isThirdParty
(false), m_contentType(CFilter::contentTypeAny), | 292 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), |
| 293 m_isThirdParty(false), m_contentType(AdblockPlus::FilterEngine::ContentType::C
ONTENT_TYPE_OTHER), |
292 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) | 294 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) |
293 { | 295 { |
294 } | 296 } |
295 | 297 |
296 | 298 |
297 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const | 299 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const |
298 { | 300 { |
299 HRESULT hr; | 301 HRESULT hr; |
300 | 302 |
301 if (!m_tagId.IsEmpty()) | 303 if (!m_tagId.IsEmpty()) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 } | 467 } |
466 | 468 |
467 | 469 |
468 | 470 |
469 // ============================================================================ | 471 // ============================================================================ |
470 // CPluginFilter | 472 // CPluginFilter |
471 // ============================================================================ | 473 // ============================================================================ |
472 | 474 |
473 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) | 475 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) |
474 { | 476 { |
475 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; | 477 ClearFilters(); |
476 m_contentMapText[CFilter::contentTypeObject] = "OBJECT"; | |
477 m_contentMapText[CFilter::contentTypeObjectSubrequest] = "OBJECT_SUBREQUEST"; | |
478 m_contentMapText[CFilter::contentTypeImage] = "IMAGE"; | |
479 m_contentMapText[CFilter::contentTypeScript] = "SCRIPT"; | |
480 m_contentMapText[CFilter::contentTypeOther] = "OTHER"; | |
481 m_contentMapText[CFilter::contentTypeUnknown] = "OTHER"; | |
482 m_contentMapText[CFilter::contentTypeSubdocument] = "SUBDOCUMENT"; | |
483 m_contentMapText[CFilter::contentTypeStyleSheet] = "STYLESHEET"; | |
484 m_contentMapText[CFilter::contentTypeXmlHttpRequest] = "XMLHTTPREQUEST"; | |
485 | |
486 ClearFilters(); | |
487 } | 478 } |
488 | 479 |
489 | 480 |
490 bool CPluginFilter::AddFilterElementHide(CString filterText) | 481 bool CPluginFilter::AddFilterElementHide(CString filterText) |
491 { | 482 { |
492 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); | 483 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); |
493 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 484 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
494 { | 485 { |
495 CString filterString = filterText; | 486 CString filterString = filterText; |
496 // Create filter descriptor | 487 // Create filter descriptor |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 } | 704 } |
714 m_filterMapDefault[i].clear(); | 705 m_filterMapDefault[i].clear(); |
715 } | 706 } |
716 | 707 |
717 m_elementHideTags.clear(); | 708 m_elementHideTags.clear(); |
718 m_elementHideTagsId.clear(); | 709 m_elementHideTagsId.clear(); |
719 m_elementHideTagsClass.clear(); | 710 m_elementHideTagsClass.clear(); |
720 } | 711 } |
721 } | 712 } |
722 | 713 |
723 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const
std::wstring& domain, bool addDebug) const | 714 bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngi
ne::ContentType contentType, const std::wstring& domain, bool addDebug) const |
724 { | 715 { |
725 std::wstring srcTrimmed = TrimString(src); | 716 std::wstring srcTrimmed = TrimString(src); |
726 | 717 |
727 // We should not block the empty string, so all filtering does not make sense | 718 // We should not block the empty string, so all filtering does not make sense |
728 // Therefore we just return | 719 // Therefore we just return |
729 if (srcTrimmed.empty()) | 720 if (srcTrimmed.empty()) |
730 { | 721 { |
731 return false; | 722 return false; |
732 } | 723 } |
| 724 |
733 CPluginSettings* settings = CPluginSettings::GetInstance(); | 725 CPluginSettings* settings = CPluginSettings::GetInstance(); |
734 | 726 |
735 CString type; | 727 CPluginClient* client = CPluginClient::GetInstance(); |
| 728 bool result = client->Matches(srcTrimmed, contentType, domain); |
| 729 |
| 730 #ifdef ENABLE_DEBUG_RESULT |
736 if (addDebug) | 731 if (addDebug) |
737 { | 732 { |
738 type = "OTHER"; | 733 std::wstring type = ToUtf16String(ContentTypeToString(contentType)); |
739 | 734 if (result) |
740 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType
); | |
741 if (it != m_contentMapText.end()) | |
742 { | 735 { |
743 type = it->second; | 736 CPluginDebug::DebugResultBlocking(ToCString(type), srcTrimmed, domain); |
| 737 } |
| 738 else |
| 739 { |
| 740 CPluginDebug::DebugResultIgnoring(ToCString(type), srcTrimmed, domain); |
744 } | 741 } |
745 } | 742 } |
746 | |
747 CPluginClient* client = CPluginClient::GetInstance(); | |
748 if (client->Matches(srcTrimmed, ToWstring(type), domain)) | |
749 { | |
750 if (addDebug) | |
751 { | |
752 DEBUG_FILTER("Filter::ShouldBlock " + type + " YES") | |
753 | |
754 #ifdef ENABLE_DEBUG_RESULT | |
755 CPluginDebug::DebugResultBlocking(type, srcTrimmed, domain); | |
756 #endif | 743 #endif |
757 } | 744 return result; |
758 return true; | |
759 } | |
760 #ifdef ENABLE_DEBUG_RESULT | |
761 CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain); | |
762 #endif | |
763 return false; | |
764 } | 745 } |
OLD | NEW |