Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/PluginFilter.cpp

Issue 5316782940225536: Issue 1557 - Update to the recent libadblockplus to reduce additional updates in the logic later. (Closed)
Patch Set: rebase and remove member of CFilter Created Feb. 4, 2015, 12:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/plugin/PluginFilter.h ('k') | src/plugin/PluginWbPassThrough.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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;
276 m_filterType = filter.m_filterType; 274 m_filterType = filter.m_filterType;
277 275
278 m_isFirstParty = filter.m_isFirstParty; 276 m_isFirstParty = filter.m_isFirstParty;
279 m_isThirdParty = filter.m_isThirdParty; 277 m_isThirdParty = filter.m_isThirdParty;
280 278
281 m_isMatchCase = filter.m_isMatchCase; 279 m_isMatchCase = filter.m_isMatchCase;
282 m_isFromStart = filter.m_isFromStart; 280 m_isFromStart = filter.m_isFromStart;
283 m_isFromEnd = filter.m_isFromEnd; 281 m_isFromEnd = filter.m_isFromEnd;
284 282
285 m_filterText = filter.m_filterText; 283 m_filterText = filter.m_filterText;
286 284
287 m_hitCount = filter.m_hitCount; 285 m_hitCount = filter.m_hitCount;
288 } 286 }
289 287
290 288
291 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false), m_isThirdParty (false), m_contentType(CFilter::contentTypeAny), 289 CFilter::CFilter() : m_isMatchCase(false), m_isFirstParty(false),
290 m_isThirdParty(false),
292 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0) 291 m_isFromStart(false), m_isFromEnd(false), m_hitCount(0)
293 { 292 {
294 } 293 }
295 294
296 295
297 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const 296 bool CFilterElementHide::IsMatchFilterElementHide(IHTMLElement* pEl) const
298 { 297 {
299 HRESULT hr; 298 HRESULT hr;
300 299
301 if (!m_tagId.IsEmpty()) 300 if (!m_tagId.IsEmpty())
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 464 }
466 465
467 466
468 467
469 // ============================================================================ 468 // ============================================================================
470 // CPluginFilter 469 // CPluginFilter
471 // ============================================================================ 470 // ============================================================================
472 471
473 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) 472 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath)
474 { 473 {
475 m_contentMapText[CFilter::contentTypeDocument] = "DOCUMENT"; 474 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 } 475 }
488 476
489 477
490 bool CPluginFilter::AddFilterElementHide(CString filterText) 478 bool CPluginFilter::AddFilterElementHide(CString filterText)
491 { 479 {
492 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); 480 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile);
493 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); 481 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap);
494 { 482 {
495 CString filterString = filterText; 483 CString filterString = filterText;
496 // Create filter descriptor 484 // Create filter descriptor
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 } 701 }
714 m_filterMapDefault[i].clear(); 702 m_filterMapDefault[i].clear();
715 } 703 }
716 704
717 m_elementHideTags.clear(); 705 m_elementHideTags.clear();
718 m_elementHideTagsId.clear(); 706 m_elementHideTagsId.clear();
719 m_elementHideTagsClass.clear(); 707 m_elementHideTagsClass.clear();
720 } 708 }
721 } 709 }
722 710
723 bool CPluginFilter::ShouldBlock(const std::wstring& src, int contentType, const std::wstring& domain, bool addDebug) const 711 bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngi ne::ContentType contentType, const std::wstring& domain, bool addDebug) const
724 { 712 {
725 std::wstring srcTrimmed = TrimString(src); 713 std::wstring srcTrimmed = TrimString(src);
726 714
727 // We should not block the empty string, so all filtering does not make sense 715 // We should not block the empty string, so all filtering does not make sense
728 // Therefore we just return 716 // Therefore we just return
729 if (srcTrimmed.empty()) 717 if (srcTrimmed.empty())
730 { 718 {
731 return false; 719 return false;
732 } 720 }
721
733 CPluginSettings* settings = CPluginSettings::GetInstance(); 722 CPluginSettings* settings = CPluginSettings::GetInstance();
734 723
735 CString type; 724 CPluginClient* client = CPluginClient::GetInstance();
725 bool result = client->Matches(srcTrimmed, contentType, domain);
726
727 #ifdef ENABLE_DEBUG_RESULT
736 if (addDebug) 728 if (addDebug)
737 { 729 {
738 type = "OTHER"; 730 std::wstring type = ToUtf16String(AdblockPlus::FilterEngine::ContentTypeToSt ring(contentType));
739 731 if (result)
740 std::map<int,CString>::const_iterator it = m_contentMapText.find(contentType );
741 if (it != m_contentMapText.end())
742 { 732 {
743 type = it->second; 733 CPluginDebug::DebugResultBlocking(ToCString(type), srcTrimmed, domain);
734 }
735 else
736 {
737 CPluginDebug::DebugResultIgnoring(ToCString(type), srcTrimmed, domain);
744 } 738 }
745 } 739 }
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 740 #endif
757 } 741 return result;
758 return true;
759 }
760 #ifdef ENABLE_DEBUG_RESULT
761 CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain);
762 #endif
763 return false;
764 } 742 }
OLDNEW
« no previous file with comments | « src/plugin/PluginFilter.h ('k') | src/plugin/PluginWbPassThrough.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld