Index: libadblockplus-android/jni/JniJsEngine.cpp |
diff --git a/libadblockplus-android/jni/JniJsEngine.cpp b/libadblockplus-android/jni/JniJsEngine.cpp |
index 7c08e81ac9ca52647e67df42803cfb15267e08bb..7bc78faaace27a3ccd8300c8bada1bc6dc787e9b 100644 |
--- a/libadblockplus-android/jni/JniJsEngine.cpp |
+++ b/libadblockplus-android/jni/JniJsEngine.cpp |
@@ -18,6 +18,7 @@ |
#include <AdblockPlus.h> |
#include "Utils.h" |
#include "JniCallbacks.h" |
+#include "JniJsEngine.h" |
static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo& appInfo) |
{ |
@@ -32,6 +33,11 @@ static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo |
appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developmentBuild"); |
} |
+static AdblockPlus::JsEnginePtr& GetJsEnginePtrRef(jlong ptr) |
+{ |
+ return JniLongToTypePtr<JniJsEngine>(ptr)->jsEngine; |
+} |
+ |
static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo) |
{ |
AdblockPlus::AppInfo appInfo; |
@@ -40,19 +46,23 @@ static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo) |
try |
{ |
- return JniPtrToLong(new AdblockPlus::JsEnginePtr(AdblockPlus::JsEngine::New(appInfo))); |
+ AdblockPlus::TimerPtr timer = AdblockPlus::CreateDefaultTimer(); |
+ JniJsEngine* jniJsEngine = new JniJsEngine(); |
+ jniJsEngine->timer = timer.get(); |
+ jniJsEngine->jsEngine = AdblockPlus::JsEngine::New(appInfo, std::move(timer)); |
+ return JniPtrToLong(jniJsEngine); |
} |
CATCH_THROW_AND_RETURN(env, 0) |
} |
static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) |
{ |
- delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ delete JniLongToTypePtr<JniJsEngine>(ptr); |
} |
static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName, jlong jCallbackPtr) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr); |
std::string eventName = JniJavaToStdString(env, jEventName); |
@@ -71,7 +81,7 @@ static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js |
static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
std::string eventName = JniJavaToStdString(env, jEventName); |
@@ -84,7 +94,7 @@ static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, |
static jobject JNICALL JniEvaluate(JNIEnv* env, jclass clazz, jlong ptr, jstring jSource, jstring jFilename) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
std::string source = JniJavaToStdString(env, jSource); |
std::string filename = JniJavaToStdString(env, jFilename); |
@@ -98,7 +108,7 @@ static jobject JNICALL JniEvaluate(JNIEnv* env, jclass clazz, jlong ptr, jstring |
static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName, jarray jJsPtrs) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
std::string eventName = JniJavaToStdString(env, jEventName); |
AdblockPlus::JsValueList args; |
@@ -125,7 +135,7 @@ static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstrin |
static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr, jstring jBasePath) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |
@@ -141,7 +151,7 @@ static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr |
static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |
@@ -154,7 +164,7 @@ static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr) |
static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong logSystemPtr) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |
@@ -167,7 +177,7 @@ static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong |
static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong webRequestPtr) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |
@@ -180,7 +190,7 @@ static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong |
static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlong value) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |
@@ -191,7 +201,7 @@ static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlo |
static jobject JNICALL JniNewBooleanValue(JNIEnv* env, jclass clazz, jlong ptr, jboolean value) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |
@@ -202,7 +212,7 @@ static jobject JNICALL JniNewBooleanValue(JNIEnv* env, jclass clazz, jlong ptr, |
static jobject JNICALL JniNewStringValue(JNIEnv* env, jclass clazz, jlong ptr, jstring value) |
{ |
- AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr); |
+ AdblockPlus::JsEnginePtr& engine = GetJsEnginePtrRef(ptr); |
try |
{ |