diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java index 8250a681ad7..90335af223f 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java @@ -134,34 +134,6 @@ public void loadURL(String absoluteURL) } }); } - - public void loadFromStreamBlocking(InputStream stream, String uri, - String contentType, int contentLength, - Properties loadInfo) { - ParameterCheck.nonNull(stream); - ParameterCheck.nonNull(uri); - ParameterCheck.nonNull(contentType); - if (contentLength < -1 || contentLength == 0) { - throw new RangeException("contentLength value " + contentLength + - " is out of range. It is should be either -1 or greater than 0."); - } - - final InputStream finalStream = stream; - final String finalUri = uri; - final String finalContentType = contentType; - final int finalContentLength = contentLength; - final Properties finalLoadInfo = loadInfo; - - NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() { - public Object run() { - nativeLoadFromStream(NavigationImpl.this.getNativeBrowserControl(), - finalStream, finalUri, - finalContentType, - finalContentLength, finalLoadInfo); - return null; - } - }); - } public void refresh(long loadFlags) { @@ -275,7 +247,7 @@ public static void main(String [] args) Log.setApplicationName("NavigationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.6 2004-04-28 14:39:54 edburns%acm.org Exp $"); + Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.7 2004-04-28 16:40:15 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/src_moz/EmbedWindow.cpp b/mozilla/java/webclient/src_moz/EmbedWindow.cpp index 12bc489fa0f..faf9ef4b7c1 100644 --- a/mozilla/java/webclient/src_moz/EmbedWindow.cpp +++ b/mozilla/java/webclient/src_moz/EmbedWindow.cpp @@ -40,6 +40,9 @@ #include "nsIContentViewerEdit.h" #include "nsIDocShell.h" #include "nsIInterfaceRequestorUtils.h" +#include "nsIInputStream.h" +#include "nsIURI.h" +#include "nsIDocShellLoadInfo.h" #include "NativeBrowserControl.h" @@ -267,6 +270,20 @@ EmbedWindow::GetSelection(JNIEnv *env, jobject mSelection) return NS_OK; } +nsresult +EmbedWindow::LoadStream(nsIInputStream *aStream, nsIURI * aURI, + const nsACString &aContentType, + const nsACString &aContentCharset, + nsIDocShellLoadInfo * aLoadInfo) +{ + nsCOMPtr docShell = do_GetInterface(mWebBrowser); + if (!docShell) { + return NS_ERROR_FAILURE; + } + return docShell->LoadStream(aStream, aURI, aContentType, aContentCharset, + aLoadInfo); +} + // nsISupports NS_IMPL_ADDREF(EmbedWindow) diff --git a/mozilla/java/webclient/src_moz/EmbedWindow.h b/mozilla/java/webclient/src_moz/EmbedWindow.h index abf91a1bb14..c29c0773c0b 100644 --- a/mozilla/java/webclient/src_moz/EmbedWindow.h +++ b/mozilla/java/webclient/src_moz/EmbedWindow.h @@ -42,6 +42,9 @@ #include "nsString.h" class NativeBrowserControl; +class nsIInputStream; +class nsIURI; +class nsIDocShellLoadInfo; #include "ns_util.h" @@ -63,6 +66,11 @@ public: nsresult SelectAll (); nsresult GetSelection (JNIEnv *env, jobject selection); + + nsresult LoadStream (nsIInputStream *aStream, nsIURI * aURI, + const nsACString &aContentType, + const nsACString &aContentCharset, + nsIDocShellLoadInfo * aLoadInfo); NS_DECL_ISUPPORTS diff --git a/mozilla/java/webclient/src_moz/InputStreamShim.cpp b/mozilla/java/webclient/src_moz/InputStreamShim.cpp index 005de265718..48f59cef806 100644 --- a/mozilla/java/webclient/src_moz/InputStreamShim.cpp +++ b/mozilla/java/webclient/src_moz/InputStreamShim.cpp @@ -51,10 +51,14 @@ InputStreamShim::~InputStreamShim() mContentLength = -1; + PR_Lock(mLock); + delete [] mBuffer; mBuffer = nsnull; mBufferLength = 0; + PR_Unlock(mLock); + mAvailable = 0; mAvailableForMozilla = 0; mNumRead = 0; diff --git a/mozilla/java/webclient/src_moz/Makefile.in b/mozilla/java/webclient/src_moz/Makefile.in index 44bdde18a5f..fb1c1261ac8 100644 --- a/mozilla/java/webclient/src_moz/Makefile.in +++ b/mozilla/java/webclient/src_moz/Makefile.in @@ -86,7 +86,6 @@ REQUIRES = xpcom \ $(NULL) # BROKEN SOURCES -# nsActions.cpp \ # CBrowserContainer.cpp \ # PromptActionEvents.cpp \ # CurrentPageActionEvents.cpp \ @@ -94,11 +93,12 @@ REQUIRES = xpcom \ # HistoryActionEvents.cpp \ # ISupportsPeer.cpp \ # NativeEventThreadActionEvents.cpp \ -# NavigationActionEvents.cpp \ # WindowControlActionEvents.cpp \ # WindowCreator.cpp \ CPPSRCS = \ + nsActions.cpp \ + NavigationActionEvents.cpp \ InputStreamShim.cpp \ CurrentPageImpl.cpp \ NativeBrowserControl.cpp \ diff --git a/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp b/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp index c205b984b41..d4a3009c476 100644 --- a/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp +++ b/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp @@ -48,9 +48,10 @@ #include "nsIDocument.h" #include "nsIFrame.h" -/* - * wsLoadURLEvent - */ +#include "NativeBrowserControl.h" +#include "EmbedWindow.h" + +/***************************** wsLoadURLEvent::wsLoadURLEvent(nsIWebNavigation* webNavigation, PRUnichar * urlString, PRInt32 urlLength) : nsActionEvent(), @@ -81,14 +82,15 @@ wsLoadURLEvent::~wsLoadURLEvent () delete mURL; } +***********************/ -wsLoadFromStreamEvent::wsLoadFromStreamEvent(NativeBrowserControl *yourInitCx, +wsLoadFromStreamEvent::wsLoadFromStreamEvent(NativeBrowserControl *yourNativeBC, void *globalStream, nsString &uriToCopy, const char *contentTypeToCopy, PRInt32 contentLength, void *globalLoadProperties) : - nsActionEvent(), mInitContext(yourInitCx), mUriString(uriToCopy), + nsActionEvent(), mNativeBrowserControl(yourNativeBC), mUriString(uriToCopy), mContentType(PL_strdup(contentTypeToCopy)), mProperties(globalLoadProperties), mShim(nsnull) { @@ -96,9 +98,9 @@ wsLoadFromStreamEvent::wsLoadFromStreamEvent(NativeBrowserControl *yourInitCx, NS_IF_ADDREF(mShim); } -wsLoadFromStreamEvent::wsLoadFromStreamEvent(NativeBrowserControl *yourInitCx, +wsLoadFromStreamEvent::wsLoadFromStreamEvent(NativeBrowserControl *yourNativeBC, InputStreamShim *yourShim) : - nsActionEvent(), mInitContext(yourInitCx), mUriString(nsnull), + nsActionEvent(), mNativeBrowserControl(yourNativeBC), mUriString(nsnull), mContentType(nsnull), mProperties(nsnull), mShim(yourShim) { } @@ -128,8 +130,8 @@ wsLoadFromStreamEvent::handleEvent () JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - // we must have both mInitContext and mShim to do anything - if (!mInitContext || !mShim) { + // we must have both mNativeBrowserControl and mShim to do anything + if (!mNativeBrowserControl || !mShim) { return (void *) rv; } @@ -162,16 +164,10 @@ wsLoadFromStreamEvent::handleEvent () printf ("debug: capelli: LoadStream - mContentType: %s mUriString: %s\n", mContentType, mUriString.get()); - rv = mInitContext->docShell->LoadStream(mShim, uri, + rv = mNativeBrowserControl->mWindow->LoadStream(mShim, uri, nsDependentCString(mContentType), NS_LITERAL_CSTRING(""), nsnull); - if (mProperties) { - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - ::util_DeleteGlobalRef(env, (jobject) mProperties); - mProperties = nsnull; - } - // make it so we don't issue multiple LoadStream calls // for this InputStreamShim instance. @@ -182,9 +178,9 @@ wsLoadFromStreamEvent::handleEvent () // if there is more data if (NS_OK == readFromJavaStatus){ // and we can create a copy of ourselves - if (repeatEvent = new wsLoadFromStreamEvent(mInitContext, mShim)) { + if (repeatEvent = new wsLoadFromStreamEvent(mNativeBrowserControl, mShim)) { // do the loop - ::util_PostEvent(mInitContext, (PLEvent *) *repeatEvent); + ::util_PostEvent((PLEvent *) *repeatEvent); rv = NS_OK; } else { @@ -204,12 +200,16 @@ wsLoadFromStreamEvent::~wsLoadFromStreamEvent () { nsCRT::free(mContentType); mContentType = nsnull; + if (mProperties) { + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + ::util_DeleteGlobalRef(env, (jobject) mProperties); + mProperties = nsnull; + } + } -/* - * wsPostEvent - */ +/********************** wsPostEvent::wsPostEvent(NativeBrowserControl *yourInitContext, nsIURI *absoluteUri, const PRUnichar *targetToCopy, @@ -219,7 +219,7 @@ wsPostEvent::wsPostEvent(NativeBrowserControl *yourInitContext, PRInt32 postHeadersLength, const char *postHeadersToCopy) : nsActionEvent(), - mInitContext(yourInitContext) + mNativeBrowserControl(yourInitContext) { mAbsoluteURI = absoluteUri; if (targetToCopy != nsnull){ @@ -253,8 +253,8 @@ wsPostEvent::handleEvent () { nsresult rv = NS_ERROR_FAILURE; - // we must have mInitContext to do anything - if (!mInitContext) { + // we must have mNativeBrowserControl to do anything + if (!mNativeBrowserControl) { return (void *) rv; } nsCOMPtr presContext; @@ -265,7 +265,7 @@ wsPostEvent::handleEvent () nsCOMPtr lh; nsCOMPtr result; - rv = mInitContext->docShell->GetPresShell(getter_AddRefs(presShell)); + rv = mNativeBrowserControl->docShell->GetPresShell(getter_AddRefs(presShell)); if (NS_FAILED(rv) || !presShell) { return (void *) rv; } @@ -280,7 +280,7 @@ wsPostEvent::handleEvent () return (void *) rv; } - rv = mInitContext->docShell->GetPresContext(getter_AddRefs(presContext)); + rv = mNativeBrowserControl->docShell->GetPresContext(getter_AddRefs(presContext)); if (NS_FAILED(rv) || !presContext) { return (void *) rv; } @@ -295,7 +295,6 @@ wsPostEvent::handleEvent () if (!lh) { return (void *) rv; } - */ rv = presContext->GetLinkHandler(getter_AddRefs(lh)); if (NS_FAILED(rv) || (!lh)) { @@ -342,10 +341,6 @@ wsPostEvent::~wsPostEvent () } -/* - * wsStopEvent - */ - wsStopEvent::wsStopEvent(nsIWebNavigation* webNavigation) : nsActionEvent(), mWebNavigation(webNavigation) @@ -366,9 +361,6 @@ wsStopEvent::handleEvent () // Added by Mark Goddard OTMP 9/2/1999 -/* - * wsRefreshEvent - */ wsRefreshEvent::wsRefreshEvent(nsIWebNavigation* webNavigation, PRInt32 reloadType) : nsActionEvent(), @@ -408,3 +400,5 @@ wsSetPromptEvent::handleEvent () } return nsnull; } // handleEvent() + +**********************/ diff --git a/mozilla/java/webclient/src_moz/NavigationActionEvents.h b/mozilla/java/webclient/src_moz/NavigationActionEvents.h index 205911857b9..bb16017c6ab 100644 --- a/mozilla/java/webclient/src_moz/NavigationActionEvents.h +++ b/mozilla/java/webclient/src_moz/NavigationActionEvents.h @@ -40,10 +40,10 @@ #include "nsIURI.h" #include "ns_util.h" -struct NativeBrowserControl; +class NativeBrowserControl; class InputStreamShim; - +/******************** class wsLoadURLEvent : public nsActionEvent { public: wsLoadURLEvent (nsIWebNavigation* webNavigation, PRUnichar * urlString, PRInt32 urlLength); @@ -55,9 +55,11 @@ protected: nsString * mURL; }; +******************/ + class wsLoadFromStreamEvent : public nsActionEvent { public: - wsLoadFromStreamEvent(NativeBrowserControl *yourInitContext, + wsLoadFromStreamEvent(NativeBrowserControl *yourNativeBC, void *globalStream, nsString &uriToCopy, const char *contentTypeToCopy, @@ -71,17 +73,18 @@ private: protected: - NativeBrowserControl *mInitContext; + NativeBrowserControl *mNativeBrowserControl; nsString mUriString; char *mContentType; // MUST be delete'd in destructor void * mProperties; // MUST be util_deleteGlobalRef'd in destructor. InputStreamShim *mShim; // DO NOT delete this in the destructor }; +/***************** class wsPostEvent : public nsActionEvent { public: - wsPostEvent(NativeBrowserControl *yourInitContext, + wsPostEvent(NativeBrowserControl *yourNativeBC, nsIURI *absoluteUrl, const PRUnichar *targetToCopy, PRInt32 targetLength, @@ -97,7 +100,7 @@ private: protected: - NativeBrowserControl *mInitContext; + NativeBrowserControl *mNativeBrowserControl; nsCOMPtr mAbsoluteURI; nsString *mTarget; const char *mPostData; @@ -139,7 +142,7 @@ protected: jobject mUserPrompt; }; - +*******************/ #endif /* NavigationActionEvents_h___ */ diff --git a/mozilla/java/webclient/src_moz/NavigationImpl.cpp b/mozilla/java/webclient/src_moz/NavigationImpl.cpp index 73517d2ec49..ed970a8a7a7 100644 --- a/mozilla/java/webclient/src_moz/NavigationImpl.cpp +++ b/mozilla/java/webclient/src_moz/NavigationImpl.cpp @@ -38,6 +38,7 @@ #include "nsNetCID.h" #include "NativeBrowserControl.h" +#include "NavigationActionEvents.h" #include "ns_util.h" JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeLoadURL @@ -84,8 +85,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio ::util_ReleaseStringChars(env, urlString, (const jchar *) urlStringChars); } - /********************** - JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativeLoadFromStream (JNIEnv *env, jobject obj, jint nativeBCPtr, jobject stream, jstring uri, jstring contentType, jint contentLength, jobject loadProperties) @@ -117,7 +116,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio goto NLFS_CLEANUP; } - // the deleteGlobalRef is done in the wsLoadFromStream destructor + // the deleteGlobalRef is done in the InputStreamShim destructor if (!(globalStream = ::util_NewGlobalRef(env, stream))) { ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: unable to create gloabal ref to stream"); goto NLFS_CLEANUP; @@ -142,7 +141,7 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio ::util_ThrowExceptionToJava(env, "Exception: nativeLoadFromStream: can't create wsLoadFromStreamEvent"); goto NLFS_CLEANUP; } - ::util_PostSynchronousEvent(nativeBrowserControl, (PLEvent *) *actionEvent); + ::util_PostSynchronousEvent((PLEvent *) *actionEvent); NLFS_CLEANUP: ::util_ReleaseStringChars(env, uri, (const jchar *) uriStringUniChars); @@ -153,6 +152,8 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_Navigatio // wsLoadFromStreamEvent destructor. } + /********************** + JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_NavigationImpl_nativePost diff --git a/mozilla/java/webclient/src_moz/ns_util.cpp b/mozilla/java/webclient/src_moz/ns_util.cpp index 5b0797b77d0..a11215ad4f2 100644 --- a/mozilla/java/webclient/src_moz/ns_util.cpp +++ b/mozilla/java/webclient/src_moz/ns_util.cpp @@ -57,7 +57,7 @@ const char *gSupportedListenerInterfaces[] = { nsnull }; -void util_PostEvent(NativeBrowserControl * initContext, PLEvent * event) +void util_PostEvent(PLEvent * event) { PL_ENTER_EVENT_QUEUE_MONITOR(NativeWrapperFactory::sActionQueue); @@ -67,7 +67,7 @@ void util_PostEvent(NativeBrowserControl * initContext, PLEvent * event) } // PostEvent() -void *util_PostSynchronousEvent(NativeWrapperFactory * initContext, PLEvent * event) +void *util_PostSynchronousEvent(PLEvent * event) { void * voidResult = nsnull; diff --git a/mozilla/java/webclient/src_moz/ns_util.h b/mozilla/java/webclient/src_moz/ns_util.h index da82130788b..522eea91f08 100644 --- a/mozilla/java/webclient/src_moz/ns_util.h +++ b/mozilla/java/webclient/src_moz/ns_util.h @@ -97,15 +97,14 @@ extern const char *gSupportedListenerInterfaces[]; // defined in ns_util.cpp * http://lxr.mozilla.org/mozilla/source/xpcom/threads/plevent.c#248 * which simply uses nice monitors to insert the event into the provided - * event queue, which is from NativeBrowserControl->actionQueue, which is - * created in NativeEventThread.cpp:InitMozillaStuff(). The events are - * processed in NativeEventThread.cpp:processEventLoop, which is called - * from the Java NativeEventThread.run(). See the code and comments for - * processEventLoop in NativeEventThread.cpp. + * event queue, which is from NativeWrapperFactory::sActionQueue. The + * events are processed in NativeEventThread.cpp:processEventLoop, which + * is called from the Java NativeEventThread.run(). See the code and + * comments for processEventLoop in NativeEventThread.cpp. */ -void util_PostEvent (NativeBrowserControl * initContext, PLEvent * event); +void util_PostEvent (PLEvent * event); /** @@ -121,7 +120,7 @@ void util_PostEvent (NativeBrowserControl * initContext, PLEvent * event); */ -void * util_PostSynchronousEvent (NativeBrowserControl * initContext, PLEvent * event); +void * util_PostSynchronousEvent (PLEvent * event); typedef struct _wsStringStruct { const PRUnichar *uniStr; diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java index 58f9a0510c4..4aa83dc75de 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/NavigationTest.java @@ -1,5 +1,5 @@ /* - * $Id: NavigationTest.java,v 1.4 2004-04-28 14:39:54 edburns%acm.org Exp $ + * $Id: NavigationTest.java,v 1.5 2004-04-28 16:40:15 edburns%acm.org Exp $ */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -89,11 +89,12 @@ public class NavigationTest extends WebclientTestCase { assertTrue(-1 != selection.toString().indexOf("This test file is for the NavigationTest.")); System.out.println("Selection is: " + selection.toString()); - /********* - RandomHTMLInputStream rhis = new RandomHTMLInputStream(3); + RandomHTMLInputStream rhis = new RandomHTMLInputStream(5, false); nav.loadFromStream(rhis, "http://randomstream.com/", "text/html", -1, null); - ************/ + selection = currentPage.getSelection(); + System.out.println("Selection is: " + selection.toString()); + frame.setVisible(false); BrowserControlFactory.deleteBrowserControl(firstBrowserControl); BrowserControlFactory.appTerminate(); diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/RandomHTMLInputStream.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/RandomHTMLInputStream.java index 2c3daae342b..1b3b8ec71ab 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/RandomHTMLInputStream.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/RandomHTMLInputStream.java @@ -75,6 +75,8 @@ private boolean isClosed; private boolean firstRead; +private boolean randomExceptions = true; + /** * the number of times that read(bytearray) can be called and still get @@ -97,9 +99,10 @@ static { CHARSET = charSet.getBytes(); } -public RandomHTMLInputStream(int yourNumReads) +public RandomHTMLInputStream(int yourNumReads, boolean yourRandomExceptions) { ParameterCheck.greaterThan(yourNumReads, 1); + randomExceptions = yourRandomExceptions; random = new Random(); Assert.assert_it(null != random); @@ -255,6 +258,9 @@ public void close() throws IOException private boolean shouldThrowException() { + if (!randomExceptions) { + return false; + } int nextInt = random.nextInt(10000); boolean result = false;