| Left: | ||
| Right: |
| 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 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 *JniLocalReference<jclass>(*env, | 72 *JniLocalReference<jclass>(*env, |
| 73 env->GetObjectClass(GetCallbackObject())), | 73 env->GetObjectClass(GetCallbackObject())), |
| 74 "httpGET", | 74 "httpGET", |
| 75 "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse")); | 75 "(Ljava/lang/String;Ljava/util/List;)" TYP("ServerResponse")); |
| 76 | 76 |
| 77 AdblockPlus::ServerResponse sResponse; | 77 AdblockPlus::ServerResponse sResponse; |
| 78 sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; | 78 sResponse.status = AdblockPlus::WebRequest::NS_ERROR_FAILURE; |
| 79 | 79 |
| 80 if (method) | 80 if (method) |
| 81 { | 81 { |
| 82 JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env)); | 82 JniLocalReference<jobject> arrayList(*env, NewJniArrayList(*env)); |
|
anton
2016/09/23 13:05:25
Consider using LinkedList instead of ArrayList - f
diegocarloslima
2016/11/04 11:34:19
Yeah, LinkedList are better for insertion while Ar
| |
| 83 jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList); | 83 jmethodID addMethod = JniGetAddToListMethod(*env, *arrayList); |
|
anton
2016/09/23 13:05:25
Now searching for the method once
| |
| 84 | 84 |
| 85 for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), | 85 for (AdblockPlus::HeaderList::const_iterator it = requestHeaders.begin(), |
| 86 end = requestHeaders.end(); it != end; it++) | 86 end = requestHeaders.end(); it != end; it++) |
| 87 { | 87 { |
| 88 JniLocalReference<jobject> headerEntry(*env, NewHeaderEntry(*env, it->firs t, it->second)); | 88 JniLocalReference<jobject> headerEntry(*env, NewTuple(*env, it->first, it- >second)); |
| 89 JniAddObjectToList(*env, *arrayList, addMethod, *headerEntry); | 89 JniAddObjectToList(*env, *arrayList, addMethod, *headerEntry); |
| 90 } | 90 } |
| 91 | 91 |
| 92 JniLocalReference<jobject> response(*env, | 92 JniLocalReference<jobject> response(*env, |
| 93 env->CallObjectMethod(GetCallbackObject(), method, | 93 env->CallObjectMethod(GetCallbackObject(), method, |
| 94 *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())), | 94 *JniLocalReference<jstring>(*env, env->NewStringUTF(url.c_str())), |
| 95 *arrayList)); | 95 *arrayList)); |
| 96 | 96 |
| 97 if (!env->ExceptionCheck()) | 97 if (!env->ExceptionCheck()) |
| 98 { | 98 { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 CheckAndLogJavaException(*env); | 134 CheckAndLogJavaException(*env); |
| 135 | 135 |
| 136 return sResponse; | 136 return sResponse; |
| 137 } | 137 } |
| 138 | 138 |
| 139 jobject JniWebRequest::NewHeaderEntry(JNIEnv* env, const std::string& a, | 139 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, |
| 140 const std::string& b) const | 140 const std::string& b) const |
| 141 { | 141 { |
| 142 jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>", | 142 jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>", |
| 143 "(Ljava/lang/String;Ljava/lang/String;)V"); | 143 "(Ljava/lang/String;Ljava/lang/String;)V"); |
| 144 | 144 |
| 145 JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str())); | 145 JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str())); |
| 146 JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str())); | 146 JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str())); |
| 147 | 147 |
| 148 return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB); | 148 return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB); |
| 149 } | 149 } |
| 150 | 150 |
| 151 static JNINativeMethod methods[] = | 151 static JNINativeMethod methods[] = |
| 152 { | 152 { |
| 153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
| 154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz) | 157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest _registerNatives(JNIEnv *env, jclass clazz) |
| 158 { | 158 { |
| 159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
| 160 } | 160 } |
| LEFT | RIGHT |