bug 32011

r=ashuk
a=edburns

Add an "eventData" argument to WebclientEvent and subclasses.
This argument is sub-event specific.  For example, when a user
gets a DocumentLoadEvent, with an event type of
STATUS_URL_LOAD, the eventData is a String containing
the status string from the browser.

Added support for doing this in a BAL context.


git-svn-id: svn://10.0.0.236/trunk@66321 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
2000-04-18 21:58:29 +00:00
parent 3d85343708
commit b51ab218cc
8 changed files with 172 additions and 57 deletions

View File

@@ -82,48 +82,12 @@ DocumentLoaderObserverImpl::DocumentLoaderObserverImpl(JNIEnv *env,
}
if (-1 == maskValues[0]) {
InitializeMaskValues();
util_InitializeEventMaskValuesFromClass("org/mozilla/webclient/DocumentLoadEvent",
maskNames, maskValues);
}
mRefCnt = 1; // PENDING(edburns): not sure about how right this is to do.
}
void DocumentLoaderObserverImpl::InitializeMaskValues()
{
// if we don't have a VM, do nothing
if (nsnull == gVm) {
return;
}
JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
if (nsnull == env) {
return;
}
jclass documentLoadEventClass = ::util_FindClass(env,
"org/mozilla/webclient/DocumentLoadEvent");
if (nsnull == documentLoadEventClass) {
return;
}
int i = 0;
jfieldID fieldID;
while (nsnull != maskNames[i]) {
fieldID = ::util_GetStaticFieldID(env, documentLoadEventClass,
maskNames[i], "J");
if (nsnull == fieldID) {
return;
}
maskValues[i] = ::util_GetStaticLongField(env, documentLoadEventClass,
fieldID);
i++;
}
}
NS_IMETHODIMP DocumentLoaderObserverImpl::QueryInterface(REFNSIID aIID, void** aInstance)
{
if (nsnull == aInstance)
@@ -155,7 +119,7 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartDocumentLoad(nsIDocumentLoader*
#endif
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[START_DOCUMENT_LOAD_EVENT_MASK]);
maskValues[START_DOCUMENT_LOAD_EVENT_MASK], nsnull);
return NS_OK;
}
@@ -173,7 +137,7 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndDocumentLoad(nsIDocumentLoader* l
util_SendEventToJava(mInitContext->env,
mInitContext->nativeEventThread, mTarget,
maskValues[END_DOCUMENT_LOAD_EVENT_MASK]);
maskValues[END_DOCUMENT_LOAD_EVENT_MASK], nsnull);
return NS_OK;
}
@@ -187,7 +151,7 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStartURLLoad(nsIDocumentLoader* load
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[START_URL_LOAD_EVENT_MASK]);
maskValues[START_URL_LOAD_EVENT_MASK], nsnull);
return NS_OK;
}
@@ -204,7 +168,7 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnProgressURLLoad(nsIDocumentLoader* l
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[PROGRESS_URL_LOAD_EVENT_MASK]);
maskValues[PROGRESS_URL_LOAD_EVENT_MASK], nsnull);
return NS_OK;
@@ -217,12 +181,26 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnStatusURLLoad(nsIDocumentLoader* loa
#if DEBUG_RAPTOR_CANVAS
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("!DocumentLoaderObserverImpl: OnStatusURLLoad\n"));
("!DocumentLoaderObserverImpl: OnStatusURLLoad: %S\n",
aMsg.GetUnicode()));
}
#endif
int length = aMsg.Length();
jstring statusMessage = ::util_NewString(mInitContext->env,
aMsg.GetUnicode(), length);
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[STATUS_URL_LOAD_EVENT_MASK]);
maskValues[STATUS_URL_LOAD_EVENT_MASK], (jobject) statusMessage);
#ifdef BAL_INTERFACE
// This violates my goal of confining all #ifdef BAL_INTERFACE to
// jni_util files, but this is the only part of the code that knows
// that eventData is a jstring. In java, this will get garbage
// collected, but in non-java contexts, it will not. Thus, we have
// to manually de-allocate it.
::util_DeleteString(mInitContext->env, statusMessage);
#endif
return NS_OK;
}
@@ -238,7 +216,7 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::OnEndURLLoad(nsIDocumentLoader* loader
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[END_URL_LOAD_EVENT_MASK]);
maskValues[END_URL_LOAD_EVENT_MASK], nsnull);
return NS_OK;
}
@@ -255,7 +233,7 @@ NS_IMETHODIMP DocumentLoaderObserverImpl::HandleUnknownContentType(nsIDocumentLo
}
#endif
util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mTarget,
maskValues[UNKNOWN_CONTENT_EVENT_MASK]);
maskValues[UNKNOWN_CONTENT_EVENT_MASK], nsnull);
return NS_OK;
}

