| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-2017 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 #pragma once | |
| 19 | |
| 20 #include <vector> | |
| 21 | |
| 22 #include "../filter/Filter.h" | |
| 23 #include "../String.h" | |
| 24 #include "../intrusive_ptr.h" | |
| 25 #include "../debug.h" | |
| 26 | |
| 27 #define SUBSCRIPTION_PROPERTY(type, name, getter, setter) \ | |
| 28 private:\ | |
| 29 type name;\ | |
| 30 public:\ | |
| 31 type EMSCRIPTEN_KEEPALIVE getter() const\ | |
| 32 {\ | |
| 33 return name;\ | |
| 34 }\ | |
| 35 void EMSCRIPTEN_KEEPALIVE setter(type value)\ | |
| 36 {\ | |
| 37 if (name != value)\ | |
| 38 {\ | |
| 39 type oldvalue = name;\ | |
| 40 name = value;\ | |
| 41 DependentString action(u"subscription."_str #name);\ | |
| 42 if (sizeof(type) <= 4)\ | |
| 43 {\ | |
| 44 EM_ASM_ARGS({\ | |
| 45 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | |
| 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);\ | |
|
sergei
2017/04/12 12:04:33
It seems SUBSCRIPTION_PROPERTY is only for numbers
Wladimir Palant
2017/04/13 13:04:41
Done.
| |
| 55 }\ | |
| 56 }\ | |
| 57 } | |
| 58 | |
| 59 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ | |
| 60 private:\ | |
| 61 OwnedString name;\ | |
| 62 public:\ | |
| 63 const String& EMSCRIPTEN_KEEPALIVE getter() const\ | |
| 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);\ | |
|
sergei
2017/04/12 12:04:33
I'm not sure that the `action` value is correct he
Wladimir Palant
2017/04/13 13:04:41
No, it's not correct - and neither for filter clas
| |
| 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 | |
| 81 class Subscription : public ref_counted | |
| 82 { | |
| 83 protected: | |
| 84 OwnedString mID; | |
| 85 std::vector<Filter> mFilters; | |
| 86 | |
| 87 public: | |
| 88 enum Type | |
| 89 { | |
| 90 UNKNOWN = 0, | |
| 91 DOWNLOADABLE = 1, | |
| 92 USERDEFINED = 2 | |
| 93 }; | |
| 94 | |
| 95 explicit Subscription(Type type, const String& id); | |
| 96 ~Subscription(); | |
| 97 | |
| 98 Type mType; | |
| 99 | |
| 100 EMSCRIPTEN_KEEPALIVE const String& GetID() const | |
| 101 { | |
| 102 return mID; | |
| 103 } | |
| 104 | |
| 105 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); | |
| 106 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); | |
| 107 | |
| 108 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; | |
| 109 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; | |
| 110 | |
| 111 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); | |
| 112 }; | |
| 113 | |
| 114 typedef intrusive_ptr<Subscription> SubscriptionPtr; | |
| OLD | NEW |