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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /** | 18 /** |
19 * @fileOverview Element hiding implementation. | 19 * @fileOverview Element hiding implementation. |
20 */ | 20 */ |
21 | 21 |
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include <unordered_map> | |
25 #include <vector> | 24 #include <vector> |
26 | 25 |
27 #include "bindings/runtime.h" | 26 #include "bindings/runtime.h" |
28 #include "intrusive_ptr.h" | 27 #include "intrusive_ptr.h" |
29 #include "StringMap.h" | 28 #include "StringMap.h" |
30 #include "filter/Filter.h" | 29 #include "filter/Filter.h" |
31 #include "filter/ElemHideBase.h" | 30 #include "filter/ElemHideBase.h" |
32 #include "filter/ElemHideException.h" | 31 #include "filter/ElemHideException.h" |
33 | 32 |
34 class ElemHide_SelectorList : public ref_counted | 33 class ElemHide_SelectorList : public ref_counted |
(...skipping 16 matching lines...) Expand all Loading... |
51 { | 50 { |
52 mSelectors.insert(mSelectors.end(), | 51 mSelectors.insert(mSelectors.end(), |
53 list.mSelectors.cbegin(), list.mSelectors.cend()); | 52 list.mSelectors.cbegin(), list.mSelectors.cend()); |
54 } | 53 } |
55 }; | 54 }; |
56 | 55 |
57 class ElemHide : public ref_counted | 56 class ElemHide : public ref_counted |
58 { | 57 { |
59 // All filters. Key is filter text. Exception filters excluded. | 58 // All filters. Key is filter text. Exception filters excluded. |
60 StringMap<ElemHideBasePtr> mFilters; | 59 StringMap<ElemHideBasePtr> mFilters; |
61 // StringMap is non copyable. std::unordered_map<> it is | 60 // Filters by domain. Key is domain. |
62 // Filters by domain. Key is domain. Subkey is filter text. | 61 // In value key is filter text, value is filter or NULL |
63 StringMap<std::unordered_map<DependentString,ElemHideBasePtr,StringHash>> mFil
tersByDomain; | 62 OwnedStringMap<OwnedStringMap<ElemHideBasePtr>> mFiltersByDomain; |
64 | 63 |
65 // Exceptions. The key is the selector. | 64 // Exceptions. The key is the selector. |
66 OwnedStringMap<std::vector<ElemHideExceptionPtr>> mExceptions; | 65 OwnedStringMap<std::vector<ElemHideExceptionPtr>> mExceptions; |
67 // Known exceptions. Filter text as keys. | 66 // Known exceptions. Filter text as keys. |
68 StringSet mKnownExceptions; | 67 StringSet mKnownExceptions; |
69 | 68 |
70 // Unconditional selectors. Filter text as key | 69 // Unconditional selectors. Filter selector as key. Filter as value. |
71 StringSet mUnconditionalSelectors; | 70 OwnedStringMap<ElemHideBasePtr> mUnconditionalSelectors; |
72 | 71 |
73 mutable intrusive_ptr<ElemHide_SelectorList> mUnconditionalSelectorsCache; | 72 mutable intrusive_ptr<ElemHide_SelectorList> mUnconditionalSelectorsCache; |
74 | 73 |
75 ElemHide() | |
76 { | |
77 if (defaultDomains.size() == 0) | |
78 defaultDomains[ActiveFilter::DEFAULT_DOMAIN] = true; | |
79 } | |
80 public: | 74 public: |
81 static ElemHide* BINDINGS_EXPORTED Create() | 75 static ElemHide* BINDINGS_EXPORTED Create() |
82 { | 76 { |
83 return new ElemHide(); | 77 return new ElemHide(); |
84 } | 78 } |
85 // Used by GetSelectorsForDomain to narrow down selectors to return. | 79 // Used by GetSelectorsForDomain to narrow down selectors to return. |
| 80 // Keep these value up to date in the ElemHide.js import script. |
86 enum Criteria | 81 enum Criteria |
87 { | 82 { |
88 // Return all selectors applying to a particular hostname. | 83 // Return all selectors applying to a particular hostname. |
89 ALL_MATCHING = 0, | 84 ALL_MATCHING = 0, |
90 // Exclude selectors which apply to all websites without exception. | 85 // Exclude selectors which apply to all websites without exception. |
91 NO_UNCONDITIONAL = 1, | 86 NO_UNCONDITIONAL = 1, |
92 // Return only selectors for filters which specifically match the | 87 // Return only selectors for filters which specifically match the |
93 // given host name. | 88 // given host name. |
94 SPECIFIC_ONLY = 2, | 89 SPECIFIC_ONLY = 2, |
95 }; | 90 }; |
96 | 91 |
97 void BINDINGS_EXPORTED Clear(); | 92 void BINDINGS_EXPORTED Clear(); |
98 void BINDINGS_EXPORTED Add(ElemHideBase& filter); | 93 void BINDINGS_EXPORTED Add(ElemHideBase& filter); |
99 void BINDINGS_EXPORTED Remove(ElemHideBase& filter); | 94 void BINDINGS_EXPORTED Remove(ElemHideBase& filter); |
100 | 95 |
101 ElemHide_SelectorList* BINDINGS_EXPORTED GetSelectorsForDomain(const String& d
omain, | 96 ElemHide_SelectorList* BINDINGS_EXPORTED GetSelectorsForDomain(const String& d
omain, |
102 Criteria criter
ia) const; | 97 Criteria criter
ia) const; |
103 ElemHide_SelectorList* BINDINGS_EXPORTED GetUnconditionalSelectors() const; | 98 ElemHide_SelectorList* BINDINGS_EXPORTED GetUnconditionalSelectors() const; |
104 | 99 |
105 ElemHideException* BINDINGS_EXPORTED GetException(const ElemHideBase& filter, | 100 ElemHideException* BINDINGS_EXPORTED GetException(const ElemHideBase& filter, |
106 DependentString& docDomain)
const; | 101 DependentString& docDomain)
const; |
107 | 102 |
108 private: | 103 private: |
109 static ActiveFilter::DomainMap defaultDomains; | 104 void AddToFiltersByDomain(const ElemHideBasePtr & filter); |
110 void AddToFiltersByDomain(ElemHideBase& filter); | |
111 }; | 105 }; |
112 | 106 |
LEFT | RIGHT |