| 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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 const char* cStr = env->GetStringUTFChars(str, 0); | 29 const char* cStr = env->GetStringUTFChars(str, 0); |
| 30 std::string ret(cStr); | 30 std::string ret(cStr); |
| 31 env->ReleaseStringUTFChars(str, cStr); | 31 env->ReleaseStringUTFChars(str, cStr); |
| 32 | 32 |
| 33 return ret; | 33 return ret; |
| 34 } | 34 } |
| 35 | 35 |
| 36 jobject NewJniArrayList(JNIEnv* env) | 36 jobject NewJniArrayList(JNIEnv* env) |
| 37 { | 37 { |
| 38 jclass clazz = env->FindClass("java/util/ArrayList"); | 38 JniLocalReference<jclass> clazz(env, env->FindClass("java/util/ArrayList")); |
| 39 jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V"); | 39 jmethodID ctor = env->GetMethodID(*clazz, "<init>", "()V"); |
| 40 return env->NewObject(clazz, ctor); | 40 return env->NewObject(*clazz, ctor); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value) | 43 void JniAddObjectToList(JNIEnv* env, jobject list, jobject value) |
| 44 { | 44 { |
| 45 jmethodID add = env->GetMethodID(env->GetObjectClass(list), "add", "(Ljava/lan
g/Object;)Z"); | 45 JniLocalReference<jclass> clazz(env, env->GetObjectClass(list)); |
| 46 jmethodID add = env->GetMethodID(*clazz, "add", "(Ljava/lang/Object;)Z"); |
| 46 env->CallBooleanMethod(list, add, value); | 47 env->CallBooleanMethod(list, add, value); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void JniThrowException(JNIEnv* env, const std::string& message) | 50 void JniThrowException(JNIEnv* env, const std::string& message) |
| 50 { | 51 { |
| 51 jclass clazz = env->FindClass(PKG("AdblockPlusException")); | 52 JniLocalReference<jclass> clazz(env, env->FindClass(PKG("AdblockPlusException"
))); |
| 52 env->ThrowNew(clazz, message.c_str()); | 53 env->ThrowNew(*clazz, message.c_str()); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void JniThrowException(JNIEnv* env, const std::exception& e) | 56 void JniThrowException(JNIEnv* env, const std::exception& e) |
| 56 { | 57 { |
| 57 JniThrowException(env, e.what()); | 58 JniThrowException(env, e.what()); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void JniThrowException(JNIEnv* env) | 61 void JniThrowException(JNIEnv* env) |
| 61 { | 62 { |
| 62 JniThrowException(env, "Unknown exception from libadblockplus"); | 63 JniThrowException(env, "Unknown exception from libadblockplus"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 JNIEnvAcquire::~JNIEnvAcquire() | 81 JNIEnvAcquire::~JNIEnvAcquire() |
| 81 { | 82 { |
| 82 if (attachmentStatus == JNI_EDETACHED) | 83 if (attachmentStatus == JNI_EDETACHED) |
| 83 { | 84 { |
| 84 javaVM->DetachCurrentThread(); | 85 javaVM->DetachCurrentThread(); |
| 85 } | 86 } |
| 86 } | 87 } |
| OLD | NEW |