Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/ElemHide.h

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: mFiltersByDomain is now an OwnedStringMap Created Jan. 26, 2018, 8:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | compiled/ElemHide.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #pragma once
23
24 #include <vector>
25
26 #include "bindings/runtime.h"
27 #include "intrusive_ptr.h"
28 #include "StringMap.h"
29 #include "filter/Filter.h"
30 #include "filter/ElemHideBase.h"
31 #include "filter/ElemHideException.h"
32
33 class ElemHide_SelectorList : public ref_counted
34 {
35 std::vector<ElemHideBasePtr> mSelectors;
36 public:
37 size_t BINDINGS_EXPORTED GetSelectorCount() const
38 {
39 return mSelectors.size();
40 }
41 OwnedString BINDINGS_EXPORTED SelectorAt(size_t idx) const;
42 const String& BINDINGS_EXPORTED FilterKeyAt(size_t idx) const;
43
44 void push_back(const ElemHideBasePtr& filter)
45 {
46 mSelectors.push_back(filter);
47 }
48
49 void append(const ElemHide_SelectorList& list)
50 {
51 mSelectors.insert(mSelectors.end(),
52 list.mSelectors.cbegin(), list.mSelectors.cend());
53 }
54 };
55
56 class ElemHide : public ref_counted
57 {
58 // All filters. Key is filter text. Exception filters excluded.
59 StringMap<ElemHideBasePtr> mFilters;
60 // Filters by domain. Key is domain.
61 // In value key is filter text, value is filter or NULL
62 OwnedStringMap<OwnedStringMap<ElemHideBasePtr>> mFiltersByDomain;
63
64 // Exceptions. The key is the selector.
65 OwnedStringMap<std::vector<ElemHideExceptionPtr>> mExceptions;
66 // Known exceptions. Filter text as keys.
67 StringSet mKnownExceptions;
68
69 // Unconditional selectors. Filter selector as key. Filter as value.
70 OwnedStringMap<ElemHideBasePtr> mUnconditionalSelectors;
71
72 mutable intrusive_ptr<ElemHide_SelectorList> mUnconditionalSelectorsCache;
73
74 public:
75 static ElemHide* BINDINGS_EXPORTED Create()
76 {
77 return new ElemHide();
78 }
79 // Used by GetSelectorsForDomain to narrow down selectors to return.
80 // Keep these value up to date in the ElemHide.js import script.
81 enum Criteria
82 {
83 // Return all selectors applying to a particular hostname.
84 ALL_MATCHING = 0,
85 // Exclude selectors which apply to all websites without exception.
86 NO_UNCONDITIONAL = 1,
87 // Return only selectors for filters which specifically match the
88 // given host name.
89 SPECIFIC_ONLY = 2,
90 };
91
92 void BINDINGS_EXPORTED Clear();
93 void BINDINGS_EXPORTED Add(ElemHideBase& filter);
94 void BINDINGS_EXPORTED Remove(ElemHideBase& filter);
95
96 ElemHide_SelectorList* BINDINGS_EXPORTED GetSelectorsForDomain(const String& d omain,
97 Criteria criter ia) const;
98 ElemHide_SelectorList* BINDINGS_EXPORTED GetUnconditionalSelectors() const;
99
100 ElemHideException* BINDINGS_EXPORTED GetException(const ElemHideBase& filter,
101 DependentString& docDomain) const;
102
103 private:
104 void AddToFiltersByDomain(const ElemHideBasePtr & filter);
105 };
106
OLDNEW
« no previous file with comments | « no previous file | compiled/ElemHide.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld