Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android/jni/JniFilterEngine.cpp

Issue 29379647: Issue 4948 - add possibility to not send data depending on connection properties (Closed)
Patch Set: after Sergei's comments minor clean-up Created March 15, 2017, 10:35 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android/jni/JniFilterEngine.cpp
diff --git a/libadblockplus-android/jni/JniFilterEngine.cpp b/libadblockplus-android/jni/JniFilterEngine.cpp
index f9981f024922c74874f6a70c096c21cb23dc8e6e..f568279a8b26f307698e7233eb09809b376440d0 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 filterEngine;
+
+ 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;
+
+ filterEngine = AdblockPlus::FilterEngine::Create(jsEngine, createParameters);
+ }
+ else
+ {
+ filterEngine = AdblockPlus::FilterEngine::Create(jsEngine);
+ }
+
+ return JniPtrToLong(filterEngine.get());
}
CATCH_THROW_AND_RETURN(env, 0)
}
@@ -434,9 +453,44 @@ 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 +513,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 }
};
« no previous file with comments | « libadblockplus-android/jni/JniCallbacks.h ('k') | libadblockplus-android/jni/JniIsAllowedConnectionTypeCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld