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

Unified Diff: jni/JniFilterEngine.cpp

Issue 29331923: Issue 3364 - Implement JNI bindings for IsDocument/ElemhideWhitelisted (Closed)
Patch Set: Typo Created Dec. 4, 2015, 5:44 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
« no previous file with comments | « dependencies ('k') | src/org/adblockplus/android/ABPEngine.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/JniFilterEngine.cpp
diff --git a/jni/JniFilterEngine.cpp b/jni/JniFilterEngine.cpp
index b225245aed05e59bee9667fe3f77b8348d92263b..2b76121e20ffd297f790360ed49659044334cdcd 100644
--- a/jni/JniFilterEngine.cpp
+++ b/jni/JniFilterEngine.cpp
@@ -311,6 +311,24 @@ static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring
CATCH_THROW_AND_RETURN(env, 0)
}
+static void JavaStringArrayToStringVector(JNIEnv* env, jobjectArray jArray,
+ std::vector<std::string>& out)
+{
+ if (jArray)
+ {
+ jsize len = env->GetArrayLength(jArray);
+
+ for (jsize i = 0; i < len; i++)
+ {
+ out.push_back(
+ JniJavaToStdString(env,
+ *JniLocalReference<jstring>(env,
+ static_cast<jstring>(
+ env->GetObjectArrayElement(jArray, i)))));
+ }
+ }
+}
+
static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
{
@@ -322,17 +340,7 @@ static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
ConvertContentType(env, jContentType);
std::vector<std::string> documentUrls;
-
- jsize len = env->GetArrayLength(jDocumentUrls);
-
- for (jsize i = 0; i < len; i++)
- {
- documentUrls.push_back(
- JniJavaToStdString(env,
- *JniLocalReference<jstring>(env,
- static_cast<jstring>(env->GetObjectArrayElement(jDocumentUrls,
- i)))));
- }
+ JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
try
{
@@ -344,6 +352,40 @@ static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr,
CATCH_THROW_AND_RETURN(env, 0)
}
+static jboolean JNICALL JniIsDocumentWhitelisted(JNIEnv* env, jclass clazz, jlong ptr,
+ jstring jUrl, jobjectArray jDocumentUrls)
+{
+ AdblockPlus::FilterEngine* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+
+ std::string url = JniJavaToStdString(env, jUrl);
+ std::vector<std::string> documentUrls;
+ JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
+ try
+ {
+ return engine->IsDocumentWhitelisted(url, documentUrls) ?
+ JNI_TRUE : JNI_FALSE;
+ }
+ CATCH_THROW_AND_RETURN(env, JNI_FALSE)
+}
+
+static jboolean JNICALL JniIsElemhideWhitelisted(JNIEnv* env, jclass clazz, jlong ptr,
+ jstring jUrl, jobjectArray jDocumentUrls)
+{
+ AdblockPlus::FilterEngine* engine =
+ JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
+
+ std::string url = JniJavaToStdString(env, jUrl);
+ std::vector<std::string> documentUrls;
+ JavaStringArrayToStringVector(env, jDocumentUrls, documentUrls);
+ try
+ {
+ return engine->IsElemhideWhitelisted(url, documentUrls) ?
+ JNI_TRUE : JNI_FALSE;
+ }
+ CATCH_THROW_AND_RETURN(env, JNI_FALSE)
+}
+
static jobject JNICALL JniGetPref(JNIEnv* env, jclass clazz, jlong ptr, jstring jPref)
{
AdblockPlus::FilterEngine* engine = JniLongToTypePtr < AdblockPlus::FilterEngine > (ptr);
@@ -393,6 +435,8 @@ static JNINativeMethod methods[] =
{ (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/List;", (void*)JniGetElementHidingSelectors },
{ (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentType") "Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches },
{ (char*)"matches", (char*)"(JLjava/lang/String;" TYP("FilterEngine$ContentType") "[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
+ { (char*)"isDocumentWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/String;)Z", (void*)JniIsDocumentWhitelisted },
+ { (char*)"isElemhideWhitelisted", (char*)"(JLjava/lang/String;[Ljava/lang/String;)Z", (void*)JniIsElemhideWhitelisted },
{ (char*)"getPref", (char*)"(JLjava/lang/String;)" TYP("JsValue"), (void*)JniGetPref },
{ (char*)"setPref", (char*)"(JLjava/lang/String;J)V", (void*)JniSetPref },
{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
« no previous file with comments | « dependencies ('k') | src/org/adblockplus/android/ABPEngine.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld