Bug 596385: Update FormData to latest spec. r=jst a=blocker

This commit is contained in:
Jonas Sicking 2010-09-15 15:52:02 -07:00
Родитель 4672335b7e
Коммит e0d6f4ab59
7 изменённых файлов: 56 добавлений и 26 удалений

Просмотреть файл

@ -304,6 +304,10 @@ public:
return IsInNamespace(kNameSpaceID_XHTML);
}
inline PRBool IsHTML(nsIAtom* aTag) const {
return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
}
inline PRBool IsSVG() const {
/* Some things in the SVG namespace are not in fact SVG elements */
return IsNodeOfType(eSVG);

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsIInputStream.h"
#include "nsIDOMFile.h"
#include "nsContentUtils.h"
#include "nsHTMLFormElement.h"
nsFormData::nsFormData()
: nsFormSubmission(NS_LITERAL_CSTRING("UTF-8"), nsnull)
@ -55,6 +56,7 @@ NS_IMPL_RELEASE(nsFormData)
NS_INTERFACE_MAP_BEGIN(nsFormData)
NS_INTERFACE_MAP_ENTRY(nsIDOMFormData)
NS_INTERFACE_MAP_ENTRY(nsIXHRSendable)
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(FormData)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFormData)
NS_INTERFACE_MAP_END
@ -130,7 +132,7 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
}
// -------------------------------------------------------------------------
// nsIDXHRSendable
// nsIXHRSendable
NS_IMETHODIMP
nsFormData::GetSendInfo(nsIInputStream** aBody, nsACString& aContentType,
@ -153,3 +155,35 @@ nsFormData::GetSendInfo(nsIInputStream** aBody, nsACString& aContentType,
return NS_OK;
}
// -------------------------------------------------------------------------
// nsIJSNativeInitializer
NS_IMETHODIMP
nsFormData::Initialize(nsISupports* aOwner,
JSContext* aCx,
JSObject* aObj,
PRUint32 aArgc,
jsval* aArgv)
{
if (aArgc > 0) {
if (JSVAL_IS_PRIMITIVE(aArgv[0])) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIContent> formCont = do_QueryInterface(
nsContentUtils::XPConnect()->
GetNativeOfWrapper(aCx, JSVAL_TO_OBJECT(aArgv[0])));
if (!formCont || !formCont->IsHTML(nsGkAtoms::form)) {
return NS_ERROR_UNEXPECTED;
}
nsresult rv = static_cast<nsHTMLFormElement*>(formCont.get())->
WalkFormElements(this);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}

Просмотреть файл

@ -40,12 +40,14 @@
#include "nsIDOMFormData.h"
#include "nsIXMLHttpRequest.h"
#include "nsFormSubmission.h"
#include "nsIJSNativeInitializer.h"
#include "nsTArray.h"
class nsIDOMFile;
class nsFormData : public nsIDOMFormData,
public nsIXHRSendable,
public nsIJSNativeInitializer,
public nsFormSubmission
{
public:
@ -63,6 +65,8 @@ public:
virtual nsresult AddNameFilePair(const nsAString& aName,
nsIDOMFile* aFile);
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
PRUint32 aArgc, jsval* aArgv);
private:
struct FormDataTuple
{

Просмотреть файл

@ -1576,19 +1576,6 @@ nsHTMLFormElement::SetEncoding(const nsAString& aEncoding)
return SetEnctype(aEncoding);
}
NS_IMETHODIMP
nsHTMLFormElement::GetFormData(nsIDOMFormData** aFormData)
{
nsRefPtr<nsFormData> fd = new nsFormData();
nsresult rv = WalkFormElements(fd);
NS_ENSURE_SUCCESS(rv, rv);
*aFormData = fd.forget().get();
return NS_OK;
}
NS_IMETHODIMP
nsHTMLFormElement::GetLength(PRInt32* aLength)
{

Просмотреть файл

@ -284,6 +284,15 @@ public:
bool CheckValidFormSubmission();
virtual nsXPCClassInfo* GetClassInfo();
/**
* Walk over the form elements and call SubmitNamesValues() on them to get
* their data pumped into the FormSubmitter.
*
* @param aFormSubmission the form submission object
*/
nsresult WalkFormElements(nsFormSubmission* aFormSubmission);
protected:
class RemoveElementRunnable;
friend class RemoveElementRunnable;
@ -338,13 +347,6 @@ protected:
* @param aFormSubmission the submission object
*/
nsresult SubmitSubmission(nsFormSubmission* aFormSubmission);
/**
* Walk over the form elements and call SubmitNamesValues() on them to get
* their data pumped into the FormSubmitter.
*
* @param aFormSubmission the form submission object
*/
nsresult WalkFormElements(nsFormSubmission* aFormSubmission);
/**
* Notify any submit observers of the submit.

Просмотреть файл

@ -608,7 +608,7 @@ function runTest() {
xhr = new XMLHttpRequest();
xhr.onload = function() { gen.next(); };
xhr.open("POST", "form_submit_server.sjs");
xhr.send(form.getFormData());
xhr.send(new FormData(form));
yield; // Wait for XHR load
checkMPSubmission(JSON.parse(xhr.responseText), expectedSub);
@ -616,7 +616,7 @@ function runTest() {
setDisabled(document.getElementsByTagName("input"), true);
setDisabled(document.getElementsByTagName("select"), true);
xhr.open("POST", "form_submit_server.sjs");
xhr.send(form.getFormData());
xhr.send(new FormData(form));
yield;
checkMPSubmission(JSON.parse(xhr.responseText), []);
setDisabled(document.getElementsByTagName("input"), false);
@ -637,7 +637,7 @@ function runTest() {
checkMPSubmission(JSON.parse(xhr.responseText), expectedAugment);
// Augment <form> using FormData
fd = form.getFormData();
fd = new FormData(form);
addToFormData(fd);
xhr.open("POST", "form_submit_server.sjs");
xhr.send(fd);

Просмотреть файл

@ -41,10 +41,9 @@
interface nsIDOMFormData;
[scriptable, uuid(55bdaf9b-eacb-49d6-b4b1-a27e61ed54fc)]
[scriptable, uuid(d38a782f-f33c-4a8d-85a9-0d5da3650064)]
interface nsIDOMNSHTMLFormElement : nsISupports
{
attribute DOMString encoding;
nsIDOMFormData getFormData();
boolean checkValidity();
};