| OLD | NEW |
| 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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 26 matching lines...) Expand all Loading... |
| 37 headerEntryClass = NULL; | 37 headerEntryClass = NULL; |
| 38 } | 38 } |
| 39 | 39 |
| 40 if (serverResponseClass) | 40 if (serverResponseClass) |
| 41 { | 41 { |
| 42 delete serverResponseClass; | 42 delete serverResponseClass; |
| 43 serverResponseClass = NULL; | 43 serverResponseClass = NULL; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 | 46 |
| 47 static jlong JNICALL JniCtor(JNIEnv* env, jclass clazz, jobject callbackObject) | |
| 48 { | |
| 49 try | |
| 50 { | |
| 51 return JniPtrToLong(new AdblockPlus::WebRequestSharedPtr(std::make_shared<Jn
iWebRequest>(env, callbackObject))); | |
| 52 } | |
| 53 CATCH_THROW_AND_RETURN(env, 0) | |
| 54 } | |
| 55 | |
| 56 static void JNICALL JniDtor(JNIEnv* env, jclass clazz, jlong ptr) | |
| 57 { | |
| 58 delete JniLongToTypePtr<AdblockPlus::WebRequestSharedPtr>(ptr); | |
| 59 } | |
| 60 | |
| 61 JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject) | 47 JniWebRequest::JniWebRequest(JNIEnv* env, jobject callbackObject) |
| 62 : JniCallbackBase(env, callbackObject), AdblockPlus::WebRequest() | 48 : JniCallbackBase(env, callbackObject) |
| 63 { | 49 { |
| 64 } | 50 } |
| 65 | 51 |
| 66 AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, | 52 AdblockPlus::ServerResponse JniWebRequest::GET(const std::string& url, |
| 67 const AdblockPlus::HeaderList& requestHeaders) const | 53 const AdblockPlus::HeaderList& requestHeaders) const |
| 68 { | 54 { |
| 69 JNIEnvAcquire env(GetJavaVM()); | 55 JNIEnvAcquire env(GetJavaVM()); |
| 70 | 56 |
| 71 jmethodID method = env->GetMethodID( | 57 jmethodID method = env->GetMethodID( |
| 72 *JniLocalReference<jclass>(*env, | 58 *JniLocalReference<jclass>(*env, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, | 125 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, |
| 140 const std::string& b) const | 126 const std::string& b) const |
| 141 { | 127 { |
| 142 jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>", | 128 jmethodID factory = env->GetMethodID(headerEntryClass->Get(), "<init>", |
| 143 "(Ljava/lang/String;Ljava/lang/String;)V"); | 129 "(Ljava/lang/String;Ljava/lang/String;)V"); |
| 144 | 130 |
| 145 JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str())); | 131 JniLocalReference<jstring> strA(env, env->NewStringUTF(a.c_str())); |
| 146 JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str())); | 132 JniLocalReference<jstring> strB(env, env->NewStringUTF(b.c_str())); |
| 147 | 133 |
| 148 return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB); | 134 return env->NewObject(headerEntryClass->Get(), factory, *strA, *strB); |
| 149 } | 135 } |
| 150 | |
| 151 static JNINativeMethod methods[] = | |
| 152 { | |
| 153 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | |
| 154 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | |
| 155 }; | |
| 156 | |
| 157 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest
_registerNatives(JNIEnv *env, jclass clazz) | |
| 158 { | |
| 159 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | |
| 160 } | |
| OLD | NEW |