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

Side by Side Diff: libadblockplus-android/jni/JniWebRequest.cpp

Issue 29345369: Issue 4081 - Fix failing MockWebRequestTest test for libadblockplus-android (Closed)
Patch Set: reverting changes to .hgignore Created Sept. 13, 2016, 10: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 | « .hgignore ('k') | libadblockplus-android/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 <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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 *arrayList)); 71 *arrayList));
71 72
72 if (!env->ExceptionCheck()) 73 if (!env->ExceptionCheck())
73 { 74 {
74 sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), 75 sResponse.status = JniGetLongField(*env, serverResponseClass->Get(),
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 // TODO: transform Headers 81
82 // map headers
83 jobjectArray responseHeadersArray = JniGetStringArrayField(*env,
84 serverResponseClass->Get(), *response, "headers");
85
86 if (responseHeadersArray)
87 {
88 int itemsCount = env->GetArrayLength(responseHeadersArray) / 2;
89 for (int i = 0; i < itemsCount; i++)
90 {
91 jstring jKey = (jstring)env->GetObjectArrayElement(responseHeadersArra y, i * 2);
92 std::string stdKey = JniJavaToStdString(*env, jKey);
93
94 jstring jValue = (jstring)env->GetObjectArrayElement(responseHeadersAr ray, i * 2 + 1);
95 std::string stdValue = JniJavaToStdString(*env, jValue);
96
97 std::pair<std::string,std::string> keyValue(stdKey, stdValue);
98 sResponse.responseHeaders.push_back(keyValue);
99 }
100 }
81 } 101 }
82 } 102 }
83 103
84 CheckAndLogJavaException(*env); 104 CheckAndLogJavaException(*env);
85 105
86 return sResponse; 106 return sResponse;
87 } 107 }
88 108
89 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, 109 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a,
90 const std::string& b) const 110 const std::string& b) const
(...skipping 10 matching lines...) Expand all
101 static JNINativeMethod methods[] = 121 static JNINativeMethod methods[] =
102 { 122 {
103 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, 123 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor },
104 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } 124 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor }
105 }; 125 };
106 126
107 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)
108 { 128 {
109 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); 129 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0]));
110 } 130 }
OLDNEW
« no previous file with comments | « .hgignore ('k') | libadblockplus-android/jni/Utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld