From 0f416e8f78b421c66bb53d32a1806ec2fb38d5a2 Mon Sep 17 00:00:00 2001 From: "aaronr%us.ibm.com" Date: Sat, 24 Feb 2007 21:51:46 +0000 Subject: [PATCH] [XForms] submission post to file doesn't work. Bug 357901, r=doronr+olli --- .../xforms/nsXFormsSubmissionElement.cpp | 119 +++++++++++------- .../resources/locale/en-US/xforms.properties | 1 + 2 files changed, 77 insertions(+), 43 deletions(-) diff --git a/extensions/xforms/nsXFormsSubmissionElement.cpp b/extensions/xforms/nsXFormsSubmissionElement.cpp index f46e849554c..7ded1a9bcad 100644 --- a/extensions/xforms/nsXFormsSubmissionElement.cpp +++ b/extensions/xforms/nsXFormsSubmissionElement.cpp @@ -2175,22 +2175,87 @@ nsXFormsSubmissionElement::SendData(const nsCString &uriSpec, return NS_ERROR_ABORT; } - // wrap the entire upload stream in a buffered input stream, so that - // it can be read in large chunks. - // XXX necko should probably do this (or something like this) for us. - nsCOMPtr bufferedStream; - if (stream) - { - NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), stream, 4096); - NS_ENSURE_STATE(bufferedStream); - } - nsCOMPtr channel; ios->NewChannelFromURI(uri, getter_AddRefs(channel)); NS_ENSURE_STATE(channel); - if (bufferedStream) + PRBool ignoreStream = PR_FALSE; + + if (mFormat & METHOD_POST) { + nsCOMPtr httpChannel = do_QueryInterface(channel); + if (!httpChannel) { + // The spec doesn't really say how to handle post with anything other + // than http. So we are free to make up our own rules. + // The only other protocols we quasi support are file and mailto. Mailto + // has already been handled by this point. For file we'll still do the + // post, but we won't bother to 'send any data' since that really has + // no meaning. This will cause Mozilla to get the local file. + // Since this is a kludgy kind of behavior to begin with (the user + // really shouldn't use POST with file:/// to begin with) we'll + // behave like formsPlayer and only allow this for replace="all" and + // replace="none". If replace="instance", we'll throw an + // xforms-submit-error. Again, this is for compliance with formsPlayer. + // A good form author should never cause us to reach here! + nsCAutoString scheme; + rv = uri->GetScheme(scheme); + NS_ENSURE_SUCCESS(rv, rv); + + PRBool allowSubmission = scheme.EqualsLiteral("file"); + if (allowSubmission) { + if (!mIsReplaceInstance) { + ignoreStream = PR_TRUE; + } else { + allowSubmission = PR_FALSE; + } + } + + if (!allowSubmission) { + nsAutoString schemeTemp = NS_ConvertASCIItoUTF16(scheme); + const PRUnichar *strings[] = { schemeTemp.get() }; + nsXFormsUtils::ReportError(NS_LITERAL_STRING("warnSubmitProtocolPost"), + strings, 1, mElement, mElement, + nsIScriptError::warningFlag); + return NS_ERROR_UNEXPECTED; + } + } else { + + rv = httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST")); + NS_ENSURE_SUCCESS(rv, rv); + + if (mIsSOAPRequest) { + nsCOMPtr mimeHdrParser = + do_GetService("@mozilla.org/network/mime-hdrparam;1"); + NS_ENSURE_STATE(mimeHdrParser); + + nsAutoString mediatype, action; + mElement->GetAttribute(NS_LITERAL_STRING("mediatype"), + mediatype); + if (!mediatype.IsEmpty()) { + + rv = mimeHdrParser->GetParameter(NS_ConvertUTF16toUTF8(mediatype), + "action", EmptyCString(), PR_FALSE, + nsnull, action); + } + if (action.IsEmpty()) { + action.AssignLiteral(" "); + } + rv = httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("SOAPAction"), + NS_ConvertUTF16toUTF8(action), + PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + } + } + } + + // wrap the entire upload stream in a buffered input stream, so that + // it can be read in large chunks. + // XXX necko should probably do this (or something like this) for us. + nsCOMPtr bufferedStream; + if (stream && !ignoreStream) { + NS_NewBufferedInputStream(getter_AddRefs(bufferedStream), stream, 4096); + NS_ENSURE_STATE(bufferedStream); + nsCOMPtr uploadChannel = do_QueryInterface(channel); NS_ENSURE_STATE(uploadChannel); @@ -2199,38 +2264,6 @@ nsXFormsSubmissionElement::SendData(const nsCString &uriSpec, NS_ENSURE_SUCCESS(rv, rv); } - if (mFormat & METHOD_POST) - { - nsCOMPtr httpChannel = do_QueryInterface(channel); - NS_ENSURE_STATE(httpChannel); - - rv = httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST")); - NS_ENSURE_SUCCESS(rv, rv); - - if (mIsSOAPRequest) { - nsCOMPtr mimeHdrParser = - do_GetService("@mozilla.org/network/mime-hdrparam;1"); - NS_ENSURE_STATE(mimeHdrParser); - - nsAutoString mediatype, action; - mElement->GetAttribute(NS_LITERAL_STRING("mediatype"), - mediatype); - if (!mediatype.IsEmpty()) { - - rv = mimeHdrParser->GetParameter(NS_ConvertUTF16toUTF8(mediatype), - "action", EmptyCString(), PR_FALSE, - nsnull, action); - } - if (action.IsEmpty()) { - action.AssignLiteral(" "); - } - rv = httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("SOAPAction"), - NS_ConvertUTF16toUTF8(action), - PR_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - } - } - // set loadGroup and notificationCallbacks nsCOMPtr loadGroup = doc->GetDocumentLoadGroup(); diff --git a/extensions/xforms/resources/locale/en-US/xforms.properties b/extensions/xforms/resources/locale/en-US/xforms.properties index 45c19f09fdc..a293a8b5ca8 100644 --- a/extensions/xforms/resources/locale/en-US/xforms.properties +++ b/extensions/xforms/resources/locale/en-US/xforms.properties @@ -87,6 +87,7 @@ warnSubmitAlreadyRunning = XForms Warning (4): Submission is already running. warnSubmitInvalidNode = XForms Warning (5): Submission validation failed for node warnSubmitSerializeFailed = XForms Warning (6): Submission failed to serialize data warnSubmitNetworkFailure = XForms Warning (7): Submission could not send data to the network +warnSubmitProtocolPost = XForms Warning (8): Submission could not be processed. We do not handle method="post" with protocol: %S. # XForms Permission Messages: xformsXDPermissionDialogTitle = Allowed Sites - XForms Cross Domain Access