diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java index 1c091fccdf7..9258d15a0ed 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/EventRegistrationImpl.java @@ -107,6 +107,14 @@ public void delete() // Methods from EventRegistration // +/** + + * We create a WCEventListenerWrapper containing the user passed + * DocumentLoadListener, and the string obtained from + * DocumentLoadListener.class.getName(); + + */ + public void addDocumentLoadListener(DocumentLoadListener listener) { ParameterCheck.nonNull(listener); @@ -114,9 +122,16 @@ public void addDocumentLoadListener(DocumentLoadListener listener) Assert.assert(-1 != nativeWebShell); Assert.assert(null != nativeEventThread); ParameterCheck.nonNull(listener); + + WCEventListenerWrapper listenerWrapper = + new WCEventListenerWrapper(listener, + DocumentLoadListener.class.getName()); + if (null == listenerWrapper) { + throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory."); + } synchronized(myBrowserControl) { - nativeEventThread.addListener(listener); + nativeEventThread.addListener(listenerWrapper); } } @@ -128,8 +143,15 @@ public void removeDocumentLoadListener(DocumentLoadListener listener) Assert.assert(null != nativeEventThread); ParameterCheck.nonNull(listener); + WCEventListenerWrapper listenerWrapper = + new WCEventListenerWrapper(listener, + DocumentLoadListener.class.getName()); + if (null == listenerWrapper) { + throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory."); + } + synchronized(myBrowserControl) { - nativeEventThread.removeListener(listener); + nativeEventThread.removeListener(listenerWrapper); } } @@ -149,8 +171,20 @@ public void addMouseListener(MouseListener listener) WCMouseListenerImpl mouseListenerWrapper = new WCMouseListenerImpl(listener); + if (null == mouseListenerWrapper) { + throw new NullPointerException("Can't instantiate WCMouseListenerImpl, out of memory."); + } + + WCEventListenerWrapper listenerWrapper = + new WCEventListenerWrapper(mouseListenerWrapper, + MouseListener.class.getName()); + + if (null == listenerWrapper) { + throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory."); + } + synchronized(myBrowserControl) { - nativeEventThread.addListener(mouseListenerWrapper); + nativeEventThread.addListener(listenerWrapper); } } @@ -161,9 +195,24 @@ public void removeMouseListener(MouseListener listener) Assert.assert(-1 != nativeWebShell); Assert.assert(null != nativeEventThread); ParameterCheck.nonNull(listener); + + WCMouseListenerImpl mouseListenerWrapper = + new WCMouseListenerImpl(listener); + + if (null == mouseListenerWrapper) { + throw new NullPointerException("Can't instantiate WCMouseListenerImpl, out of memory."); + } + + WCEventListenerWrapper listenerWrapper = + new WCEventListenerWrapper(mouseListenerWrapper, + MouseListener.class.getName()); + + if (null == listenerWrapper) { + throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory."); + } synchronized(myBrowserControl) { - nativeEventThread.removeListener((WebclientEventListener)listener); + nativeEventThread.removeListener(listenerWrapper); } } @@ -179,7 +228,7 @@ public static void main(String [] args) Log.setApplicationName("EventRegistrationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.8 2000-07-26 20:03:09 ashuk%eng.sun.com Exp $"); + Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.9 2000-08-09 21:47:37 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java index ba7e6d442c4..78b2b65aea9 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java @@ -228,9 +228,10 @@ public void run() tempEnum = listenersToAdd.elements(); while (tempEnum.hasMoreElements()) { - WebclientEventListener tempListener = (WebclientEventListener) - tempEnum.nextElement(); - nativeAddListener(nativeWebShell,tempListener); + WCEventListenerWrapper tempListener = + (WCEventListenerWrapper) tempEnum.nextElement(); + nativeAddListener(nativeWebShell,tempListener.listener, + tempListener.listenerClassName); } listenersToAdd.clear(); } @@ -269,11 +270,12 @@ private void doRemoveListeners() } } else { - // throw new UnimplementedException("Webclient nativeRemoveListener not yet implemented"); - + WCEventListenerWrapper tempListener = + (WCEventListenerWrapper) listenerObj; nativeRemoveListener(nativeWebShell, - (WebclientEventListener) listenerObj); - + tempListener.listener, + tempListener.listenerClassName); + } } listenersToRemove.clear(); @@ -288,13 +290,18 @@ private void doRemoveListeners() * Takes the abstract WebclientEventListener instance and adds it to a * Vector of listeners to be added. This vector is scanned each time - * around the event loop in run(). + * around the event loop in run().
+ + * The vector is a vector of WCEventListenerWrapper instances. In run() + * these are unpacked and sent to nativeAddListener like this: + * nativeAddListener(nativeWebShell,tempListener.listener, + * tempListener.listenerClassName);
* @see run
*/
-void addListener(WebclientEventListener newListener)
+void addListener(WCEventListenerWrapper newListener)
{
Assert.assert(-1 != nativeWebShell);
Assert.assert(null != windowControl);
@@ -315,7 +322,7 @@ void addListener(WebclientEventListener newListener)
*/
-void removeListener(WebclientEventListener newListener)
+void removeListener(WCEventListenerWrapper newListener)
{
Assert.assert(-1 != nativeWebShell);
Assert.assert(null != windowControl);
@@ -332,7 +339,7 @@ void removeListener(WebclientEventListener newListener)
listenersToRemove.add(newListener);
}
}
-
+
}
/**
@@ -425,7 +432,8 @@ public native void nativeProcessEvents(int webShellPtr);
*/
public native void nativeAddListener(int webShellPtr,
- WebclientEventListener typedListener);
+ WebclientEventListener typedListener,
+ String listenerName);
/**
@@ -434,7 +442,8 @@ public native void nativeAddListener(int webShellPtr,
*/
public native void nativeRemoveListener(int webShellPtr,
- WebclientEventListener typedListener);
+ WebclientEventListener typedListener,
+ String listenerName);
/**
diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCEventListenerWrapper.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCEventListenerWrapper.java
new file mode 100644
index 00000000000..7b9196feac0
--- /dev/null
+++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/WCEventListenerWrapper.java
@@ -0,0 +1,80 @@
+/* -*- 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
+
+ * This is simply a "struct" type class that encapsulates a listener
+ * instance with its class name. This is necessary because the class
+ * name is lost when we deal with the listener as a
+ * WebclientEventListener, and not a WebclientEventListener subclass.
+
+ * @see org.mozilla.webclient.wrapper_native.NativeEventThread#addListener
+ * @see org.mozilla.webclient.wrapper_native.NativeEventThread#removeListener
+
+ * note that we use "package protection" here since this class isn't
+ * public.
+
+ */
+
+class WCEventListenerWrapper extends Object
+{
+//
+// Instance Variables
+//
+
+// Attribute Instance Variables
+
+// Relationship Instance Variables
+
+/**
+
+ * These are public for easy access
+
+ */
+
+public WebclientEventListener listener;
+public String listenerClassName;
+
+//
+// Constructors and Initializers
+//
+
+public WCEventListenerWrapper(WebclientEventListener yourListener,
+ String yourListenerClassName)
+{
+ ParameterCheck.nonNull(yourListener);
+ ParameterCheck.nonNull(yourListenerClassName);
+ listener = yourListener;
+ listenerClassName = yourListenerClassName;
+}
+
+
+} // end of class WCEventListenerWrapper
diff --git a/mozilla/java/webclient/src_moz/NativeEventThread.cpp b/mozilla/java/webclient/src_moz/NativeEventThread.cpp
index db7aaf1043d..96fe875e302 100644
--- a/mozilla/java/webclient/src_moz/NativeEventThread.cpp
+++ b/mozilla/java/webclient/src_moz/NativeEventThread.cpp
@@ -167,8 +167,8 @@ char * errorMessages[] = {
*/
const char *gSupportedListenerInterfaces[] = {
- "org/mozilla/webclient/DocumentLoadListener",
- "java/awt/event/MouseListener",
+ "org.mozilla.webclient.DocumentLoadListener",
+ "java.awt.event.MouseListener",
nsnull
};
@@ -251,14 +251,16 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener
-(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener)
+(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
+ jstring listenerString)
{
WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr;
-
+
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null initContext passed tonativeAddListener");
return;
}
+
if (nsnull == initContext->nativeEventThread) {
// store the java EventRegistrationImpl class in the initContext
initContext->nativeEventThread =
@@ -269,20 +271,23 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
jclass clazz = nsnull;
int listenerType = 0;
-
+ const char *listenerStringChars = ::util_GetStringUTFChars(env,
+ listenerString);
+ if (listenerStringChars == nsnull) {
+ ::util_ThrowExceptionToJava(env, "Exception: nativeAddListener: Can't get className for listener.");
+ return;
+ }
+
while (nsnull != gSupportedListenerInterfaces[listenerType]) {
- if (nsnull ==
- (clazz =
- ::util_FindClass(env,
- gSupportedListenerInterfaces[listenerType]))) {
- return;
- }
- if (::util_IsInstanceOf(env, typedListener, clazz)) {
+ if (0 == nsCRT::strcmp(gSupportedListenerInterfaces[listenerType],
+ listenerStringChars)) {
// We've got a winner!
break;
}
listenerType++;
}
+ ::util_ReleaseStringUTFChars(env, listenerString, listenerStringChars);
+ listenerStringChars = nsnull;
if (LISTENER_NOT_FOUND == (LISTENER_CLASSES) listenerType) {
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeAddListener(): can't find listener \n\tclass for argument");
@@ -312,9 +317,11 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListener
-(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener)
+(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener,
+ jstring listenerString)
{
WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr;
+
if (initContext == nsnull) {
::util_ThrowExceptionToJava(env, "Exception: null initContext passed to nativeRemoveListener");
return;
@@ -322,20 +329,23 @@ Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListene
jclass clazz = nsnull;
int listenerType = 0;
-
+ const char *listenerStringChars = ::util_GetStringUTFChars(env,
+ listenerString);
+ if (listenerStringChars == nsnull) {
+ ::util_ThrowExceptionToJava(env, "Exception: nativeRemoveListener: Can't get className for listener.");
+ return;
+ }
+
while (nsnull != gSupportedListenerInterfaces[listenerType]) {
- if (nsnull ==
- (clazz =
- ::util_FindClass(env,
- gSupportedListenerInterfaces[listenerType]))) {
- return;
- }
- if (::util_IsInstanceOf(env, typedListener, clazz)) {
+ if (0 == nsCRT::strcmp(gSupportedListenerInterfaces[listenerType],
+ listenerStringChars)) {
// We've got a winner!
break;
}
listenerType++;
}
+ ::util_ReleaseStringUTFChars(env, listenerString, listenerStringChars);
+ listenerStringChars = nsnull;
if (LISTENER_NOT_FOUND == (LISTENER_CLASSES) listenerType) {
::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeRemoveListener(): can't find listener \n\tclass for argument");
diff --git a/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp b/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp
index 99146c5bfcb..a60d4eccaaf 100644
--- a/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp
+++ b/mozilla/java/webclient/src_moz/motif/NativeLoaderStub.cpp
@@ -103,7 +103,8 @@ jboolean (* nativeWebShellRefresh)(JNIEnv *, jobject, jint);
jboolean (* nativeWebShellAddDocListener) (JNIEnv *, jobject, jint, jobject);
*/
// from NativeEventThread.h
-void (* nativeAddListener) (JNIEnv *, jobject, jint, jobject);
+void (* nativeAddListener) (JNIEnv *, jobject, jint, jobject, jstring);
+void (* nativeRemoveListener) (JNIEnv *, jobject, jint, jobject, jstring);
void (* nativeRemoveAllListeners) (JNIEnv *, jobject, jint);
void (* nativeInitialize) (JNIEnv *, jobject, jint);
void (* nativeProcessEvents) (JNIEnv *, jobject, jint);
@@ -379,10 +380,14 @@ void locateBrowserControlStubFunctions(void * dll) {
printf("got dlsym error %s\n", dlerror());
}
- nativeAddListener = (void (*) (JNIEnv *, jobject, jint, jobject)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener");
+ nativeAddListener = (void (*) (JNIEnv *, jobject, jint, jobject, jstring)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener");
if (!nativeAddListener) {
printf("got dlsym error %s\n", dlerror());
}
+ nativeRemoveListener = (void (*) (JNIEnv *, jobject, jint, jobject, jstring)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListener");
+ if (!nativeRemoveListener) {
+ printf("got dlsym error %s\n", dlerror());
+ }
nativeRemoveAllListeners = (void (*) (JNIEnv *, jobject, jint)) dlsym(dll, "Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveAllListeners");
if (!nativeRemoveAllListeners) {
printf("got dlsym error %s\n", dlerror());
@@ -416,8 +421,18 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr
* Signature: (ILorg/mozilla/webclient/WebclientEventListener;)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeAddListener
-(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener) {
- (* nativeAddListener) (env, obj, webShellPtr, typedListener);
+(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener, jstring listenerString) {
+ (* nativeAddListener) (env, obj, webShellPtr, typedListener, listenerString);
+}
+
+/*
+ * Class: org_mozilla_webclient_wrapper_0005fnative_NativeEventThread
+ * Method: nativeRemoveListener
+ * Signature: (ILorg/mozilla/webclient/WebclientEventListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListener
+(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener, jstring listenerString) {
+ (* nativeRemoveListener) (env, obj, webShellPtr, typedListener, listenerString);
}
JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveAllListeners