Bug 776539 - Move FormData to Paris bindings; r=bz

This commit is contained in:
Ms2ger 2012-12-11 19:09:56 +01:00
Родитель f86cd2d8b1
Коммит 8fc67dfff7
13 изменённых файлов: 131 добавлений и 98 удалений

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

@ -6,26 +6,29 @@
#include "nsIVariant.h"
#include "nsIInputStream.h"
#include "nsIDOMFile.h"
#include "nsContentUtils.h"
#include "nsHTMLFormElement.h"
#include "mozilla/dom/FormDataBinding.h"
nsFormData::nsFormData()
using namespace mozilla;
using namespace mozilla::dom;
nsFormData::nsFormData(nsISupports* aOwner)
: nsFormSubmission(NS_LITERAL_CSTRING("UTF-8"), nullptr)
, mOwner(aOwner)
{
SetIsDOMBinding();
}
// -------------------------------------------------------------------------
// nsISupports
DOMCI_DATA(FormData, nsFormData)
NS_IMPL_ADDREF(nsFormData)
NS_IMPL_RELEASE(nsFormData)
NS_INTERFACE_MAP_BEGIN(nsFormData)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsFormData, mOwner)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormData)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormData)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormData)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
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
@ -39,28 +42,22 @@ nsFormData::GetEncodedSubmission(nsIURI* aURI,
return NS_OK;
}
nsresult
nsFormData::AddNameValuePair(const nsAString& aName,
const nsAString& aValue)
void
nsFormData::Append(const nsAString& aName, const nsAString& aValue)
{
FormDataTuple* data = mFormData.AppendElement();
data->name = aName;
data->stringValue = aValue;
data->valueIsFile = false;
return NS_OK;
}
nsresult
nsFormData::AddNameFilePair(const nsAString& aName,
nsIDOMBlob* aBlob)
void
nsFormData::Append(const nsAString& aName, nsIDOMBlob* aBlob)
{
FormDataTuple* data = mFormData.AppendElement();
data->name = aName;
data->fileValue = aBlob;
data->valueIsFile = true;
return NS_OK;
}
// -------------------------------------------------------------------------
@ -84,7 +81,8 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports);
if (domBlob) {
return AddNameFilePair(aName, domBlob);
Append(aName, domBlob);
return NS_OK;
}
}
@ -96,7 +94,27 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
nsString valAsString;
valAsString.Adopt(stringData, stringLen);
return AddNameValuePair(aName, valAsString);
Append(aName, valAsString);
return NS_OK;
}
/* virtual */ JSObject*
nsFormData::WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap)
{
return FormDataBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
/* static */ already_AddRefed<nsFormData>
nsFormData::Constructor(nsISupports* aGlobal,
const Optional<nsHTMLFormElement*>& aFormElement,
ErrorResult& aRv)
{
nsRefPtr<nsFormData> formData = new nsFormData(aGlobal);
if (aFormElement.WasPassed()) {
MOZ_ASSERT(aFormElement.Value());
aRv = aFormElement.Value()->WalkFormElements(formData);
}
return formData.forget();
}
// -------------------------------------------------------------------------
@ -124,35 +142,3 @@ nsFormData::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
return NS_OK;
}
// -------------------------------------------------------------------------
// nsIJSNativeInitializer
NS_IMETHODIMP
nsFormData::Initialize(nsISupports* aOwner,
JSContext* aCx,
JSObject* aObj,
uint32_t 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;
}

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

@ -8,34 +8,72 @@
#include "nsIDOMFormData.h"
#include "nsIXMLHttpRequest.h"
#include "nsFormSubmission.h"
#include "nsIJSNativeInitializer.h"
#include "nsWrapperCache.h"
#include "nsTArray.h"
#include "mozilla/ErrorResult.h"
class nsHTMLFormElement;
class nsIDOMFile;
namespace mozilla {
class ErrorResult;
namespace dom {
template<class> class Optional;
} // namespace dom
} // namespace mozilla
class nsFormData : public nsIDOMFormData,
public nsIXHRSendable,
public nsIJSNativeInitializer,
public nsFormSubmission
public nsFormSubmission,
public nsWrapperCache
{
public:
nsFormData();
nsFormData(nsISupports* aOwner = nullptr);
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData,
nsIDOMFormData)
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMFORMDATA
NS_DECL_NSIXHRSENDABLE
// nsWrapperCache
virtual JSObject*
WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap) MOZ_OVERRIDE;
// WebIDL
nsISupports*
GetParentObject() const
{
return mOwner;
}
static already_AddRefed<nsFormData>
Constructor(nsISupports* aGlobal,
const mozilla::dom::Optional<nsHTMLFormElement*>& aFormElement,
mozilla::ErrorResult& aRv);
void Append(const nsAString& aName, const nsAString& aValue);
void Append(const nsAString& aName, nsIDOMBlob* aBlob);
// nsFormSubmission
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
nsIInputStream** aPostDataStream);
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue);
const nsAString& aValue)
{
Append(aName, aValue);
return NS_OK;
}
virtual nsresult AddNameFilePair(const nsAString& aName,
nsIDOMBlob* aBlob);
nsIDOMBlob* aBlob)
{
Append(aName, aBlob);
return NS_OK;
}
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
uint32_t aArgc, jsval* aArgv);
private:
nsCOMPtr<nsISupports> mOwner;
struct FormDataTuple
{
nsString name;
@ -43,7 +81,7 @@ private:
nsCOMPtr<nsIDOMBlob> fileValue;
bool valueIsFile;
};
nsTArray<FormDataTuple> mFormData;
};

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

@ -79,9 +79,10 @@
#include "nsIPermissionManager.h"
#include "nsMimeTypes.h"
#include "nsIHttpChannelInternal.h"
#include "nsFormData.h"
#include "nsStreamListenerWrapper.h"
#include "nsWrapperCacheInlines.h"
#include "nsStreamListenerWrapper.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -2666,11 +2667,9 @@ nsXMLHttpRequest::GetRequestBody(nsIVariant* aVariant,
}
case nsXMLHttpRequest::RequestBody::FormData:
{
nsresult rv;
nsCOMPtr<nsIXHRSendable> sendable = do_QueryInterface(value.mFormData, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return ::GetRequestBody(sendable, aResult, aContentLength, aContentType, aCharset);
MOZ_ASSERT(value.mFormData);
return ::GetRequestBody(value.mFormData, aResult, aContentLength,
aContentType, aCharset);
}
case nsXMLHttpRequest::RequestBody::InputStream:
{

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

@ -52,7 +52,7 @@
class nsILoadGroup;
class AsyncVerifyRedirectCallbackForwarder;
class nsIUnicodeDecoder;
class nsIDOMFormData;
class nsFormData;
class nsXHREventTarget : public nsDOMEventTargetHelper,
public nsIXMLHttpRequestEventTarget
@ -288,9 +288,9 @@ private:
{
mValue.mString = &aString;
}
RequestBody(nsIDOMFormData* aFormData) : mType(FormData)
RequestBody(nsFormData& aFormData) : mType(FormData)
{
mValue.mFormData = aFormData;
mValue.mFormData = &aFormData;
}
RequestBody(nsIInputStream* aStream) : mType(InputStream)
{
@ -311,7 +311,7 @@ private:
nsIDOMBlob* mBlob;
nsIDocument* mDocument;
const nsAString* mString;
nsIDOMFormData* mFormData;
nsFormData* mFormData;
nsIInputStream* mStream;
};
@ -376,9 +376,8 @@ public:
aRv = Send(RequestBody(aString));
}
}
void Send(nsIDOMFormData* aFormData, ErrorResult& aRv)
void Send(nsFormData& aFormData, ErrorResult& aRv)
{
NS_ASSERTION(aFormData, "Null should go to string version");
aRv = Send(RequestBody(aFormData));
}
void Send(nsIInputStream* aStream, ErrorResult& aRv)

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

