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

Unified Diff: jni/JniJsEngine.cpp

Issue 6606493159784448: New JNI bindings (Closed)
Patch Set: Style review fixes Created March 28, 2014, 11 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: jni/JniJsEngine.cpp
diff --git a/jni/JniJsEngine.cpp b/jni/JniJsEngine.cpp
index 59a4a9efbac1147b1f95e1c05f056fda9453d49a..f4b94836e68be8445047746e29b64424e7b6689f 100644
--- a/jni/JniJsEngine.cpp
+++ b/jni/JniJsEngine.cpp
@@ -23,14 +23,14 @@ static void TransformAppInfo(JNIEnv* env, jobject jAppInfo, AdblockPlus::AppInfo
{
jclass clazz = env->GetObjectClass(jAppInfo);
- appInfo.application = AdblockPlus::Android::JniGetStringField(env, clazz, jAppInfo, "application");
- appInfo.applicationVersion = AdblockPlus::Android::JniGetStringField(env, clazz, jAppInfo, "applicationVersion");
- appInfo.id = AdblockPlus::Android::JniGetStringField(env, clazz, jAppInfo, "id");
- appInfo.locale = AdblockPlus::Android::JniGetStringField(env, clazz, jAppInfo, "locale");
- appInfo.name = AdblockPlus::Android::JniGetStringField(env, clazz, jAppInfo, "name");
- appInfo.version = AdblockPlus::Android::JniGetStringField(env, clazz, jAppInfo, "version");
-
- appInfo.developmentBuild = AdblockPlus::Android::JniGetBooleanField(env, clazz, jAppInfo, "developmentBuild");
+ appInfo.application = JniGetStringField(env, clazz, jAppInfo, "application");
+ appInfo.applicationVersion = JniGetStringField(env, clazz, jAppInfo, "applicationVersion");
+ appInfo.id = JniGetStringField(env, clazz, jAppInfo, "id");
+ appInfo.locale = JniGetStringField(env, clazz, jAppInfo, "locale");
+ appInfo.name = JniGetStringField(env, clazz, jAppInfo, "name");
+ appInfo.version = JniGetStringField(env, clazz, jAppInfo, "version");
+
+ appInfo.developmentBuild = JniGetBooleanField(env, clazz, jAppInfo, "developmentBuild");
}
static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo)
@@ -41,25 +41,23 @@ static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject jAppInfo)
TRY
{
- return AdblockPlus::Android::JniPtr2Long(new AdblockPlus::JsEnginePtr(AdblockPlus::JsEngine::New(appInfo)));
+ return JniPtrToLong(new AdblockPlus::JsEnginePtr(AdblockPlus::JsEngine::New(appInfo)));
}
CATCH_THROW_AND_RETURN(env, 0)
}
static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
{
- delete AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ delete JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
}
static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName, jlong jCallbackPtr)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
- AdblockPlus::Android::JniEventCallback* callback = AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::Android::JniEventCallback>(
- jCallbackPtr);
- std::string eventName = AdblockPlus::Android::JniJava2StdString(env, jEventName);
- AdblockPlus::JsEngine::EventCallback eCallback = std::tr1::bind(&AdblockPlus::Android::JniEventCallback::Callback, callback,
- std::tr1::placeholders::_1);
+ JniEventCallback* callback = JniLongToTypePtr<JniEventCallback>(jCallbackPtr);
+ std::string eventName = JniJava2StdString(env, jEventName);
Felix Dahlke 2014/03/28 11:27:18 Would also prefer a s/2/To/ for this function.
+ AdblockPlus::JsEngine::EventCallback eCallback = std::tr1::bind(&JniEventCallback::Callback, callback, std::tr1::placeholders::_1);
TRY
{
@@ -70,9 +68,9 @@ static void JNICALL JniSetEventCallback(JNIEnv* env, jclass clazz, jlong ptr, js
static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
- std::string eventName = AdblockPlus::Android::JniJava2StdString(env, jEventName);
+ std::string eventName = JniJava2StdString(env, jEventName);
TRY
{
@@ -83,23 +81,23 @@ static void JNICALL JniRemoveEventCallback(JNIEnv* env, jclass clazz, jlong ptr,
static jobject JNICALL JniEvaluate(JNIEnv* env, jclass clazz, jlong ptr, jstring jSource, jstring jFilename)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
- std::string source = AdblockPlus::Android::JniJava2StdString(env, jSource);
- std::string filename = AdblockPlus::Android::JniJava2StdString(env, jFilename);
+ std::string source = JniJava2StdString(env, jSource);
+ std::string filename = JniJava2StdString(env, jFilename);
TRY
{
AdblockPlus::JsValuePtr jsValue = engine->Evaluate(source, filename);
- return AdblockPlus::Android::NewJniJsValue(env, jsValue);
+ return NewJniJsValue(env, jsValue);
}
CATCH_THROW_AND_RETURN(env, 0)
}
static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstring jEventName, jarray jJsPtrs)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
- std::string eventName = AdblockPlus::Android::JniJava2StdString(env, jEventName);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ std::string eventName = JniJava2StdString(env, jEventName);
AdblockPlus::JsValueList args;
if (jJsPtrs)
@@ -110,7 +108,7 @@ static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstrin
for (jsize i = 0; i < length; i++)
{
- args.push_back(AdblockPlus::Android::JniGetJsValuePtr(ptrs[i]));
+ args.push_back(JniGetJsValuePtr(ptrs[i]));
}
env->ReleasePrimitiveArrayCritical(jJsPtrs, ptrs, JNI_ABORT);
@@ -125,13 +123,13 @@ static void JNICALL JniTriggerEvent(JNIEnv* env, jclass clazz, jlong ptr, jstrin
static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr, jstring jBasePath)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());
- std::string basePath = AdblockPlus::Android::JniJava2StdString(env, jBasePath);
+ std::string basePath = JniJava2StdString(env, jBasePath);
reinterpret_cast<AdblockPlus::DefaultFileSystem*>(fileSystem.get())->SetBasePath(basePath);
engine->SetFileSystem(fileSystem);
@@ -141,7 +139,7 @@ static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr
static void JNICALL JniSetDefaultWebRequest(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
@@ -154,7 +152,7 @@ static void JNICALL JniSetDefaultWebRequest(JNIEnv* env, jclass clazz, jlong ptr
static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
@@ -167,11 +165,11 @@ static void JNICALL JniSetDefaultLogSystem(JNIEnv* env, jclass clazz, jlong ptr)
static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong logSystemPtr)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
- AdblockPlus::LogSystemPtr logSystem(AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::Android::JniLogSystemCallback>(logSystemPtr));
+ AdblockPlus::LogSystemPtr logSystem(JniLongToTypePtr<JniLogSystemCallback>(logSystemPtr));
engine->SetLogSystem(logSystem);
}
@@ -180,11 +178,11 @@ static void JNICALL JniSetLogSystem(JNIEnv* env, jclass clazz, jlong ptr, jlong
static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong webRequestPtr)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
- AdblockPlus::WebRequestPtr& webRequest = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::WebRequestPtr>(webRequestPtr);
+ AdblockPlus::WebRequestPtr& webRequest = *JniLongToTypePtr<AdblockPlus::WebRequestPtr>(webRequestPtr);
engine->SetWebRequest(webRequest);
}
@@ -193,37 +191,37 @@ static void JNICALL JniSetWebRequest(JNIEnv* env, jclass clazz, jlong ptr, jlong
static jobject JNICALL JniNewLongValue(JNIEnv* env, jclass clazz, jlong ptr, jlong value)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
AdblockPlus::JsValuePtr jsValue = engine->NewValue(static_cast<int64_t>(value));
- return AdblockPlus::Android::NewJniJsValue(env, jsValue);
+ return NewJniJsValue(env, jsValue);
}
CATCH_THROW_AND_RETURN(env, 0)
}
static jobject JNICALL JniNewBooleanValue(JNIEnv* env, jclass clazz, jlong ptr, jboolean value)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
AdblockPlus::JsValuePtr jsValue = engine->NewValue(value == JNI_TRUE ? true : false);
- return AdblockPlus::Android::NewJniJsValue(env, jsValue);
+ return NewJniJsValue(env, jsValue);
}
CATCH_THROW_AND_RETURN(env, 0)
}
static jobject JNICALL JniNewStringValue(JNIEnv* env, jclass clazz, jlong ptr, jstring value)
{
- AdblockPlus::JsEnginePtr& engine = *AdblockPlus::Android::JniLong2TypePtr<AdblockPlus::JsEnginePtr>(ptr);
+ AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);
TRY
{
- std::string strValue = AdblockPlus::Android::JniJava2StdString(env, value);
+ std::string strValue = JniJava2StdString(env, value);
AdblockPlus::JsValuePtr jsValue = engine->NewValue(strValue);
- return AdblockPlus::Android::NewJniJsValue(env, jsValue);
+ return NewJniJsValue(env, jsValue);
}
CATCH_THROW_AND_RETURN(env, 0)
}
@@ -235,25 +233,24 @@ static jobject JNICALL JniNewStringValue(JNIEnv* env, jclass clazz, jlong ptr, j
static JNINativeMethod methods[] =
{
-{ (char*)"ctor", (char*)"(" TYP("AppInfo") ")J", (void*)JniCtor },
-{ (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
+ { (char*)"ctor", (char*)"(" TYP("AppInfo") ")J", (void*)JniCtor },
+ { (char*)"dtor", (char*)"(J)V", (void*)JniDtor },
-{ (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEventCallback },
-{ (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRemoveEventCallback },
-{ (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerEvent },
+ { (char*)"setEventCallback", (char*)"(JLjava/lang/String;J)V", (void*)JniSetEventCallback },
+ { (char*)"removeEventCallback", (char*)"(JLjava/lang/String;)V", (void*)JniRemoveEventCallback },
+ { (char*)"triggerEvent", (char*)"(JLjava/lang/String;[J)V", (void*)JniTriggerEvent },
-{ (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsValue"), (void*)JniEvaluate },
+ { (char*)"evaluate", (char*)"(JLjava/lang/String;Ljava/lang/String;)" TYP("JsValue"), (void*)JniEvaluate },
-{ (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSetDefaultFileSystem },
-{ (char*)"setLogSystem", (char*)"(JJ)V", (void*)JniSetLogSystem },
-{ (char*)"setDefaultLogSystem", (char*)"(J)V", (void*)JniSetDefaultLogSystem },
-{ (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest },
-{ (char*)"setDefaultWebRequest", (char*)"(J)V", (void*)JniSetDefaultWebRequest },
-
-{ (char*)"newValue", (char*)"(JJ)"TYP("JsValue"), (void*)JniNewLongValue },
-{ (char*)"newValue", (char*)"(JZ)"TYP("JsValue"), (void*)JniNewBooleanValue },
-{ (char*)"newValue", (char*)"(JLjava/lang/String;)"TYP("JsValue"), (void*)JniNewStringValue },
+ { (char*)"setDefaultFileSystem", (char*)"(JLjava/lang/String;)V", (void*)JniSetDefaultFileSystem },
+ { (char*)"setLogSystem", (char*)"(JJ)V", (void*)JniSetLogSystem },
+ { (char*)"setDefaultLogSystem", (char*)"(J)V", (void*)JniSetDefaultLogSystem },
+ { (char*)"setWebRequest", (char*)"(JJ)V", (void*)JniSetWebRequest },
+ { (char*)"setDefaultWebRequest", (char*)"(J)V", (void*)JniSetDefaultWebRequest },
+ { (char*)"newValue", (char*)"(JJ)"TYP("JsValue"), (void*)JniNewLongValue },
+ { (char*)"newValue", (char*)"(JZ)"TYP("JsValue"), (void*)JniNewBooleanValue },
+ { (char*)"newValue", (char*)"(JLjava/lang/String;)"TYP("JsValue"), (void*)JniNewStringValue }
};
extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_android_api_JsEngine_registerNatives(JNIEnv *env, jclass clazz)

Powered by Google App Engine
This is Rietveld