2015-01-10 00:33:57 +00:00
|
|
|
#ifndef mozilla_jni_Utils_h__
|
|
|
|
#define mozilla_jni_Utils_h__
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
|
2015-08-13 04:53:39 +00:00
|
|
|
#if defined(DEBUG) || !defined(RELEASE_BUILD)
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#endif
|
2015-01-10 00:33:57 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace jni {
|
|
|
|
|
2015-08-13 04:53:39 +00:00
|
|
|
extern JNIEnv* sGeckoThreadEnv;
|
|
|
|
|
|
|
|
inline bool IsAvailable()
|
|
|
|
{
|
|
|
|
return !!sGeckoThreadEnv;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline JNIEnv* GetGeckoThreadEnv()
|
|
|
|
{
|
|
|
|
#if defined(DEBUG) || !defined(RELEASE_BUILD)
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
MOZ_CRASH("Not on main thread");
|
|
|
|
}
|
|
|
|
if (!sGeckoThreadEnv) {
|
|
|
|
MOZ_CRASH("Don't have a JNIEnv");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return sGeckoThreadEnv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetGeckoThreadEnv(JNIEnv* aEnv);
|
|
|
|
|
|
|
|
JNIEnv* GetEnvForThread();
|
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
bool ThrowException(JNIEnv *aEnv, const char *aClass,
|
|
|
|
const char *aMessage);
|
|
|
|
|
|
|
|
inline bool ThrowException(JNIEnv *aEnv, const char *aMessage)
|
|
|
|
{
|
|
|
|
return ThrowException(aEnv, "java/lang/Exception", aMessage);
|
|
|
|
}
|
|
|
|
|
2015-08-04 21:47:28 +00:00
|
|
|
inline bool ThrowException(const char *aClass, const char *aMessage)
|
|
|
|
{
|
2015-08-13 04:53:39 +00:00
|
|
|
return ThrowException(GetEnvForThread(), aClass, aMessage);
|
2015-08-04 21:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool ThrowException(const char *aMessage)
|
|
|
|
{
|
2015-08-13 04:53:39 +00:00
|
|
|
return ThrowException(GetEnvForThread(), aMessage);
|
2015-08-04 21:47:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-30 23:36:41 +00:00
|
|
|
bool HandleUncaughtException(JNIEnv* aEnv);
|
|
|
|
|
|
|
|
#define MOZ_CATCH_JNI_EXCEPTION(env) \
|
|
|
|
do { \
|
|
|
|
if (mozilla::jni::HandleUncaughtException((env))) { \
|
|
|
|
MOZ_CRASH("JNI exception"); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2015-01-10 00:33:57 +00:00
|
|
|
|
2015-07-29 19:11:15 +00:00
|
|
|
uintptr_t GetNativeHandle(JNIEnv* env, jobject instance);
|
|
|
|
|
|
|
|
void SetNativeHandle(JNIEnv* env, jobject instance, uintptr_t handle);
|
|
|
|
|
2016-02-09 22:27:28 +00:00
|
|
|
jclass GetClassGlobalRef(JNIEnv* aEnv, const char* aClassName);
|
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
} // jni
|
|
|
|
} // mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_jni_Utils_h__
|