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

Unified Diff: jni/JniFilterEngine.cpp

Issue 6245218638626816: Issue 1424 - Update libadblockplus-binaries to 6f79af14ad4e (Closed)
Patch Set: Created Sept. 22, 2014, 4:44 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
« no previous file with comments | « jni/JniCallbacks.h ('k') | jni/JniUpdateCheckDoneCallback.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: jni/JniFilterEngine.cpp
===================================================================
--- a/jni/JniFilterEngine.cpp
+++ b/jni/JniFilterEngine.cpp
@@ -31,6 +31,17 @@
return list;
}
+static AdblockPlus::FilterEngine::ContentType ConvertContentType(JNIEnv *env,
+ jobject jContentType)
+{
+ jclass enumClass = env->FindClass("java/lang/Enum");
René Jeschke 2014/09/22 12:56:26 Could you please use "env->GetObjectClass(jContent
Felix Dahlke 2014/09/22 13:20:16 Done.
+ jmethodID nameMethod = env->GetMethodID(enumClass, "name",
René Jeschke 2014/09/22 12:56:26 Is this line break really necessary?
Felix Dahlke 2014/09/22 13:20:16 IMO yes - we have an 80 column rule in C++ code af
René Jeschke 2014/09/22 13:30:06 Ah, right. The Android project can be confusing wh
+ "()Ljava/lang/String;");
+ jstring jValue = (jstring) env->CallObjectMethod(jContentType, nameMethod);
+ const std::string value = JniJavaToStdString(env, jValue);
+ return AdblockPlus::FilterEngine::StringToContentType(value);
+}
+
static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jlong enginePtr)
{
try
@@ -160,18 +171,22 @@
static void JNICALL JniForceUpdateCheck(JNIEnv* env, jclass clazz, jlong ptr, jlong updaterPtr)
{
AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
- JniUpdaterCallback* callback = JniLongToTypePtr<JniUpdaterCallback>(updaterPtr);
+ JniUpdateCheckDoneCallback* callback =
René Jeschke 2014/09/22 12:56:26 Are those new line breaks really needed? (See also
Felix Dahlke 2014/09/22 13:20:16 IMO yes, see above.
+ JniLongToTypePtr<JniUpdateCheckDoneCallback>(updaterPtr);
- AdblockPlus::FilterEngine::UpdaterCallback updaterCallback = 0;
+ AdblockPlus::FilterEngine::UpdateCheckDoneCallback
+ updateCheckDoneCallback = 0;
if (updaterPtr)
{
- updaterCallback = std::tr1::bind(&JniUpdaterCallback::Callback, callback, std::tr1::placeholders::_1);
+ updateCheckDoneCallback =
+ std::tr1::bind(&JniUpdateCheckDoneCallback::Callback, callback,
+ std::tr1::placeholders::_1);
}
try
{
- engine->ForceUpdateCheck(updaterCallback);
+ engine->ForceUpdateCheck(updateCheckDoneCallback);
}
CATCH_AND_THROW(env)
}
@@ -198,12 +213,13 @@
CATCH_THROW_AND_RETURN(env, 0)
}
-static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jstring jContentType, jstring jDocumentUrl)
+static jobject JNICALL JniMatches(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jstring jDocumentUrl)
{
AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
- std::string contentType = JniJavaToStdString(env, jContentType);
+ AdblockPlus::FilterEngine::ContentType contentType =
+ ConvertContentType(env, jContentType);
std::string documentUrl = JniJavaToStdString(env, jDocumentUrl);
try
@@ -215,12 +231,13 @@
CATCH_THROW_AND_RETURN(env, 0)
}
-static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jstring jContentType, jobjectArray jDocumentUrls)
+static jobject JNICALL JniMatchesMany(JNIEnv* env, jclass clazz, jlong ptr, jstring jUrl, jobject jContentType, jobjectArray jDocumentUrls)
{
AdblockPlus::FilterEngine* engine = JniLongToTypePtr<AdblockPlus::FilterEngine>(ptr);
std::string url = JniJavaToStdString(env, jUrl);
- std::string contentType = JniJavaToStdString(env, jContentType);
+ AdblockPlus::FilterEngine::ContentType contentType =
+ ConvertContentType(env, jContentType);
std::vector<std::string> documentUrls;
@@ -282,8 +299,8 @@
{ (char*)"removeFilterChangeCallback", (char*)"(J)V", (void*)JniRemoveFilterChangeCallback },
{ (char*)"forceUpdateCheck", (char*)"(JJ)V", (void*)JniForceUpdateCheck },
{ (char*)"getElementHidingSelectors", (char*)"(JLjava/lang/String;)Ljava/util/List;", (void*)JniGetElementHidingSelectors },
- { (char*)"matches", (char*)"(JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)" TYP("Filter"), (void*)JniMatches },
- { (char*)"matches", (char*)"(JLjava/lang/String;Ljava/lang/String;[Ljava/lang/String;)" TYP("Filter"), (void*)JniMatchesMany },
+ { (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*)"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 | « jni/JniCallbacks.h ('k') | jni/JniUpdateCheckDoneCallback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld