OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 #pragma once |
| 19 |
| 20 #include <vector> |
| 21 |
| 22 #include "../debug.h" |
| 23 #include "../bindings/runtime.h" |
| 24 #include "../StringMap.h" |
| 25 #include "Filter.h" |
| 26 |
| 27 class Matcher : public ref_counted |
| 28 { |
| 29 private: |
| 30 friend class CombinedMatcher; |
| 31 StringMap<std::vector<FilterPtr>> mFilterByKeyword; |
| 32 StringMap<OwnedString> mKeywordByFilter; |
| 33 public: |
| 34 void BINDINGS_EXPORTED Add(Filter&); |
| 35 void BINDINGS_EXPORTED Remove(Filter&); |
| 36 void BINDINGS_EXPORTED Clear() ; |
| 37 bool BINDINGS_EXPORTED HasFilter(const Filter&) const; |
| 38 const String& BINDINGS_EXPORTED GetKeywordForFilter(const Filter& filter) cons
t; |
| 39 Filter* BINDINGS_EXPORTED MatchesAny(const String& location, |
| 40 int typeMask, DependentString& docDomain, bool thirdParty, |
| 41 const String& sitekey, bool specificOnly) const; |
| 42 OwnedString BINDINGS_EXPORTED FindKeyword(const Filter&) const; |
| 43 |
| 44 private: |
| 45 FilterPtr CheckEntryMatch(const String& keyword, |
| 46 const String& location, |
| 47 int typeMask, DependentString& docDomain, bool thirdParty, |
| 48 const String& sitekey, bool specificOnly) const; |
| 49 }; |
| 50 |
| 51 class CombinedMatcher : public ref_counted |
| 52 { |
| 53 private: |
| 54 static const size_t MAX_CACHE_ENTRIES; |
| 55 StringMap<FilterPtr> mResultCache; |
| 56 Matcher mBlacklist; |
| 57 Matcher mWhitelist; |
| 58 |
| 59 public: |
| 60 void BINDINGS_EXPORTED Add(Filter& filter); |
| 61 void BINDINGS_EXPORTED Remove(Filter& filter); |
| 62 void BINDINGS_EXPORTED Clear(); |
| 63 bool BINDINGS_EXPORTED HasFilter(const Filter& filter) const; |
| 64 const String& BINDINGS_EXPORTED GetKeywordForFilter(const Filter& filter) cons
t; |
| 65 Filter* BINDINGS_EXPORTED MatchesAny(const String& location, |
| 66 int typeMask, DependentString& docDomain, bool thirdParty, |
| 67 const String& sitekey, bool specificOnly); |
| 68 OwnedString BINDINGS_EXPORTED FindKeyword(const Filter& filter) const; |
| 69 |
| 70 private: |
| 71 void ResetCache(); |
| 72 FilterPtr MatchesAnyInternal(const String& location, |
| 73 int typeMask, DependentString& docDomain, bool thirdParty, |
| 74 const String& sitekey, bool specificOnly) const; |
| 75 }; |
OLD | NEW |