Index: jni/JniCallbacks.cpp |
diff --git a/jni/JniCallbacks.cpp b/jni/JniCallbacks.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ddbd6aec8683664ee4aa69f6100a9e4ffd2ecf1f |
--- /dev/null |
+++ b/jni/JniCallbacks.cpp |
@@ -0,0 +1,49 @@ |
+/* |
+ * This file is part of Adblock Plus <http://adblockplus.org/>, |
+ * Copyright (C) 2006-2014 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+#include "JniCallbacks.h" |
+ |
+JniCallbackBase::JniCallbackBase(JNIEnv* env, jobject callbackObject) |
+{ |
+ env->GetJavaVM(&javaVM); |
+ this->callbackObject.reset(new JniGlobalReference<jobject>(env, callbackObject)); |
+ exceptionLoggerClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler")))); |
+} |
+ |
+JniCallbackBase::~JniCallbackBase() |
+{ |
+ |
+} |
+ |
+void JniCallbackBase::LogException(JNIEnv* env, jthrowable throwable) const |
+{ |
+ jmethodID logMethod = env->GetStaticMethodID(exceptionLoggerClass->get(), "logException", "(Ljava/lang/Throwable;)V"); |
+ if (logMethod) |
+ { |
+ env->CallStaticVoidMethod(exceptionLoggerClass->get(), logMethod, throwable); |
+ } |
+} |
+ |
+void JniCallbackBase::CheckAndLogJavaException(JNIEnv* env) const |
+{ |
+ if (env->ExceptionCheck()) |
+ { |
+ jthrowable throwable = env->ExceptionOccurred(); |
+ env->ExceptionClear(); |
+ LogException(env, throwable); |
+ } |
+} |