LEFT | RIGHT |
1 #ifndef ADBLOCK_PLUS_ACTIVE_FILTER_H | 1 #pragma once |
2 #define ADBLOCK_PLUS_ACTIVE_FILTER_H | |
3 | 2 |
4 #include <emscripten.h> | 3 #include <emscripten.h> |
5 | 4 |
6 #include "Filter.h" | 5 #include "Filter.h" |
7 #include "StringMap.h" | 6 #include "StringMap.h" |
8 | 7 |
9 #define FILTER_PROPERTY(type, name, getter, setter) \ | 8 #define FILTER_PROPERTY(type, name, getter, setter) \ |
10 private:\ | 9 private:\ |
11 type name;\ | 10 type name;\ |
12 public:\ | 11 public:\ |
13 type EMSCRIPTEN_KEEPALIVE getter() const\ | 12 type EMSCRIPTEN_KEEPALIVE getter() const\ |
14 {\ | 13 {\ |
15 return name;\ | 14 return name;\ |
16 }\ | 15 }\ |
17 void EMSCRIPTEN_KEEPALIVE setter(type value)\ | 16 void EMSCRIPTEN_KEEPALIVE setter(type value)\ |
18 {\ | 17 {\ |
19 if (name != value)\ | 18 if (name != value)\ |
20 {\ | 19 {\ |
21 type oldvalue = name;\ | 20 type oldvalue = name;\ |
22 name = value;\ | 21 name = value;\ |
23 String action(u"filter."_str #name);\ | 22 DependentString action(u"filter."_str #name);\ |
24 EM_ASM_ARGS({\ | 23 EM_ASM_ARGS({\ |
25 var filter = new (exports[Filter_mapping[$2]])($1);\ | 24 var filter = new (exports[Filter_mapping[$2]])($1);\ |
26 FilterNotifier.triggerListeners(getStringData($0), filter, $3, $4);\ | 25 FilterNotifier.triggerListeners(readString($0), filter, $3, $4);\ |
27 }, &action, this, GetType(), value, oldvalue);\ | 26 }, &action, this, mType, value, oldvalue);\ |
28 }\ | 27 }\ |
29 } | 28 } |
30 | 29 |
31 class ActiveFilter : public Filter | 30 class ActiveFilter : public Filter |
32 { | 31 { |
33 protected: | 32 protected: |
34 typedef StringMap<bool> DomainMap; | 33 typedef StringMap<bool> DomainMap; |
35 typedef StringSet SitekeySet; | 34 typedef StringSet SitekeySet; |
36 void ParseDomains(const String& domains, char16_t separator) const; | 35 void ParseDomains(const String& domains, String::value_type separator) const; |
37 void AddSitekey(const String& sitekey) const; | 36 void AddSitekey(const String& sitekey) const; |
38 virtual DomainMap* GetDomains() const; | 37 virtual DomainMap* GetDomains() const; |
39 virtual SitekeySet* GetSitekeys() const; | 38 virtual SitekeySet* GetSitekeys() const; |
40 mutable std::unique_ptr<DomainMap> mDomains; | 39 mutable std::unique_ptr<DomainMap> mDomains; |
41 mutable std::unique_ptr<SitekeySet> mSitekeys; | 40 mutable std::unique_ptr<SitekeySet> mSitekeys; |
42 private: | 41 private: |
43 bool mIgnoreTrailingDot; | 42 bool mIgnoreTrailingDot; |
44 public: | 43 public: |
45 ActiveFilter(const String& text, bool ignoreTrailingDot); | 44 explicit ActiveFilter(Type type, const String& text, bool ignoreTrailingDot); |
46 FILTER_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); | 45 FILTER_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); |
47 FILTER_PROPERTY(unsigned int, mHitCount, GetHitCount, SetHitCount); | 46 FILTER_PROPERTY(unsigned int, mHitCount, GetHitCount, SetHitCount); |
48 FILTER_PROPERTY(unsigned int, mLastHit, GetLastHit, SetLastHit); | 47 FILTER_PROPERTY(unsigned int, mLastHit, GetLastHit, SetLastHit); |
49 static void ToLower(String& str, String::size_type start, | |
50 String::size_type end); | |
51 bool EMSCRIPTEN_KEEPALIVE IsActiveOnDomain(DependentString& docDomain, | 48 bool EMSCRIPTEN_KEEPALIVE IsActiveOnDomain(DependentString& docDomain, |
52 const String& sitekey) const; | 49 const String& sitekey) const; |
53 bool EMSCRIPTEN_KEEPALIVE IsActiveOnlyOnDomain(DependentString& docDomain) con
st; | 50 bool EMSCRIPTEN_KEEPALIVE IsActiveOnlyOnDomain(DependentString& docDomain) con
st; |
54 bool EMSCRIPTEN_KEEPALIVE IsGeneric() const; | 51 bool EMSCRIPTEN_KEEPALIVE IsGeneric() const; |
55 OwnedString EMSCRIPTEN_KEEPALIVE Serialize() const; | 52 OwnedString EMSCRIPTEN_KEEPALIVE Serialize() const; |
56 }; | 53 }; |
57 | |
58 #endif | |
LEFT | RIGHT |