@ -427,7 +427,6 @@
#include "nsDOMFile.h"
#include "nsDOMFileReader.h"
#include "nsIDOMFormData.h"
#include "ArchiveReader.h"
#include "ArchiveRequest.h"
@ -1566,9 +1565,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageSender, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(FormData, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DesktopNotification, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DesktopNotificationCenter, nsDOMGenericSH,
@ -1709,7 +1705,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CONTRACT_CTOR(FileReader, NS_FILEREADER_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(ArchiveReader, NS_ARCHIVEREADER_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(FormData, NS_FORMDATA_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(XPathEvaluator, NS_XPATH_EVALUATOR_CONTRACTID)
NS_DEFINE_CONTRACT_CTOR(XSLTProcessor,
"@mozilla.org/document-transformer;1?type=xslt")
@ -1774,7 +1769,6 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] =
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozSmsFilter, sms::SmsFilter::NewSmsFilter)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(FileReader, FileReaderCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(ArchiveReader, ArchiveReaderCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(FormData, FormDataCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XPathEvaluator, XPathEvaluatorCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(EventSource, EventSourceCtor)
@ -4201,10 +4195,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(FormData, nsIDOMFormData)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMFormData)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DesktopNotification, nsIDOMDesktopNotification)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDesktopNotification)
DOM_CLASSINFO_MAP_END

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

@ -448,8 +448,6 @@ DOMCI_CLASS(ContentFrameMessageManager)
DOMCI_CLASS(ChromeMessageBroadcaster)
DOMCI_CLASS(ChromeMessageSender)
DOMCI_CLASS(FormData)
DOMCI_CLASS(DesktopNotification)
DOMCI_CLASS(DesktopNotificationCenter)

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

@ -245,8 +245,13 @@ DOMInterfaces = {
},
'FormData': [
{
'nativeType': 'nsFormData'
},
{
'workers': True,
'skipGen': True,
'nativeType': 'JSObject'
}],
'GainNode': [
@ -743,6 +748,7 @@ def addExternalHTMLElement(element):
headerFile=nativeElement + '.h')
addExternalHTMLElement('HTMLCanvasElement')
addExternalHTMLElement('HTMLFormElement')
addExternalHTMLElement('HTMLImageElement')
addExternalHTMLElement('HTMLMenuElement')
addExternalHTMLElement('HTMLOptionElement')

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

@ -2,14 +2,5 @@
"XMLHttpRequest interface constructor": true,
"XMLHttpRequest interface: operation open(DOMString,DOMString,boolean,DOMString,DOMString)": true,
"XMLHttpRequest interface: operation send(union)": true,
"FormData interface: existence and properties of interface object": true,
"FormData interface constructor": true,
"FormData interface: existence and properties of interface prototype object": true,
"FormData interface: existence and properties of interface prototype object's \"constructor\" property": true,
"Stringification of new FormData()": "debug",
"FormData interface: calling append(DOMString,Blob,DOMString) on new FormData() with too few arguments must throw TypeError": true,
"FormData interface: calling append(DOMString,DOMString) on new FormData() with too few arguments must throw TypeError": true,
"Stringification of new FormData(form)": "debug",
"FormData interface: calling append(DOMString,Blob,DOMString) on new FormData(form) with too few arguments must throw TypeError": true,
"FormData interface: calling append(DOMString,DOMString) on new FormData(form) with too few arguments must throw TypeError": true
"FormData interface constructor": true
}

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

@ -0,0 +1,18 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this IDL file is
* http://xhr.spec.whatwg.org
*/
interface HTMLFormElement;
[Constructor(optional HTMLFormElement form)]
interface FormData {
// Not supported (bug 739174)
// void append(DOMString name, Blob value, optional DOMString filename);
void append(DOMString name, Blob value);
void append(DOMString name, DOMString value);
};

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

@ -36,6 +36,7 @@ webidl_files = \
FileHandle.webidl \
FileList.webidl \
FileReaderSync.webidl \
FormData.webidl \
Function.webidl \
GainNode.webidl \
HTMLCollection.webidl \

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

@ -12,7 +12,6 @@
interface Document;
interface Blob;
interface FormData;
interface InputStream;
interface MozChannel;
interface IID;

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

@ -178,6 +178,12 @@ public:
void
Send(JSObject* aBody, ErrorResult& aRv);
void
Send(JSObject& aBody, ErrorResult& aRv)
{
Send(&aBody, aRv);
}
void
Send(ArrayBuffer& aBody, ErrorResult& aRv) {
return Send(aBody.Obj(), aRv);

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

@ -9,6 +9,7 @@
#include "nsGenericHTMLElement.h"
#include "nsHTMLCanvasElement.h"
#include "nsHTMLDivElement.h"
#include "nsHTMLFormElement.h"
#include "nsHTMLImageElement.h"
#include "nsHTMLOptionElement.h"
#include "nsHTMLOptGroupElement.h"
@ -156,6 +157,7 @@ xpc_qsUnwrapArg<_clazz>(JSContext *cx, jsval v, _clazz **ppArg, \
DEFINE_UNWRAP_CAST_HTML(canvas, nsHTMLCanvasElement)
DEFINE_UNWRAP_CAST_HTML(div, nsHTMLDivElement)
DEFINE_UNWRAP_CAST_HTML(form, nsHTMLFormElement)
DEFINE_UNWRAP_CAST_HTML(img, nsHTMLImageElement)
DEFINE_UNWRAP_CAST_HTML(optgroup, nsHTMLOptGroupElement)
DEFINE_UNWRAP_CAST_HTML(option, nsHTMLOptionElement)