Left: | ||
Right: |
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 /** | |
19 * @fileOverview Element hiding implementation. | |
20 */ | |
21 | |
22 #include <unordered_map> | |
23 #include <vector> | |
24 | |
25 #include "bindings/runtime.h" | |
26 #include "intrusive_ptr.h" | |
27 #include "StringMap.h" | |
28 #include "filter/Filter.h" | |
29 #include "filter/ElemHideBase.h" | |
30 #include "filter/ElemHideException.h" | |
31 | |
32 class _ElemHide_SelectorList : public ref_counted | |
33 { | |
34 std::vector<ElemHideBasePtr> mSelectors; | |
35 public: | |
36 size_t BINDINGS_EXPORTED GetSelectorCount() const | |
37 { | |
38 return mSelectors.size(); | |
39 } | |
40 DependentString BINDINGS_EXPORTED SelectorAt(size_t idx) const; | |
41 const String& BINDINGS_EXPORTED FilterKeyAt(size_t idx) const; | |
42 | |
43 void push_back(ElemHideBasePtr filter) | |
hub
2017/10/26 20:53:30
I'm doing this wrong. We are supposed to return se
hub
2017/10/26 20:58:27
but then FilterKeyAt() needs more than just the se
| |
44 { | |
45 mSelectors.push_back(filter); | |
46 } | |
47 | |
48 void append(const _ElemHide_SelectorList* list) | |
49 { | |
50 mSelectors.insert(mSelectors.end(), | |
51 list->mSelectors.cbegin(), list->mSelectors.cend()); | |
52 } | |
53 }; | |
54 | |
55 class ElemHide : public ref_counted | |
56 { | |
57 // All filters. Key is filter text. Exception filters excluded. | |
58 StringMap<ElemHideBasePtr> mFilters; | |
59 // StringMap is non copyable. std::unordered_map<> it is | |
60 // Filters by domain. Key is domain. Subkey is filter text. | |
61 StringMap<std::unordered_map<DependentString,ElemHideBasePtr,StringHash>> mFil tersByDomain; | |
62 | |
63 // Exceptions. The key is the selector. | |
64 StringMap<std::vector<ElemHideExceptionPtr>> mExceptions; | |
65 // Known exceptions. Filter text as keys. | |
66 StringSet mKnownExceptions; | |
67 | |
68 // Unconditional selectors. Filter text as key | |
69 StringSet mUnconditionalSelectors; | |
70 | |
71 mutable intrusive_ptr<_ElemHide_SelectorList> mUnconditionalSelectorsCache; | |
72 | |
73 static ElemHide* mInstance; | |
74 public: | |
75 enum Criteria | |
76 { | |
77 ALL_MATCHING = 0, | |
78 NO_UNCONDITIONAL = 1, | |
79 SPECIFIC_ONLY = 2, | |
80 }; | |
81 | |
82 static ElemHide* BINDINGS_EXPORTED GetInstance() | |
83 { | |
84 return mInstance; | |
85 } | |
86 | |
87 void BINDINGS_EXPORTED Clear(); | |
88 void BINDINGS_EXPORTED Add(ElemHideBase& filter); | |
89 void BINDINGS_EXPORTED Remove(ElemHideBase& filter); | |
90 | |
91 _ElemHide_SelectorList* BINDINGS_EXPORTED GetSelectorsForDomain(const String& domain, Criteria criteria) const; | |
92 _ElemHide_SelectorList* BINDINGS_EXPORTED GetUnconditionalSelectors() const; | |
93 | |
94 ElemHideException* BINDINGS_EXPORTED GetException(const ElemHideBase& filter, | |
95 DependentString& docDomain) const; | |
96 | |
97 private: | |
98 void AddToFiltersByDomain(ElemHideBase& filter); | |
99 }; | |
100 | |
OLD | NEW |