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-2017 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 <type_traits> | 20 #include <type_traits> |
21 #include <vector> | 21 #include <vector> |
22 | 22 |
23 #include <emscripten.h> | |
24 | |
25 #include "../filter/Filter.h" | 23 #include "../filter/Filter.h" |
26 #include "../String.h" | 24 #include "../String.h" |
27 #include "../FilterNotifier.h" | 25 #include "../FilterNotifier.h" |
28 #include "../intrusive_ptr.h" | 26 #include "../intrusive_ptr.h" |
29 #include "../debug.h" | 27 #include "../debug.h" |
| 28 #include "../bindings/runtime.h" |
30 | 29 |
31 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett
er, setter) \ | 30 #define SUBSCRIPTION_PROPERTY_INTERNAL(field_type, param_type, name, topic, gett
er, setter) \ |
32 private:\ | 31 private:\ |
33 field_type name;\ | 32 field_type name;\ |
34 public:\ | 33 public:\ |
35 param_type EMSCRIPTEN_KEEPALIVE getter() const\ | 34 param_type BINDINGS_EXPORTED getter() const\ |
36 {\ | 35 {\ |
37 return name;\ | 36 return name;\ |
38 }\ | 37 }\ |
39 void EMSCRIPTEN_KEEPALIVE setter(param_type value)\ | 38 void BINDINGS_EXPORTED setter(param_type value)\ |
40 {\ | 39 {\ |
41 if (name != value)\ | 40 if (name != value)\ |
42 {\ | 41 {\ |
43 name = value;\ | 42 name = value;\ |
44 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\ | 43 if (FilterNotifier::Topic::topic != FilterNotifier::Topic::NONE)\ |
45 {\ | 44 {\ |
46 FilterNotifier::SubscriptionChange(FilterNotifier::Topic::topic,\ | 45 FilterNotifier::SubscriptionChange(FilterNotifier::Topic::topic,\ |
47 this);\ | 46 this);\ |
48 }\ | 47 }\ |
49 }\ | 48 }\ |
50 } | 49 } |
51 | 50 |
52 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \ | 51 #define SUBSCRIPTION_PROPERTY(type, name, topic, getter, setter) \ |
53 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro
can only be used with arithmetic types");\ | 52 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro
can only be used with arithmetic types");\ |
54 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter) | 53 SUBSCRIPTION_PROPERTY_INTERNAL(type, type, name, topic, getter, setter) |
55 | 54 |
56 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \ | 55 #define SUBSCRIPTION_STRING_PROPERTY(name, topic, getter, setter) \ |
57 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett
er, setter) | 56 SUBSCRIPTION_PROPERTY_INTERNAL(OwnedString, const String&, name, topic, gett
er, setter) |
58 | 57 |
59 class Subscription : public ref_counted | 58 class Subscription : public ref_counted |
60 { | 59 { |
| 60 public: |
| 61 typedef std::vector<FilterPtr> Filters; |
| 62 |
61 protected: | 63 protected: |
62 OwnedString mID; | 64 OwnedString mID; |
63 std::vector<FilterPtr> mFilters; | 65 Filters mFilters; |
64 | 66 |
65 public: | 67 public: |
66 enum Type | 68 enum Type |
67 { | 69 { |
68 UNKNOWN = 0, | 70 UNKNOWN = 0, |
69 DOWNLOADABLE = 1, | 71 DOWNLOADABLE = 1, |
70 USERDEFINED = 2 | 72 USERDEFINED = 2 |
71 }; | 73 }; |
72 | 74 |
73 explicit Subscription(Type type, const String& id); | 75 explicit Subscription(Type type, const String& id); |
74 ~Subscription(); | 76 ~Subscription(); |
75 | 77 |
76 Type mType; | 78 Type mType; |
77 | 79 |
78 EMSCRIPTEN_KEEPALIVE const String& GetID() const | 80 BINDINGS_EXPORTED const String& GetID() const |
79 { | 81 { |
80 return mID; | 82 return mID; |
81 } | 83 } |
82 | 84 |
83 SUBSCRIPTION_STRING_PROPERTY(mTitle, SUBSCRIPTION_TITLE, GetTitle, SetTitle); | 85 SUBSCRIPTION_STRING_PROPERTY(mTitle, SUBSCRIPTION_TITLE, GetTitle, SetTitle); |
84 SUBSCRIPTION_PROPERTY(bool, mDisabled, SUBSCRIPTION_DISABLED, | 86 SUBSCRIPTION_PROPERTY(bool, mDisabled, SUBSCRIPTION_DISABLED, |
85 GetDisabled, SetDisabled); | 87 GetDisabled, SetDisabled); |
86 SUBSCRIPTION_PROPERTY(bool, mListed, NONE, GetListed, SetListed); | 88 SUBSCRIPTION_PROPERTY(bool, mListed, NONE, GetListed, SetListed); |
87 | 89 |
88 EMSCRIPTEN_KEEPALIVE unsigned GetFilterCount() const | 90 BINDINGS_EXPORTED Filters::size_type GetFilterCount() const |
89 { | 91 { |
90 return mFilters.size(); | 92 return mFilters.size(); |
91 } | 93 } |
92 | 94 |
93 EMSCRIPTEN_KEEPALIVE Filter* FilterAt(unsigned index); | 95 BINDINGS_EXPORTED Filter* FilterAt(Filters::size_type index); |
94 EMSCRIPTEN_KEEPALIVE int IndexOfFilter(Filter* filter); | 96 BINDINGS_EXPORTED int IndexOfFilter(Filter* filter); |
95 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; | 97 BINDINGS_EXPORTED OwnedString Serialize() const; |
96 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; | 98 BINDINGS_EXPORTED OwnedString SerializeFilters() const; |
97 | 99 |
98 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); | 100 static BINDINGS_EXPORTED Subscription* FromID(const String& id); |
99 | 101 |
100 template<typename T> | 102 template<typename T> |
101 T* As(); | 103 T* As(); |
102 }; | 104 }; |
103 | 105 |
104 typedef intrusive_ptr<Subscription> SubscriptionPtr; | 106 typedef intrusive_ptr<Subscription> SubscriptionPtr; |
LEFT | RIGHT |