View File

@@ -109,8 +109,6 @@ static char *maskNames [];
protected:
static void InitializeMaskValues(void);
JNIEnv *mJNIEnv;
WebShellInitContext *mInitContext;
jobject mTarget;

View File

@@ -59,6 +59,27 @@ void JNICALL bal_jstring_newFromAscii(jstring *newStr, const char *value)
*p = 0;
}
void JNICALL bal_jstring_newFromJcharArray(jstring *newStr, const jchar *value,
jsize len)
{
jint i;
jstring p;
*newStr = (jstring)bal_allocateMemory(sizeof(jchar) +
(len * sizeof(jchar)));
if (!(*newStr)) return;
p = *newStr;
for (i = 0; i < len; i++) {
/* Check ASCII range */
// OSL_ENSHURE( (*value & 0x80) == 0, "Found ASCII char > 127");
*(p++) = (jchar)*(value++);
}
*p = 0;
}
void JNICALL bal_str_newFromJstring(char **newStr, const jstring inValue)
{
jint length;

View File

@@ -42,6 +42,9 @@ extern "C" {
void JNICALL bal_jstring_newFromAscii(jstring *newStr, const char *value);
void JNICALL bal_jstring_newFromJcharArray(jstring *newStr, const jchar *value,
jsize len);
jint JNICALL bal_str_getLength(const char *str);
jint JNICALL bal_jstring_getLength(const jstring str);

View File

@@ -89,12 +89,12 @@ void *util_PostSynchronousEvent(WebShellInitContext * initContext, PLEvent * eve
void util_SendEventToJava(JNIEnv *yourEnv, jobject nativeEventThread,
jobject webclientEventListener,
jlong eventType)
jlong eventType, jobject eventData)
{
#ifdef BAL_INTERFACE
if (nsnull != externalEventOccurred) {
externalEventOccurred(yourEnv, nativeEventThread,
webclientEventListener, eventType);
webclientEventListener, eventType, eventData);
}
#else
if (nsnull == gVm) {
@@ -115,10 +115,10 @@ void util_SendEventToJava(JNIEnv *yourEnv, jobject nativeEventThread,
jclass clazz = env->GetObjectClass(nativeEventThread);
jmethodID mid = env->GetMethodID(clazz, "nativeEventOccurred",
"(Lorg/mozilla/webclient/WebclientEventListener;J)V");
"(Lorg/mozilla/webclient/WebclientEventListener;JLjava/lang/Object;)V");
if ( mid != nsnull) {
env->CallVoidMethod(nativeEventThread, mid, webclientEventListener,
eventType);
eventType, eventData);
} else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,

View File

@@ -144,7 +144,8 @@ void * util_PostSynchronousEvent (WebShellInitContext * initContext, PLEvent *
void util_SendEventToJava(JNIEnv *env, jobject eventRegistrationImpl,
jobject webclientEventListener,
jlong eventType);
jlong eventType,
jobject eventData);
char *util_GetCurrentThreadName(JNIEnv *env);

View File

@@ -22,6 +22,7 @@
*/
#include "jni_util_export.h"
#include "jni_util.h"
#include "bal_util.h"
@@ -37,6 +38,8 @@ fpEventOccurredType externalEventOccurred = nsnull; // jni_util_export.h
fpInstanceOfType externalInstanceOf = nsnull; // jni_util_export.h
fpInitializeEventMaskType externalInitializeEventMask = nsnull; // jni_util_export.h
JNIEXPORT const char * JNICALL util_GetStringUTFChars(JNIEnv *env,
jstring inString)
{
@@ -124,6 +127,7 @@ JNIEXPORT jstring JNICALL util_NewString(JNIEnv *env, const jchar *inString,
{
jstring result = nsnull;
#ifdef BAL_INTERFACE
bal_jstring_newFromJcharArray(&result, inString, len);
#else
result = env->NewString(inString, len);
#endif
@@ -184,3 +188,56 @@ JNIEXPORT void JNICALL util_SetInstanceOfFunction(fpInstanceOfType fp)
externalInstanceOf = fp;
}
JNIEXPORT void JNICALL util_SetInitializeEventMaskFunction(fpInitializeEventMaskType fp)
{
externalInitializeEventMask = fp;
}
JNIEXPORT void JNICALL
util_InitializeEventMaskValuesFromClass(const char *className,
char *maskNames[],
jlong maskValues[])
{
int i = 0;
JNIEnv *env = nsnull;
if (nsnull == className) {
return;
}
if (nsnull != gVm) {
env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2);
}
jclass clazz = ::util_FindClass(env, className);
if (nsnull == clazz) {
return;
}
#ifdef BAL_INTERFACE
if (nsnull != externalInitializeEventMask) {
externalInitializeEventMask(env, clazz,
(const char **) maskNames, maskValues);
}
#else
if (nsnull == env) {
return;
}
jfieldID fieldID;
while (nsnull != maskNames[i]) {
fieldID = ::util_GetStaticFieldID(env, clazz,
maskNames[i], "J");
if (nsnull == fieldID) {
return;
}
maskValues[i] = ::util_GetStaticLongField(env, clazz,
fieldID);
i++;
}
#endif
}

View File

@@ -67,7 +67,7 @@ JNIEXPORT void JNICALL util_DeleteString(JNIEnv *env, jstring toDelete);
/*
* The following methods are used by non Java JNI clients, such a
* The following methods are used by non Java JNI clients, such as
* StarOfficeDesktop.
*/
@@ -115,17 +115,41 @@ typedef JNIEXPORT jboolean (JNICALL *fpInstanceOfType) (JNIEnv *env,
* 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
* NativeEventThreadImpl_nativeAddListener(). The fourth argument is a
* listener specific type field, to indicate what kind of sub-event
* within the listener has occurred.
* within the listener has occurred. The last argument is a listener
* sub-event specific argument. For example, when the event class is
* DocumentLoadListener, and the sub-event is "STATUS_URL_LOAD", the
* last argument is a string with a status message, ie "Contacting host
* blah...", etc.
*/
typedef JNIEXPORT void (JNICALL * fpEventOccurredType) (JNIEnv *env,
jobject nativeEventThread,
jobject webclientEventListener,
jlong eventType);
jlong eventType,
jobject eventData);
/**
* Called at app initialization to external user to provide a function
* that will fill in the event mask values for the given listener class.
* @param nullTermMaskNameArray a NULL terminated const char * array for
* the mask names.
* @param maskValueArray a parallel array for the values that match the
* corresponding elements in nullTermMaskNameArray
*/
typedef JNIEXPORT void (JNICALL * fpInitializeEventMaskType)
(JNIEnv *env,
jclass listenerClass,
const char **nullTermMaskNameArray,
jlong *maskValueArray);
/**
* This function must be called at app initialization.
@@ -146,6 +170,17 @@ JNIEXPORT void JNICALL util_SetInstanceOfFunction(fpInstanceOfType fp);
JNIEXPORT void JNICALL util_SetEventOccurredFunction(fpEventOccurredType fp);
/**
* This function must be called at app initialization.
* @see fpInitializeEventMaskType
*/
JNIEXPORT void JNICALL util_SetInitializeEventMaskFunction(fpInitializeEventMaskType fp);
/**
* defined in jni_util_export.cpp
@@ -166,6 +201,28 @@ extern fpEventOccurredType externalEventOccurred;
extern fpInstanceOfType externalInstanceOf;
/**
* defined in jni_util_export.cpp
* The function pointer set with util_SetInitializeEventMaskFunction
*/
extern fpInitializeEventMaskType externalInitializeEventMask;
/**
* Called by the mozilla event listener implementation class at
* construction time.
*/
JNIEXPORT void JNICALL
util_InitializeEventMaskValuesFromClass(const char *className,
char *maskNames[],
jlong maskValues[]);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */