From 573dca278a12a5d1b84717e5706c4afa4a734fa8 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Sat, 15 Apr 2000 00:27:35 +0000 Subject: [PATCH] bug=http://bugzilla.mozilla.org/show_bug.cgi?id=32011 Added ability to allow Native webclient client to populate the listener class hash table and provide an InstanceOf function. This enables listeners to work for the future. git-svn-id: svn://10.0.0.236/trunk@66043 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/webclient/src_moz/jni_util.cpp | 21 ++--- .../webclient/src_moz/jni_util_export.cpp | 43 ++++++++- .../java/webclient/src_moz/jni_util_export.h | 94 ++++++++++++++++++- 3 files changed, 139 insertions(+), 19 deletions(-) diff --git a/mozilla/java/webclient/src_moz/jni_util.cpp b/mozilla/java/webclient/src_moz/jni_util.cpp index e2f9953bd01..a4b8161c597 100644 --- a/mozilla/java/webclient/src_moz/jni_util.cpp +++ b/mozilla/java/webclient/src_moz/jni_util.cpp @@ -93,8 +93,8 @@ void util_SendEventToJava(JNIEnv *yourEnv, jobject nativeEventThread, { #ifdef BAL_INTERFACE if (nsnull != externalEventOccurred) { - externalEventOccurred((void *) yourEnv, (void *) nativeEventThread, - (void *) webclientEventListener, eventType); + externalEventOccurred(yourEnv, nativeEventThread, + webclientEventListener, eventType); } #else if (nsnull == gVm) { @@ -220,13 +220,7 @@ jclass util_FindClass(JNIEnv *env, const char *fullyQualifiedClassName) { jclass result = nsnull; #ifdef BAL_INTERFACE - // PENDING(edburns): there will be a function in jni_util_export - // that UNO can use to populate a 2d array with const char *, type - // pairs. The const char* will be the fullyQualifiedClassName - // argument, the type will be returned from this function. - - // For now we just return the argument - result = (jclass) fullyQualifiedClassName; + result = util_GetClassMapping(fullyQualifiedClassName); #else result = env->FindClass(fullyQualifiedClassName); #endif @@ -259,12 +253,9 @@ jboolean util_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz) { jboolean result = JNI_FALSE; #ifdef BAL_INTERFACE - // PENDING(edburns): the user will set the value of a function - // pointer. This function will do QI type stuff. This function - // pointer must be initialized at startup. - - // for now we just return JNI_TRUE - result = JNI_TRUE; + if (nsnull != externalInstanceOf) { + result = externalInstanceOf(env, obj, clazz); + } #else result = env->IsInstanceOf(obj, clazz); #endif diff --git a/mozilla/java/webclient/src_moz/jni_util_export.cpp b/mozilla/java/webclient/src_moz/jni_util_export.cpp index d89c784b45c..a4b3e87b3c2 100644 --- a/mozilla/java/webclient/src_moz/jni_util_export.cpp +++ b/mozilla/java/webclient/src_moz/jni_util_export.cpp @@ -29,7 +29,13 @@ #include "ns_globals.h" // for prLogModuleInfo -fpEventOccurredType externalEventOccurred = nsnull; +#include "nsHashtable.h" // PENDING(edburns): size optimization? + +static nsHashtable *gClassMappingTable = nsnull; + +fpEventOccurredType externalEventOccurred = nsnull; // jni_util_export.h + +fpInstanceOfType externalInstanceOf = nsnull; // jni_util_export.h JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env, jstring inString) @@ -138,8 +144,43 @@ JNIEXPORT void JNICALL util_DeleteString(JNIEnv *env, jstring toDelete) } +JNIEXPORT jint JNICALL util_StoreClassMapping(const char* jniClassName, + jclass yourClassType) +{ + if (nsnull == gClassMappingTable) { + if (nsnull == (gClassMappingTable = new nsHashtable(20, PR_TRUE))) { + return -1; + } + } + + nsStringKey key(jniClassName); + gClassMappingTable->Put(&key, yourClassType); + + return 0; +} + +JNIEXPORT jclass JNICALL util_GetClassMapping(const char* jniClassName) +{ + jclass result = nsnull; + + if (nsnull == gClassMappingTable) { + return nsnull; + } + + nsStringKey key(jniClassName); + result = (jclass) gClassMappingTable->Get(&key); + + return result; +} + + JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp) { externalEventOccurred = fp; } +JNIEXPORT void JNICALL util_SetInstanceOfFunction(fpInstanceOfType fp) +{ + externalInstanceOf = fp; +} + diff --git a/mozilla/java/webclient/src_moz/jni_util_export.h b/mozilla/java/webclient/src_moz/jni_util_export.h index 35356d1b9b4..0940ae62465 100644 --- a/mozilla/java/webclient/src_moz/jni_util_export.h +++ b/mozilla/java/webclient/src_moz/jni_util_export.h @@ -61,11 +61,89 @@ JNIEXPORT jstring JNICALL util_NewString(JNIEnv *env, const jchar *inString, JNIEXPORT void JNICALL util_DeleteString(JNIEnv *env, jstring toDelete); -typedef JNIEXPORT void (JNICALL * fpEventOccurredType) (void *env, - void *nativeEventThread, - void *webclientEventListener, +// +// BAL methods +// + +/* + + * The following methods are used by non Java JNI clients, such a + * StarOfficeDesktop. + + */ + +/** + + * This method is used to store a mapping from a jniClass Name, such as + * "org/mozilla/webclient/DocumentLoadListener" to some external class + * type, such as + * org::mozilla::webclient::wrapper_native::uno::DocumentLoadListener. + + * This table is used in util_IsInstanceOf. + + * @see util_SetInstanceOfFunction + + * @ret 0 on success + + */ + +JNIEXPORT jint JNICALL util_StoreClassMapping(const char* jniClassName, + jclass yourClassType); + +JNIEXPORT jclass JNICALL util_GetClassMapping(const char* jniClassName); + + +/** + + * Function declaration for the user defined InstanceOf function. It + * tells whether the second argument, which is an instance, is an + * instance of the type in the third argument. + + * @see util_SetInstanceOfFunction + + */ + + +typedef JNIEXPORT jboolean (JNICALL *fpInstanceOfType) (JNIEnv *env, + jobject obj, + jclass clazz); + +/** + + * Function declaration for the user defined EventOccurred function. It + * is called when an event occurrs. The second argument is the context + * for the event, passed in by the user as the second argument to + * NativeEventThreadImpl_nativeAddListener(). The third arcument is the + * listener object, passed in as the last argument to + * NativeEventThreadImpl_nativeAddListener(). The last argument is a + * listener specific type field, to indicate what kind of sub-event + * within the listener has occurred. + + */ + +typedef JNIEXPORT void (JNICALL * fpEventOccurredType) (JNIEnv *env, + jobject nativeEventThread, + jobject webclientEventListener, jlong eventType); +/** + + * This function must be called at app initialization. + + * @see fpInstanceOfType + + */ + +JNIEXPORT void JNICALL util_SetInstanceOfFunction(fpInstanceOfType fp); + +/** + + * This function must be called at app initialization. + + * @see fpEventOccurredType + + */ + JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp); /** @@ -78,6 +156,16 @@ JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp); extern fpEventOccurredType externalEventOccurred; +/** + + * defined in jni_util_export.cpp + + * The function pointer set with util_SetInstanceOfFunction. + + */ + +extern fpInstanceOfType externalInstanceOf; + #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */