r=ashuk
a=edburns
This set of changes replaces all occurrences of

env->Func(args...)

with

::util_Func(env, args...)

Except of course, for the implementations of the above mentioned
::util_Func() functions.

This is done to allow the JNI functions to be called from a non JNI
context, such as UNO.
This commit is contained in:
edburns%acm.org 2000-03-16 23:07:03 +00:00
Родитель c8a009c6f0
Коммит 1cb45027a0
13 изменённых файлов: 337 добавлений и 133 удалений

Просмотреть файл

@ -61,13 +61,13 @@ Java_org_mozilla_webclient_wrapper_1native_BookmarksImpl_nativeNewRDFNode
jint result = -1;
nsAutoString uri("NC:BookmarksRoot");
const char *url = env->GetStringUTFChars(urlString, nsnull);
const char *url = ::util_GetStringUTFChars(env, urlString);
uri.Append("#$");
uri.Append(url);
printf("debug: edburns: nativeNewRDFNode: url: %s\n", url);
rv = gRDF->GetUnicodeResource(uri.GetUnicode(), getter_AddRefs(newNode));
env->ReleaseStringUTFChars(urlString, url);
::util_ReleaseStringUTFChars(env, urlString, url);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewRDFNode: can't create new nsIRDFResource.");
return result;

Просмотреть файл

