michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsFormData_h__ michael@0: #define nsFormData_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsIDOMFile.h" michael@0: #include "nsIDOMFormData.h" michael@0: #include "nsIXMLHttpRequest.h" michael@0: #include "nsFormSubmission.h" michael@0: #include "nsWrapperCache.h" michael@0: #include "nsTArray.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: michael@0: class nsIDOMFile; michael@0: michael@0: namespace mozilla { michael@0: class ErrorResult; michael@0: michael@0: namespace dom { michael@0: class HTMLFormElement; michael@0: class GlobalObject; michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: class nsFormData : public nsIDOMFormData, michael@0: public nsIXHRSendable, michael@0: public nsFormSubmission, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: nsFormData(nsISupports* aOwner = nullptr); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData, michael@0: nsIDOMFormData) michael@0: michael@0: NS_DECL_NSIDOMFORMDATA michael@0: NS_DECL_NSIXHRSENDABLE michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: nsISupports* michael@0: GetParentObject() const michael@0: { michael@0: return mOwner; michael@0: } michael@0: static already_AddRefed michael@0: Constructor(const mozilla::dom::GlobalObject& aGlobal, michael@0: const mozilla::dom::Optional >& aFormElement, michael@0: mozilla::ErrorResult& aRv); michael@0: void Append(const nsAString& aName, const nsAString& aValue); michael@0: void Append(const nsAString& aName, nsIDOMBlob* aBlob, michael@0: const mozilla::dom::Optional& aFilename); michael@0: michael@0: // nsFormSubmission michael@0: virtual nsresult GetEncodedSubmission(nsIURI* aURI, michael@0: nsIInputStream** aPostDataStream) MOZ_OVERRIDE; michael@0: virtual nsresult AddNameValuePair(const nsAString& aName, michael@0: const nsAString& aValue) MOZ_OVERRIDE michael@0: { michael@0: FormDataTuple* data = mFormData.AppendElement(); michael@0: data->name = aName; michael@0: data->stringValue = aValue; michael@0: data->valueIsFile = false; michael@0: return NS_OK; michael@0: } michael@0: virtual nsresult AddNameFilePair(const nsAString& aName, michael@0: nsIDOMBlob* aBlob, michael@0: const nsString& aFilename) MOZ_OVERRIDE michael@0: { michael@0: FormDataTuple* data = mFormData.AppendElement(); michael@0: data->name = aName; michael@0: data->fileValue = aBlob; michael@0: data->filename = aFilename; michael@0: data->valueIsFile = true; michael@0: return NS_OK; michael@0: } michael@0: michael@0: private: michael@0: nsCOMPtr mOwner; michael@0: michael@0: struct FormDataTuple michael@0: { michael@0: nsString name; michael@0: nsString stringValue; michael@0: nsCOMPtr fileValue; michael@0: nsString filename; michael@0: bool valueIsFile; michael@0: }; michael@0: michael@0: nsTArray mFormData; michael@0: }; michael@0: michael@0: #endif // nsFormData_h__