Index: libadblockplus-android/jni/JniFilterEngine.cpp |
diff --git a/libadblockplus-android/jni/JniFilterEngine.cpp b/libadblockplus-android/jni/JniFilterEngine.cpp |
index f9981f024922c74874f6a70c096c21cb23dc8e6e..bde6005194800dc4f6dd9a2061d791b41e0b4e66 100644 |
--- a/libadblockplus-android/jni/JniFilterEngine.cpp |
+++ b/libadblockplus-android/jni/JniFilterEngine.cpp |
@@ -44,12 +44,31 @@ static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env, |
return AdblockPlus::FilterEngine::StringToContentType(value); |
} |
-static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr) |
+static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong jsEnginePtr, jlong isAllowedConnectionCallbackPtr) |
{ |
try |
{ |
- AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(enginePtr); |
- return JniPtrToLong(new AdblockPlus::FilterEngine(jsEngine)); |
+ AdblockPlus::JsEnginePtr& jsEngine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(jsEnginePtr); |
+ AdblockPlus::FilterEnginePtr filterEnginePtr = NULL; |
sergei
2017/03/15 10:01:38
smart pointer is already initialized to nullptr, s
sergei
2017/03/15 10:01:38
I would just call the variable as filterEngine, wi
anton
2017/03/15 10:13:52
Acknowledged.
|
+ |
+ if (isAllowedConnectionCallbackPtr != 0) |
+ { |
+ AdblockPlus::FilterEngine::CreateParameters createParameters; |
+ JniIsAllowedConnectionTypeCallback* callback = |
+ JniLongToTypePtr<JniIsAllowedConnectionTypeCallback>(isAllowedConnectionCallbackPtr); |
+ |
+ AdblockPlus::FilterEngine::IsConnectionAllowedCallback cppCallback = |
+ std::bind(&JniIsAllowedConnectionTypeCallback::Callback, callback, std::placeholders::_1); |
+ createParameters.isConnectionAllowed = cppCallback; |
+ |
+ filterEnginePtr = AdblockPlus::FilterEngine::Create(jsEngine, createParameters); // here (1) - create engine sync |
+ } |
+ else |
+ { |
+ filterEnginePtr = AdblockPlus::FilterEngine::Create(jsEngine); |
+ } |
+ |
+ return JniPtrToLong(filterEnginePtr.get()); |
anton
2017/03/10 06:50:40
for some (unknown) reason new static methods (inst
sergei
2017/03/15 10:01:38
TL;DR: Actually here is a bug, but my vote is to a
anton
2017/03/15 10:13:52
Acknowledged.
|
} |
CATCH_THROW_AND_RETURN(env, 0) |
} |
@@ -434,9 +453,45 @@ static jstring JNICALL JniGetHostFromURL(JNIEnv* env, jclass clazz, jlong ptr, j |
CATCH_THROW_AND_RETURN(env, 0) |
} |
+static void JNICALL JniSetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr, jstring jvalue) |
+{ |
+ AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
+ |
+ std::string* value = NULL; |
+ if (jvalue != NULL) |
+ { |
+ std::string stdValue = JniJavaToStdString(env, jvalue); |
+ value = &stdValue; |
+ } |
+ |
+ try |
+ { |
+ engine->SetAllowedConnectionType(value); |
+ } |
+ CATCH_AND_THROW(env) |
+} |
+ |
+ |
+static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr) |
+{ |
+ try |
+ { |
+ AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr); |
+ std::unique_ptr<std::string> value = engine->GetAllowedConnectionType(); |
+ |
+ if (value == NULL) |
+ { |
+ return NULL; |
+ } |
+ |
+ return JniStdStringToJava(env, *value.get()); |
+ } |
+ CATCH_THROW_AND_RETURN(env, 0) |
+} |
+ |
static JNINativeMethod methods[] = |
{ |
- { (char*)"ctor", (char*)"(J)J", (void*)JniCtor }, |
+ { (char*)"ctor", (char*)"(JJ)J", (void*)JniCtor }, |
{ (char*)"isFirstRun", (char*)"(J)Z", (void*)JniIsFirstRun }, |
{ (char*)"getFilter", (char*)"(JLjava/lang/String;)" TYP("Filter"), (void*)JniGetFilter }, |
{ (char*)"getListedFilters", (char*)"(J)Ljava/util/List;", (void*)JniGetListedFilters }, |
@@ -459,6 +514,8 @@ static JNINativeMethod methods[] = |
{ (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniGetPref }, |
{ (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref }, |
{ (char*)"getHostFromURL", (char*)"(JLjava/lang/String;)Ljava/lang/String;", (void*)JniGetHostFromURL }, |
+ { (char*)"setAllowedConnectionType", (char*)"(JLjava/lang/String;)V", (void*)JniSetAllowedConnectionType }, |
+ { (char*)"getAllowedConnectionType", (char*)"(J)Ljava/lang/String;", (void*)JniGetAllowedConnectionType }, |
{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
}; |