Index: jni/JniWebRequest.cpp |
diff --git a/jni/JniWebRequest.cpp b/jni/JniWebRequest.cpp |
index a479301fcd31a8fceba2cccf4699c3ed108ef4a2..e704d4cc56f1712a01e9176656114fc0dda553e4 100644 |
--- a/jni/JniWebRequest.cpp |
+++ b/jni/JniWebRequest.cpp |
@@ -38,32 +38,44 @@ JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject) |
{ |
} |
-AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const |
+AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, |
+ const AdblockPlus::HeaderList& requestHeaders) const |
{ |
JNIEnvAcquire env(GetJavaVM()); |
- jclass clazz = env->GetObjectClass(GetCallbackObject()); |
- jmethodID method = env->GetMethodID(clazz, "httpGET", "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse")); |
+ jmethodID method = env->GetMethodID( |
+ *JniLocalReference<jclass>(*env, |
+ env->GetObjectClass(GetCallbackObject())), "httpGET", |
Felix Dahlke
2015/02/04 04:11:51
Since you changed this in JniUpdateAvailableCallba
René Jeschke
2015/02/04 12:02:47
Done.
|
+ "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse")); |
AdblockPlus::ServerResponse sResponse; |
sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; |
if (method) |
{ |
- jobject arrayList = NewJniArrayList(*env); |
+ JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env)); |
- for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), end = requestHeaders.end(); it != end; it++) |
+ for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), |
+ end = requestHeaders.end(); it != end; it++) |
{ |
- JniAddObjectToList(*env, arrayList, NewTuple(*env, it->first, it->second)); |
+ JniLocalReference<jobject> tuple(*env, |
+ NewTuple(*env, it->first, it->second)); |
+ JniAddObjectToList(*env, *arrayList, *tuple); |
} |
- jobject response = env->CallObjectMethod(GetCallbackObject(), method, env->NewStringUTF(url.c_str()), arrayList); |
+ JniLocalReference<jobject> response(*env, |
+ env->CallObjectMethod(GetCallbackObject(), method, |
+ *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())), |
+ *arrayList)); |
if (!env->ExceptionCheck()) |
{ |
- sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), response, "status"); |
- sResponse.responseStatus = JniGetIntField(*env, serverResponseClass->Get(), response, "responseStatus"); |
- sResponse.responseText = JniGetStringField(*env, serverResponseClass->Get(), response, "response"); |
+ sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), |
+ *response, "status"); |
+ sResponse.responseStatus = JniGetIntField(*env, |
+ serverResponseClass->Get(), *response, "responseStatus"); |
+ sResponse.responseText = JniGetStringField(*env, |
+ serverResponseClass->Get(), *response, "response"); |
// TODO: transform Headers |
} |
} |
@@ -73,10 +85,16 @@ AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, const Adb |
return sResponse; |
} |
-jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, const std::string& b) const |
+jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, |
+ const std::string& b) const |
{ |
- jmethodID factory = env->GetMethodID(tupleClass->Get(), "<init>", "(Ljava/lang/String;Ljava/lang/String;)V"); |
- return env->NewObject(tupleClass->Get(), factory, env->NewStringUTF(a.c_str()), env->NewStringUTF(b.c_str())); |
+ jmethodID factory = env->GetMethodID(tupleClass->Get(), "<init>", |
+ "(Ljava/lang/String;Ljava/lang/String;)V"); |
+ |
+ JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str())); |
+ JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str())); |
+ |
+ return env->NewObject(tupleClass->Get(), factory, *strA, *strB); |
} |
static JNINativeMethod methods[] = |