| LEFT | RIGHT |
| 1 #include <emscripten.h> | 1 #include "bindings.ipp" |
| 2 | |
| 3 #include "bindings.h" | |
| 4 #include "String.h" | |
| 5 #include "intrusive_ptr.h" | |
| 6 #include "Filter.h" | 2 #include "Filter.h" |
| 7 #include "InvalidFilter.h" | 3 #include "InvalidFilter.h" |
| 8 #include "CommentFilter.h" | 4 #include "CommentFilter.h" |
| 9 #include "ActiveFilter.h" | 5 #include "ActiveFilter.h" |
| 10 #include "RegExpFilter.h" | 6 #include "RegExpFilter.h" |
| 7 #include "BlockingFilter.h" |
| 11 #include "WhitelistFilter.h" | 8 #include "WhitelistFilter.h" |
| 12 #include "ElemHideBase.h" | 9 #include "ElemHideBase.h" |
| 13 #include "ElemHideFilter.h" | 10 #include "ElemHideFilter.h" |
| 14 #include "ElemHideException.h" | 11 #include "ElemHideException.h" |
| 15 #include "CSSPropertyFilter.h" | 12 #include "CSSPropertyFilter.h" |
| 16 | 13 |
| 17 extern "C" | 14 EMSCRIPTEN_BINDINGS |
| 18 { | |
| 19 void EMSCRIPTEN_KEEPALIVE InitString(String* str, String::value_type* data, | |
| 20 String::size_type len) | |
| 21 { | |
| 22 // String is already allocated on stack, we merely need to call constructor. | |
| 23 new (str) String(data, len); | |
| 24 } | |
| 25 | |
| 26 void EMSCRIPTEN_KEEPALIVE DestroyString(String* str) | |
| 27 { | |
| 28 // Stack memory will be freed automatically, we need to call destructor | |
| 29 // explicitly however. | |
| 30 str->~String(); | |
| 31 } | |
| 32 | |
| 33 String::size_type EMSCRIPTEN_KEEPALIVE GetStringLength(const String& str) | |
| 34 { | |
| 35 return str.length(); | |
| 36 } | |
| 37 | |
| 38 const String::value_type* EMSCRIPTEN_KEEPALIVE GetStringData(const String& str
) | |
| 39 { | |
| 40 return str.data(); | |
| 41 } | |
| 42 | |
| 43 void EMSCRIPTEN_KEEPALIVE AddRef(ref_counted* ptr) | |
| 44 { | |
| 45 ptr->AddRef(); | |
| 46 } | |
| 47 | |
| 48 void EMSCRIPTEN_KEEPALIVE ReleaseRef(ref_counted* ptr) | |
| 49 { | |
| 50 ptr->ReleaseRef(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 #if defined(PRINT_BINDINGS) | |
| 55 EMSCRIPTEN_BINDINGS(api) | |
| 56 { | 15 { |
| 57 class_<Filter>("Filter") | 16 class_<Filter>("Filter") |
| 58 .property("text", &Filter::GetText) | 17 .property("text", &Filter::GetText) |
| 59 .function("serialize", &Filter::Serialize) | 18 .function("serialize", &Filter::Serialize) |
| 60 .class_function("fromText", &Filter::FromText) | 19 .class_function("fromText", &Filter::FromText) |
| 61 .class_function("normalize", &Filter::Normalize) | 20 .subclass_differentiator(&Filter::mType, { |
| 62 .subclass_differentiator(&Filter::GetType, { | |
| 63 {Filter::Type::INVALID, "InvalidFilter"}, | 21 {Filter::Type::INVALID, "InvalidFilter"}, |
| 64 {Filter::Type::COMMENT, "CommentFilter"}, | 22 {Filter::Type::COMMENT, "CommentFilter"}, |
| 65 {Filter::Type::BLOCKING, "RegExpFilter"}, | 23 {Filter::Type::BLOCKING, "BlockingFilter"}, |
| 66 {Filter::Type::WHITELIST, "WhitelistFilter"}, | 24 {Filter::Type::WHITELIST, "WhitelistFilter"}, |
| 67 {Filter::Type::ELEMHIDE, "ElemHideFilter"}, | 25 {Filter::Type::ELEMHIDE, "ElemHideFilter"}, |
| 68 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"}, | 26 {Filter::Type::ELEMHIDEEXCEPTION, "ElemHideException"}, |
| 69 {Filter::Type::CSSPROPERTY, "CSSPropertyFilter"}, | 27 {Filter::Type::CSSPROPERTY, "CSSPropertyFilter"}, |
| 70 }); | 28 }); |
| 71 | 29 |
| 72 class_<InvalidFilter,Filter>("InvalidFilter") | 30 class_<InvalidFilter,Filter>("InvalidFilter") |
| 73 .class_property("type", "'invalid'") | 31 .class_property("type", "'invalid'") |
| 74 .property("reason", &InvalidFilter::GetReason); | 32 .property("reason", &InvalidFilter::GetReason); |
| 75 | 33 |
| 76 class_<CommentFilter,Filter>("CommentFilter") | 34 class_<CommentFilter,Filter>("CommentFilter") |
| 77 .class_property("type", "'comment'"); | 35 .class_property("type", "'comment'"); |
| 78 | 36 |
| 79 class_<ActiveFilter,Filter>("ActiveFilter") | 37 class_<ActiveFilter,Filter>("ActiveFilter") |
| 80 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisabl
ed) | 38 .property("disabled", &ActiveFilter::GetDisabled, &ActiveFilter::SetDisabl
ed) |
| 81 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitCou
nt) | 39 .property("hitCount", &ActiveFilter::GetHitCount, &ActiveFilter::SetHitCou
nt) |
| 82 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHit) | 40 .property("lastHit", &ActiveFilter::GetLastHit, &ActiveFilter::SetLastHit) |
| 83 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain) | 41 .function("isActiveOnDomain", &ActiveFilter::IsActiveOnDomain) |
| 84 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain) | 42 .function("isActiveOnlyOnDomain", &ActiveFilter::IsActiveOnlyOnDomain) |
| 85 .function("isGeneric", &ActiveFilter::IsGeneric) | 43 .function("isGeneric", &ActiveFilter::IsGeneric) |
| 86 .function("serialize", &ActiveFilter::Serialize); | 44 .function("serialize", &ActiveFilter::Serialize); |
| 87 | 45 |
| 88 class_<RegExpFilter,ActiveFilter>("RegExpFilter") | 46 class_<RegExpFilter,ActiveFilter>("RegExpFilter") |
| 89 .class_property("type", "'blocking'") | |
| 90 .function("matches", &RegExpFilter::Matches) | 47 .function("matches", &RegExpFilter::Matches) |
| 91 .class_initializer(&RegExpFilter::InitJSTypes); | 48 .class_initializer(&RegExpFilter::InitJSTypes); |
| 49 |
| 50 class_<BlockingFilter,RegExpFilter>("BlockingFilter") |
| 51 .class_property("type", "'blocking'"); |
| 92 | 52 |
| 93 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter") | 53 class_<WhitelistFilter,RegExpFilter>("WhitelistFilter") |
| 94 .class_property("type", "'whitelist'"); | 54 .class_property("type", "'whitelist'"); |
| 95 | 55 |
| 96 class_<ElemHideBase,ActiveFilter>("ElemHideBase") | 56 class_<ElemHideBase,ActiveFilter>("ElemHideBase") |
| 97 .property("selector", &ElemHideBase::GetSelector) | 57 .property("selector", &ElemHideBase::GetSelector) |
| 98 .property("selectorDomain", &ElemHideBase::GetSelectorDomain); | 58 .property("selectorDomain", &ElemHideBase::GetSelectorDomain); |
| 99 | 59 |
| 100 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter") | 60 class_<ElemHideFilter,ElemHideBase>("ElemHideFilter") |
| 101 .class_property("type", "'elemhide'"); | 61 .class_property("type", "'elemhide'"); |
| 102 | 62 |
| 103 class_<ElemHideException,ElemHideBase>("ElemHideException") | 63 class_<ElemHideException,ElemHideBase>("ElemHideException") |
| 104 .class_property("type", "'elemhideexception'"); | 64 .class_property("type", "'elemhideexception'"); |
| 105 | 65 |
| 106 class_<CSSPropertyFilter,ElemHideBase>("CSSPropertyFilter") | 66 class_<CSSPropertyFilter,ElemHideBase>("CSSPropertyFilter") |
| 107 .class_property("type", "'cssproperty'") | 67 .class_property("type", "'cssproperty'") |
| 108 .property("regexpString", &CSSPropertyFilter::GetRegExpString) | 68 .property("regexpString", &CSSPropertyFilter::GetRegExpString) |
| 109 .property("selectorPrefix", &CSSPropertyFilter::GetSelectorPrefix) | 69 .property("selectorPrefix", &CSSPropertyFilter::GetSelectorPrefix) |
| 110 .property("selectorSuffix", &CSSPropertyFilter::GetSelectorSuffix); | 70 .property("selectorSuffix", &CSSPropertyFilter::GetSelectorSuffix); |
| 111 } | 71 } |
| 112 #endif | |
| LEFT | RIGHT |