@ -133,7 +133,7 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_CurrentPage
charResult = (char *) ::util_PostSynchronousEvent(initContext, event);
if (charResult != nsnull) {
urlString = env->NewStringUTF((const char *) charResult);
urlString = ::util_NewStringUTF(env, (const char *) charResult);
}
else {
::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned NULL");

Просмотреть файл

@ -78,24 +78,9 @@ DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env,
mJNIEnv(env), mInitContext(yourInitContext), mTarget(yourTarget)
{
if (nsnull == gVm) { // declared in jni_util.h
env->GetJavaVM(&gVm); // save this vm reference away for the callback!
::util_GetJavaVM(env, &gVm); // save this vm reference away for the callback!
}
#ifdef XP_PC
// debug: edburns:
DWORD nativeThreadID = GetCurrentThreadId();
printf("debug: edburns: DocumentLoaderObserverImpl ctor nativeThreadID: %d\n",
nativeThreadID);
#endif
char *currentThreadName = nsnull;
if (nsnull != (currentThreadName = util_GetCurrentThreadName(env))) {
printf("debug: edburns: DocumentLoaderObserverImpl ctor threadName: %s\n",
currentThreadName);
delete currentThreadName;
}
if (-1 == maskValues[0]) {
InitializeMaskValues();
}
@ -115,7 +100,8 @@ void DocumentLoaderObserverImpl::InitializeMaskValues()
return;
}
jclass documentLoadEventClass = env->FindClass("org/mozilla/webclient/DocumentLoadEvent");
jclass documentLoadEventClass = ::util_FindClass(env,
"org/mozilla/webclient/DocumentLoadEvent");
if (nsnull == documentLoadEventClass) {
return;
@ -125,14 +111,15 @@ void DocumentLoaderObserverImpl::InitializeMaskValues()
jfieldID fieldID;
while (nsnull != maskNames[i]) {
fieldID = env->GetStaticFieldID(documentLoadEventClass, maskNames[i],
"J");
fieldID = ::util_GetStaticFieldID(env, documentLoadEventClass,
maskNames[i], "J");
if (nsnull == fieldID) {
return;
}
maskValues[i] = env->GetStaticLongField(documentLoadEventClass, fieldID);
maskValues[i] = ::util_GetStaticLongField(env, documentLoadEventClass,
fieldID);
i++;
}
}

Просмотреть файл

@ -304,7 +304,7 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_webclient_wrapper_1native_HistoryImpl
charResult = (char *) ::util_PostSynchronousEvent(initContext, event);
if (charResult != nsnull) {
urlString = env->NewStringUTF((const char *) charResult);
urlString = ::util_NewStringUTF(env, (const char *) charResult);
}
else {
::util_ThrowExceptionToJava(env, "raptorWebShellGetURL Exception: GetURL() returned nsnull");

Просмотреть файл

@ -47,12 +47,12 @@ OBJS = \
.\$(OBJDIR)\nsSetupRegistry.obj \
$(NULL)
LINCS = \
INCS = \
-I$(JDKHOME)\include \
-I$(JDKHOME)\include\win32 \
$(INCS) \
$(NULL)
LCFLAGS = \
-DDEBUG_RAPTOR_CANVAS \
$(NULL)
@ -134,6 +134,7 @@ buildRunems:
install:: $(DLL) buildRunems
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber_all:: clobber

Просмотреть файл

@ -108,6 +108,9 @@ char * errorMessages[] = {
* PENDING(): this should probably live in EventRegistration.h
* PENDING(edburns): need to abstract this out so we can use it from uno
* and JNI.
*/
const char *gSupportedListenerInterfaces[] = {
@ -140,7 +143,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
return;
}
if (nsnull == gVm) { // declared in jni_util.h
env->GetJavaVM(&gVm); // save this vm reference
::util_GetJavaVM(env, &gVm); // save this vm reference
}
rv = InitMozillaStuff(initContext);
@ -155,7 +158,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
::PR_Sleep(PR_INTERVAL_NO_WAIT);
if (initContext->initFailCode != 0) {
::util_ThrowExceptionToJava(initContext->env, errorMessages[initContext->initFailCode]);
::util_ThrowExceptionToJava(env, errorMessages[initContext->initFailCode]);
return;
}
}
@ -217,10 +220,11 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
while (nsnull != gSupportedListenerInterfaces[listenerType]) {
if (nsnull ==
(clazz =
env->FindClass(gSupportedListenerInterfaces[listenerType]))) {
::util_FindClass(env,
gSupportedListenerInterfaces[listenerType]))) {
return;
}
if (env->IsInstanceOf(typedListener, clazz)) {
if (::util_IsInstanceOf(env, typedListener, clazz)) {
// We've got a winner!
break;
}
@ -235,7 +239,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
jobject globalRef = nsnull;
// PENDING(edburns): make sure do DeleteGlobalRef on the removeListener
if (nsnull == (globalRef = env->NewGlobalRef(typedListener))) {
if (nsnull == (globalRef = ::util_NewGlobalRef(env, typedListener))) {
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeAddListener(): can't create NewGlobalRef\n\tfor argument");
return;
}
@ -466,8 +470,6 @@ nsresult InitMozillaStuff (WebShellInitContext * initContext)
if (NS_FAILED(rv)) {
initContext->initFailCode = kHistoryWebShellError;
::util_ThrowExceptionToJava(initContext->env,
"Exception: Can't get DocShell from nsIWebShell");
return rv;
}

Просмотреть файл

@ -35,17 +35,19 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl
(JNIEnv *env, jobject obj, jint webShellPtr, jstring urlString)
{
jobject jobj = obj;
const char * urlChars = (char *) env->GetStringUTFChars(urlString, 0);
const char * urlChars = (char *) ::util_GetStringUTFChars(env,
urlString);
printf("Native URL = \"%s\"\n", urlChars);
env->ReleaseStringUTFChars(urlString, urlChars);
::util_ReleaseStringUTFChars(env, urlString, urlChars);
PRUnichar * urlStringChars = (PRUnichar *) env->GetStringChars(urlString, 0);
PRUnichar * urlStringChars = (PRUnichar *) ::util_GetStringChars(env,
urlString);
if (env->ExceptionOccurred()) {
if (::util_ExceptionOccurred(env)) {
::util_ThrowExceptionToJava(env, "raptorWebShellLoadURL Exception: unable to extract Java string");
if (urlStringChars != nsnull)
env->ReleaseStringChars(urlString, urlStringChars);
::util_ReleaseStringChars(env, urlString, urlStringChars);
return;
}
@ -54,7 +56,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to raptorWebShellLoadURL");
if (urlStringChars != nsnull)
env->ReleaseStringChars(urlString, urlStringChars);
::util_ReleaseStringChars(env, urlString, urlStringChars);
return;
}
@ -65,7 +67,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl
::util_PostEvent(initContext, event);
}
env->ReleaseStringChars(urlString, urlStringChars);
::util_ReleaseStringChars(env, urlString, urlStringChars);
}
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeRefresh

Просмотреть файл

@ -121,37 +121,24 @@ JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_RDFEnumeration_nativeFinalize
(JNIEnv *env, jobject obj)
{
jclass objClass;
jfieldID nativeEnumFieldID;
jfieldID nativeContainerFieldID;
jint nativeEnum, nativeContainer;
objClass = env->GetObjectClass(obj);
if (nsnull == objClass) {
printf("nativeFinalize: Can't get object class for RDFEnumeration.\n");
return;
}
// release the nsISimpleEnumerator
nativeEnumFieldID = env->GetFieldID(objClass, "nativeEnum", "I");
if (nsnull == nativeEnumFieldID) {
if (-1 == (nativeEnum =
::util_GetIntValueFromInstance(env, obj, "nativeEnum"))) {
printf("nativeFinalize: Can't get fieldID for nativeEnum.\n");
return;
}
nativeEnum = env->GetIntField(obj, nativeEnumFieldID);
nsCOMPtr<nsISimpleEnumerator> enumerator =
(nsISimpleEnumerator *) nativeEnum;
((nsISupports *)enumerator.get())->Release();
// release the nsIRDFContainer
nativeContainerFieldID = env->GetFieldID(objClass, "nativeContainer", "I");
if (nsnull == nativeContainerFieldID) {
printf("nativeFinalize: Can't get fieldID for nativeContainer.\n");
if (-1 == (nativeContainer =
::util_GetIntValueFromInstance(env, obj, "nativeContainer"))) {
printf("nativeFinalize: Can't get fieldID for nativeContainerFieldID.\n");
return;
}
nativeContainer = env->GetIntField(obj, nativeContainerFieldID);
nsCOMPtr<nsIRDFContainer> container =
(nsIRDFContainer *) nativeContainer;
((nsISupports *)container.get())->Release();
@ -169,23 +156,8 @@ jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode)
{
nsresult rv;
jint result = -1;
jclass objClass;
jfieldID nativeEnumFieldID;
jfieldID nativeContainerFieldID;
objClass = env->GetObjectClass(obj);
if (nsnull == objClass) {
printf("getNativeEnumFromJava: Can't get object class for RDFEnumeration.\n");
return -1;
}
nativeEnumFieldID = env->GetFieldID(objClass, "nativeEnum", "I");
if (nsnull == nativeEnumFieldID) {
printf("getNativeEnumFromJava: Can't get fieldID for nativeEnum.\n");
return -1;
}
result = env->GetIntField(obj, nativeEnumFieldID);
result = ::util_GetIntValueFromInstance(env, obj, "nativeEnum");
// if the field has been initialized, just return the value
if (-1 != result) {
@ -229,7 +201,7 @@ jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode)
}
// IMPORTANT: Store the enum back into java
env->SetIntField(obj, nativeEnumFieldID, (jint) enumerator.get());
::util_SetIntValueForInstance(env,obj,"nativeEnum",(jint)enumerator.get());
// IMPORTANT: make sure it doesn't get deleted when it goes out of scope
((nsISupports *)enumerator.get())->AddRef();
@ -237,12 +209,8 @@ jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode)
// nsIRDFContainer from being destructed in order to maintain the
// validity of the nsISimpleEnumerator that came from the container.
// Just to be safe, I'm doing so.
nativeContainerFieldID = env->GetFieldID(objClass, "nativeContainer", "I");
if (nsnull == nativeContainerFieldID) {
printf("getNativeEnumFromJava: Can't get fieldID for nativeContainer.\n");
return -1;
}
env->SetIntField(obj, nativeContainerFieldID, (jint) container.get());
::util_SetIntValueForInstance(env, obj, "nativeContainer",
(jint) container.get());
((nsISupports *)container.get())->AddRef();
// NORMAL EXIT 2

Просмотреть файл

@ -218,10 +218,10 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString
length = string->Length();
}
result = env->NewString(textForNode, length);
result = ::util_NewString(env, textForNode, length);
}
else {
result = env->NewStringUTF("");
result = ::util_NewStringUTF(env, "");
}
return result;
}

Просмотреть файл

@ -62,7 +62,6 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
(JNIEnv *env, jobject obj, jint windowPtr, jint x, jint y,
jint width, jint height, jobject aBrowserControlImpl)
{
jobject jobj = obj;
#ifdef XP_MAC
WindowPtr pWindow = (WindowPtr) windowPtr;
Rect webRect = pWindow->portRect;
@ -87,8 +86,8 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
initContext->embeddedThread = nsnull;
initContext->sessionHistory = nsnull;
initContext->actionQueue = nsnull;
initContext->nativeEventThread = nsnull;
initContext->env = env;
initContext->nativeEventThread = nsnull;
initContext->stopThread = FALSE;
initContext->x = x;
initContext->y = y;
@ -96,36 +95,8 @@ JNIEXPORT jint JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
initContext->h = height;
#ifdef XP_UNIX
jclass cls = env->GetObjectClass(aBrowserControlImpl); // Get Class for BrowserControlImpl object
jclass clz = env->FindClass("org/mozilla/webclient/BrowserControlImpl");
if (nsnull == clz) {
::util_ThrowExceptionToJava(env, "Exception: Could not find class for BrowserControlImpl");
return (jint) 0;
}
jboolean ans = env->IsInstanceOf(aBrowserControlImpl, clz);
if (JNI_FALSE == ans) {
::util_ThrowExceptionToJava(env, "Exception: We have a problem");
return (jint) 0;
}
// Get myCanvas IVar
jfieldID fid = env->GetFieldID(cls, "myCanvas", "Lorg/mozilla/webclient/BrowserControlCanvas;");
if (nsnull == fid) {
::util_ThrowExceptionToJava(env, "Exception: field myCanvas not found in the jobject for BrowserControlImpl");
return (jint) 0;
}
jobject canvasObj = env->GetObjectField(aBrowserControlImpl, fid);
jclass canvasCls = env->GetObjectClass(canvasObj);
if (nsnull == canvasCls) {
::util_ThrowExceptionToJava(env, "Exception: Could Not find Class for CanvasObj");
return (jint) 0;
}
jfieldID gtkfid = env->GetFieldID(canvasCls, "gtkWinPtr", "I");
if (nsnull == gtkfid) {
::util_ThrowExceptionToJava(env, "Exception: field gtkWinPtr not found in the jobject for BrowserControlCanvas");
return (jint) 0;
}
jint mozPtr = env->GetIntField(canvasObj, gtkfid);
initContext->gtkWinPtr = (int) mozPtr;
initContext->gtkWinPtr =
(int)::util_GetGTKWinPtrFromCanvas(env, aBrowserControlImpl);
#else
initContext->gtkWinPtr = nsnull;
#endif
@ -174,9 +145,6 @@ Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeDestroyInitCo
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeMoveWindowTo
(JNIEnv *env, jobject obj, jint webShellPtr, jint x, jint y)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
if (initContext == nsnull) {
@ -195,9 +163,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeRemoveFocus
(JNIEnv *env, jobject obj, jint webShellPtr)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
if (initContext == nsnull) {
@ -216,9 +181,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeRepaint
(JNIEnv *env, jobject obj, jint webShellPtr, jboolean forceRepaint)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
if (initContext == nsnull) {
@ -261,9 +223,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlI
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_WindowControlImpl_nativeSetFocus
(JNIEnv *env, jobject obj, jint webShellPtr)
{
JNIEnv * pEnv = env;
jobject jobj = obj;
WebShellInitContext* initContext = (WebShellInitContext *) webShellPtr;
if (initContext == nsnull) {

Просмотреть файл

@ -27,6 +27,8 @@
#include "WrapperFactoryImpl.h"
#include "jni_util.h"
#include "nsIServiceManager.h" // for NS_InitXPCOM
#include "nsAppShellCIDs.h" // for NS_SESSIONHISTORY_CID
#include "nsCRT.h" // for nsCRT::strcmp
@ -83,7 +85,8 @@ Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeAppInitializ
jobject jobj = obj;
static PRBool gFirstTime = PR_TRUE;
if (gFirstTime) {
const char *nativePath = (const char *) env->GetStringUTFChars(verifiedBinDirAbsolutePath, 0);
const char *nativePath = (const char *) ::util_GetStringUTFChars(env,
verifiedBinDirAbsolutePath);
gBinDir = nativePath;
NS_InitXPCOM(nsnull, &gBinDir);
@ -93,7 +96,7 @@ Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeAppInitializ
PR_FALSE, PR_FALSE);
NS_AutoregisterComponents();
gFirstTime = PR_FALSE;
env->ReleaseStringUTFChars(verifiedBinDirAbsolutePath, nativePath);
::util_ReleaseStringUTFChars(env, verifiedBinDirAbsolutePath, nativePath);
}
}
@ -109,8 +112,8 @@ JNIEXPORT jboolean JNICALL
Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeDoesImplement
(JNIEnv *env, jobject obj, jstring interfaceName)
{
const char *iName = (const char *) env->GetStringUTFChars(interfaceName,
0);
const char *iName = (const char *) ::util_GetStringUTFChars(env,
interfaceName);
jboolean result = JNI_FALSE;
int i = 0;
@ -125,7 +128,7 @@ Java_org_mozilla_webclient_wrapper_1native_WrapperFactoryImpl_nativeDoesImplemen
break;
}
}
env->ReleaseStringUTFChars(interfaceName, iName);
::util_ReleaseStringUTFChars(env, interfaceName, iName);
return result;
}

Просмотреть файл

@ -165,6 +165,240 @@ void util_DumpJavaStack(JNIEnv *env)
}
}
const char * util_GetStringUTFChars(JNIEnv *env, jstring inString)
{
const char *result = nsnull;
#ifdef BAL_INTERFACE
#else
result = (const char *) env->GetStringUTFChars(inString, 0);
#endif
return result;
}
void util_ReleaseStringUTFChars(JNIEnv *env, jstring inString,
const char *stringFromGet)
{
#ifdef BAL_INTERFACE
#else
env->ReleaseStringUTFChars(inString, stringFromGet);
#endif
}
const jchar * util_GetStringChars(JNIEnv *env, jstring inString)
{
const jchar *result = nsnull;
#ifdef BAL_INTERFACE
#else
result = (const jchar *) env->GetStringChars(inString, 0);
#endif
return result;
}
void util_ReleaseStringChars(JNIEnv *env, jstring inString,
const jchar *stringFromGet)
{
#ifdef BAL_INTERFACE
#else
env->ReleaseStringChars(inString, stringFromGet);
#endif
}
jstring util_NewStringUTF(JNIEnv *env, const char *inString)
{
jstring result;
#ifdef BAL_INTERFACE
#else
result = env->NewStringUTF(inString);
#endif
return result;
}
jstring util_NewString(JNIEnv *env, const jchar *inString, jsize len)
{
jstring result;
#ifdef BAL_INTERFACE
#else
result = env->NewString(inString, len);
#endif
return result;
}
jobject util_NewGlobalRef(JNIEnv *env, jobject obj)
{
jobject result = nsnull;
#ifdef BAL_INTERFACE
#else
result = env->NewGlobalRef(obj);
#endif
return result;
}
void util_DeleteGlobalRef(JNIEnv *env, jobject obj)
{
#ifdef BAL_INTERFACE
#else
env->DeleteGlobalRef(obj);
#endif
}
jthrowable util_ExceptionOccurred(JNIEnv *env)
{
jthrowable result = nsnull;
#ifdef BAL_INTERFACE
#else
result = env->ExceptionOccurred();
#endif
return result;
}
jint util_GetJavaVM(JNIEnv *env, JavaVM **vm)
{
int result = -1;
#ifdef BAL_INTERFACE
#else
result = env->GetJavaVM(vm);
#endif
return result;
}
jclass util_FindClass(JNIEnv *env, const char *fullyQualifiedClassName)
{
jclass result = nsnull;
#ifdef BAL_INTERFACE
#else
result = env->FindClass(fullyQualifiedClassName);
#endif
return result;
}
jfieldID util_GetStaticFieldID(JNIEnv *env, jclass clazz,
const char *fieldName,
const char *signature)
{
jfieldID result = nsnull;
#ifdef BAL_INTERFACE
#else
result = env->GetStaticFieldID(clazz, fieldName, signature);
#endif
return result;
}
jlong util_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID id)
{
jlong result = -1;
#ifdef BAL_INTERFACE
#else
result = env->GetStaticLongField(clazz, id);
#endif
return result;
}
jboolean util_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
{
jboolean result = JNI_FALSE;
#ifdef BAL_INTERFACE
#else
result = env->IsInstanceOf(obj, clazz);
#endif
return result;
}
#ifdef XP_UNIX
jint util_GetGTKWinPtrFromCanvas(JNIEnv *env, jobject browserControlCanvas)
{
jint result = -1;
#ifdef BAL_INTERFACE
#else
jclass cls = env->GetObjectClass(browserControlCanvas); // Get Class for BrowserControlImpl object
jclass clz = env->FindClass("org/mozilla/webclient/BrowserControlImpl");
if (nsnull == clz) {
::util_ThrowExceptionToJava(env, "Exception: Could not find class for BrowserControlImpl");
return (jint) 0;
}
jboolean ans = env->IsInstanceOf(browserControlCanvas, clz);
if (JNI_FALSE == ans) {
::util_ThrowExceptionToJava(env, "Exception: We have a problem");
return (jint) 0;
}
// Get myCanvas IVar
jfieldID fid = env->GetFieldID(cls, "myCanvas", "Lorg/mozilla/webclient/BrowserControlCanvas;");
if (nsnull == fid) {
::util_ThrowExceptionToJava(env, "Exception: field myCanvas not found in the jobject for BrowserControlImpl");
return (jint) 0;
}
jobject canvasObj = env->GetObjectField(browserControlCanvas, fid);
jclass canvasCls = env->GetObjectClass(canvasObj);
if (nsnull == canvasCls) {
::util_ThrowExceptionToJava(env, "Exception: Could Not find Class for CanvasObj");
return (jint) 0;
}
jfieldID gtkfid = env->GetFieldID(canvasCls, "gtkWinPtr", "I");
if (nsnull == gtkfid) {
::util_ThrowExceptionToJava(env, "Exception: field gtkWinPtr not found in the jobject for BrowserControlCanvas");
return (jint) 0;
}
result = env->GetIntField(canvasObj, gtkfid);
#endif
return result;
}
#endif
jint util_GetIntValueFromInstance(JNIEnv *env, jobject obj,
const char *fieldName)
{
int result = -1;
#ifdef BAL_INTERFACE
#else
jclass objClass = env->GetObjectClass(obj);
if (nsnull == objClass) {
printf("util_GetIntValueFromInstance: Can't get object class from instance.\n");
return result;
}
jfieldID theFieldID = env->GetFieldID(objClass, fieldName, "I");
if (nsnull == theFieldID) {
printf("util_GetIntValueFromInstance: Can't get fieldID for fieldName.\n");
return result;
}
result = env->GetIntField(obj, theFieldID);
#endif
return result;
}
void util_SetIntValueForInstance(JNIEnv *env, jobject obj,
const char *fieldName, jint newValue)
{
#ifdef BAL_INTERFACE
#else
jclass objClass = env->GetObjectClass(obj);
if (nsnull == objClass) {
printf("util_SetIntValueForInstance: Can't get object class from instance.\n");
return;
}
jfieldID fieldID = env->GetFieldID(objClass, fieldName, "I");
if (nsnull == fieldID) {
printf("util_SetIntValueForInstance: Can't get fieldID for fieldName.\n");
return;
}
env->SetIntField(obj, fieldID, newValue);
#endif;
}
JNIEXPORT jvalue JNICALL
JNU_CallMethodByName(JNIEnv *env,
jboolean *hasException,

Просмотреть файл

@ -70,7 +70,7 @@ struct WebShellInitContext {
nsISessionHistory* sessionHistory;
PLEventQueue * actionQueue;
PRThread * embeddedThread;
JNIEnv * env;
JNIEnv * env;
jobject nativeEventThread;
int stopThread;
int initComplete;
@ -144,6 +144,49 @@ char *util_GetCurrentThreadName(JNIEnv *env);
void util_DumpJavaStack(JNIEnv *env);
//
// Functions to wrap JNIEnv functions.
//
const char *util_GetStringUTFChars(JNIEnv *env, jstring inString);
void util_ReleaseStringUTFChars(JNIEnv *env, jstring inString,
const char *stringFromGet);
const jchar *util_GetStringChars(JNIEnv *env, jstring inString);
void util_ReleaseStringChars(JNIEnv *env, jstring inString,
const jchar *stringFromGet);
jstring util_NewStringUTF(JNIEnv *env, const char * inString);
jstring util_NewString(JNIEnv *env, const jchar *inString, jsize len);
jobject util_NewGlobalRef(JNIEnv *env, jobject toAddRef);
void util_DeleteGlobalRef(JNIEnv *env, jobject toAddRef);
jthrowable util_ExceptionOccurred(JNIEnv *env);
jint util_GetJavaVM(JNIEnv *env, JavaVM **vm);
jclass util_FindClass(JNIEnv *env, const char *fullyQualifiedClassName);
jfieldID util_GetStaticFieldID(JNIEnv *env, jclass clazz,
const char *fieldName,
const char *signature);
jlong util_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID id);
jboolean util_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz);
jint util_GetIntValueFromInstance(JNIEnv *env, jobject instance,
const char *fieldName);
void util_SetIntValueForInstance(JNIEnv *env, jobject instance,
const char *fieldName, jint newValue);
//
// Functions from secret JDK files
//
@ -167,4 +210,9 @@ JNU_CallMethodByNameV(JNIEnv *env,
JNIEXPORT void * JNICALL
JNU_GetEnv(JavaVM *vm, jint version);
// hack functions to get around mozilla oddities
#ifdef XP_UNIX
jint util_GetGTKWinPtrFromCanvas(JNIEnv *env, jobject browserControlCanvas);
#endif
#endif // jni_util_h