| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present eyeo GmbH | |
| 4 * | |
| 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 | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 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/>. | |
| 16 */ | |
| 17 | |
| 18 #include "JniCallbacks.h" | |
| 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 | |
| 37 JniCallbackBase::JniCallbackBase(JNIEnv* env, jobject callbackObject) | |
| 38 : callbackObject(new JniGlobalReference<jobject>(env, callbackObject)) | |
| 39 { | |
| 40 env->GetJavaVM(&javaVM); | |
| 41 } | |
| 42 | |
| 43 JniCallbackBase::~JniCallbackBase() | |
| 44 { | |
| 45 | |
| 46 } | |
| 47 | |
| 48 void JniCallbackBase::LogException(JNIEnv* env, jthrowable throwable) const | |
| 49 { | |
| 50 jmethodID logMethod = env->GetStaticMethodID( | |
| 51 exceptionHandlerClass->Get(), "logException", "(Ljava/lang/Throwable;)V"); | |
| 52 if (logMethod) | |
| 53 { | |
| 54 env->CallStaticVoidMethod(exceptionHandlerClass->Get(), logMethod, throwable
); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 void JniCallbackBase::CheckAndLogJavaException(JNIEnv* env) const | |
| 59 { | |
| 60 if (env->ExceptionCheck()) | |
| 61 { | |
| 62 JniLocalReference<jthrowable> throwable(env, env->ExceptionOccurred()); | |
| 63 env->ExceptionClear(); | |
| 64 LogException(env, *throwable); | |
| 65 } | |
| 66 } | |
| OLD | NEW |