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.
This commit is contained in:
Родитель
45a49ce848
Коммит
fd78722617
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -109,8 +109,6 @@ static char *maskNames [];
|
|||
|
||||
protected:
|
||||
|
||||
static void InitializeMaskValues(void);
|
||||
|
||||
JNIEnv *mJNIEnv;
|
||||
WebShellInitContext *mInitContext;
|
||||
jobject mTarget;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is RaptorCanvas.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Kirk Baker and
|
||||
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
|
||||
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Ed Burns <edburns@acm.org>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Methods used in the jni_util_export implementation, but not exported
|
||||
* from webclient.dll.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef bal_util_h
|
||||
#define bal_util_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#define bnull 0
|
||||
|
||||
void JNICALL bal_jstring_newFromAscii(jstring *newStr, const char *value);
|
||||
|
||||
jint JNICALL bal_str_getLength(const char *str);
|
||||
|
||||
jint JNICALL bal_jstring_getLength(const jstring str);
|
||||
|
||||
void JNICALL bal_str_newFromJstring(char **newStr, const jstring value);
|
||||
|
||||
void JNICALL bal_jstring_release(jstring value);
|
||||
|
||||
void JNICALL bal_str_release(const char *str);
|
||||
|
||||
void * JNICALL bal_allocateMemory(jint bytes);
|
||||
|
||||
void JNICALL bal_freeMemory(void *MemA);
|
||||
|
||||
void * JNICALL bal_findInMemory(const void *MemA,
|
||||
jchar ch,
|
||||
jint bytes);
|
||||
|
||||
jstring JNICALL bal_findInJstring(const jstring MemA,
|
||||
jchar ch);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // bal_util_h
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Загрузка…
Ссылка в новой задаче