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 76ca29a9a15..1c091fccdf7 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 @@ -90,8 +90,6 @@ public EventRegistrationImpl(WrapperFactory yourFactory, public void delete() { - // this removes all listeners - nativeEventThread.removeListener(null); nativeEventThread = null; super.delete(); @@ -127,11 +125,12 @@ public void removeDocumentLoadListener(DocumentLoadListener listener) ParameterCheck.nonNull(listener); myFactory.throwExceptionIfNotInitialized(); Assert.assert(-1 != nativeWebShell); - - throw new UnimplementedException("\nUnimplementedException -----\n API Function EventRegistration.removeDocumentLoadListener has not yet been implemented.\n"); - - // synchronized(myBrowserControl) { - // } + Assert.assert(null != nativeEventThread); + ParameterCheck.nonNull(listener); + + synchronized(myBrowserControl) { + nativeEventThread.removeListener(listener); + } } public void addMouseListener(MouseListener listener) @@ -160,11 +159,12 @@ public void removeMouseListener(MouseListener listener) ParameterCheck.nonNull(listener); myFactory.throwExceptionIfNotInitialized(); Assert.assert(-1 != nativeWebShell); + Assert.assert(null != nativeEventThread); + ParameterCheck.nonNull(listener); - throw new UnimplementedException("\nUnimplementedException -----\n API Function EventRegistration.removeMouseListener has not yet been implemented.\n"); - - // synchronized(myBrowserControl) { - // } + synchronized(myBrowserControl) { + nativeEventThread.removeListener((WebclientEventListener)listener); + } } // ----VERTIGO_TEST_START @@ -179,7 +179,7 @@ public static void main(String [] args) Log.setApplicationName("EventRegistrationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.7 2000-07-22 02:48:25 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.8 2000-07-26 20:03:09 ashuk%eng.sun.com 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 55d826fd9ee..ba7e6d442c4 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 @@ -226,14 +226,15 @@ public void run() if (null != listenersToAdd && !listenersToAdd.isEmpty()) { tempEnum = listenersToAdd.elements(); - while (tempEnum.hasMoreElements()) { - nativeAddListener(nativeWebShell, - (WebclientEventListener) - tempEnum.nextElement()); - } - listenersToAdd.clear(); + + while (tempEnum.hasMoreElements()) { + WebclientEventListener tempListener = (WebclientEventListener) + tempEnum.nextElement(); + nativeAddListener(nativeWebShell,tempListener); } - doRemoveListeners(); + listenersToAdd.clear(); + } + doRemoveListeners(); } } @@ -268,9 +269,12 @@ private void doRemoveListeners() } } else { - throw new UnimplementedException("Webclient nativeRemoveListener not yet implemented"); + // throw new UnimplementedException("Webclient nativeRemoveListener not yet implemented"); + + nativeRemoveListener(nativeWebShell, + (WebclientEventListener) listenerObj); + } - } listenersToRemove.clear(); } @@ -423,6 +427,15 @@ public native void nativeProcessEvents(int webShellPtr); public native void nativeAddListener(int webShellPtr, WebclientEventListener typedListener); +/** + + * Called from Java to allow the native code to remove a listener. + + */ + +public native void nativeRemoveListener(int webShellPtr, + WebclientEventListener typedListener); + /** * Called from Java to allow the native code to remove all listeners. diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp index a9ded31b59b..3df1d28e142 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp @@ -700,9 +700,13 @@ CBrowserContainer::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, ::Recycle(urlStr); } } + + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mDocTarget, - DocumentLoader_maskValues[START_DOCUMENT_LOAD_EVENT_MASK], urlJStr); + DocumentLoader_maskValues[START_DOCUMENT_LOAD_EVENT_MASK], + urlJStr); + if (urlJStr) { ::util_DeleteStringUTF(mInitContext->env, (jstring) urlJStr); @@ -747,7 +751,10 @@ CBrowserContainer::OnEndDocumentLoad(nsIDocumentLoader* loader, nsIChannel *aCha util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mDocTarget, - DocumentLoader_maskValues[END_DOCUMENT_LOAD_EVENT_MASK], nsnull); + DocumentLoader_maskValues[END_DOCUMENT_LOAD_EVENT_MASK], + nsnull); + + return NS_OK; } @@ -768,7 +775,9 @@ CBrowserContainer::OnStartURLLoad(nsIDocumentLoader* loader, nsIChannel* aChanne util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mDocTarget, - DocumentLoader_maskValues[START_URL_LOAD_EVENT_MASK], nsnull); + DocumentLoader_maskValues[START_URL_LOAD_EVENT_MASK], + nsnull); + return NS_OK; } @@ -787,9 +796,12 @@ CBrowserContainer::OnProgressURLLoad(nsIDocumentLoader* loader, nsIChannel* aCha } #endif + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mDocTarget, - DocumentLoader_maskValues[PROGRESS_URL_LOAD_EVENT_MASK], nsnull); + DocumentLoader_maskValues[PROGRESS_URL_LOAD_EVENT_MASK], + nsnull); + return NS_OK; } @@ -818,12 +830,13 @@ CBrowserContainer::OnStatusURLLoad(nsIDocumentLoader* loader, JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); jstring statusMessage = ::util_NewString(env, (const jchar *) aMsg.GetUnicode(), length); - + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mDocTarget, DocumentLoader_maskValues[STATUS_URL_LOAD_EVENT_MASK], (jobject) statusMessage); + if (statusMessage) { ::util_DeleteString(mInitContext->env, statusMessage); } @@ -850,6 +863,7 @@ CBrowserContainer::OnEndURLLoad(nsIDocumentLoader* loader, nsIChannel* channel, mInitContext->nativeEventThread, mDocTarget, DocumentLoader_maskValues[END_URL_LOAD_EVENT_MASK], nsnull); + return NS_OK; } @@ -870,11 +884,14 @@ CBrowserContainer::MouseDown(nsIDOMEvent* aMouseEvent) PR_ASSERT(nsnull != aMouseEvent); getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mMouseTarget, DOMMouseListener_maskValues[MOUSE_DOWN_EVENT_MASK], properties); + + return NS_OK; } @@ -888,11 +905,14 @@ CBrowserContainer::MouseUp(nsIDOMEvent* aMouseEvent) PR_ASSERT(nsnull != aMouseEvent); getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mMouseTarget, DOMMouseListener_maskValues[MOUSE_UP_EVENT_MASK], properties); + + return NS_OK; } @@ -915,6 +935,8 @@ CBrowserContainer::MouseClick(nsIDOMEvent* aMouseEvent) mMouseTarget, DOMMouseListener_maskValues[MOUSE_CLICK_EVENT_MASK], properties); + + return NS_OK; } @@ -938,6 +960,8 @@ CBrowserContainer::MouseDblClick(nsIDOMEvent* aMouseEvent) mMouseTarget, DOMMouseListener_maskValues[MOUSE_DOUBLE_CLICK_EVENT_MASK], properties); + + return NS_OK; } @@ -951,11 +975,14 @@ CBrowserContainer::MouseOver(nsIDOMEvent* aMouseEvent) PR_ASSERT(nsnull != aMouseEvent); getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mMouseTarget, DOMMouseListener_maskValues[MOUSE_OVER_EVENT_MASK], properties); + + return NS_OK; } @@ -969,11 +996,14 @@ CBrowserContainer::MouseOut(nsIDOMEvent* aMouseEvent) PR_ASSERT(nsnull != aMouseEvent); getPropertiesFromEvent(aMouseEvent); + util_SendEventToJava(mInitContext->env, mInitContext->nativeEventThread, mMouseTarget, DOMMouseListener_maskValues[MOUSE_OUT_EVENT_MASK], properties); + + return NS_OK; } @@ -994,6 +1024,7 @@ NS_IMETHODIMP CBrowserContainer::AddMouseListener(jobject target) DOMMouseListener_maskNames, DOMMouseListener_maskValues); } + mMouseTarget = target; return rv; @@ -1011,11 +1042,39 @@ NS_IMETHODIMP CBrowserContainer::AddDocumentLoadListener(jobject target) DocumentLoader_maskNames, DocumentLoader_maskValues); } + mDocTarget = target; return rv; } +NS_IMETHODIMP CBrowserContainer::RemoveMouseListener() +{ + nsresult rv = NS_OK; + if (!mInitContext->initComplete) { + return NS_ERROR_FAILURE; + } + + + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mMouseTarget); + mMouseTarget = nsnull; + return rv; +} + +NS_IMETHODIMP CBrowserContainer::RemoveDocumentLoadListener() +{ + nsresult rv = NS_OK; + if (!mInitContext->initComplete) { + return NS_ERROR_FAILURE; + } + + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mDocTarget); + mDocTarget = nsnull; + return rv; +} + + + NS_IMETHODIMP CBrowserContainer::RemoveAllListeners() { if (mDomEventTarget) { @@ -1024,9 +1083,14 @@ NS_IMETHODIMP CBrowserContainer::RemoveAllListeners() mDomEventTarget->RemoveEventListener(eTypeUni, this, PR_FALSE); nsCRT::free(eTypeUni); mDomEventTarget = nsnull; - } + } + + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mDocTarget); + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mMouseTarget); + mMouseTarget = nsnull; mDocTarget = nsnull; + return NS_OK; } diff --git a/mozilla/java/webclient/src_moz/NativeEventThread.cpp b/mozilla/java/webclient/src_moz/NativeEventThread.cpp index ab2eb795b16..a25058c4fa8 100644 --- a/mozilla/java/webclient/src_moz/NativeEventThread.cpp +++ b/mozilla/java/webclient/src_moz/NativeEventThread.cpp @@ -307,6 +307,52 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NativeEventThr break; } + return; +} + + +JNIEXPORT void JNICALL +Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveListener +(JNIEnv *env, jobject obj, jint webShellPtr, jobject typedListener) +{ + WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr; + if (initContext == nsnull) { + ::util_ThrowExceptionToJava(env, "Exception: null initContext passed to nativeRemoveListener"); + return; + } + + jclass clazz = nsnull; + int listenerType = 0; + + while (nsnull != gSupportedListenerInterfaces[listenerType]) { + if (nsnull == + (clazz = + ::util_FindClass(env, + gSupportedListenerInterfaces[listenerType]))) { + return; + } + if (::util_IsInstanceOf(env, typedListener, clazz)) { + // We've got a winner! + break; + } + listenerType++; + } + + if (LISTENER_NOT_FOUND == (LISTENER_CLASSES) listenerType) { + ::util_ThrowExceptionToJava(env, "Exception: NativeEventThread.nativeRemoveListener(): can't find listener \n\tclass for argument"); + return; + } + + PR_ASSERT(initContext->browserContainer); + + switch(listenerType) { + case DOCUMENT_LOAD_LISTENER: + initContext->browserContainer->RemoveDocumentLoadListener(); + break; + case MOUSE_LISTENER: + initContext->browserContainer->RemoveMouseListener(); + break; + } } JNIEXPORT void JNICALL @@ -315,11 +361,11 @@ Java_org_mozilla_webclient_wrapper_1native_NativeEventThread_nativeRemoveAllList WebShellInitContext *initContext = (WebShellInitContext *)webShellPtr; if (initContext == nsnull) { - ::util_ThrowExceptionToJava(env, "Exception: null initContext passed tonativeRemoveAllListeners"); + ::util_ThrowExceptionToJava(env, "Exception: null initContext passed to nativeRemoveAllListeners"); return; } - // removeAllListeners(env, initContext); + initContext->browserContainer->RemoveAllListeners(); } /** diff --git a/mozilla/java/webclient/src_moz/wcIBrowserContainer.h b/mozilla/java/webclient/src_moz/wcIBrowserContainer.h index 03f65e8bacd..94764aebf2f 100644 --- a/mozilla/java/webclient/src_moz/wcIBrowserContainer.h +++ b/mozilla/java/webclient/src_moz/wcIBrowserContainer.h @@ -47,13 +47,17 @@ public: NS_IMETHOD AddMouseListener(jobject target) = 0; NS_IMETHOD AddDocumentLoadListener(jobject target) = 0; NS_IMETHOD RemoveAllListeners() = 0; + NS_IMETHOD RemoveMouseListener() = 0; + NS_IMETHOD RemoveDocumentLoadListener() = 0; }; #define NS_DECL_WCIBROWSERCONTAINER \ NS_IMETHOD AddMouseListener(jobject target); \ NS_IMETHOD AddDocumentLoadListener(jobject target); \ - NS_IMETHOD RemoveAllListeners(); + NS_IMETHOD RemoveAllListeners(); \ + NS_IMETHOD RemoveMouseListener(); \ + NS_IMETHOD RemoveDocumentLoadListener(); #endif