| LEFT | RIGHT |
| 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-2016 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 416 |
| 417 return true; | 417 return true; |
| 418 } | 418 } |
| 419 | 419 |
| 420 | 420 |
| 421 | 421 |
| 422 // ============================================================================ | 422 // ============================================================================ |
| 423 // CPluginFilter | 423 // CPluginFilter |
| 424 // ============================================================================ | 424 // ============================================================================ |
| 425 | 425 |
| 426 CPluginFilter::CPluginFilter(const CString& dataPath) : m_dataPath(dataPath) | |
| 427 { | |
| 428 ClearFilters(); | |
| 429 } | |
| 430 | |
| 431 | |
| 432 bool CPluginFilter::AddFilterElementHide(CString filterText) | 426 bool CPluginFilter::AddFilterElementHide(CString filterText) |
| 433 { | 427 { |
| 434 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); | 428 DEBUG_FILTER("Input: " + filterText + " filterFile" + filterFile); |
| 435 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 429 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| 436 { | 430 { |
| 437 CString filterString = filterText; | 431 CString filterString = filterText; |
| 438 // Create filter descriptor | 432 // Create filter descriptor |
| 439 std::auto_ptr<CFilterElementHide> filter; | 433 std::auto_ptr<CFilterElementHide> filter; |
| 440 | 434 |
| 441 CString wholeFilterString = filterString; | 435 CString wholeFilterString = filterString; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 CPluginDebug::DebugResultHiding(tag, L"-", ToWstring(tagIt->second.m_f
ilterText)); | 592 CPluginDebug::DebugResultHiding(tag, L"-", ToWstring(tagIt->second.m_f
ilterText)); |
| 599 #endif | 593 #endif |
| 600 return true; | 594 return true; |
| 601 } | 595 } |
| 602 } | 596 } |
| 603 } | 597 } |
| 604 | 598 |
| 605 return false; | 599 return false; |
| 606 } | 600 } |
| 607 | 601 |
| 608 bool CPluginFilter::LoadHideFilters(const std::vector<std::wstring>& filters) | 602 CPluginFilter::CPluginFilter(const std::vector<std::wstring>& filters) |
| 609 { | 603 { |
| 610 ClearFilters(); | |
| 611 m_hideFilters = filters; | 604 m_hideFilters = filters; |
| 612 bool isRead = false; | |
| 613 CPluginClient* client = CPluginClient::GetInstance(); | 605 CPluginClient* client = CPluginClient::GetInstance(); |
| 614 | 606 |
| 615 // Parse hide string | 607 // Parse hide string |
| 616 int pos = 0; | 608 int pos = 0; |
| 617 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | 609 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); |
| 618 { | 610 { |
| 619 for (auto it = filters.begin(); it < filters.end(); ++it) | 611 for (auto it = filters.begin(); it < filters.end(); ++it) |
| 620 { | 612 { |
| 621 CString filter((*it).c_str()); | 613 CString filter((*it).c_str()); |
| 622 // If the line is not commented out | 614 // If the line is not commented out |
| 623 if (!filter.Trim().IsEmpty() && filter.GetAt(0) != '!' && filter.GetAt(0)
!= '[') | 615 if (!filter.Trim().IsEmpty() && filter.GetAt(0) != '!' && filter.GetAt(0)
!= '[') |
| 624 { | 616 { |
| 625 int filterType = 0; | 617 int filterType = 0; |
| 626 | 618 |
| 627 // See http://adblockplus.org/en/filters for further documentation | 619 // See http://adblockplus.org/en/filters for further documentation |
| 628 | 620 |
| 629 try | 621 try |
| 630 { | 622 { |
| 631 AddFilterElementHide(filter); | 623 AddFilterElementHide(filter); |
| 632 } | 624 } |
| 633 catch(...) | 625 catch(...) |
| 634 { | 626 { |
| 635 #ifdef ENABLE_DEBUG_RESULT | 627 #ifdef ENABLE_DEBUG_RESULT |
| 636 CPluginDebug::DebugResult(L"Error loading hide filter: " + ToWstring(f
ilter)); | 628 CPluginDebug::DebugResult(L"Error loading hide filter: " + ToWstring(f
ilter)); |
| 637 #endif | 629 #endif |
| 638 } | 630 } |
| 639 } | 631 } |
| 640 } | 632 } |
| 641 } | 633 } |
| 642 | |
| 643 return isRead; | |
| 644 } | |
| 645 | |
| 646 void CPluginFilter::ClearFilters() | |
| 647 { | |
| 648 // Clear filter maps | |
| 649 CriticalSection::Lock filterEngineLock(s_criticalSectionFilterMap); | |
| 650 m_elementHideTags.clear(); | |
| 651 m_elementHideTagsId.clear(); | |
| 652 m_elementHideTagsClass.clear(); | |
| 653 m_hideFilters.clear(); | |
| 654 } | |
| 655 | |
| 656 bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngi
ne::ContentType contentType, const std::wstring& domain, bool addDebug) const | |
| 657 { | |
| 658 std::wstring srcTrimmed = TrimString(src); | |
| 659 | |
| 660 // We should not block the empty string, so all filtering does not make sense | |
| 661 // Therefore we just return | |
| 662 if (srcTrimmed.empty()) | |
| 663 { | |
| 664 return false; | |
| 665 } | |
| 666 | |
| 667 CPluginSettings* settings = CPluginSettings::GetInstance(); | |
| 668 | |
| 669 CPluginClient* client = CPluginClient::GetInstance(); | |
| 670 bool result = client->Matches(srcTrimmed, contentType, domain); | |
| 671 | |
| 672 #ifdef ENABLE_DEBUG_RESULT | |
| 673 if (addDebug) | |
| 674 { | |
| 675 std::wstring type = ToUtf16String(AdblockPlus::FilterEngine::ContentTypeToSt
ring(contentType)); | |
| 676 if (result) | |
| 677 { | |
| 678 CPluginDebug::DebugResultBlocking(type, srcTrimmed, domain); | |
| 679 } | |
| 680 else | |
| 681 { | |
| 682 CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain); | |
| 683 } | |
| 684 } | |
| 685 #endif | |
| 686 return result; | |
| 687 } | |
| 688 | |
| 689 const std::vector<std::wstring>& CPluginFilter::GetHideFilters() const | |
| 690 { | |
| 691 DWORD res = WaitForSingleObject(hideFiltersLoadedEvent, ENGINE_STARTUP_TIMEOUT
); | |
| 692 return m_hideFilters; | |
| 693 } | 634 } |
| LEFT | RIGHT |