OLD | NEW |
(Empty) | |
| 1 #include <exception> |
| 2 #include <string> |
| 3 |
| 4 #include <emscripten.h> |
| 5 |
| 6 #include "Filter.h" |
| 7 #include "InvalidFilter.h" |
| 8 #include "ActiveFilter.h" |
| 9 #include "RegExpFilter.h" |
| 10 #include "ElemHideBase.h" |
| 11 |
| 12 #pragma clang diagnostic push |
| 13 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage" |
| 14 |
| 15 #define EXPOSE_FILTER_PROPERTY(class, type, getter, setter) \ |
| 16 type EMSCRIPTEN_KEEPALIVE class##_##getter(const FilterPtr& filter)\ |
| 17 {\ |
| 18 return std::dynamic_pointer_cast<class>(filter)->getter();\ |
| 19 }\ |
| 20 void EMSCRIPTEN_KEEPALIVE class##_##setter(\ |
| 21 const FilterPtr& filter, type value)\ |
| 22 {\ |
| 23 std::dynamic_pointer_cast<class>(filter)->setter(value);\ |
| 24 } |
| 25 |
| 26 extern "C" |
| 27 { |
| 28 const char* EMSCRIPTEN_KEEPALIVE GetException(const std::exception& e) |
| 29 { |
| 30 return e.what(); |
| 31 } |
| 32 |
| 33 size_t EMSCRIPTEN_KEEPALIVE GetSizeofString() |
| 34 { |
| 35 return sizeof(std::u16string); |
| 36 } |
| 37 |
| 38 void EMSCRIPTEN_KEEPALIVE InitString(std::u16string* str, char16_t* data, size
_t len) |
| 39 { |
| 40 // String is already allocated on stack, we merely need to call constructor. |
| 41 new (str) std::u16string(data, len); |
| 42 } |
| 43 |
| 44 void EMSCRIPTEN_KEEPALIVE DestroyString(std::u16string* str) |
| 45 { |
| 46 // Stack memory will be freed automatically, we need to call destructor |
| 47 // explicitly however. |
| 48 using namespace std; |
| 49 str->~u16string(); |
| 50 } |
| 51 |
| 52 size_t EMSCRIPTEN_KEEPALIVE GetStringLength(const std::u16string& str) |
| 53 { |
| 54 return str.length(); |
| 55 } |
| 56 |
| 57 FilterPtr* EMSCRIPTEN_KEEPALIVE CreatePointer() |
| 58 { |
| 59 return new FilterPtr(); |
| 60 } |
| 61 |
| 62 void EMSCRIPTEN_KEEPALIVE DeletePointer(FilterPtr* ptr) |
| 63 { |
| 64 delete ptr; |
| 65 } |
| 66 |
| 67 const char16_t* EMSCRIPTEN_KEEPALIVE GetStringData(const std::u16string& str) |
| 68 { |
| 69 return str.c_str(); |
| 70 } |
| 71 |
| 72 std::u16string EMSCRIPTEN_KEEPALIVE Filter_GetText(const FilterPtr& filter) |
| 73 { |
| 74 return filter->GetText(); |
| 75 } |
| 76 |
| 77 Filter::Type EMSCRIPTEN_KEEPALIVE Filter_GetType(const FilterPtr& filter) |
| 78 { |
| 79 return filter->GetType(); |
| 80 } |
| 81 |
| 82 std::u16string EMSCRIPTEN_KEEPALIVE Filter_Serialize(const FilterPtr& filter) |
| 83 { |
| 84 return filter->Serialize(); |
| 85 } |
| 86 |
| 87 FilterPtr EMSCRIPTEN_KEEPALIVE Filter_FromText(const std::u16string& text) |
| 88 { |
| 89 return Filter::FromText(text); |
| 90 } |
| 91 |
| 92 const std::u16string EMSCRIPTEN_KEEPALIVE Filter_Normalize(const std::u16strin
g& text) |
| 93 { |
| 94 return Filter::Normalize(text); |
| 95 } |
| 96 |
| 97 const std::u16string EMSCRIPTEN_KEEPALIVE InvalidFilter_GetReason(const Filter
Ptr& filter) |
| 98 { |
| 99 return std::dynamic_pointer_cast<InvalidFilter>(filter)->GetReason(); |
| 100 } |
| 101 |
| 102 EXPOSE_FILTER_PROPERTY(ActiveFilter, bool, GetDisabled, SetDisabled); |
| 103 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetHitCount, SetHitCount); |
| 104 EXPOSE_FILTER_PROPERTY(ActiveFilter, unsigned int, GetLastHit, SetLastHit); |
| 105 |
| 106 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnDomain( |
| 107 const FilterPtr& filter, const std::u16string& domain, |
| 108 const std::u16string& sitekey) |
| 109 { |
| 110 return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsActiveOnDomain( |
| 111 domain, sitekey |
| 112 ); |
| 113 } |
| 114 |
| 115 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsActiveOnlyOnDomain( |
| 116 const FilterPtr& filter, const std::u16string& domain) |
| 117 { |
| 118 return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsActiveOnlyOnDomain
( |
| 119 domain |
| 120 ); |
| 121 } |
| 122 |
| 123 bool EMSCRIPTEN_KEEPALIVE ActiveFilter_IsGeneric(const FilterPtr& filter) |
| 124 { |
| 125 return std::dynamic_pointer_cast<ActiveFilter>(filter)->IsGeneric(); |
| 126 } |
| 127 |
| 128 void EMSCRIPTEN_KEEPALIVE RegExpFilter_InitJSTypes() |
| 129 { |
| 130 RegExpFilter::InitJSTypes(); |
| 131 } |
| 132 |
| 133 bool EMSCRIPTEN_KEEPALIVE RegExpFilter_Matches(const FilterPtr& filter, |
| 134 const std::u16string& location, int typeMask, |
| 135 const std::u16string& docDomain, bool thirdParty, |
| 136 const std::u16string& sitekey) |
| 137 { |
| 138 return std::dynamic_pointer_cast<RegExpFilter>(filter)->Matches( |
| 139 location, typeMask, docDomain, thirdParty, sitekey |
| 140 ); |
| 141 } |
| 142 |
| 143 const std::u16string EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelector( |
| 144 const FilterPtr& filter) |
| 145 { |
| 146 return std::dynamic_pointer_cast<ElemHideBase>(filter)->GetSelector(); |
| 147 } |
| 148 |
| 149 const std::u16string EMSCRIPTEN_KEEPALIVE ElemHideBase_GetSelectorDomain( |
| 150 const FilterPtr& filter) |
| 151 { |
| 152 return std::dynamic_pointer_cast<ElemHideBase>(filter)->GetSelectorDomain(); |
| 153 } |
| 154 } |
| 155 |
| 156 #pragma clang diagnostic pop |
OLD | NEW |