diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 32e6eaed8da..17e9ae8e2d2 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -163,7 +163,7 @@ public: NS_IMETHOD GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData, - PRUint32 aHeadersDataLen); + PRUint32 aHeadersDataLen, PRBool isFile = PR_FALSE); NS_IMETHOD ShowStatus(const char *aStatusMsg); @@ -2235,7 +2235,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetInstance(nsIPluginInstance *&aInstance) } NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData, - PRUint32 aHeadersDataLen) + PRUint32 aHeadersDataLen, PRBool isFile) { NS_ENSURE_TRUE(mOwner,NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(mContext,NS_ERROR_NULL_POINTER); @@ -2271,9 +2271,28 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, const char *aTarge nsCOMPtr result; nsCOMPtr postDataStream; nsCOMPtr headersDataStream; + + // deal with post data, either in a file or raw data, and any headers if (aPostData) { - rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), PR_FALSE, (const char *) aPostData, 0); + if (isFile) { + // convert file:///c:/ to c: + const char * fileURL = (const char*)aPostData; // default to raw data + nsXPIDLCString path; + nsCOMPtr aFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + if (NS_SUCCEEDED(aFile->SetURL(fileURL))) + if (NS_SUCCEEDED(aFile->GetPath(getter_Copies(path)))) + fileURL = (const char*)path; + + // use NewPostDataStream only for post data on disk + rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), isFile, fileURL, 0); + } else { + // use NewByteInputStream to handle binary post data, see bug 105417 + rv = NS_NewByteInputStream(getter_AddRefs(result), (const char *) aPostData, aPostDataLen); + if (result) + postDataStream = do_QueryInterface(result, &rv); + } } + if (aHeadersData) { rv = NS_NewByteInputStream(getter_AddRefs(result), (const char *) aHeadersData, aHeadersDataLen); if (result) { diff --git a/layout/html/base/src/nsObjectFrame.cpp b/layout/html/base/src/nsObjectFrame.cpp index 32e6eaed8da..17e9ae8e2d2 100644 --- a/layout/html/base/src/nsObjectFrame.cpp +++ b/layout/html/base/src/nsObjectFrame.cpp @@ -163,7 +163,7 @@ public: NS_IMETHOD GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData, - PRUint32 aHeadersDataLen); + PRUint32 aHeadersDataLen, PRBool isFile = PR_FALSE); NS_IMETHOD ShowStatus(const char *aStatusMsg); @@ -2235,7 +2235,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetInstance(nsIPluginInstance *&aInstance) } NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData, - PRUint32 aHeadersDataLen) + PRUint32 aHeadersDataLen, PRBool isFile) { NS_ENSURE_TRUE(mOwner,NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(mContext,NS_ERROR_NULL_POINTER); @@ -2271,9 +2271,28 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL, const char *aTarge nsCOMPtr result; nsCOMPtr postDataStream; nsCOMPtr headersDataStream; + + // deal with post data, either in a file or raw data, and any headers if (aPostData) { - rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), PR_FALSE, (const char *) aPostData, 0); + if (isFile) { + // convert file:///c:/ to c: + const char * fileURL = (const char*)aPostData; // default to raw data + nsXPIDLCString path; + nsCOMPtr aFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + if (NS_SUCCEEDED(aFile->SetURL(fileURL))) + if (NS_SUCCEEDED(aFile->GetPath(getter_Copies(path)))) + fileURL = (const char*)path; + + // use NewPostDataStream only for post data on disk + rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), isFile, fileURL, 0); + } else { + // use NewByteInputStream to handle binary post data, see bug 105417 + rv = NS_NewByteInputStream(getter_AddRefs(result), (const char *) aPostData, aPostDataLen); + if (result) + postDataStream = do_QueryInterface(result, &rv); + } } + if (aHeadersData) { rv = NS_NewByteInputStream(getter_AddRefs(result), (const char *) aHeadersData, aHeadersDataLen); if (result) { diff --git a/modules/plugin/base/src/nsIPluginInstanceOwner.h b/modules/plugin/base/src/nsIPluginInstanceOwner.h index cb74a6b5fab..e69de29bb2d 100644 --- a/modules/plugin/base/src/nsIPluginInstanceOwner.h +++ b/modules/plugin/base/src/nsIPluginInstanceOwner.h @@ -1,144 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the NPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIPluginInstanceOwner_h___ -#define nsIPluginInstanceOwner_h___ - -#include "nsISupports.h" -#include "nsplugin.h" - -class nsIDocument; - -#define NS_IPLUGININSTANCEOWNER_IID \ -{ 0x18270870, 0x32f1, 0x11d2, \ -{ 0xa8, 0x30, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } - -struct nsIPluginInstanceOwner : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPLUGININSTANCEOWNER_IID) - - /** - * Let the owner know that an instance has been created - * - */ - NS_IMETHOD - SetInstance(nsIPluginInstance *aInstance) = 0; - - /** - * Get the instance associated with this owner. - * - */ - NS_IMETHOD - GetInstance(nsIPluginInstance *&aInstance) = 0; - - /** - * Get a handle to the window structure of the owner. - * This pointer cannot be made persistant by the caller. - * - */ - NS_IMETHOD - GetWindow(nsPluginWindow *&aWindow) = 0; - - /** - * Get the display mode for the plugin instance. - */ - NS_IMETHOD - GetMode(nsPluginMode *aMode) = 0; - - /** - * Create a place for the plugin to live in the owner's - * environment. this may or may not create a window - * depending on the windowless state of the plugin instance. - * - */ - NS_IMETHOD - CreateWidget(void) = 0; - - /** - * Called when there is a valid target so that the proper - * frame can be updated with new content. will not be called - * with nsnull aTarget. - * - */ - NS_IMETHOD - GetURL(const char *aURL, const char *aTarget, - void *aPostData, PRUint32 aPostDataLen, - void *aHeadersData, PRUint32 aHeadersDataLen) = 0; - - /** - * Show a status message in the host environment. - * - */ - NS_IMETHOD - ShowStatus(const char *aStatusMsg) = 0; - - NS_IMETHOD - ShowStatus(const PRUnichar *aStatusMsg) = 0; - - /** - * Get the associated document. - */ - NS_IMETHOD - GetDocument(nsIDocument* *aDocument) = 0; - - /** - * Invalidate the rectangle - */ - NS_IMETHOD - InvalidateRect(nsPluginRect *invalidRect) = 0; - - /** - * Invalidate the region - */ - NS_IMETHOD - InvalidateRegion(nsPluginRegion invalidRegion) = 0; - - /** - * Force a redraw - */ - NS_IMETHOD - ForceRedraw() = 0; - - /** - * Get the specified variable - */ - NS_IMETHOD - GetValue(nsPluginInstancePeerVariable variable, void *value) = 0; -}; - -#endif diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index 58e1f1264ba..d76aabca09a 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -2798,8 +2798,21 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, else if (0 == PL_strcmp(target, "_current")) target = "_self"; } + + // Make sure there is "r\n\r\n" before the post data + if (!PL_strnstr(postData, "\r\n\r\n", postDataLen)) + { + char *newPostData = nsnull; + PRUint32 newPostDataLen = 0; + if (NS_SUCCEEDED(FixPostData(postData, postDataLen, &newPostData, &newPostDataLen))) + { + postData = newPostData; + postDataLen = newPostDataLen; + } + } + rv = owner->GetURL(url, target, (void*)postData, postDataLen, - (void*) postHeaders, postHeadersLength); + (void*) postHeaders, postHeadersLength, isFile); } NS_RELEASE(peer); @@ -5290,30 +5303,22 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, // In the file case, hand the filename off to NewPostDataStream if (aIsFile) { + // convert file:///c:/ to c: nsXPIDLCString filename; - - nsCOMPtr url; - NS_NewURI(getter_AddRefs(url), aPostData); - nsCOMPtr fileURL(do_QueryInterface(url)); - if (fileURL) { - nsCOMPtr file; - fileURL->GetFile(getter_AddRefs(file)); - nsCOMPtr localFile(do_QueryInterface(file)); - if (localFile) { - localFile->GetPath(getter_Copies(filename)); - + nsCOMPtr aFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + if (NS_SUCCEEDED(aFile->SetURL(aPostData))) + if (NS_SUCCEEDED(aFile->GetPath(getter_Copies(filename)))) { // tell the listener about it so it will delete the file later listenerPeer->SetLocalFile(filename); - + // use NewPostDataStream only for post data on disk NS_NewPostDataStream(getter_AddRefs(postDataStream), aIsFile, filename, 0); } - } } else { // In the string case, we create a string buffer stream - //Make sure there is "r\n\r\n" before the post data - if (!PL_strstr(aPostData, "\r\n\r\n")) + // Make sure there is "r\n\r\n" before the post data + if (!PL_strnstr(aPostData, "\r\n\r\n", aPostDataLen)) { if (NS_SUCCEEDED(FixPostData(aPostData, aPostDataLen, &newPostData, &newPostDataLen))) { @@ -5321,8 +5326,13 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, aPostDataLen = newPostDataLen; } } - if (aPostData) - NS_NewPostDataStream(getter_AddRefs(postDataStream), aIsFile, aPostData, 0); + if (aPostData) { + nsCOMPtr result; + // use NewByteInputStream to handle binary post data, see bug 105417 + rv = NS_NewByteInputStream(getter_AddRefs(result), aPostData, aPostDataLen); + if (result) + postDataStream = do_QueryInterface(result, &rv); + } } if (!postDataStream) @@ -5385,7 +5395,7 @@ nsPluginHostImpl::FixPostData(const char *inPostData, PRUint32 inPostDataLen, } nsCRT::memset(newBuf, 0, inPostDataLen + 4); - if (!(crlf = PL_strstr(postData, "\r\n\n"))) { + if (!(crlf = PL_strnstr(postData, "\r\n\n", inPostDataLen))) { delete [] newBuf; return NS_ERROR_NULL_POINTER; } diff --git a/modules/plugin/base/src/nsPluginHostImpl.h b/modules/plugin/base/src/nsPluginHostImpl.h index 2f059116e95..6fbb6fc02e4 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.h +++ b/modules/plugin/base/src/nsPluginHostImpl.h @@ -393,7 +393,7 @@ private: * character after the last header. It will then create a new buffer * with the existing headers, a correct "\r\n\r\n", then the post data. * If no "\r\n" is found, the data does not contain headers, and a simple - * "\r\n\r\n" is prepended to the buffer. + * "\r\n\r\n" is prepended to the buffer. See bug 60228 for more info. * @param inPostData, the post data from NewPluginURLStream * @param the length of inPostData * @param outPostData the buffer which must be freed with delete []. diff --git a/modules/plugin/base/src/nsPluginViewer.cpp b/modules/plugin/base/src/nsPluginViewer.cpp index 9d0c70d2bd6..58072f26cd1 100644 --- a/modules/plugin/base/src/nsPluginViewer.cpp +++ b/modules/plugin/base/src/nsPluginViewer.cpp @@ -124,7 +124,8 @@ public: NS_IMETHOD GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, - void *aHeadersData, PRUint32 aHeadersDataLen); + void *aHeadersData, PRUint32 aHeadersDataLen, + PRBool isFile = PR_FALSE); NS_IMETHOD ShowStatus(const char *aStatusMsg); @@ -1032,8 +1033,8 @@ NS_IMETHODIMP pluginInstanceOwner :: CreateWidget(void) return rv; } -NS_IMETHODIMP pluginInstanceOwner :: GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData, - PRUint32 aHeadersDataLen) +NS_IMETHODIMP pluginInstanceOwner::GetURL(const char *aURL, const char *aTarget, void *aPostData, PRUint32 aPostDataLen, void *aHeadersData, + PRUint32 aHeadersDataLen, PRBool isFile) { NS_ENSURE_TRUE(mViewer,NS_ERROR_NULL_POINTER); @@ -1057,13 +1058,28 @@ NS_IMETHODIMP pluginInstanceOwner :: GetURL(const char *aURL, const char *aTarge nsCOMPtr result; nsCOMPtr postDataStream; nsCOMPtr headersDataStream; + + // deal with post data, either in a file or raw data, and any headers if (aPostData) { - if (PL_strncasecmp((const char*)aPostData, "file:///", 8) == 0) { - const char *fileURL = (const char*)aPostData + 8 ; - rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), PR_TRUE, fileURL, 0); - } else - rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), PR_FALSE, (const char *) aPostData, 0); + if (isFile) { + // convert file:///c:/ to c: + const char * fileURL = (const char*)aPostData; // default to raw data + nsXPIDLCString path; + nsCOMPtr aFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); + if (NS_SUCCEEDED(aFile->SetURL(fileURL))) + if (NS_SUCCEEDED(aFile->GetPath(getter_Copies(path)))) + fileURL = (const char*)path; + + // use NewPostDataStream only for post data on disk + rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), isFile, fileURL, 0); + } else { + // use NewByteInputStream to handle binary post data, see bug 105417 + rv = NS_NewByteInputStream(getter_AddRefs(result), (const char *) aPostData, aPostDataLen); + if (result) + postDataStream = do_QueryInterface(result, &rv); + } } + if (aHeadersData) { rv = NS_NewByteInputStream(getter_AddRefs(result), (const char *) aHeadersData, aHeadersDataLen); if (result) {