OLD | NEW |
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 <vector> | 20 #include <vector> |
21 | 21 |
22 #include "../filter/Filter.h" | 22 #include "../filter/Filter.h" |
23 #include "../String.h" | 23 #include "../String.h" |
| 24 #include "../FilterNotifier.h" |
24 #include "../intrusive_ptr.h" | 25 #include "../intrusive_ptr.h" |
25 #include "../debug.h" | 26 #include "../debug.h" |
26 | 27 |
27 #define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \ | 28 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett
er, setter) \ |
28 private:\ | 29 private:\ |
29 type name;\ | 30 field_type name;\ |
30 public:\ | 31 public:\ |
31 type EMSCRIPTEN_KEEPALIVE getter() const\ | 32 param_type EMSCRIPTEN_KEEPALIVE getter() const\ |
32 {\ | 33 {\ |
33 return name;\ | 34 return name;\ |
34 }\ | 35 }\ |
35 void EMSCRIPTEN_KEEPALIVE setter(type value)\ | 36 void EMSCRIPTEN_KEEPALIVE setter(param_type value)\ |
36 {\ | 37 {\ |
37 if (name != value)\ | 38 if (name != value)\ |
38 {\ | 39 {\ |
39 type oldvalue = name;\ | 40 field_type oldvalue = name;\ |
40 name = value;\ | 41 name = value;\ |
41 DependentString action(u"subscription."_str #name);\ | 42 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\ |
42 if (sizeof(type) <= 4)\ | |
43 {\ | 43 {\ |
44 EM_ASM_ARGS({\ | 44 FilterNotifier::PropertyChange(FilterNotifier::Topic::topic,\ |
45 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | 45 this, value, oldvalue);\ |
46 FilterNotifier.triggerListeners(readString($0), subscription, $3,
$4);\ | |
47 }, &action, this, mType, value, oldvalue);\ | |
48 }\ | |
49 else\ | |
50 {\ | |
51 EM_ASM_ARGS({\ | |
52 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | |
53 FilterNotifier.triggerListeners(readString($0), subscription, $3,
$4);\ | |
54 }, &action, this, mType, (double)value, (double)oldvalue);\ | |
55 }\ | 46 }\ |
56 }\ | 47 }\ |
57 } | 48 } |
58 | 49 |
59 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ | 50 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \ |
60 private:\ | 51 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter) |
61 OwnedString name;\ | 52 |
62 public:\ | 53 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \ |
63 const String& EMSCRIPTEN_KEEPALIVE getter() const\ | 54 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett
er, setter) |
64 {\ | |
65 return name;\ | |
66 }\ | |
67 void EMSCRIPTEN_KEEPALIVE setter(const String& value)\ | |
68 {\ | |
69 if (!name.equals(value))\ | |
70 {\ | |
71 OwnedString oldvalue(name);\ | |
72 name = value;\ | |
73 DependentString action(u"subscription."_str #name);\ | |
74 EM_ASM_ARGS({\ | |
75 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | |
76 FilterNotifier.triggerListeners(readString($0), subscription, readSt
ring($3), readString($4));\ | |
77 }, &action, this, mType, &value, &oldvalue);\ | |
78 }\ | |
79 } | |
80 | 55 |
81 class Subscription : public ref_counted | 56 class Subscription : public ref_counted |
82 { | 57 { |
83 protected: | 58 protected: |
84 OwnedString mID; | 59 OwnedString mID; |
85 std::vector<FilterPtr> mFilters; | 60 std::vector<FilterPtr> mFilters; |
86 | 61 |
87 public: | 62 public: |
88 enum Type | 63 enum Type |
89 { | 64 { |
90 UNKNOWN = 0, | 65 UNKNOWN = 0, |
91 DOWNLOADABLE = 1, | 66 DOWNLOADABLE = 1, |
92 USERDEFINED = 2 | 67 USERDEFINED = 2 |
93 }; | 68 }; |
94 | 69 |
95 explicit Subscription(Type type, const String& id); | 70 explicit Subscription(Type type, const String& id); |
96 ~Subscription(); | 71 ~Subscription(); |
97 | 72 |
98 Type mType; | 73 Type mType; |
99 | 74 |
100 EMSCRIPTEN_KEEPALIVE const String& GetID() const | 75 EMSCRIPTEN_KEEPALIVE const String& GetID() const |
101 { | 76 { |
102 return mID; | 77 return mID; |
103 } | 78 } |
104 | 79 |
105 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); | 80 SUBSCRIPTION_STRING_PROPERTY(mTitle, SUBSCRIPTION_TITLE, GetTitle, SetTitle); |
106 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); | 81 SUBSCRIPTION_PROPERTY(bool, mDisabled, SUBSCRIPTION_DISABLED, |
| 82 GetDisabled, SetDisabled); |
107 | 83 |
108 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const | 84 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const |
109 { | 85 { |
110 return mFilters.size(); | 86 return mFilters.size(); |
111 } | 87 } |
112 | 88 |
113 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); | 89 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); |
114 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); | 90 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); |
115 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; | 91 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; |
116 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; | 92 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; |
117 | 93 |
118 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); | 94 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); |
119 }; | 95 }; |
120 | 96 |
121 typedef intrusive_ptr<Subscription> SubscriptionPtr; | 97 typedef intrusive_ptr<Subscription> SubscriptionPtr; |
OLD | NEW |