| 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 { | 49 { |
| 50 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); | 50 delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js tring jEventName, jlong jCallbackPtr) | 53 static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js tring jEventName, jlong jCallbackPtr) |
| 54 { | 54 { |
| 55 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); | 55 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); |
| 56 | 56 |
| 57 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); | 57 JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); |
| 58 std::string eventName = JniJavaToStdString(env, jEventName); | 58 std::string eventName = JniJavaToStdString(env, jEventName); |
| 59 AdblockPlus::JsEngine::EventCallback eCallback = | 59 |
| 60 std::bind(&JniEventCallback::Callback, callback, std::placeholders::_1); | 60 auto eCallback = [callback](AdblockPlus::JsValueList&& params) |
| 61 { | |
| 62 callback->Callback(std::move(params)); | |
| 63 }; | |
| 61 | 64 |
| 62 try | 65 try |
| 63 { | 66 { |
| 64 engine->SetEventCallback(eventName, eCallback); | 67 engine->SetEventCallback(eventName, eCallback); |
| 65 } | 68 } |
| 66 CATCH_AND_THROW(env) | 69 CATCH_AND_THROW(env) |
| 67 } | 70 } |
| 68 | 71 |
| 69 static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName) | 72 static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName) |
| 70 { | 73 { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 for (jsize i = 0; i < length; i++) | 111 for (jsize i = 0; i < length; i++) |
| 109 { | 112 { |
| 110 args.push_back(JniGetJsValue(ptrs[i])); | 113 args.push_back(JniGetJsValue(ptrs[i])); |
| 111 } | 114 } |
| 112 | 115 |
| 113 env->ReleasePrimitiveArrayCritical(jJsPtrs, ptrs, JNI_ABORT); | 116 env->ReleasePrimitiveArrayCritical(jJsPtrs, ptrs, JNI_ABORT); |
| 114 } | 117 } |
| 115 | 118 |
| 116 try | 119 try |
| 117 { | 120 { |
| 118 engine->TriggerEvent(eventName, args); | 121 engine->TriggerEvent(eventName, std::move(args)); |
| 119 } | 122 } |
| 120 CATCH_AND_THROW(env) | 123 CATCH_AND_THROW(env) |
| 121 } | 124 } |
| 122 | 125 |
| 123 static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr , jstring jBasePath) | 126 static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr , jstring jBasePath) |
| 124 { | 127 { |
| 125 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); | 128 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); |
| 126 | 129 |
| 127 try | 130 try |
| 128 { | 131 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 } | 163 } |
| 161 CATCH_AND_THROW(env) | 164 CATCH_AND_THROW(env) |
| 162 } | 165 } |
| 163 | 166 |
| 164 static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong logSystemPtr) | 167 static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong logSystemPtr) |
| 165 { | 168 { |
| 166 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); | 169 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); |
| 167 | 170 |
| 168 try | 171 try |
| 169 { | 172 { |
| 170 AdblockPlus::LogSystemPtr logSystem = | 173 AdblockPlus::LogSystemPtr logSystem = *JniLongToTypePtr<AdblockPlus::LogSyst emPtr>(logSystemPtr); |
|
sergei
2017/04/26 14:12:56
it seems these changes are unrelated, do you mind
anton
2017/04/27 06:21:01
Acknowledged.
| |
| 171 *JniLongToTypePtr<AdblockPlus::LogSystemPtr>(logSystemPtr); | |
| 172 | 174 |
| 173 engine->SetLogSystem(logSystem); | 175 engine->SetLogSystem(logSystem); |
| 174 } | 176 } |
| 175 CATCH_AND_THROW(env) | 177 CATCH_AND_THROW(env) |
| 176 } | 178 } |
| 177 | 179 |
| 178 static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong webRequestPtr) | 180 static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong webRequestPtr) |
| 179 { | 181 { |
| 180 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); | 182 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); |
| 181 | 183 |
| 182 try | 184 try |
| 183 { | 185 { |
| 184 AdblockPlus::WebRequestPtr& webRequest = | 186 AdblockPlus::WebRequestPtr& webRequest = *JniLongToTypePtr<AdblockPlus::WebR equestPtr>(webRequestPtr); |
| 185 *JniLongToTypePtr<AdblockPlus::WebRequestPtr>(webRequestPtr); | |
| 186 | 187 |
| 187 engine->SetWebRequest(webRequest); | 188 engine->SetWebRequest(webRequest); |
| 188 } | 189 } |
| 189 CATCH_AND_THROW(env) | 190 CATCH_AND_THROW(env) |
| 190 } | 191 } |
| 191 | 192 |
| 192 static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo ng value) | 193 static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo ng value) |
| 193 { | 194 { |
| 194 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); | 195 AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr> (ptr); |
| 195 | 196 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 217 | 218 |
| 218 try | 219 try |
| 219 { | 220 { |
| 220 std::string strValue = JniJavaToStdString(env, value); | 221 std::string strValue = JniJavaToStdString(env, value); |
| 221 return NewJniJsValue(env, engine->NewValue(strValue)); | 222 return NewJniJsValue(env, engine->NewValue(strValue)); |
| 222 } | 223 } |
| 223 CATCH_THROW_AND_RETURN(env, 0) | 224 CATCH_THROW_AND_RETURN(env, 0) |
| 224 } | 225 } |
| 225 | 226 |
| 226 // TODO: List of functions that lack JNI bindings | 227 // TODO: List of functions that lack JNI bindings |
| 227 //JsValue NewObject(); | 228 //JsValuePtr NewObject(); |
| 228 //JsValue NewCallback(v8::InvocationCallback callback); | 229 //JsValuePtr NewCallback(v8::InvocationCallback callback); |
| 229 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); | 230 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); |
| 230 //JsValueList ConvertArguments(const v8::Arguments& arguments); | 231 //JsValueList ConvertArguments(const v8::Arguments& arguments); |
| 231 | 232 |
| 232 static JNINativeMethod methods[] = | 233 static JNINativeMethod methods[] = |
| 233 { | 234 { |
| 234 { (char*)"ctor", (char*)"(" TYP("AppInfo") ")J", (void*)JniCtor }, | 235 { (char*)"ctor", (char*)"(" TYP("AppInfo") ")J", (void*)JniCtor }, |
| 235 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, | 236 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, |
| 236 | 237 |
| 237 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv entCallback }, | 238 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv entCallback }, |
| 238 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem oveEventCallback }, | 239 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem oveEventCallback }, |
| 239 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE vent }, | 240 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE vent }, |
| 240 | 241 |
| 241 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV alue"), (void*)JniEvaluate }, | 242 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV alue"), (void*)JniEvaluate }, |
| 242 | 243 |
| 243 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe tDefaultFileSystem }, | 244 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe tDefaultFileSystem }, |
| 244 { (char*)"setLogSystem", (char*)"(JJ)V", (void*)JniSetLogSystem }, | 245 { (char*)"setLogSystem", (char*)"(JJ)V", (void*)JniSetLogSystem }, |
| 245 { (char*)"setDefaultLogSystem", (char*)"(J)V", (void*)JniSetDefaultLogSystem } , | 246 { (char*)"setDefaultLogSystem", (char*)"(J)V", (void*)JniSetDefaultLogSystem } , |
| 246 { (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest }, | 247 { (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest }, |
| 247 { (char*)"setDefaultWebRequest", (char*)"(J)V", (void*)JniSetDefaultWebRequest }, | 248 { (char*)"setDefaultWebRequest", (char*)"(J)V", (void*)JniSetDefaultWebRequest }, |
| 248 | 249 |
| 249 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, | 250 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, |
| 250 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } , | 251 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue } , |
| 251 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue } | 252 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni NewStringValue } |
| 252 }; | 253 }; |
| 253 | 254 |
| 254 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r egisterNatives(JNIEnv *env, jclass clazz) | 255 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r egisterNatives(JNIEnv *env, jclass clazz) |
| 255 { | 256 { |
| 256 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 257 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 257 } | 258 } |
| LEFT | RIGHT |