Left: | ||
Right: |
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 12 matching lines...) Expand all Loading... | |
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 | 32 |
33 | |
34 // The filters are described at http://adblockplus.org/en/filters | 33 // The filters are described at http://adblockplus.org/en/filters |
35 | 34 |
36 static CriticalSection s_criticalSectionFilterMap; | 35 static CriticalSection s_criticalSectionFilterMap; |
37 | 36 |
38 namespace | 37 namespace |
39 { | 38 { |
40 struct GetHtmlElementAttributeResult | 39 struct GetHtmlElementAttributeResult |
41 { | 40 { |
42 GetHtmlElementAttributeResult() : isAttributeFound(false) | 41 GetHtmlElementAttributeResult() : isAttributeFound(false) |
43 { | 42 { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 m_predecessor = filter.m_predecessor; | 264 m_predecessor = filter.m_predecessor; |
266 } | 265 } |
267 | 266 |
268 | 267 |
269 // ============================================================================ | 268 // ============================================================================ |
270 // CFilter | 269 // CFilter |
271 // ============================================================================ | 270 // ============================================================================ |
272 | 271 |
273 CFilter::CFilter(const CFilter& filter) | 272 CFilter::CFilter(const CFilter& filter) |
274 { | 273 { |
275 m_contentType = filter.m_contentType; | 274 m_contentType = filter.m_contentType; |
Eric
2015/02/02 06:58:27
Here it is in the copy constructor.
| |
276 m_filterType = filter.m_filterType; | 275 m_filterType = filter.m_filterType; |
277 | 276 |
278 m_isFirstParty = filter.m_isFirstParty; | 277 m_isFirstParty = filter.m_isFirstParty; |
279 m_isThirdParty = filter.m_isThirdParty; | 278 m_isThirdParty = filter.m_isThirdParty; |
280 | 279 |
281 m_isMatchCase = filter.m_isMatchCase; | 280 m_isMatchCase = filter.m_isMatchCase; |
282 m_isFromStart = filter.m_isFromStart; | 281 m_isFromStart = filter.m_isFromStart; |
283 m_isFromEnd = filter.m_isFromEnd; | 282 m_isFromEnd = filter.m_isFromEnd; |
284 | 283 |
285 m_filterText = filter.m_filterText; | 284 m_filterText = filter.m_filterText; |
286 | 285 |
287 m_hitCount = filter.m_hitCount; | 286 m_hitCount = filter.m_hitCount; |
288 } | 287 } |
289 | 288 |
290 | 289 |
291 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), m_isThirdParty (false), m_contentType(CFilter::contentTypeAny), | 290 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), |
291 m_isThirdParty(false), m_contentType(AdblockPlus::FilterEngine::ContentType::C ONTENT_TYPE_OTHER), | |
Eric
2015/02/02 06:58:27
Here it is in the default constructor.
| |
292 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) | 292 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) |
293 { | 293 { |
294 } | 294 } |
295 | 295 |
296 | 296 |
297 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const | 297 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const |
298 { | 298 { |
299 HRESULT hr; | 299 HRESULT hr; |
300 | 300 |
301 if (!m_tagId.IsEmpty()) | 301 if (!m_tagId.IsEmpty()) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 } | 465 } |
466 | 466 |
467 | 467 |
468 | 468 |
469 // ============================================================================ | 469 // ============================================================================ |
470 // CPluginFilter | 470 // CPluginFilter |
471 // ============================================================================ | 471 // ============================================================================ |
472 | 472 |
473 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) | 473 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) |
474 { | 474 { |
475 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; | 475 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 } | 476 } |
488 | 477 |
489 | 478 |
490 bool CPluginFilter::AddFilterElementHide(CString filterText) | 479 bool CPluginFilter::AddFilterElementHide(CString filterText) |
491 { | 480 { |
492 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); | 481 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); |
493 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 482 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
494 { | 483 { |
495 CString filterString = filterText; | 484 CString filterString = filterText; |
496 // Create filter descriptor | 485 // Create filter descriptor |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 } | 702 } |
714 m_filterMapDefault[i].clear(); | 703 m_filterMapDefault[i].clear(); |
715 } | 704 } |
716 | 705 |
717 m_elementHideTags.clear(); | 706 m_elementHideTags.clear(); |
718 m_elementHideTagsId.clear(); | 707 m_elementHideTagsId.clear(); |
719 m_elementHideTagsClass.clear(); | 708 m_elementHideTagsClass.clear(); |
720 } | 709 } |
721 } | 710 } |
722 | 711 |
723 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const | 712 bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngi ne::ContentType contentType, const std::wstring& domain, bool addDebug) const |
724 { | 713 { |
725 std::wstring srcTrimmed = TrimString(src); | 714 std::wstring srcTrimmed = TrimString(src); |
726 | 715 |
727 // We should not block the empty string, so all filtering does not make sense | 716 // We should not block the empty string, so all filtering does not make sense |
728 // Therefore we just return | 717 // Therefore we just return |
729 if (srcTrimmed.empty()) | 718 if (srcTrimmed.empty()) |
730 { | 719 { |
731 return false; | 720 return false; |
732 } | 721 } |
722 | |
733 CPluginSettings* settings = CPluginSettings::GetInstance(); | 723 CPluginSettings* settings = CPluginSettings::GetInstance(); |
734 | 724 |
735 CString type; | 725 CPluginClient* client = CPluginClient::GetInstance(); |
726 bool result = client->Matches(srcTrimmed, contentType, domain); | |
727 | |
728 #ifdef ENABLE_DEBUG_RESULT | |
736 if (addDebug) | 729 if (addDebug) |
737 { | 730 { |
738 type = "OTHER"; | 731 std::wstring type = ToUtf16String(AdblockPlus::FilterEngine::ContentTypeToSt ring(contentType)); |
739 | 732 if (result) |
740 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType ); | |
741 if (it != m_contentMapText.end()) | |
742 { | 733 { |
743 type = it->second; | 734 CPluginDebug::DebugResultBlocking(ToCString(type), srcTrimmed, domain); |
735 } | |
736 else | |
737 { | |
738 CPluginDebug::DebugResultIgnoring(ToCString(type), srcTrimmed, domain); | |
744 } | 739 } |
745 } | 740 } |
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 | 741 #endif |
757 } | 742 return result; |
758 return true; | |
759 } | |
760 #ifdef ENABLE_DEBUG_RESULT | |
761 CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain); | |
762 #endif | |
763 return false; | |
764 } | 743 } |
OLD | NEW |