Index: jni/JniCallbacks.h |
diff --git a/jni/JniCallbacks.h b/jni/JniCallbacks.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7ead721c7ca16a7a304547f51138ee8d811d4680 |
--- /dev/null |
+++ b/jni/JniCallbacks.h |
@@ -0,0 +1,129 @@ |
+/* |
+ * 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/>. |
+ */ |
+ |
+#ifndef JNICALLBACKS_H_ |
Felix Dahlke
2014/03/28 08:29:00
Our convention is: JNI_CALLBACKS_H (no trailing _,
|
+#define JNICALLBACKS_H_ |
+ |
+#include <AdblockPlus.h> |
+#include "Utils.h" |
+#include "JniJsValue.h" |
+ |
+namespace AdblockPlus |
+{ |
+namespace Android |
Felix Dahlke
2014/03/28 08:29:00
Namespace bodies are to be indented:
https://adblo
|
+{ |
+ |
+class JniCallbackBase |
+{ |
+public: |
+ JniCallbackBase(JNIEnv* env, jobject callbackObject) |
+ { |
+ env->GetJavaVM(&m_JavaVM); |
Felix Dahlke
2014/03/28 08:29:00
IMO, we should move all the function definitions f
|
+ m_CallbackObject.reset(new JniGlobalReference<jobject>(env, callbackObject)); |
+ m_ExceptionLoggerClass.reset(new JniGlobalReference<jclass>(env, env->FindClass(PKG("JniExceptionHandler")))); |
+ } |
+ |
+ virtual ~JniCallbackBase() |
+ { |
+ } |
+ |
+ inline JavaVM* GetJavaVM() const |
Felix Dahlke
2014/03/28 08:29:00
inline is redundant for member functions. Same bel
|
+ { |
+ return m_JavaVM; |
+ } |
+ |
+ inline jobject GetCallbackObject() const |
+ { |
+ return m_CallbackObject->get(); |
+ } |
+ |
+ void LogException(JNIEnv* env, jthrowable throwable) const |
+ { |
+ jmethodID logMethod = env->GetStaticMethodID(m_ExceptionLoggerClass->get(), "logException", "(Ljava/lang/Throwable;)V"); |
+ if (logMethod) |
+ { |
+ env->CallStaticVoidMethod(m_ExceptionLoggerClass->get(), logMethod, throwable); |
+ } |
+ } |
+ |
+ void CheckAndLogJavaException(JNIEnv* env) const |
+ { |
+ if (env->ExceptionCheck()) |
+ { |
+ jthrowable throwable = env->ExceptionOccurred(); |
+ env->ExceptionClear(); |
+ LogException(env, throwable); |
+ } |
+ } |
+ |
+private: |
+ JavaVM* m_JavaVM; |
Felix Dahlke
2014/03/28 08:29:00
From https://adblockplus.org/en/coding-style:
"No
René Jeschke
2014/03/28 10:59:15
I'll change this, but we should think this over ag
|
+ JniGlobalReference<jobject>::PTR m_CallbackObject; |
+ JniGlobalReference<jclass>::PTR m_ExceptionLoggerClass; |
+}; |
+ |
+class JniEventCallback: public JniCallbackBase |
Felix Dahlke
2014/03/28 08:29:00
Space before ":" please :) Likewise below.
|
+{ |
+public: |
+ JniEventCallback(JNIEnv* env, jobject callbackObject); |
+ virtual ~JniEventCallback(); |
+ void Callback(AdblockPlus::JsValueList& params); |
+}; |
+ |
+class JniUpdaterCallback: public JniCallbackBase |
+{ |
+public: |
+ JniUpdaterCallback(JNIEnv* env, jobject callbackObject); |
+ virtual ~JniUpdaterCallback(); |
+ void Callback(const std::string& arg); |
+}; |
+ |
+class JniFilterChangeCallback: public JniCallbackBase |
+{ |
+public: |
+ JniFilterChangeCallback(JNIEnv* env, jobject callbackObject); |
+ virtual ~JniFilterChangeCallback(); |
+ void Callback(const std::string& arg, const AdblockPlus::JsValuePtr jsValue); |
+}; |
+ |
+class JniLogSystemCallback: public JniCallbackBase, public AdblockPlus::LogSystem |
+{ |
+public: |
+ JniLogSystemCallback(JNIEnv* env, jobject callbackObject); |
+ virtual ~JniLogSystemCallback(); |
+ void operator()(AdblockPlus::LogSystem::LogLevel logLevel, const std::string& message, const std::string& source); |
+private: |
Felix Dahlke
2014/03/28 08:29:00
Whitespace before "private"?
|
+ JniGlobalReference<jclass>::PTR m_LogLevelClass; |
+}; |
+ |
+class JniWebRequest: public JniCallbackBase, public AdblockPlus::WebRequest |
+{ |
+public: |
+ JniWebRequest(JNIEnv* env, jobject callbackObject); |
+ virtual ~JniWebRequest(); |
+ AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders) const; |
+private: |
Felix Dahlke
2014/03/28 08:29:00
Whitespace before "private"?
|
+ jobject NewTuple(JNIEnv* env, const std::string& a, const std::string& b) const; |
+ |
+ JniGlobalReference<jclass>::PTR m_TupleClass; |
+ JniGlobalReference<jclass>::PTR m_ServerResponseClass; |
+}; |
+ |
+} // namespace Android |
+} // namespace AdblockPlus |
+ |
+#endif /* JNICALLBACKS_H_ */ |