diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation2.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation2.java new file mode 100644 index 00000000000..b5df4071458 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/Navigation2.java @@ -0,0 +1,54 @@ +/* -*- 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): Kirk Baker + * Ian Wilkinson + * Mark Lin + * Mark Goddard + * Ed Burns + * Ann Sunhachawee + * Brian Satterfield + * Anthony Sizer + */ + +package org.mozilla.webclient; + +public interface Navigation2 extends Navigation +{ + +/** + + * @param absoluteUrl, must be absolute + + * @param target null at the moment + + * @param postData must end with a \r\n + + * @param postHeaders Each header, including the last, must be of the + * form "Name: value\r\n". The last header must have an additional + * "\r\n". + + */ +public void post(String absoluteUrl, + String target, + String postData, + String postHeaders); + +} +// end of interface Navigation2 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 69b4016cc88..fd11917e404 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 @@ -24,6 +24,8 @@ * Ashutosh Kulkarni * Louis-Philippe Gagnon * Jason Mawdsley + * Brian Satterfield + * Anthony Sizer */ package org.mozilla.webclient.test; @@ -57,7 +59,7 @@ import java.io.FileInputStream; * This is a test application for using the BrowserControl. * - * @version $Id: EMWindow.java,v 1.32 2001-05-29 18:34:21 ashuk%eng.sun.com Exp $ + * @version $Id: EMWindow.java,v 1.33 2001-07-12 23:18:49 edburns%acm.org Exp $ * * @see org.mozilla.webclient.BrowserControlFactory @@ -73,7 +75,7 @@ public class EMWindow extends Frame implements DialogClient, ActionListener, Doc private BrowserControl browserControl; private BrowserControlCanvas browserCanvas; - private Navigation navigation = null; + private Navigation2 navigation = null; private CurrentPage currentPage; private History history; private static Preferences prefs; @@ -229,6 +231,7 @@ private UniversalDialog uniDialog = null; refreshButton = makeItem(buttonsPanel, "Refresh", 3, 0, 1, 1, 0.0, 0.0); refreshButton.setEnabled(false); makeItem(buttonsPanel, "DOMViewer", 4, 0, 1, 1, 0.0, 0.0); + makeItem(buttonsPanel, "POST", 5, 0, 1, 1, 0.0, 0.0); // Create the control panel controlPanel = new Panel(); @@ -310,7 +313,7 @@ private UniversalDialog uniDialog = null; toFront(); try { - navigation = (Navigation) + navigation = (Navigation2) browserControl.queryInterface(BrowserControl.NAVIGATION_NAME); navigation.setPrompt(this); currentPage = (CurrentPage) @@ -565,6 +568,13 @@ public void actionPerformed (ActionEvent evt) domViewer.setVisible(true); } } + else if (command.equals("POST")) { + System.out.println("debug: edburns: post"); + navigation.post(urlField.getText(), + null, + "TESTDATA\r\n", + "Content-Length: 8\r\nX-Header:hello\r\n\r\n"); + } else if (command.equals("Back")) { if (history.canBack()) { history.back(); diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java index 3c56fb341fe..9a9d929f8b2 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/wrapper_native/NavigationImpl.java @@ -18,6 +18,8 @@ * Rights Reserved. * * Contributor(s): Ed Burns + * Brian Satterfield + * Anthony Sizer */ package org.mozilla.webclient.wrapper_native; @@ -29,6 +31,7 @@ import org.mozilla.util.RangeException; import org.mozilla.webclient.BrowserControl; import org.mozilla.webclient.Navigation; +import org.mozilla.webclient.Navigation2; import org.mozilla.webclient.WindowControl; import org.mozilla.webclient.WrapperFactory; import org.mozilla.webclient.Prompt; @@ -36,7 +39,7 @@ import org.mozilla.webclient.Prompt; import java.io.InputStream; import java.util.Properties; -public class NavigationImpl extends ImplObjectNative implements Navigation +public class NavigationImpl extends ImplObjectNative implements Navigation2 { // // Protected Constants @@ -109,7 +112,6 @@ public void loadFromStream(InputStream stream, String uri, } } - public void refresh(long loadFlags) { ParameterCheck.noLessThan(loadFlags, 0); @@ -143,6 +145,46 @@ public void setPrompt(Prompt yourPrompt) } +// +// Methods from Navigation2 +// + +public void post(String absoluteUrl, + String target, + String postData, + String postHeaders) +{ + ParameterCheck.nonNull(absoluteUrl); + myFactory.throwExceptionIfNotInitialized(); + Assert.assert_it(-1 != nativeWebShell); + + int postDataLength = 0; + int postHeadersLength = 0; + + // PENDING(edburns): make it so the url doesn't have to be absolute. + + // PENDING(edburns): check postData and postHeaders for correct + // "\r\n" as specified in Navigation.java + + if (postData != null){ + postDataLength = postData.length(); + } + + if (postHeaders != null){ + postHeadersLength = postHeaders.length(); + } + + synchronized(myBrowserControl) { + nativePost(nativeWebShell, + absoluteUrl, + target, + postDataLength, + postData, + postHeadersLength, + postHeaders); + } +} + // // Native methods // @@ -155,6 +197,15 @@ public native void nativeLoadFromStream(int webShellPtr, InputStream stream, int contentLength, Properties loadInfo); +public native void nativePost(int webShellPtr, + String absoluteUrl, + String target, + int postDataLength, + String postData, + int PostHeadersLength, + String postHeaders); + + public native void nativeRefresh(int webShellPtr, long loadFlags); public native void nativeStop(int webShellPtr); @@ -173,7 +224,7 @@ public static void main(String [] args) Log.setApplicationName("NavigationImpl"); Log.setApplicationVersion("0.0"); - Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.5 2001-05-29 18:36:10 ashuk%eng.sun.com Exp $"); + Log.setApplicationVersionDate("$Id: NavigationImpl.java,v 1.6 2001-07-12 23:18:50 edburns%acm.org Exp $"); try { org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]); diff --git a/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp b/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp index bc7fcaac12f..7edae9007fa 100644 --- a/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp +++ b/mozilla/java/webclient/src_moz/NavigationActionEvents.cpp @@ -25,6 +25,8 @@ * Ed Burns * Jason Mawdsley * Louis-Philippe Gagnon + * Brian Satterfield + * Anthony Sizer */ /* @@ -37,6 +39,14 @@ #include "InputStreamShim.h" #include "nsNetUtil.h" +#include "nsIPresContext.h" +#include "nsIPresShell.h" +#include "nsILinkHandler.h" +#include "nsIContent.h" +#include "nsNetUtil.h" // for NS_NewPostInputStream +#include "nsIDocument.h" +#include "nsIFrame.h" + /* * wsLoadURLEvent */ @@ -190,6 +200,143 @@ wsLoadFromStreamEvent::~wsLoadFromStreamEvent () } +/* + * wsPostEvent + */ +wsPostEvent::wsPostEvent(WebShellInitContext *yourInitContext, + const PRUnichar *absoluteUrlToCopy, + PRInt32 absoluteUrlLength, + const PRUnichar *targetToCopy, + PRInt32 targetLength, + PRInt32 postDataLength, + const char *postDataToCopy, + PRInt32 postHeadersLength, + const char *postHeadersToCopy) : + nsActionEvent(), + mInitContext(yourInitContext) +{ + mAbsoluteURL = new nsString(absoluteUrlToCopy, absoluteUrlLength); + + if (targetToCopy != nsnull){ + mTarget = new nsString(targetToCopy, targetLength); + } + else { + mTarget = nsnull; + } + + if (postDataToCopy != nsnull){ + mPostDataLength = postDataLength; + mPostData = PL_strdup(postDataToCopy); + } + else { + mPostDataLength = 0; + mPostData = nsnull; + } + + if (postHeadersToCopy != nsnull){ + mPostHeaderLength = postHeadersLength; + mPostHeaders = PL_strdup(postHeadersToCopy); + } + else { + mPostHeaderLength = 0; + mPostHeaders = nsnull; + } +} + +void * +wsPostEvent::handleEvent () +{ + nsresult rv = NS_ERROR_FAILURE; + + // we must have mInitContext to do anything + if (!mInitContext) { + return (void *) rv; + } + nsCOMPtr presContext; + nsCOMPtr presShell; + nsCOMPtr container; + nsCOMPtr doc; + nsCOMPtr content; + nsCOMPtr lh; + nsCOMPtr result; + + rv = mInitContext->docShell->GetPresShell(getter_AddRefs(presShell)); + if (NS_FAILED(rv) || !presShell) { + return (void *) rv; + } + + rv = presShell->GetDocument(getter_AddRefs(doc)); + if (NS_FAILED(rv) || !doc) { + return (void *) rv; + } + + content = doc->GetRootContent(); + if (!content) { + return (void *) rv; + } + + rv = mInitContext->docShell->GetPresContext(getter_AddRefs(presContext)); + if (NS_FAILED(rv) || !presContext) { + return (void *) rv; + } + + /* Alternate way to get link handler + rv = presContext->GetContainer(getter_AddRefs(container)); + if (NS_FAILED(rv) || !container) { + return (void *) rv; + } + + lh = do_QueryInterface(container, &rv); + if (!lh) { + return (void *) rv; + } + */ + + rv = presContext->GetLinkHandler(getter_AddRefs(lh)); + if (NS_FAILED(rv) || (!lh)) { + return (void *) rv; + } + + // create the streams + nsCOMPtr postDataStream = nsnull; + nsCOMPtr headersDataStream = nsnull; + + if (mPostData) { + NS_NewPostDataStream(getter_AddRefs(postDataStream), + PR_FALSE, + (const char *) mPostData, 0); + } + + if (mPostHeaders) { + NS_NewByteInputStream(getter_AddRefs(result), + (const char *) mPostHeaders, mPostHeaderLength); + if (result) { + headersDataStream = do_QueryInterface(result, &rv); + } + } + + rv = lh->OnLinkClick(content, + eLinkVerb_Replace, + mAbsoluteURL->GetUnicode(), + ((mTarget != nsnull) ? mTarget->GetUnicode() : nsnull), + postDataStream, + headersDataStream); + + return (void *) rv; + +} // handleEvent() + +wsPostEvent::~wsPostEvent () +{ + if (mAbsoluteURL != nsnull) + delete mAbsoluteURL; + if (mTarget != nsnull) + delete mTarget; + mPostData = nsnull; + mPostHeaders = nsnull; +} + + /* * wsStopEvent */ diff --git a/mozilla/java/webclient/src_moz/NavigationActionEvents.h b/mozilla/java/webclient/src_moz/NavigationActionEvents.h index 947b86436f6..6ccda90e4d5 100644 --- a/mozilla/java/webclient/src_moz/NavigationActionEvents.h +++ b/mozilla/java/webclient/src_moz/NavigationActionEvents.h @@ -23,6 +23,8 @@ * Mark Lin * Mark Goddard * Ed Burns + * Brian Satterfield + * Anthony Sizer */ /* @@ -76,6 +78,35 @@ protected: }; +class wsPostEvent : public nsActionEvent { +public: + wsPostEvent(WebShellInitContext *yourInitContext, + const PRUnichar *absoluteUrlToCopy, + PRInt32 absoluteUrlLength, + const PRUnichar *targetToCopy, + PRInt32 targetLength, + PRInt32 postDataLength, + const char *postData, + PRInt32 postHeadersLength, + const char *postHeaders); + + virtual ~wsPostEvent(); + void * handleEvent(void); + +private: + +protected: + + WebShellInitContext *mInitContext; + nsString *mAbsoluteURL; + nsString *mTarget; + const char *mPostData; + const char *mPostHeaders; + PRInt32 mPostDataLength; + PRInt32 mPostHeaderLength; +}; + + class wsStopEvent : public nsActionEvent { public: wsStopEvent (nsIWebNavigation* webNavigation); diff --git a/mozilla/java/webclient/src_moz/NavigationImpl.cpp b/mozilla/java/webclient/src_moz/NavigationImpl.cpp index e55ce287573..46e82951b42 100644 --- a/mozilla/java/webclient/src_moz/NavigationImpl.cpp +++ b/mozilla/java/webclient/src_moz/NavigationImpl.cpp @@ -24,6 +24,8 @@ * Ed Burns * Ashutosh Kulkarni * Ann Sunhachawee + * Brian Satterfield + * Anthony Sizer */ #include "NavigationImpl.h" @@ -144,6 +146,109 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl // wsLoadFromStreamEvent destructor. } +JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativePost +(JNIEnv *env, jobject obj, jint webShellPtr, jstring absoluteURL, jstring target, jint postDataLength, + jstring postData, jint postHeadersLength, jstring postHeaders) +{ + WebShellInitContext *initContext = (WebShellInitContext *) webShellPtr; + const PRUnichar *urlChars = nsnull; + PRInt32 urlLen; + const PRUnichar *targetChars = nsnull; + PRInt32 targetLen; + const char *postDataChars = nsnull; + const char *postHeadersChars = nsnull; + char *headersAndData = nsnull; + wsPostEvent *actionEvent = nsnull; + + if (initContext == nsnull || !initContext->initComplete) { + ::util_ThrowExceptionToJava(env, "Exception: null webShellPtr passed to nativePost"); + return; + } + + urlChars = (PRUnichar *) ::util_GetStringChars(env, absoluteURL); + urlLen = (PRInt32) ::util_GetStringLength(env, absoluteURL); + + if (::util_ExceptionOccurred(env)) { + ::util_ThrowExceptionToJava(env, "nativePost Exception: unable to extract Java string"); + goto NPFS_CLEANUP; + } + + if (target){ + targetChars = (PRUnichar *) ::util_GetStringChars(env, target); + targetLen = (PRInt32) ::util_GetStringLength(env, target); + } + + if (::util_ExceptionOccurred(env)) { + ::util_ThrowExceptionToJava(env, "nativePost Exception: unable to extract Java string"); + goto NPFS_CLEANUP; + } + + + if (postDataLength > 0){ + postDataChars = (char *) ::util_GetStringUTFChars(env, postData); + } + if (::util_ExceptionOccurred(env)) { + ::util_ThrowExceptionToJava(env, "nativePost Exception: unable to extract Java string"); + goto NPFS_CLEANUP; + } + + if (postHeadersLength > 0){ + postHeadersChars = (char *) ::util_GetStringUTFChars(env, postHeaders); + } + if (::util_ExceptionOccurred(env)) { + ::util_ThrowExceptionToJava(env, "nativePost Exception: unable to extract Java string"); + goto NPFS_CLEANUP; + } + + // if we have postHeaders, work around mozilla bug and prepend the + // headers to the data. + if (postHeadersChars && postDataChars) { + headersAndData = new char[postHeadersLength + postDataLength + 1]; + if (headersAndData) { + nsCRT::memcpy(headersAndData, postHeadersChars, postHeadersLength); + nsCRT::memcpy((headersAndData + postHeadersLength), + postDataChars, postDataLength); + headersAndData[postHeadersLength + postDataLength] = '\0'; + // free the existing postHeadersChars and postDataChars + ::util_ReleaseStringUTFChars(env, postHeaders, postHeadersChars); + postHeadersChars = nsnull; + postHeadersLength = 0; + ::util_ReleaseStringUTFChars(env, postData, postDataChars); + postDataChars = nsnull; + postDataLength = postHeadersLength + postDataLength; + } + } + + + if (!(actionEvent = new wsPostEvent(initContext, + urlChars, + urlLen, + targetChars, + targetLen, + (PRInt32) postDataLength, + headersAndData ? headersAndData : postDataChars, + (PRInt32) postHeadersLength, + postHeadersChars))) { + + ::util_ThrowExceptionToJava(env, "Exception: nativePost: can't create wsPostEvent"); + goto NPFS_CLEANUP; + } + + ::util_PostSynchronousEvent(initContext, (PLEvent *) *actionEvent); + + NPFS_CLEANUP: + if (urlChars != nsnull) + ::util_ReleaseStringChars(env, absoluteURL, (const jchar *) urlChars); + if (targetChars != nsnull) + ::util_ReleaseStringChars(env, target, (const jchar *) targetChars); + if (postDataChars != nsnull) + ::util_ReleaseStringUTFChars(env, postData, postDataChars); + if (postHeadersChars != nsnull) + ::util_ReleaseStringUTFChars(env, postHeaders, postHeadersChars); + if (headersAndData != nsnull) + delete [] headersAndData; + return; +} JNIEXPORT void JNICALL Java_org_mozilla_webclient_wrapper_1native_NavigationImpl_nativeRefresh (JNIEnv *env, jobject obj, jint webShellPtr, jlong loadFlags)