Bug 839831 - make jsjni_* functions usable without MOZILLA_INTERNAL_API. r=blassey

This commit is contained in:
Gian-Carlo Pascutto 2013-02-09 15:50:28 -08:00
parent 4056ec70fd
commit 96378720fd
5 changed files with 99 additions and 59 deletions

View File

@ -16,6 +16,7 @@
#include "nsXPCOMStrings.h"
#include "AndroidBridge.h"
#include "AndroidJNIWrapper.h"
#include "nsAppShell.h"
#include "nsOSHelperAppService.h"
#include "nsWindow.h"
@ -2558,54 +2559,3 @@ AndroidBridge::UnlockProfile()
return ret;
}
extern "C" {
__attribute__ ((visibility("default")))
jclass
jsjni_FindClass(const char *className) {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env) return NULL;
return env->FindClass(className);
}
__attribute__ ((visibility("default")))
jmethodID
jsjni_GetStaticMethodID(jclass methodClass,
const char *methodName,
const char *signature) {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env) return NULL;
return env->GetStaticMethodID(methodClass, methodName, signature);
}
__attribute__ ((visibility("default")))
bool
jsjni_ExceptionCheck() {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env) return NULL;
return env->ExceptionCheck();
}
__attribute__ ((visibility("default")))
void
jsjni_CallStaticVoidMethodA(jclass cls,
jmethodID method,
jvalue *values) {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env) return;
AutoLocalJNIFrame jniFrame(env);
env->CallStaticVoidMethodA(cls, method, values);
}
__attribute__ ((visibility("default")))
int
jsjni_CallStaticIntMethodA(jclass cls,
jmethodID method,
jvalue *values) {
JNIEnv *env = AndroidBridge::GetJNIEnv();
if (!env) return -1;
AutoLocalJNIFrame jniFrame(env);
return env->CallStaticIntMethodA(cls, method, values);
}
}

View File

@ -39,13 +39,6 @@ class nsIDOMMozSmsMessage;
/* See the comment in AndroidBridge about this function before using it */
extern "C" JNIEnv * GetJNIForThread();
extern "C" jclass jsjni_FindClass(const char *className);
extern "C" jmethodID jsjni_GetStaticMethodID(jclass methodClass,
const char *methodName,
const char *signature);
extern "C" bool jsjni_ExceptionCheck();
extern "C" void jsjni_CallStaticVoidMethodA(jclass cls, jmethodID method, jvalue *values);
extern "C" int jsjni_CallStaticIntMethodA(jclass cls, jmethodID method, jvalue *values);
extern bool mozilla_AndroidBridge_SetMainThread(void *);
extern jclass GetGeckoAppShellClass();

View File

@ -0,0 +1,75 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Util.h"
#include <android/log.h>
#include <dlfcn.h>
#include <prthread.h>
#include "mozilla/Assertions.h"
#include "nsThreadUtils.h"
#include "AndroidBridge.h"
#ifdef DEBUG
#define ALOG_BRIDGE(args...) ALOG(args)
#else
#define ALOG_BRIDGE(args...)
#endif
extern "C" {
__attribute__ ((visibility("default")))
jclass
jsjni_FindClass(const char *className) {
// FindClass outside the main thread will run into problems due
// to missing the classpath
MOZ_ASSERT(NS_IsMainThread());
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
if (!env) return NULL;
return env->FindClass(className);
}
__attribute__ ((visibility("default")))
jmethodID
jsjni_GetStaticMethodID(jclass methodClass,
const char *methodName,
const char *signature) {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
if (!env) return NULL;
return env->GetStaticMethodID(methodClass, methodName, signature);
}
__attribute__ ((visibility("default")))
bool
jsjni_ExceptionCheck() {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
if (!env) return NULL;
return env->ExceptionCheck();
}
__attribute__ ((visibility("default")))
void
jsjni_CallStaticVoidMethodA(jclass cls,
jmethodID method,
jvalue *values) {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
if (!env) return;
mozilla::AutoLocalJNIFrame jniFrame(env);
env->CallStaticVoidMethodA(cls, method, values);
}
__attribute__ ((visibility("default")))
int
jsjni_CallStaticIntMethodA(jclass cls,
jmethodID method,
jvalue *values) {
JNIEnv *env = mozilla::AndroidBridge::GetJNIEnv();
if (!env) return -1;
mozilla::AutoLocalJNIFrame jniFrame(env);
return env->CallStaticIntMethodA(cls, method, values);
}
}

View File

@ -0,0 +1,21 @@
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef AndroidJNIWrapper_h__
#define AndroidJNIWrapper_h__
#include <jni.h>
#include <android/log.h>
extern "C" jclass jsjni_FindClass(const char *className);
extern "C" jmethodID jsjni_GetStaticMethodID(jclass methodClass,
const char *methodName,
const char *signature);
extern "C" bool jsjni_ExceptionCheck();
extern "C" void jsjni_CallStaticVoidMethodA(jclass cls, jmethodID method, jvalue *values);
extern "C" int jsjni_CallStaticIntMethodA(jclass cls, jmethodID method, jvalue *values);
#endif /* AndroidJNIWrapper_h__ */

View File

@ -32,6 +32,7 @@ CPPSRCS = \
AndroidDirectTexture.cpp \
AndroidGraphicBuffer.cpp \
AndroidJNI.cpp \
AndroidJNIWrapper.cpp \
nsWindow.cpp \
nsLookAndFeel.cpp \
nsScreenManagerAndroid.cpp \
@ -54,7 +55,7 @@ NOT_THERE_YET_CPPSRCS = \
SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h AndroidJNIWrapper.h
include $(topsrcdir)/config/rules.mk