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

Side by Side Diff: jni/JniWebRequest.cpp

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Patch Set: Addressed new review issues Created April 28, 2014, 8:34 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « jni/JniLogSystem.cpp ('k') | jni/Utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 CATCH_THROW_AND_RETURN(env, 0) 26 CATCH_THROW_AND_RETURN(env, 0)
27 } 27 }
28 28
29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) 29 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr)
30 { 30 {
31 delete JniLongToTypePtr<AdblockPlus::WebRequestPtr>(ptr); 31 delete JniLongToTypePtr<AdblockPlus::WebRequestPtr>(ptr);
32 } 32 }
33 33
34 JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject) 34 JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject)
35 : JniCallbackBase(env, callbackObject), AdblockPlus::WebRequest() 35 : JniCallbackBase(env, callbackObject), AdblockPlus::WebRequest(),
36 tupleClass(new JniGlobalReference<jclass>(env, env->FindClass(PKG("HeaderEnt ry")))),
37 serverResponseClass(new JniGlobalReference<jclass>(env, env->FindClass(PKG(" ServerResponse"))))
36 { 38 {
37 tupleClass.reset(new JniGlobalReference<jclass>(env, env->FindClass("com/githu b/rjeschke/neetutils/collections/Tuple")));
38 serverResponseClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(P KG("ServerResponse"))));
39 } 39 }
40 40
41 AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, const Adb lockPlus::HeaderList& requestHeaders) const 41 AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, const Adb lockPlus::HeaderList& requestHeaders) const
42 { 42 {
43 JNIEnvAcquire env(GetJavaVM()); 43 JNIEnvAcquire env(GetJavaVM());
44 44
45 jclass clazz = env->GetObjectClass(GetCallbackObject()); 45 jclass clazz = env->GetObjectClass(GetCallbackObject());
46 jmethodID method = env->GetMethodID(clazz, "httpGET", "(Ljava/lang/String;Ljav a/util/List;)" TYP("ServerResponse")); 46 jmethodID method = env->GetMethodID(clazz, "httpGET", "(Ljava/lang/String;Ljav a/util/List;)" TYP("ServerResponse"));
47 47
48 AdblockPlus::ServerResponse sResponse; 48 AdblockPlus::ServerResponse sResponse;
(...skipping 19 matching lines...) Expand all
68 } 68 }
69 } 69 }
70 70
71 CheckAndLogJavaException(*env); 71 CheckAndLogJavaException(*env);
72 72
73 return sResponse; 73 return sResponse;
74 } 74 }
75 75
76 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, const std::st ring& b) const 76 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, const std::st ring& b) const
77 { 77 {
78 jmethodID factory = env->GetMethodID(tupleClass->Get(), "<init>", "(Ljava/lang /Object;Ljava/lang/Object;)V"); 78 jmethodID factory = env->GetMethodID(tupleClass->Get(), "<init>", "(Ljava/lang /String;Ljava/lang/String;)V");
79 return env->NewObject(tupleClass->Get(), factory, env->NewStringUTF(a.c_str()) , env->NewStringUTF(b.c_str())); 79 return env->NewObject(tupleClass->Get(), factory, env->NewStringUTF(a.c_str()) , env->NewStringUTF(b.c_str()));
80 } 80 }
81 81
82 static JNINativeMethod methods[] = 82 static JNINativeMethod methods[] =
83 { 83 {
84 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 84 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
85 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 85 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
86 }; 86 };
87 87
88 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz) 88 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz)
89 { 89 {
90 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 90 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
91 } 91 }
OLDNEW
« no previous file with comments | « jni/JniLogSystem.cpp ('k') | jni/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld