зеркало из https://github.com/mozilla/gecko-dev.git
[XForms] Support SOAPAction header on submission (set xforms.enableExperimentalFeatures to enable). Bug 309442, r=aaronr, smaug, doronr
This commit is contained in:
Родитель
8c052f6e97
Коммит
1a673fff79
|
@ -93,6 +93,7 @@
|
|||
#include "nsIPermissionManager.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIMIMEHeaderParam.h"
|
||||
|
||||
// namespace literals
|
||||
#define NAMESPACE_XML_SCHEMA \
|
||||
|
@ -603,6 +604,7 @@ nsXFormsSubmissionElement::Submit()
|
|||
LOG(("+++ nsXFormsSubmissionElement::Submit\n"));
|
||||
|
||||
nsresult rv;
|
||||
mIsSOAPRequest = PR_FALSE;
|
||||
|
||||
// 1. ensure that we are not currently processing a xforms-submit (see E37)
|
||||
NS_ENSURE_STATE(!mSubmissionActive);
|
||||
|
@ -773,12 +775,56 @@ nsXFormsSubmissionElement::SerializeDataXML(nsIDOMNode *data,
|
|||
nsCString &contentType,
|
||||
SubmissionAttachmentArray *attachments)
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoString mediaType;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("mediatype"), mediaType);
|
||||
if (mediaType.IsEmpty())
|
||||
contentType.AssignLiteral("application/xml");
|
||||
else
|
||||
CopyUTF16toUTF8(mediaType, contentType);
|
||||
|
||||
// Check for preference, disabling SOAP requests
|
||||
PRBool enableExperimental = PR_FALSE;
|
||||
nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && pref) {
|
||||
PRBool val;
|
||||
if (NS_SUCCEEDED(pref->GetBoolPref("xforms.enableExperimentalFeatures",
|
||||
&val)))
|
||||
enableExperimental = val;
|
||||
}
|
||||
|
||||
// Check for SOAP Envelope and handle SOAP
|
||||
if (enableExperimental) {
|
||||
nsAutoString nodeName, nodeNS;
|
||||
data->GetLocalName(nodeName);
|
||||
data->GetNamespaceURI(nodeNS);
|
||||
if (nodeName.Equals(NS_LITERAL_STRING("Envelope")) &&
|
||||
nodeNS.Equals(NS_LITERAL_STRING(NS_NAMESPACE_SOAP_ENVELOPE))) {
|
||||
mIsSOAPRequest = PR_TRUE;
|
||||
nsXFormsUtils::ReportError(NS_LITERAL_STRING("warnSOAP"), mElement,
|
||||
nsIScriptError::warningFlag);
|
||||
contentType.AssignLiteral("text/xml");
|
||||
|
||||
if (!mediaType.IsEmpty()) {
|
||||
// copy charset from mediatype
|
||||
nsAutoString charset;
|
||||
nsCOMPtr<nsIMIMEHeaderParam> mimeHdrParser =
|
||||
do_GetService("@mozilla.org/network/mime-hdrparam;1");
|
||||
NS_ENSURE_STATE(mimeHdrParser);
|
||||
rv = mimeHdrParser->GetParameter(NS_ConvertUTF16toUTF8(mediaType),
|
||||
"charset", EmptyCString(), PR_FALSE,
|
||||
nsnull, charset);
|
||||
if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) {
|
||||
contentType.AppendLiteral("; charset=");
|
||||
contentType.Append(NS_ConvertUTF16toUTF8(charset));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle non-SOAP requests
|
||||
if (!mIsSOAPRequest) {
|
||||
if (mediaType.IsEmpty())
|
||||
contentType.AssignLiteral("application/xml");
|
||||
else
|
||||
CopyUTF16toUTF8(mediaType, contentType);
|
||||
}
|
||||
|
||||
nsAutoString encoding;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("encoding"), encoding);
|
||||
|
@ -800,7 +846,6 @@ nsXFormsSubmissionElement::SerializeDataXML(nsIDOMNode *data,
|
|||
nsCOMPtr<nsIDOMDocument> doc, newDoc;
|
||||
data->GetOwnerDocument(getter_AddRefs(doc));
|
||||
|
||||
nsresult rv;
|
||||
// XXX: We can't simply pass in data if !doc, since it crashes
|
||||
if (!doc) {
|
||||
// owner doc is null when the data node is the document (e.g., ref="/")
|
||||
|
@ -1840,6 +1885,29 @@ nsXFormsSubmissionElement::SendData(const nsCString &uriSpec,
|
|||
|
||||
rv = httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mIsSOAPRequest) {
|
||||
nsCOMPtr<nsIMIMEHeaderParam> 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
|
||||
|
|
|
@ -83,6 +83,7 @@ public:
|
|||
: mElement(nsnull)
|
||||
, mSubmissionActive(PR_FALSE)
|
||||
, mIsReplaceInstance(PR_FALSE)
|
||||
, mIsSOAPRequest(PR_FALSE)
|
||||
, mFormat(0)
|
||||
{}
|
||||
|
||||
|
@ -118,6 +119,7 @@ private:
|
|||
nsIDOMElement *mElement;
|
||||
PRPackedBool mSubmissionActive;
|
||||
PRPackedBool mIsReplaceInstance; // Valid when mSubmissionActive == PR_TRUE
|
||||
PRPackedBool mIsSOAPRequest;
|
||||
PRUint32 mFormat; // Valid when mSubmissionActive == PR_TRUE
|
||||
nsCOMPtr<nsIXFormsSubmitElement> mActivator;
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ class nsIDOMEvent;
|
|||
#define NS_NAMESPACE_XML_SCHEMA "http://www.w3.org/2001/XMLSchema"
|
||||
#define NS_NAMESPACE_XML_SCHEMA_INSTANCE "http://www.w3.org/2001/XMLSchema-instance"
|
||||
#define NS_NAMESPACE_MOZ_XFORMS_TYPE "http://www.mozilla.org/projects/xforms/2005/type"
|
||||
#define NS_NAMESPACE_SOAP_ENVELOPE "http://schemas.xmlsoap.org/soap/envelope/"
|
||||
#define NS_NAMESPACE_MOZ_XFORMS_LAZY "http://www.mozilla.org/projects/xforms/2005/lazy"
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,6 +59,9 @@ invalidSeparator = XForms Error (20): Submission separator may only be eithe
|
|||
instanceBindError = XForms Error (21): Submission failed trying to replace instance document '%S'. Instance document doesn't exist in same model as submission element.
|
||||
instanceInstanceLoad = XForms Error (22): Instance document not allowed to load external instance: %S
|
||||
|
||||
# Warning Messages:
|
||||
warnSOAP = XForms Warning (1): You are using the SOAP post feature, which is an experimental feature! Beware that the functionality might change, and forms may stop working at any time.
|
||||
|
||||
# XForms Permission Messages:
|
||||
xformsXDPermissionDialogTitle = Allowed Sites - XForms Cross Domain Access
|
||||
xformsXDPermissionDialogIntro = You can specify which web sites containing XForms may submit data to other domains. Type the exact address of the site you want to allow and then press Allow.
|
||||
|
|
Загрузка…
Ссылка в новой задаче