| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme
ntBuild"); | 34 appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developme
ntBuild"); |
| 35 } | 35 } |
| 36 | 36 |
| 37 static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr) | 37 static AdblockPlus::JsEngine& GetJsEngineRef(jlong ptr) |
| 38 { | 38 { |
| 39 return *JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine; | 39 return *JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine; |
| 40 } | 40 } |
| 41 | 41 |
| 42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo, | 42 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo, |
| 43 jobject logSystem, jlong webRequestPtr) | 43 jobject logSystem, jobject webRequest) |
| 44 { | 44 { |
| 45 AdblockPlus::AppInfo appInfo; | 45 AdblockPlus::AppInfo appInfo; |
| 46 | 46 |
| 47 TransformAppInfo(env, jAppInfo, appInfo); | 47 TransformAppInfo(env, jAppInfo, appInfo); |
| 48 | 48 |
| 49 try | 49 try |
| 50 { | 50 { |
| 51 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer(); | 51 AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer(); |
| 52 JniJsEngine* jniJsEngine = new JniJsEngine(); | 52 JniJsEngine* jniJsEngine = new JniJsEngine(); |
| 53 jniJsEngine->timer = timer.get(); | 53 jniJsEngine->timer = timer.get(); |
| 54 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer)
); | 54 jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer)
); |
| 55 if (logSystem) | 55 if (logSystem) |
| 56 { | 56 { |
| 57 jniJsEngine->jsEngine->SetLogSystem(std::make_shared<JniLogSystemCallback>
(env, logSystem)); | 57 jniJsEngine->jsEngine->SetLogSystem(std::make_shared<JniLogSystemCallback>
(env, logSystem)); |
| 58 } | 58 } |
| 59 if (webRequestPtr) | 59 if (webRequest) |
| 60 { | 60 { |
| 61 jniJsEngine->jsEngine->SetWebRequest(*JniLongToTypePtr<AdblockPlus::WebReq
uestSharedPtr>(webRequestPtr)); | 61 jniJsEngine->jsEngine->SetWebRequest(std::make_shared<JniWebRequest>(env,
webRequest)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 return JniPtrToLong(jniJsEngine); | 64 return JniPtrToLong(jniJsEngine); |
| 65 } | 65 } |
| 66 CATCH_THROW_AND_RETURN(env, 0) | 66 CATCH_THROW_AND_RETURN(env, 0) |
| 67 } | 67 } |
| 68 | 68 |
| 69 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | 69 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
| 70 { | 70 { |
| 71 delete JniLongToTypePtr<JniJsEngine>(ptr); | 71 delete JniLongToTypePtr<JniJsEngine>(ptr); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 // TODO: List of functions that lack JNI bindings | 197 // TODO: List of functions that lack JNI bindings |
| 198 //JsValuePtr NewObject(); | 198 //JsValuePtr NewObject(); |
| 199 //JsValuePtr NewCallback(v8::InvocationCallback callback); | 199 //JsValuePtr NewCallback(v8::InvocationCallback callback); |
| 200 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); | 200 //static JsEnginePtr FromArguments(const v8::Arguments& arguments); |
| 201 //JsValueList ConvertArguments(const v8::Arguments& arguments); | 201 //JsValueList ConvertArguments(const v8::Arguments& arguments); |
| 202 | 202 |
| 203 static JNINativeMethod methods[] = | 203 static JNINativeMethod methods[] = |
| 204 { | 204 { |
| 205 { (char*)"ctor", (char*)"(" TYP("AppInfo") TYP("LogSystem")"J)J", (void*)JniCt
or }, | 205 { (char*)"ctor", (char*)"(" TYP("AppInfo") TYP("LogSystem") TYP("WebRequest")
")J", (void*)JniCtor }, |
| 206 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, | 206 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }, |
| 207 | 207 |
| 208 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv
entCallback }, | 208 { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEv
entCallback }, |
| 209 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem
oveEventCallback }, | 209 { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRem
oveEventCallback }, |
| 210 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE
vent }, | 210 { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerE
vent }, |
| 211 | 211 |
| 212 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV
alue"), (void*)JniEvaluate }, | 212 { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsV
alue"), (void*)JniEvaluate }, |
| 213 | 213 |
| 214 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe
tDefaultFileSystem }, | 214 { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSe
tDefaultFileSystem }, |
| 215 | 215 |
| 216 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, | 216 { (char*)"newValue", (char*)"(JJ)" TYP("JsValue"), (void*)JniNewLongValue }, |
| 217 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue }
, | 217 { (char*)"newValue", (char*)"(JZ)" TYP("JsValue"), (void*)JniNewBooleanValue }
, |
| 218 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni
NewStringValue } | 218 { (char*)"newValue", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)Jni
NewStringValue } |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r
egisterNatives(JNIEnv *env, jclass clazz) | 221 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_JsEngine_r
egisterNatives(JNIEnv *env, jclass clazz) |
| 222 { | 222 { |
| 223 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 223 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 224 } | 224 } |
| OLD | NEW |