LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "JniCallbacks.h" | 18 #include "JniCallbacks.h" |
| 19 #include "Utils.h" |
19 | 20 |
20 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) | 21 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) |
21 { | 22 { |
22 try | 23 try |
23 { | 24 { |
24 return JniPtrToLong(new AdblockPlus::WebRequestPtr(new JniWebRequest(env, ca
llbackObject))); | 25 return JniPtrToLong(new AdblockPlus::WebRequestPtr(new JniWebRequest(env, ca
llbackObject))); |
25 } | 26 } |
26 CATCH_THROW_AND_RETURN(env, 0) | 27 CATCH_THROW_AND_RETURN(env, 0) |
27 } | 28 } |
28 | 29 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 *response, "status"); | 76 *response, "status"); |
76 sResponse.responseStatus = JniGetIntField(*env, | 77 sResponse.responseStatus = JniGetIntField(*env, |
77 serverResponseClass->Get(), *response, "responseStatus"); | 78 serverResponseClass->Get(), *response, "responseStatus"); |
78 sResponse.responseText = JniGetStringField(*env, | 79 sResponse.responseText = JniGetStringField(*env, |
79 serverResponseClass->Get(), *response, "response"); | 80 serverResponseClass->Get(), *response, "response"); |
80 | 81 |
81 // map headers | 82 // map headers |
82 jobjectArray responseHeadersArray = JniGetStringArrayField(*env, | 83 jobjectArray responseHeadersArray = JniGetStringArrayField(*env, |
83 serverResponseClass->Get(), *response, "headers"); | 84 serverResponseClass->Get(), *response, "headers"); |
84 | 85 |
85 if (responseHeadersArray) { | 86 if (responseHeadersArray) |
| 87 { |
86 int itemsCount = env->GetArrayLength(responseHeadersArray) / 2; | 88 int itemsCount = env->GetArrayLength(responseHeadersArray) / 2; |
87 for (int i=0; i<itemsCount; i++) { | 89 for (int i = 0; i < itemsCount; i++) |
88 // key | 90 { |
89 jstring jKey = (jstring)env->GetObjectArrayElement(responseHeadersArra
y, i * 2); | 91 jstring jKey = (jstring)env->GetObjectArrayElement(responseHeadersArra
y, i * 2); |
90 const char *cKey = env->GetStringUTFChars(jKey, 0); | 92 std::string stdKey = JniJavaToStdString(*env, jKey); |
91 std::string stdCKey(cKey); | 93 |
92 env->ReleaseStringUTFChars(jKey, cKey); | |
93 | |
94 // value | |
95 jstring jValue = (jstring)env->GetObjectArrayElement(responseHeadersAr
ray, i * 2 + 1); | 94 jstring jValue = (jstring)env->GetObjectArrayElement(responseHeadersAr
ray, i * 2 + 1); |
96 const char *cValue = env->GetStringUTFChars(jValue, 0); | 95 std::string stdValue = JniJavaToStdString(*env, jValue); |
97 std::string stdCValue(cValue); | 96 |
98 env->ReleaseStringUTFChars(jValue, cValue); | 97 std::pair<std::string,std::string> keyValue(stdKey, stdValue); |
99 | |
100 std::pair<std::string,std::string> keyValue(stdCKey, stdCValue); | |
101 sResponse.responseHeaders.push_back(keyValue); | 98 sResponse.responseHeaders.push_back(keyValue); |
102 } | 99 } |
103 } | 100 } |
104 } | 101 } |
105 } | 102 } |
106 | 103 |
107 CheckAndLogJavaException(*env); | 104 CheckAndLogJavaException(*env); |
108 | 105 |
109 return sResponse; | 106 return sResponse; |
110 } | 107 } |
(...skipping 13 matching lines...) Expand all Loading... |
124 static JNINativeMethod methods[] = | 121 static JNINativeMethod methods[] = |
125 { | 122 { |
126 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 123 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
127 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 124 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
128 }; | 125 }; |
129 | 126 |
130 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest
_registerNatives(JNIEnv *env, jclass clazz) | 127 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest
_registerNatives(JNIEnv *env, jclass clazz) |
131 { | 128 { |
132 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 129 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
133 } | 130 } |
LEFT | RIGHT |