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 int mCandidatesReId; |
| 34 public: |
| 35 Matcher(); |
| 36 ~Matcher(); |
| 37 |
| 38 void BINDINGS_EXPORTED Add(const FilterPtr&); |
| 39 void BINDINGS_EXPORTED Remove(const FilterPtr&); |
| 40 void BINDINGS_EXPORTED Clear() ; |
| 41 bool BINDINGS_EXPORTED HasFilter(const FilterPtr&) const; |
| 42 const String& BINDINGS_EXPORTED GetKeywordForFilter(const FilterPtr& filter); |
| 43 Filter* BINDINGS_EXPORTED MatchesAny(const String& location, |
| 44 int typeMask, DependentString& docDomain, bool thirdParty, |
| 45 const String& sitekey, bool specificOnly); |
| 46 OwnedString BINDINGS_EXPORTED FindKeyword(const FilterPtr&); |
| 47 private: |
| 48 FilterPtr CheckEntryMatch(const String& keyword, |
| 49 const String& location, |
| 50 int typeMask, DependentString& docDomain, bool thirdParty, |
| 51 const String& sitekey, bool specificOnly); |
| 52 }; |
| 53 |
| 54 class CombinedMatcher : public ref_counted |
| 55 { |
| 56 private: |
| 57 static const size_t MAX_CACHE_ENTRIES; |
| 58 StringMap<FilterPtr> mResultCache; |
| 59 int mMatchReId; |
| 60 Matcher mBlacklist; |
| 61 Matcher mWhitelist; |
| 62 |
| 63 public: |
| 64 CombinedMatcher(); |
| 65 ~CombinedMatcher(); |
| 66 |
| 67 void BINDINGS_EXPORTED Add(const FilterPtr& filter); |
| 68 void BINDINGS_EXPORTED Remove(const FilterPtr& filter); |
| 69 void BINDINGS_EXPORTED Clear(); |
| 70 bool BINDINGS_EXPORTED HasFilter(const FilterPtr& filter) const; |
| 71 const String& BINDINGS_EXPORTED GetKeywordForFilter(const FilterPtr& filter); |
| 72 Filter* BINDINGS_EXPORTED MatchesAny(const String& location, |
| 73 int typeMask, DependentString& docDomain, bool thirdParty, |
| 74 const String& sitekey, bool specificOnly); |
| 75 OwnedString BINDINGS_EXPORTED FindKeyword(const FilterPtr& filter); |
| 76 |
| 77 private: |
| 78 void ResetCache(); |
| 79 FilterPtr MatchesAnyInternal(const String& location, |
| 80 int typeMask, DependentString& docDomain, bool thirdParty, |
| 81 const String& sitekey, bool specificOnly); |
| 82 }; |
OLD | NEW |