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__
|
|
|
|
|
|
|
|
#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"
|
2010-02-24 21:58:18 -08:00
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
class nsHTMLFormElement;
|
2010-09-05 11:00:05 -07:00
|
|
|
class nsIDOMFile;
|
|
|
|
|
2012-12-11 10:09:56 -08:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
template<class> class Optional;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
class nsFormData : public nsIDOMFormData,
|
|
|
|
public nsIXHRSendable,
|
2012-12-11 10:09:56 -08:00
|
|
|
public nsFormSubmission,
|
|
|
|
public nsWrapperCache
|
2010-02-24 21:58:18 -08:00
|
|
|
{
|
|
|
|
public:
|
2012-12-11 10:09:56 -08:00
|
|
|
nsFormData(nsISupports* aOwner = nullptr);
|
|
|
|
|
|
|
|
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
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JSObject* aScope, bool* aTriedToWrap) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsISupports*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
static already_AddRefed<nsFormData>
|
2013-01-28 03:08:21 -08:00
|
|
|
Constructor(nsISupports* aGlobal,
|
2012-12-11 10:09:56 -08:00
|
|
|
const mozilla::dom::Optional<nsHTMLFormElement*>& aFormElement,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
void Append(const nsAString& aName, const nsAString& aValue);
|
|
|
|
void Append(const nsAString& aName, nsIDOMBlob* aBlob);
|
|
|
|
|
2010-02-24 21:58:18 -08:00
|
|
|
// nsFormSubmission
|
|
|
|
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
|
|
|
|
nsIInputStream** aPostDataStream);
|
|
|
|
virtual nsresult AddNameValuePair(const nsAString& aName,
|
2012-12-11 10:09:56 -08:00
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
|
|
|
Append(aName, aValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-02-24 21:58:18 -08:00
|
|
|
virtual nsresult AddNameFilePair(const nsAString& aName,
|
2012-12-11 10:09:56 -08:00
|
|
|
nsIDOMBlob* aBlob)
|
|
|
|
{
|
|
|
|
Append(aName, aBlob);
|
|
|
|
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;
|
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__
|