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: migrated from FilterEngine* to FilterEnginePtr*, minor improvements Created March 15, 2017, 12:48 p.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..3996e0d32228c888d7f8ef6efa344625b055796f 100644
--- a/libadblockplus-android/jni/JniFilterEngine.cpp
+++ b/libadblockplus-android/jni/JniFilterEngine.cpp
@@ -44,40 +44,61 @@ 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 = NULL;
+
+ 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 = new AdblockPlus::FilterEnginePtr(
+ AdblockPlus::FilterEngine::Create(jsEngine, createParameters));
+ }
+ else
+ {
+ filterEngine = new AdblockPlus::FilterEnginePtr(
+ AdblockPlus::FilterEngine::Create(jsEngine));
+ }
+
+ return JniPtrToLong(filterEngine);
anton 2017/03/15 12:52:54 i had to migrate from FilterEngine* to FilterEngin
sergei 2017/03/15 13:41:48 It's not removed in internals of libadblockplus, i
}
CATCH_THROW_AND_RETURN(env, 0)
}
static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
{
- delete JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ delete JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
}
static jboolean JNICALL JniIsFirstRun(JNIEnv* env, jclass clazz, jlong ptr)
{
try
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
- return engine->IsFirstRun() ? JNI_TRUE : JNI_FALSE;
+ return engine->get()->IsFirstRun() ? JNI_TRUE : JNI_FALSE;
}
CATCH_THROW_AND_RETURN(env, JNI_FALSE);
}
static jobject JNICALL JniGetFilter(JNIEnv* env, jclass clazz, jlong ptr, jstring jText)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string text = JniJavaToStdString(env, jText);
try
{
- AdblockPlus::FilterPtr filter = engine->GetFilter(text);
+ AdblockPlus::FilterPtr filter = engine->get()->GetFilter(text);
return NewJniFilter(env, filter);
}
@@ -86,11 +107,11 @@ static jobject JNICALL JniGetFilter(JNIEnv* env, jclass clazz, jlong ptr, jstrin
static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
try
{
- std::vector<AdblockPlus::FilterPtr> filters = engine->GetListedFilters();
+ std::vector<AdblockPlus::FilterPtr> filters = engine->get()->GetListedFilters();
jobject list = NewJniArrayList(env);
@@ -106,12 +127,12 @@ static jobject JNICALL JniGetListedFilters(JNIEnv* env, jclass clazz, jlong ptr)
static jobject JNICALL JniGetSubscription(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
try
{
- AdblockPlus::SubscriptionPtr subscription = engine->GetSubscription(url);
+ AdblockPlus::SubscriptionPtr subscription = engine->get()->GetSubscription(url);
return NewJniSubscription(env, subscription);
}
@@ -120,12 +141,12 @@ static jobject JNICALL JniGetSubscription(JNIEnv* env, jclass clazz, jlong ptr,
static void JNICALL JniShowNextNotification(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
try
{
- engine->ShowNextNotification(url);
+ engine->get()->ShowNextNotification(url);
}
CATCH_AND_THROW(env);
}
@@ -133,8 +154,8 @@ static void JNICALL JniShowNextNotification(JNIEnv* env, jclass clazz, jlong ptr
static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz,
jlong ptr, jlong callbackPtr)
{
- AdblockPlus::FilterEngine* const engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
JniShowNotificationCallback* const callback =
JniLongToTypePtr<JniShowNotificationCallback>(callbackPtr);
AdblockPlus::FilterEngine::ShowNotificationCallback showNotificationCallback =
@@ -142,29 +163,29 @@ static void JNICALL JniSetShowNotificationCallback(JNIEnv* env, jclass clazz,
std::placeholders::_1);
try
{
- engine->SetShowNotificationCallback(showNotificationCallback);
+ engine->get()->SetShowNotificationCallback(showNotificationCallback);
}
CATCH_AND_THROW(env)
}
static void JNICALL JniRemoveShowNotificationCallback(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
try
{
- engine->RemoveShowNotificationCallback();
+ engine->get()->RemoveShowNotificationCallback();
}
CATCH_AND_THROW(env);
}
static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
try
{
- std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->GetListedSubscriptions();
+ std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->get()->GetListedSubscriptions();
return SubscriptionsToArrayList(env, subscriptions);
}
@@ -173,11 +194,11 @@ static jobject JNICALL JniGetListedSubscriptions(JNIEnv* env, jclass clazz, jlon
static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
try
{
- std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->FetchAvailableSubscriptions();
+ std::vector<AdblockPlus::SubscriptionPtr> subscriptions = engine->get()->FetchAvailableSubscriptions();
return SubscriptionsToArrayList(env, subscriptions);
}
@@ -187,11 +208,11 @@ static jobject JNICALL JniFetchAvailableSubscriptions(JNIEnv* env, jclass clazz,
static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
jlong ptr)
{
- AdblockPlus::FilterEngine* const engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
try
{
- engine->RemoveUpdateAvailableCallback();
+ engine->get()->RemoveUpdateAvailableCallback();
}
CATCH_AND_THROW(env)
}
@@ -199,8 +220,8 @@ static void JNICALL JniRemoveUpdateAvailableCallback(JNIEnv* env, jclass clazz,
static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
jlong ptr, jlong callbackPtr)
{
- AdblockPlus::FilterEngine* const engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
JniUpdateAvailableCallback* const callback =
JniLongToTypePtr<JniUpdateAvailableCallback>(callbackPtr);
AdblockPlus::FilterEngine::UpdateAvailableCallback updateAvailableCallback =
@@ -208,18 +229,18 @@ static void JNICALL JniSetUpdateAvailableCallback(JNIEnv* env, jclass clazz,
std::placeholders::_1);
try
{
- engine->SetUpdateAvailableCallback(updateAvailableCallback);
+ engine->get()->SetUpdateAvailableCallback(updateAvailableCallback);
}
CATCH_AND_THROW(env)
}
static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
try
{
- engine->RemoveFilterChangeCallback();
+ engine->get()->RemoveFilterChangeCallback();
}
CATCH_AND_THROW(env)
}
@@ -227,8 +248,8 @@ static void JNICALL JniRemoveFilterChangeCallback(JNIEnv* env, jclass clazz, jlo
static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
jlong ptr, jlong filterPtr)
{
- AdblockPlus::FilterEngine* engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
JniFilterChangeCallback* callback = JniLongToTypePtr<JniFilterChangeCallback>(
filterPtr);
@@ -238,14 +259,14 @@ static void JNICALL JniSetFilterChangeCallback(JNIEnv* env, jclass clazz,
try
{
- engine->SetFilterChangeCallback(filterCallback);
+ engine->get()->SetFilterChangeCallback(filterCallback);
}
CATCH_AND_THROW(env)
}
static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jlong updaterPtr)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
JniUpdateCheckDoneCallback* callback =
JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
@@ -261,7 +282,7 @@ static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
try
{
- engine->ForceUpdateCheck(updateCheckDoneCallback);
+ engine->get()->ForceUpdateCheck(updateCheckDoneCallback);
}
CATCH_AND_THROW(env)
}
@@ -269,14 +290,14 @@ static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jl
static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
jlong ptr, jstring jDomain)
{
- AdblockPlus::FilterEngine* engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string domain = JniJavaToStdString(env, jDomain);
try
{
- std::vector<std::string> selectors = engine->GetElementHidingSelectors(
+ std::vector<std::string> selectors = engine->get()->GetElementHidingSelectors(
domain);
jobject list = NewJniArrayList(env);
@@ -295,7 +316,7 @@ static jobject JNICALL JniGetElementHidingSelectors(JNIEnv* env, jclass clazz,
static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
AdblockPlus::FilterEngine::ContentType contentType =
@@ -304,7 +325,7 @@ static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring
try
{
- AdblockPlus::FilterPtr filter = engine->Matches(url, contentType, documentUrl);
+ AdblockPlus::FilterPtr filter = engine->get()->Matches(url, contentType, documentUrl);
return NewJniFilter(env, filter);
}
@@ -332,8 +353,8 @@ static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray,
static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
{
- AdblockPlus::FilterEngine* engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
AdblockPlus::FilterEngine::ContentType contentType =
@@ -344,7 +365,7 @@ static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
try
{
- AdblockPlus::FilterPtr filter = engine->Matches(url, contentType,
+ AdblockPlus::FilterPtr filter = engine->get()->Matches(url, contentType,
documentUrls);
return NewJniFilter(env, filter);
@@ -355,15 +376,15 @@ static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlong ptr,
jstring jUrl, jobjectArray jDocumentUrls)
{
- AdblockPlus::FilterEngine* engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
std::vector<std::string> documentUrls;
JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
try
{
- return engine->IsDocumentWhitelisted(url, documentUrls) ?
+ return engine->get()->IsDocumentWhitelisted(url, documentUrls) ?
JNI_TRUE : JNI_FALSE;
}
CATCH_THROW_AND_RETURN(env, JNI_FALSE)
@@ -372,15 +393,15 @@ static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlon
static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlong ptr,
jstring jUrl, jobjectArray jDocumentUrls)
{
- AdblockPlus::FilterEngine* engine =
- JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
std::vector<std::string> documentUrls;
JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
try
{
- return engine->IsElemhideWhitelisted(url, documentUrls) ?
+ return engine->get()->IsElemhideWhitelisted(url, documentUrls) ?
JNI_TRUE : JNI_FALSE;
}
CATCH_THROW_AND_RETURN(env, JNI_FALSE)
@@ -388,13 +409,13 @@ static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlon
static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngine > (ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string pref = JniJavaToStdString(env, jPref);
try
{
- AdblockPlus::JsValuePtr value = engine->GetPref(pref);
+ AdblockPlus::JsValuePtr value = engine->get()->GetPref(pref);
return NewJniJsValue(env, value);
}
@@ -403,14 +424,14 @@ static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring
static void JNICALL JniSetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref, jlong jsValue)
{
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string pref = JniJavaToStdString(env, jPref);
AdblockPlus::JsValuePtr value = JniGetJsValuePtr(jsValue);
try
{
- engine->SetPref(pref, value);
+ engine->get()->SetPref(pref, value);
}
CATCH_AND_THROW(env)
}
@@ -422,21 +443,56 @@ static jstring JNICALL JniGetHostFromURL(JNIEnv* env, jclass clazz, jlong ptr, j
return NULL;
}
- AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
std::string url = JniJavaToStdString(env, jurl);
try
{
- std::string host = engine->GetHostFromURL(url);
+ std::string host = engine->get()->GetHostFromURL(url);
return JniStdStringToJava(env, host);
}
CATCH_THROW_AND_RETURN(env, 0)
}
+static void JNICALL JniSetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr, jstring jvalue)
+{
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
+
+ const std::string* value = NULL;
+ if (jvalue != NULL)
+ {
+ std::string stdValue = JniJavaToStdString(env, jvalue);
+ value = &stdValue;
sergei 2017/03/15 13:41:48 here is a bug: you assign a pointer to stdValue wh
+ }
+
+ try
+ {
+ engine->get()->SetAllowedConnectionType(value);
+ }
+ CATCH_AND_THROW(env)
+}
+
+static jstring JNICALL JniGetAllowedConnectionType(JNIEnv* env, jclass clazz, jlong ptr)
+{
+ try
+ {
+ AdblockPlus::FilterEnginePtr* engine = JniLongToTypePtr<AdblockPlus::FilterEnginePtr>(ptr);
+ std::unique_ptr<std::string> value = engine->get()->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 +515,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 }
};

Powered by Google App Engine
This is Rietveld