Left: | ||
Right: |
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 #include "bindings.ipp" | 18 #include <exception> |
19 #include "filter/Filter.h" | 19 #include <emscripten.h> |
20 #include "filter/InvalidFilter.h" | |
21 #include "filter/CommentFilter.h" | |
22 #include "filter/ActiveFilter.h" | |
23 #include "filter/RegExpFilter.h" | |
24 #include "filter/BlockingFilter.h" | |
25 #include "filter/WhitelistFilter.h" | |
26 #include "filter/ElemHideBase.h" | |
27 #include "filter/ElemHideFilter.h" | |
28 #include "filter/ElemHideException.h" | |
29 #include "filter/ElemHideEmulationFilter.h" | |
30 #include "subscription/Subscription.h" | |
31 #include "subscription/DownloadableSubscription.h" | |
32 #include "subscription/UserDefinedSubscription.h" | |
33 #include "FilterNotifier.h" | |
34 | 20 |
35 EMSCRIPTEN_BINDINGS | 21 #include "generator.h" |
22 #include "../filter/Filter.h" | |
23 #include "../filter/InvalidFilter.h" | |
24 #include "../filter/CommentFilter.h" | |
25 #include "../filter/ActiveFilter.h" | |
26 #include "../filter/RegExpFilter.h" | |
27 #include "../filter/BlockingFilter.h" | |
28 #include "../filter/WhitelistFilter.h" | |
29 #include "../filter/ElemHideBase.h" | |
30 #include "../filter/ElemHideFilter.h" | |
31 #include "../filter/ElemHideException.h" | |
32 #include "../filter/ElemHideEmulationFilter.h" | |
33 #include "../subscription/Subscription.h" | |
34 #include "../subscription/DownloadableSubscription.h" | |
35 #include "../subscription/UserDefinedSubscription.h" | |
36 #include "../FilterNotifier.h" | |
37 | |
38 int main() | |
36 { | 39 { |
37 class_<Filter>("Filter") | 40 try |
38 .property("text", &Filter::GetText) | 41 { |
39 .function("serialize", &Filter::Serialize) | 42 class_<Filter>("Filter") |
sergei
2017/04/20 14:52:00
Maybe it worth to leave these code in a function a
Wladimir Palant
2017/04/20 14:54:29
This is worth considering but let's land this chan
| |
40 .class_function("fromText", &Filter::FromText) | 43 .property("text", &Filter::GetText) |
41 .subclass_differentiator(&Filter::mType, { | 44 .function("serialize", &Filter::Serialize) |
42 {Filter::Type::INVALID, "InvalidFilter"}, | 45 .class_function("fromText", &Filter::FromText) |
43 {Filter::Type::COMMENT, "CommentFilter"}, | 46 .subclass_differentiator(&Filter::mType, { |
44 {Filter::Type::BLOCKING, "BlockingFilter"}, | 47 {Filter::Type::INVALID, "InvalidFilter"}, |
45 {Filter::Type::WHITELIST, "WhitelistFilter"}, | 48 {Filter::Type::COMMENT, "CommentFilter"}, |
46 {Filter::Type::ELEMHIDE, "ElemHideFilter"}, | 49 {Filter::Type::BLOCKING, "BlockingFilter"}, |
47 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"}, | 50 {Filter::Type::WHITELIST, "WhitelistFilter"}, |
48 {Filter::Type::ELEMHIDEEMULATION, "ElemHideEmulationFilter"}, | 51 {Filter::Type::ELEMHIDE, "ElemHideFilter"}, |
49 }); | 52 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"}, |
53 {Filter::Type::ELEMHIDEEMULATION, "ElemHideEmulationFilter"}, | |
54 }); | |
50 | 55 |
51 class_<InvalidFilter,Filter>("InvalidFilter") | 56 class_<InvalidFilter,Filter>("InvalidFilter") |
52 .class_property("type", "'invalid'") | 57 .class_property("type", "'invalid'") |
53 .property("reason", &InvalidFilter::GetReason); | 58 .property("reason", &InvalidFilter::GetReason); |
54 | 59 |
55 class_<CommentFilter,Filter>("CommentFilter") | 60 class_<CommentFilter,Filter>("CommentFilter") |
56 .class_property("type", "'comment'"); | 61 .class_property("type", "'comment'"); |
57 | 62 |
58 class_<ActiveFilter,Filter>("ActiveFilter") | 63 class_<ActiveFilter,Filter>("ActiveFilter") |
59 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisabl ed) | 64 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisa bled) |
60 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitCou nt) | 65 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitC ount) |
61 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHit) | 66 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHi t) |
62 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain) | 67 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain) |
63 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain) | 68 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain) |
64 .function("isGeneric", &ActiveFilter::IsGeneric) | 69 .function("isGeneric", &ActiveFilter::IsGeneric) |
65 .function("serialize", &ActiveFilter::Serialize); | 70 .function("serialize", &ActiveFilter::Serialize); |
66 | 71 |
67 class_<RegExpFilter,ActiveFilter>("RegExpFilter") | 72 class_<RegExpFilter,ActiveFilter>("RegExpFilter") |
68 .function("matches", &RegExpFilter::Matches); | 73 .function("matches", &RegExpFilter::Matches); |
69 | 74 |
70 custom_generator(&RegExpFilter::GenerateCustomBindings); | 75 class_<BlockingFilter,RegExpFilter>("BlockingFilter") |
76 .class_property("type", "'blocking'"); | |
71 | 77 |
72 class_<BlockingFilter,RegExpFilter>("BlockingFilter") | 78 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter") |
73 .class_property("type", "'blocking'"); | 79 .class_property("type", "'whitelist'"); |
74 | 80 |
75 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter") | 81 class_<ElemHideBase,ActiveFilter>("ElemHideBase") |
76 .class_property("type", "'whitelist'"); | 82 .property("selector", &ElemHideBase::GetSelector) |
83 .property("selectorDomain", &ElemHideBase::GetSelectorDomain); | |
77 | 84 |
78 class_<ElemHideBase,ActiveFilter>("ElemHideBase") | 85 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter") |
79 .property("selector", &ElemHideBase::GetSelector) | 86 .class_property("type", "'elemhide'"); |
80 .property("selectorDomain", &ElemHideBase::GetSelectorDomain); | |
81 | 87 |
82 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter") | 88 class_<ElemHideException,ElemHideBase>("ElemHideException") |
83 .class_property("type", "'elemhide'"); | 89 .class_property("type", "'elemhideexception'"); |
84 | 90 |
85 class_<ElemHideException,ElemHideBase>("ElemHideException") | 91 class_<ElemHideEmulationFilter,ElemHideBase>("ElemHideEmulationFilter") |
86 .class_property("type", "'elemhideexception'"); | 92 .class_property("type", "'elemhideemulation'"); |
87 | 93 |
88 class_<ElemHideEmulationFilter,ElemHideBase>("ElemHideEmulationFilter") | 94 class_<Subscription>("Subscription") |
89 .class_property("type", "'elemhideemulation'"); | 95 .property("url", &Subscription::GetID) |
96 .property("title", &Subscription::GetTitle, &Subscription::SetTitle) | |
97 .property("disabled", &Subscription::GetDisabled, &Subscription::SetDisa bled) | |
98 .property("filterCount", &Subscription::GetFilterCount) | |
99 .function("filterAt", &Subscription::FilterAt) | |
100 .function("indexOfFilter", &Subscription::IndexOfFilter) | |
101 .function("serialize", &Subscription::Serialize) | |
102 .function("serializeFilters", &Subscription::SerializeFilters) | |
103 .class_function("fromURL", &Subscription::FromID) | |
104 .subclass_differentiator(&Subscription::mType, { | |
105 {Subscription::Type::USERDEFINED, "SpecialSubscription"}, | |
106 {Subscription::Type::DOWNLOADABLE, "DownloadableSubscription"}, | |
107 }); | |
90 | 108 |
91 class_<Subscription>("Subscription") | 109 class_<UserDefinedSubscription,Subscription>("SpecialSubscription") |
92 .property("url", &Subscription::GetID) | 110 .function("isDefaultFor", &UserDefinedSubscription::IsDefaultFor) |
93 .property("title", &Subscription::GetTitle, &Subscription::SetTitle) | 111 .function("makeDefaultFor", &UserDefinedSubscription::MakeDefaultFor) |
94 .property("disabled", &Subscription::GetDisabled, &Subscription::SetDisabl ed) | 112 .function("insertFilterAt", &UserDefinedSubscription::InsertFilterAt) |
95 .property("filterCount", &Subscription::GetFilterCount) | 113 .function("removeFilterAt", &UserDefinedSubscription::RemoveFilterAt) |
96 .function("filterAt", &Subscription::FilterAt) | 114 .function("serialize", &UserDefinedSubscription::Serialize); |
97 .function("indexOfFilter", &Subscription::IndexOfFilter) | |
98 .function("serialize", &Subscription::Serialize) | |
99 .function("serializeFilters", &Subscription::SerializeFilters) | |
100 .class_function("fromURL", &Subscription::FromID) | |
101 .subclass_differentiator(&Subscription::mType, { | |
102 {Subscription::Type::USERDEFINED, "SpecialSubscription"}, | |
103 {Subscription::Type::DOWNLOADABLE, "DownloadableSubscription"}, | |
104 }); | |
105 | 115 |
106 class_<UserDefinedSubscription,Subscription>("SpecialSubscription") | 116 class_<DownloadableSubscription,Subscription>("DownloadableSubscription") |
107 .function("isDefaultFor", &UserDefinedSubscription::IsDefaultFor) | 117 .property("fixedTitle", &DownloadableSubscription::GetFixedTitle, &Downl oadableSubscription::SetFixedTitle) |
108 .function("makeDefaultFor", &UserDefinedSubscription::MakeDefaultFor) | 118 .property("homepage", &DownloadableSubscription::GetHomepage, &Downloada bleSubscription::SetHomepage) |
109 .function("insertFilterAt", &UserDefinedSubscription::InsertFilterAt) | 119 .property("lastCheck", &DownloadableSubscription::GetLastCheck, &Downloa dableSubscription::SetLastCheck) |
110 .function("removeFilterAt", &UserDefinedSubscription::RemoveFilterAt) | 120 .property("expires", &DownloadableSubscription::GetHardExpiration, &Down loadableSubscription::SetHardExpiration) |
111 .function("serialize", &UserDefinedSubscription::Serialize); | 121 .property("softExpiration", &DownloadableSubscription::GetSoftExpiration , &DownloadableSubscription::SetSoftExpiration) |
122 .property("lastDownload", &DownloadableSubscription::GetLastDownload, &D ownloadableSubscription::SetLastDownload) | |
123 .property("downloadStatus", &DownloadableSubscription::GetDownloadStatus , &DownloadableSubscription::SetDownloadStatus) | |
124 .property("lastSuccess", &DownloadableSubscription::GetLastSuccess, &Dow nloadableSubscription::SetLastSuccess) | |
125 .property("errors", &DownloadableSubscription::GetErrorCount, &Downloada bleSubscription::SetErrorCount) | |
126 .property("version", &DownloadableSubscription::GetDataRevision, &Downlo adableSubscription::SetDataRevision) | |
127 .property("requiredVersion", &DownloadableSubscription::GetRequiredVersi on, &DownloadableSubscription::SetRequiredVersion) | |
128 .property("downloadCount", &DownloadableSubscription::GetDownloadCount, &DownloadableSubscription::SetDownloadCount) | |
129 .function("serialize", &DownloadableSubscription::Serialize); | |
112 | 130 |
113 class_<DownloadableSubscription,Subscription>("DownloadableSubscription") | 131 printBindings(); |
114 .property("fixedTitle", &DownloadableSubscription::GetFixedTitle, &Downloa dableSubscription::SetFixedTitle) | 132 RegExpFilter::GenerateCustomBindings(); |
115 .property("homepage", &DownloadableSubscription::GetHomepage, &Downloadabl eSubscription::SetHomepage) | 133 FilterNotifier::GenerateCustomBindings(); |
116 .property("lastCheck", &DownloadableSubscription::GetLastCheck, &Downloada bleSubscription::SetLastCheck) | |
117 .property("expires", &DownloadableSubscription::GetHardExpiration, &Downlo adableSubscription::SetHardExpiration) | |
118 .property("softExpiration", &DownloadableSubscription::GetSoftExpiration, &DownloadableSubscription::SetSoftExpiration) | |
119 .property("lastDownload", &DownloadableSubscription::GetLastDownload, &Dow nloadableSubscription::SetLastDownload) | |
120 .property("downloadStatus", &DownloadableSubscription::GetDownloadStatus, &DownloadableSubscription::SetDownloadStatus) | |
121 .property("lastSuccess", &DownloadableSubscription::GetLastSuccess, &Downl oadableSubscription::SetLastSuccess) | |
122 .property("errors", &DownloadableSubscription::GetErrorCount, &Downloadabl eSubscription::SetErrorCount) | |
123 .property("version", &DownloadableSubscription::GetDataRevision, &Download ableSubscription::SetDataRevision) | |
124 .property("requiredVersion", &DownloadableSubscription::GetRequiredVersion , &DownloadableSubscription::SetRequiredVersion) | |
125 .property("downloadCount", &DownloadableSubscription::GetDownloadCount, &D ownloadableSubscription::SetDownloadCount) | |
126 .function("serialize", &DownloadableSubscription::Serialize); | |
127 | 134 |
128 custom_generator(&FilterNotifier::GenerateCustomBindings); | 135 return 0; |
136 } | |
137 catch (const std::exception& e) | |
138 { | |
139 EM_ASM_ARGS( | |
140 console.error("Error occurred generating JavaScript bindings: " + | |
141 Module.AsciiToString($0)), e.what() | |
142 ); | |
143 return 1; | |
144 } | |
129 } | 145 } |
OLD | NEW |