From 0898232dc595c8243c652476f09f7d03b2d5d216 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Tue, 19 Sep 2000 00:18:18 +0000 Subject: [PATCH] This fix was contributed by * Jason Mawdsley * Louis-Philippe Gagnon It enables webclient to be built and run under JDK1.1.x. Note that JavaDOM does not work under jdk1.1.x. The fix consists of two elements: On the Java side, replace all JDK1.2 specific calls with JDK1.1.x equivalents. On the native side use pre-processer macro for JNI_VERSION, like this: #ifdef JNI_VERSION_1_2 #ifndef JNI_VERSION #define JNI_VERSION JNI_VERSION_1_2 #endif #else #ifndef JNI_VERSION_1_1 #define JNI_VERSION_1_1 0x00010001 #endif #ifndef JNI_VERSION #define JNI_VERSION JNI_VERSION_1_1 #endif #endif // END: JNI_VERSION_1_2 This fix has been tested on win32, solaris, and linux. The following files are in this fix: M webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java M webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java M webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java M webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java M webclient/classes_spec/org/mozilla/webclient/wrapper_native/NativeEventThread.java M webclient/src_moz/CBrowserContainer.cpp M webclient/src_moz/nsActions.cpp M webclient/src_share/jni_util.cpp M webclient/src_share/jni_util.h M webclient/src_share/jni_util_export.cpp git-svn-id: svn://10.0.0.236/trunk@79490 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mozilla/webclient/test/DOMTreeModel.java | 6 +++- .../webclient/test/DOMViewerFrame.java | 7 +++-- .../org/mozilla/webclient/test/EMWindow.java | 3 +- .../wrapper_native/BookmarksImpl.java | 9 ++++-- .../wrapper_native/NativeEventThread.java | 22 ++++++++++--- .../webclient/src_moz/CBrowserContainer.cpp | 26 +++++++++------- mozilla/java/webclient/src_moz/nsActions.cpp | 4 ++- mozilla/java/webclient/src_share/jni_util.cpp | 31 +++++++++++++++++-- mozilla/java/webclient/src_share/jni_util.h | 24 ++++++++++++++ .../webclient/src_share/jni_util_export.cpp | 4 ++- 10 files changed, 106 insertions(+), 30 deletions(-) diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java index 799178ff2e3..ece09f8bf51 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMTreeModel.java @@ -14,6 +14,9 @@ * Inc. All Rights Reserved. * * Contributor(s): Igor Kushnirskiy + * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon */ package org.mozilla.webclient.test; @@ -35,7 +38,8 @@ class DOMTreeModel implements TreeModel, DOMTreeNotifier { rootNode = node; } public void addTreeModelListener(TreeModelListener l) { - treeModelListeners.add(l); + // use addElement instead of add for jdk1.1.x compatibility. + treeModelListeners.addElement(l); } public void removeTreeModelListener(TreeModelListener l) { treeModelListeners.removeElement(l); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java index 2f4d40e8401..9c8dc26df35 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/DOMViewerFrame.java @@ -21,6 +21,8 @@ * Ian Wilkinson * Mark Goddard * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon */ package org.mozilla.webclient.test; @@ -55,7 +57,7 @@ import java.util.Stack; * A dom viewer Frame * - * @version $Id: DOMViewerFrame.java,v 1.4 2000-07-15 18:56:30 edburns%acm.org Exp $ + * @version $Id: DOMViewerFrame.java,v 1.5 2000-09-19 00:18:13 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -188,7 +190,8 @@ protected void selectNodeInTree(Node node) } if (null != pathStack) { - pathStack.clear(); + // use removeAllElements instead of clear for jdk1.1.x compatibility. + pathStack.removeAllElements(); } populatePathStackFromNode(node); if (null == pathStack || pathStack.isEmpty()) { diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java index 96a8de8ed8b..b09569ab4a4 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/test/EMWindow.java @@ -54,7 +54,7 @@ import org.w3c.dom.Document; * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.19 2000-09-15 00:15:01 ashuk%eng.sun.com Exp $ + * @version $Id: EMWindow.java,v 1.20 2000-09-19 00:18:13 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -220,7 +220,6 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc } }); - // pack(); show(); toFront(); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java index 87742b5a856..dac362cea76 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/BookmarksImpl.java @@ -18,6 +18,8 @@ * Rights Reserved. * * Contributor(s): Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon */ package org.mozilla.webclient.wrapper_native; @@ -177,7 +179,8 @@ public BookmarkEntry newBookmarkEntry(String url) System.out.println("debug: edburns: BookmarksImpl.newBookmarkEntry: url:" + url); if (-1 != (newNode = nativeNewRDFNode(url, false))) { result = new BookmarkEntryImpl(newNode, null); - result.getProperties().setProperty(BookmarkEntry.URL, url); + // use put instead of setProperty for jdk1.1.x compatibility. + result.getProperties().put(BookmarkEntry.URL, url); } return result; @@ -193,7 +196,7 @@ public BookmarkEntry newBookmarkFolder(String name) System.out.println("debug: edburns: BookmarksImpl.newBookmarkFolder: name:" + name); if (-1 != (newNode = nativeNewRDFNode(name, true))) { result = new BookmarkEntryImpl(newNode, null); - result.getProperties().setProperty(BookmarkEntry.NAME, name); + result.getProperties().put(BookmarkEntry.NAME, name); } return result; @@ -225,7 +228,7 @@ public static void main(String [] args) Log.setApplicationName("BookmarksImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: BookmarksImpl.java,v 1.5 2000-07-22 02:48:25 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: BookmarksImpl.java,v 1.6 2000-09-19 00:18:14 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 c9987b17e34..6b3a0627226 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 @@ -19,6 +19,8 @@ * * Contributor(s): Ed Burns * Ashutosh Kulkarni + * Jason Mawdsley + * Louis-Philippe Gagnon */ package org.mozilla.webclient.wrapper_native; @@ -233,7 +235,9 @@ public void run() nativeAddListener(nativeWebShell,tempListener.listener, tempListener.listenerClassName); } - listenersToAdd.clear(); + // use removeAllElements instead of clear for jdk1.1.x + // compatibility. + listenersToAdd.removeAllElements(); } doRemoveListeners(); @@ -278,7 +282,9 @@ private void doRemoveListeners() } } - listenersToRemove.clear(); + // use removeAllElements instead of clear for jdk1.1.x + // compatibility. + listenersToRemove.removeAllElements(); } } @@ -310,7 +316,9 @@ void addListener(WCEventListenerWrapper newListener) if (null == listenersToAdd) { listenersToAdd = new Vector(); } - listenersToAdd.add(newListener); + // use addElement instead of add for jdk1.1.x + // compatibility. + listenersToAdd.addElement(newListener); } } @@ -333,10 +341,14 @@ void removeListener(WCEventListenerWrapper newListener) } if (null == newListener) { String all = "all"; - listenersToRemove.add(all); + // use addElement instead of add for jdk1.1.x + // compatibility. + listenersToRemove.addElement(all); } else { - listenersToRemove.add(newListener); + // use addElement instead of add for jdk1.1.x + // compatibility. + listenersToRemove.addElement(newListener); } } diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp index 16b78e91120..4b3fe5a8cba 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp @@ -20,6 +20,8 @@ * * Contributor(s): Ashutosh Kulkarni * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon */ @@ -68,7 +70,7 @@ CBrowserContainer::~CBrowserContainer() mMouseTarget = nsnull; mDomEventTarget = nsnull; inverseDepth = -1; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); if (properties) { ::util_DeleteGlobalRef(env, properties); } @@ -645,7 +647,7 @@ CBrowserContainer::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, // IMPORTANT: do not use initContext->env here since it comes // from another thread. Use JNU_GetEnv instead. - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); aURL->GetSpec(&urlStr); if (nsnull != urlStr) { @@ -782,7 +784,7 @@ CBrowserContainer::OnStatusURLLoad(nsIDocumentLoader* loader, // IMPORTANT: do not use initContext->env here since it comes // from another thread. Use JNU_GetEnv instead. - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); jstring statusMessage = ::util_NewString(env, (const jchar *) aMsg.GetUnicode(), length); @@ -877,7 +879,7 @@ CBrowserContainer::MouseClick(nsIDOMEvent* aMouseEvent) getPropertiesFromEvent(aMouseEvent); - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); ::util_StoreIntoPropertiesObject(env, properties, CLICK_COUNT_KEY, ONE_VALUE, (jobject) &(mInitContext->shareContext)); @@ -902,7 +904,7 @@ CBrowserContainer::MouseDblClick(nsIDOMEvent* aMouseEvent) getPropertiesFromEvent(aMouseEvent); - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); ::util_StoreIntoPropertiesObject(env, properties, CLICK_COUNT_KEY, TWO_VALUE, (jobject) &(mInitContext->shareContext)); @@ -1001,7 +1003,7 @@ NS_IMETHODIMP CBrowserContainer::RemoveMouseListener() } - ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mMouseTarget); + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), mMouseTarget); mMouseTarget = nsnull; return rv; } @@ -1013,7 +1015,7 @@ NS_IMETHODIMP CBrowserContainer::RemoveDocumentLoadListener() return NS_ERROR_FAILURE; } - ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mDocTarget); + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), mDocTarget); mDocTarget = nsnull; return rv; } @@ -1030,8 +1032,8 @@ NS_IMETHODIMP CBrowserContainer::RemoveAllListeners() mDomEventTarget = nsnull; } - ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mDocTarget); - ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), mMouseTarget); + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), mDocTarget); + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), mMouseTarget); mMouseTarget = nsnull; mDocTarget = nsnull; @@ -1080,7 +1082,7 @@ jobject JNICALL CBrowserContainer::getPropertiesFromEvent(nsIDOMEvent *event) return properties; } inverseDepth = 0; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); if (properties) { util_ClearPropertiesObject(env, properties, (jobject) @@ -1122,7 +1124,7 @@ void JNICALL CBrowserContainer::addMouseEventDataToProperties(nsIDOMEvent *aMous PRBool boolVal; char buf[20]; jstring strVal; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); // PENDING(edburns): perhaps use a macro to speed this up? rv = mouseEvent->GetScreenX(&intVal); @@ -1223,7 +1225,7 @@ nsresult JNICALL CBrowserContainer::takeActionOnNode(nsCOMPtr curren CBrowserContainer *curThis = nsnull; const PRUint32 depthStrLen = 20; // char depthStr[depthStrLen]; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); PR_ASSERT(nsnull != myObject); curThis = (CBrowserContainer *) myObject; diff --git a/mozilla/java/webclient/src_moz/nsActions.cpp b/mozilla/java/webclient/src_moz/nsActions.cpp index 8176e5ed886..50463a1aa5b 100644 --- a/mozilla/java/webclient/src_moz/nsActions.cpp +++ b/mozilla/java/webclient/src_moz/nsActions.cpp @@ -23,6 +23,8 @@ * Mark Lin * Mark Goddard * Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon */ /* @@ -718,7 +720,7 @@ wsDeallocateInitContextEvent::handleEvent () mInitContext->embeddedThread = nsnull; mInitContext->env = nsnull; if (nsnull != mInitContext->nativeEventThread) { - ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2), + ::util_DeleteGlobalRef((JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION), mInitContext->nativeEventThread); mInitContext->nativeEventThread = nsnull; } diff --git a/mozilla/java/webclient/src_share/jni_util.cpp b/mozilla/java/webclient/src_share/jni_util.cpp index 814206a0f1d..08082cc3007 100644 --- a/mozilla/java/webclient/src_share/jni_util.cpp +++ b/mozilla/java/webclient/src_share/jni_util.cpp @@ -24,6 +24,8 @@ * Ed Burns * Ashutosh Kulkarni * Ann Sunhachawee + * Jason Mawdsley + * Louis-Philippe Gagnon */ #include "jni_util.h" @@ -247,7 +249,7 @@ void util_SendEventToJava(JNIEnv *yourEnv, jobject nativeEventThread, return; } - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); if (nsnull == env) { return; @@ -451,7 +453,7 @@ void util_SetIntValueForInstance(JNIEnv *env, jobject obj, } env->SetIntField(obj, fieldID, newValue); -#endif; +#endif } jobject util_CreatePropertiesObject(JNIEnv *env, jobject initContextObj) @@ -598,8 +600,13 @@ JNU_CallMethodByNameV(JNIEnv *env, result.i = 0; +#ifdef JNI_VERSION_1_2 + if (env->EnsureLocalCapacity(3) < 0) goto done2; + +#endif + clazz = env->GetObjectClass(obj); mid = env->GetMethodID(clazz, name, signature); if (mid == 0) @@ -643,8 +650,19 @@ JNU_CallMethodByNameV(JNIEnv *env, env->DeleteLocalRef(clazz); done2: if (hasException) { +#ifdef JNI_VERSION_1_2 *hasException = env->ExceptionCheck(); - } +#else + jthrowable exception = env->ExceptionOccurred(); + if ( exception != NULL ) { + *hasException = true; + env->DeleteLocalRef( exception ); + } + else { + *hasException = false; + } +#endif + } // END return result; } @@ -656,7 +674,14 @@ JNU_GetEnv(JavaVM *vm, jint version) JNIEnv *result = nsnull; #ifdef BAL_INTERFACE #else + +#ifdef JNI_VERSION_1_2 vm->AttachCurrentThread((void **)&result, (void *) version); +#else + vm->AttachCurrentThread( &result, ( void * )version); ++ +#endif + #endif return result; } diff --git a/mozilla/java/webclient/src_share/jni_util.h b/mozilla/java/webclient/src_share/jni_util.h index 406a61e2d6b..1fb38f23fe4 100644 --- a/mozilla/java/webclient/src_share/jni_util.h +++ b/mozilla/java/webclient/src_share/jni_util.h @@ -24,6 +24,8 @@ * Ed Burns * Ashutosh Kulkarni * Ann Sunhachawee + * Jason Mawdsley + * Louis-Philippe Gagnon */ @@ -38,6 +40,28 @@ #include + +// +// added for 1.1.x compatibility +// +#ifdef JNI_VERSION_1_2 + +#ifndef JNI_VERSION +#define JNI_VERSION JNI_VERSION_1_2 +#endif + +#else + +#ifndef JNI_VERSION_1_1 +#define JNI_VERSION_1_1 0x00010001 +#endif + +#ifndef JNI_VERSION +#define JNI_VERSION JNI_VERSION_1_1 +#endif + +#endif // END: JNI_VERSION_1_2 + // // String constants, defined in jni_util.cpp // diff --git a/mozilla/java/webclient/src_share/jni_util_export.cpp b/mozilla/java/webclient/src_share/jni_util_export.cpp index f01abc55242..0efccab7bbe 100644 --- a/mozilla/java/webclient/src_share/jni_util_export.cpp +++ b/mozilla/java/webclient/src_share/jni_util_export.cpp @@ -18,6 +18,8 @@ * Rights Reserved. * * Contributor(s): Ed Burns + * Jason Mawdsley + * Louis-Philippe Gagnon * */ @@ -201,7 +203,7 @@ util_InitializeEventMaskValuesFromClass(const char *className, } if (nsnull != gVm) { - env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION_1_2); + env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); } jclass clazz = ::util_FindClass(env, className);