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-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 | 19 |
| 20 // precached in JNI_OnLoad and released in JNI_OnUnload |
| 21 JniGlobalReference<jclass>* exceptionHandlerClass; |
| 22 |
| 23 void JniCallbacks_OnLoad(JavaVM* vm, JNIEnv* env, void* reserved) |
| 24 { |
| 25 exceptionHandlerClass = new JniGlobalReference<jclass>(env, env->FindClass(PKG
("JniExceptionHandler"))); |
| 26 } |
| 27 |
| 28 void JniCallbacks_OnUnload(JavaVM* vm, JNIEnv* env, void* reserved) |
| 29 { |
| 30 if (exceptionHandlerClass) |
| 31 { |
| 32 delete exceptionHandlerClass; |
| 33 exceptionHandlerClass = NULL; |
| 34 } |
| 35 } |
| 36 |
20 JniCallbackBase::JniCallbackBase(JNIEnv* env, jobject callbackObject) | 37 JniCallbackBase::JniCallbackBase(JNIEnv* env, jobject callbackObject) |
21 : callbackObject(new JniGlobalReference<jobject>(env, callbackObject)), | 38 : callbackObject(new JniGlobalReference<jobject>(env, callbackObject)) |
22 exceptionLoggerClass(new JniGlobalReference<jclass>(env, env->FindClass(PKG(
"JniExceptionHandler")))) | |
23 { | 39 { |
24 env->GetJavaVM(&javaVM); | 40 env->GetJavaVM(&javaVM); |
25 } | 41 } |
26 | 42 |
27 JniCallbackBase::~JniCallbackBase() | 43 JniCallbackBase::~JniCallbackBase() |
28 { | 44 { |
29 | 45 |
30 } | 46 } |
31 | 47 |
32 void JniCallbackBase::LogException(JNIEnv* env, jthrowable throwable) const | 48 void JniCallbackBase::LogException(JNIEnv* env, jthrowable throwable) const |
33 { | 49 { |
34 jmethodID logMethod = env->GetStaticMethodID(exceptionLoggerClass->Get(), "log
Exception", "(Ljava/lang/Throwable;)V"); | 50 jmethodID logMethod = env->GetStaticMethodID( |
| 51 exceptionHandlerClass->Get(), "logException", "(Ljava/lang/Throwable;)V"); |
35 if (logMethod) | 52 if (logMethod) |
36 { | 53 { |
37 env->CallStaticVoidMethod(exceptionLoggerClass->Get(), logMethod, throwable)
; | 54 env->CallStaticVoidMethod(exceptionHandlerClass->Get(), logMethod, throwable
); |
38 } | 55 } |
39 } | 56 } |
40 | 57 |
41 void JniCallbackBase::CheckAndLogJavaException(JNIEnv* env) const | 58 void JniCallbackBase::CheckAndLogJavaException(JNIEnv* env) const |
42 { | 59 { |
43 if (env->ExceptionCheck()) | 60 if (env->ExceptionCheck()) |
44 { | 61 { |
45 JniLocalReference<jthrowable> throwable(env, env->ExceptionOccurred()); | 62 JniLocalReference<jthrowable> throwable(env, env->ExceptionOccurred()); |
46 env->ExceptionClear(); | 63 env->ExceptionClear(); |
47 LogException(env, *throwable); | 64 LogException(env, *throwable); |
48 } | 65 } |
49 } | 66 } |
OLD | NEW |