2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-02-24 21:58:18 -08:00
|
|
|
|
|
|
|
#ifndef nsFormData_h__
|
|
|
|
#define nsFormData_h__
|
|
|
|
|
2013-05-29 13:43:41 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-02-24 21:58:18 -08:00
|
|
|
#include "nsIDOMFormData.h"
|
|
|
|
#include "nsIXMLHttpRequest.h"
|
2010-05-26 05:49:38 -07:00
|
|
|
#include "nsFormSubmission.h"
|
2012-12-11 10:09:56 -08:00
|
|
|
#include "nsWrapperCache.h"
|
2010-02-24 21:58:18 -08:00
|
|
|
#include "nsTArray.h"
|
2012-12-11 10:09:56 -08:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-03-03 10:30:13 -08:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2010-02-24 21:58:18 -08:00
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
2014-10-08 09:15:23 -07:00
|
|
|
class File;
|
2013-06-19 07:24:37 -07:00
|
|
|
class HTMLFormElement;
|
2012-12-03 08:07:49 -08:00
|
|
|
class GlobalObject;
|
2012-12-11 10:09:56 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-08-27 11:26:48 -07:00
|
|
|
class nsFormData MOZ_FINAL : public nsIDOMFormData,
|
|
|
|
public nsIXHRSendable,
|
|
|
|
public nsFormSubmission,
|
|
|
|
public nsWrapperCache
|
2010-02-24 21:58:18 -08:00
|
|
|
{
|
2014-06-24 19:09:15 -07:00
|
|
|
~nsFormData() {}
|
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
public:
|
2014-09-01 17:49:25 -07:00
|
|
|
explicit nsFormData(nsISupports* aOwner = nullptr);
|
2012-12-11 10:09:56 -08:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData,
|
|
|
|
nsIDOMFormData)
|
2010-02-24 21:58:18 -08:00
|
|
|
|
|
|
|
NS_DECL_NSIDOMFORMDATA
|
|
|
|
NS_DECL_NSIXHRSENDABLE
|
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
// nsWrapperCache
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2012-12-11 10:09:56 -08:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsISupports*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
static already_AddRefed<nsFormData>
|
2012-12-03 08:07:49 -08:00
|
|
|
Constructor(const mozilla::dom::GlobalObject& aGlobal,
|
2013-06-19 07:24:37 -07:00
|
|
|
const mozilla::dom::Optional<mozilla::dom::NonNull<mozilla::dom::HTMLFormElement> >& aFormElement,
|
2012-12-11 10:09:56 -08:00
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
void Append(const nsAString& aName, const nsAString& aValue);
|
2014-10-08 09:15:23 -07:00
|
|
|
void Append(const nsAString& aName, mozilla::dom::File& aBlob,
|
2013-03-03 10:30:13 -08:00
|
|
|
const mozilla::dom::Optional<nsAString>& aFilename);
|
2012-12-11 10:09:56 -08:00
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
// nsFormSubmission
|
|
|
|
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
|
2013-05-29 13:43:41 -07:00
|
|
|
nsIInputStream** aPostDataStream) MOZ_OVERRIDE;
|
2010-02-24 21:58:18 -08:00
|
|
|
virtual nsresult AddNameValuePair(const nsAString& aName,
|
2013-05-29 13:43:41 -07:00
|
|
|
const nsAString& aValue) MOZ_OVERRIDE
|
2012-12-11 10:09:56 -08:00
|
|
|
{
|
2013-03-03 10:30:13 -08:00
|
|
|
FormDataTuple* data = mFormData.AppendElement();
|
|
|
|
data->name = aName;
|
|
|
|
data->stringValue = aValue;
|
|
|
|
data->valueIsFile = false;
|
2012-12-11 10:09:56 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-24 21:58:18 -08:00
|
|
|
virtual nsresult AddNameFilePair(const nsAString& aName,
|
2013-03-03 10:30:13 -08:00
|
|
|
nsIDOMBlob* aBlob,
|
2013-05-29 13:43:41 -07:00
|
|
|
const nsString& aFilename) MOZ_OVERRIDE
|
2012-12-11 10:09:56 -08:00
|
|
|
{
|
2013-03-03 10:30:13 -08:00
|
|
|
FormDataTuple* data = mFormData.AppendElement();
|
|
|
|
data->name = aName;
|
|
|
|
data->fileValue = aBlob;
|
|
|
|
data->filename = aFilename;
|
|
|
|
data->valueIsFile = true;
|
2012-12-11 10:09:56 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-24 21:58:18 -08:00
|
|
|
|
|
|
|
private:
|
2012-12-11 10:09:56 -08:00
|
|
|
nsCOMPtr<nsISupports> mOwner;
|
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
struct FormDataTuple
|
|
|
|
{
|
|
|
|
nsString name;
|
|
|
|
nsString stringValue;
|
2010-10-13 16:25:33 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> fileValue;
|
2013-03-03 10:30:13 -08:00
|
|
|
nsString filename;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool valueIsFile;
|
2010-02-24 21:58:18 -08:00
|
|
|
};
|
2012-12-11 10:09:56 -08:00
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
nsTArray<FormDataTuple> mFormData;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsFormData_h__
|