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

Delta Between Two Patch Sets: compiled/filter/ActiveFilter.h

Issue 29600641: Issue 5175 - Reject element hiding filter with empty domain names (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rebased Created Dec. 5, 2017, 6:06 p.m.
Right Patch Set: Make the new test more functional Created March 6, 2018, 7:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | compiled/filter/ActiveFilter.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 #pragma once 18 #pragma once
19 19
20 #include "../base.h"
20 #include "Filter.h" 21 #include "Filter.h"
21 #include "../StringMap.h" 22 #include "../StringMap.h"
22 #include "../FilterNotifier.h" 23 #include "../FilterNotifier.h"
23 #include "../bindings/runtime.h" 24 #include "../bindings/runtime.h"
24 25
25 #define FILTER_PROPERTY(type, name, topic, getter, setter) \ 26 #define FILTER_PROPERTY(type, name, topic, getter, setter) \
26 private:\ 27 private:\
27 type name;\ 28 type name;\
28 public:\ 29 public:\
29 type BINDINGS_EXPORTED getter() const\ 30 type BINDINGS_EXPORTED getter() const\
30 {\ 31 {\
31 return name;\ 32 return name;\
32 }\ 33 }\
33 void BINDINGS_EXPORTED setter(type value)\ 34 void BINDINGS_EXPORTED setter(type value)\
34 {\ 35 {\
35 if (name != value)\ 36 if (name != value)\
36 {\ 37 {\
37 name = value;\ 38 name = value;\
38 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\ 39 if (ABP_NS::FilterNotifier::Topic::topic != ABP_NS::FilterNotifier::To pic::NONE)\
39 {\ 40 {\
40 FilterNotifier::FilterChange(FilterNotifier::Topic::topic, *this);\ 41 ABP_NS::FilterNotifier::FilterChange(ABP_NS::FilterNotifier::Topic:: topic, *this);\
41 }\ 42 }\
42 }\ 43 }\
43 } 44 }
45
46
47 ABP_NS_BEGIN
44 48
45 struct ParsedDomains 49 struct ParsedDomains
46 { 50 {
47 struct Domain { 51 struct Domain {
48 String::size_type pos; 52 String::size_type pos;
49 String::size_type len; 53 String::size_type len;
50 bool reverse; 54 bool reverse;
51 }; 55 };
52 bool hasIncludes; 56 bool hasIncludes;
53 bool hasEmpty; 57 bool hasEmpty;
54 std::vector<Domain> domains; 58 std::vector<Domain> domains;
55 59
56 ParsedDomains() 60 ParsedDomains()
57 : hasIncludes(false), hasEmpty(false) 61 : hasIncludes(false), hasEmpty(false)
58 { 62 {
59 } 63 }
60 }; 64 };
61 65
62 class ActiveFilter : public Filter 66 class ActiveFilter : public Filter
63 { 67 {
64 public: 68 public:
65 typedef StringMap<bool> DomainMap; 69 typedef StringMap<bool> DomainMap;
66 virtual DomainMap* GetDomains() const; 70 virtual DomainMap* GetDomains() const;
71 static const DependentString DEFAULT_DOMAIN;
67 protected: 72 protected:
68 typedef StringSet SitekeySet; 73 typedef StringSet SitekeySet;
69 static ParsedDomains ParseDomainsInternal(const String& domains, 74 static ParsedDomains ParseDomainsInternal(const String& domains,
70 String::value_type separator, bool ignoreTrailingDot); 75 String::value_type separator, bool ignoreTrailingDot);
71 void FillDomains(const String& domains, const ParsedDomains& parsed) const; 76 void FillDomains(const String& domains, const ParsedDomains& parsed) const;
72 void ParseDomains(const String& domains, 77 void ParseDomains(const String& domains,
73 String::value_type separator, bool ignoreTrailingDot) const; 78 String::value_type separator, bool ignoreTrailingDot) const;
74 void AddSitekey(const String& sitekey) const; 79 void AddSitekey(const String& sitekey) const;
75 virtual SitekeySet* GetSitekeys() const; 80 virtual SitekeySet* GetSitekeys() const;
76 mutable std::unique_ptr<DomainMap> mDomains; 81 mutable std::unique_ptr<DomainMap> mDomains;
77 mutable std::unique_ptr<SitekeySet> mSitekeys; 82 mutable std::unique_ptr<SitekeySet> mSitekeys;
78 private: 83 private:
79 bool mIgnoreTrailingDot; 84 bool mIgnoreTrailingDot;
80 public: 85 public:
81 static constexpr Type classType = Type::ACTIVE; 86 static constexpr Type classType = Type::ACTIVE;
82 explicit ActiveFilter(Type type, const String& text, bool ignoreTrailingDot); 87 explicit ActiveFilter(Type type, const String& text, bool ignoreTrailingDot);
83 FILTER_PROPERTY(bool, mDisabled, FILTER_DISABLED, GetDisabled, SetDisabled); 88 FILTER_PROPERTY(bool, mDisabled, FILTER_DISABLED, GetDisabled, SetDisabled);
84 FILTER_PROPERTY(unsigned int, mHitCount, FILTER_HITCOUNT, 89 FILTER_PROPERTY(unsigned int, mHitCount, FILTER_HITCOUNT,
85 GetHitCount, SetHitCount); 90 GetHitCount, SetHitCount);
86 FILTER_PROPERTY(unsigned int, mLastHit, FILTER_LASTHIT, 91 FILTER_PROPERTY(unsigned int, mLastHit, FILTER_LASTHIT,
87 GetLastHit, SetLastHit); 92 GetLastHit, SetLastHit);
88 bool BINDINGS_EXPORTED IsActiveOnDomain(DependentString& docDomain, 93 bool BINDINGS_EXPORTED IsActiveOnDomain(DependentString& docDomain,
89 const String& sitekey) const; 94 const String& sitekey = DependentString()) const;
90 bool BINDINGS_EXPORTED IsActiveOnlyOnDomain(DependentString& docDomain) const; 95 bool BINDINGS_EXPORTED IsActiveOnlyOnDomain(DependentString& docDomain) const;
91 bool BINDINGS_EXPORTED IsGeneric() const; 96 bool BINDINGS_EXPORTED IsGeneric() const;
92 OwnedString BINDINGS_EXPORTED Serialize() const; 97 OwnedString BINDINGS_EXPORTED Serialize() const;
93 }; 98 };
94 99
95 typedef intrusive_ptr<ActiveFilter> ActiveFilterPtr; 100 typedef intrusive_ptr<ActiveFilter> ActiveFilterPtr;
101
102 ABP_NS_END
LEFTRIGHT

Powered by Google App Engine
This is Rietveld