| Left: | ||
| Right: |
| 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-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 <type_traits> | |
| 20 #include <vector> | 21 #include <vector> |
| 21 | 22 |
| 22 #include "../filter/Filter.h" | 23 #include "../filter/Filter.h" |
| 23 #include "../String.h" | 24 #include "../String.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(type, name, getter, setter) \ |
| 29 static_assert(std::is_arithmetic<type>::value, "SUBSCRIPTION_PROPERTY macro can only be used with arithmetic types");\ | |
| 28 private:\ | 30 private:\ |
| 29 type name;\ | 31 type name;\ |
| 30 public:\ | 32 public:\ |
| 31 type EMSCRIPTEN_KEEPALIVE getter() const\ | 33 type EMSCRIPTEN_KEEPALIVE getter() const\ |
| 32 {\ | 34 {\ |
| 33 return name;\ | 35 return name;\ |
| 34 }\ | 36 }\ |
| 35 void EMSCRIPTEN_KEEPALIVE setter(type value)\ | 37 void EMSCRIPTEN_KEEPALIVE setter(type value)\ |
| 36 {\ | 38 {\ |
| 37 if (name != value)\ | 39 if (name != value)\ |
| 38 {\ | 40 {\ |
| 39 type oldvalue = name;\ | 41 type oldvalue = name;\ |
| 40 name = value;\ | 42 name = value;\ |
| 41 DependentString action(u"subscription."_str #name);\ | 43 DependentString action(u"subscription."_str #name);\ |
| 42 if (sizeof(type) <= 4)\ | 44 if (sizeof(type) <= 4)\ |
| 43 {\ | 45 {\ |
| 44 EM_ASM_ARGS({\ | 46 EM_ASM_ARGS({\ |
| 45 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | 47 var subscription = new (exports[Subscription_mapping[$2]])($1);\ |
| 46 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\ | 48 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\ |
| 47 }, &action, this, mType, value, oldvalue);\ | 49 }, &action, this, mType, value, oldvalue);\ |
| 48 }\ | 50 }\ |
| 49 else\ | 51 else\ |
| 50 {\ | 52 {\ |
| 51 EM_ASM_ARGS({\ | 53 EM_ASM_ARGS({\ |
| 52 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | 54 var subscription = new (exports[Subscription_mapping[$2]])($1);\ |
| 53 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\ | 55 FilterNotifier.triggerListeners(readString($0), subscription, $3, $4);\ |
| 54 }, &action, this, mType, (double)value, (double)oldvalue);\ | 56 }, &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 }\ | 57 }\ |
| 56 }\ | 58 }\ |
| 57 } | 59 } |
| 58 | 60 |
| 59 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ | 61 #define SUBSCRIPTION_STRING_PROPERTY(name, getter, setter) \ |
| 60 private:\ | 62 private:\ |
| 61 OwnedString name;\ | 63 OwnedString name;\ |
| 62 public:\ | 64 public:\ |
| 63 const String& EMSCRIPTEN_KEEPALIVE getter() const\ | 65 const String& EMSCRIPTEN_KEEPALIVE getter() const\ |
| 64 {\ | 66 {\ |
| 65 return name;\ | 67 return name;\ |
| 66 }\ | 68 }\ |
| 67 void EMSCRIPTEN_KEEPALIVE setter(const String& value)\ | 69 void EMSCRIPTEN_KEEPALIVE setter(const String& value)\ |
| 68 {\ | 70 {\ |
| 69 if (!name.equals(value))\ | 71 if (!name.equals(value))\ |
| 70 {\ | 72 {\ |
| 71 OwnedString oldvalue(name);\ | 73 OwnedString oldvalue(name);\ |
| 72 name = value;\ | 74 name = value;\ |
| 73 DependentString action(u"subscription."_str #name);\ | 75 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({\ | 76 EM_ASM_ARGS({\ |
| 75 var subscription = new (exports[Subscription_mapping[$2]])($1);\ | 77 var subscription = new (exports[Subscription_mapping[$2]])($1);\ |
| 76 FilterNotifier.triggerListeners(readString($0), subscription, readSt ring($3), readString($4));\ | 78 FilterNotifier.triggerListeners(readString($0), subscription, readSt ring($3), readString($4));\ |
| 77 }, &action, this, mType, &value, &oldvalue);\ | 79 }, &action, this, mType, &value, &oldvalue);\ |
| 78 }\ | 80 }\ |
| 79 } | 81 } |
| 80 | 82 |
| 81 class Subscription : public ref_counted | 83 class Subscription : public ref_counted |
| 82 { | 84 { |
| 83 protected: | 85 protected: |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 105 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); | 107 SUBSCRIPTION_STRING_PROPERTY(mTitle, GetTitle, SetTitle); |
| 106 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); | 108 SUBSCRIPTION_PROPERTY(bool, mDisabled, GetDisabled, SetDisabled); |
| 107 | 109 |
| 108 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; | 110 EMSCRIPTEN_KEEPALIVE OwnedString Serialize() const; |
| 109 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; | 111 EMSCRIPTEN_KEEPALIVE OwnedString SerializeFilters() const; |
| 110 | 112 |
| 111 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); | 113 static EMSCRIPTEN_KEEPALIVE Subscription* FromID(const String& id); |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 typedef intrusive_ptr<Subscription> SubscriptionPtr; | 116 typedef intrusive_ptr<Subscription> SubscriptionPtr; |
| LEFT | RIGHT |