1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/nsFormData.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef nsFormData_h__ 1.9 +#define nsFormData_h__ 1.10 + 1.11 +#include "mozilla/Attributes.h" 1.12 +#include "nsIDOMFile.h" 1.13 +#include "nsIDOMFormData.h" 1.14 +#include "nsIXMLHttpRequest.h" 1.15 +#include "nsFormSubmission.h" 1.16 +#include "nsWrapperCache.h" 1.17 +#include "nsTArray.h" 1.18 +#include "mozilla/ErrorResult.h" 1.19 +#include "mozilla/dom/BindingDeclarations.h" 1.20 + 1.21 +class nsIDOMFile; 1.22 + 1.23 +namespace mozilla { 1.24 +class ErrorResult; 1.25 + 1.26 +namespace dom { 1.27 +class HTMLFormElement; 1.28 +class GlobalObject; 1.29 +} // namespace dom 1.30 +} // namespace mozilla 1.31 + 1.32 +class nsFormData : public nsIDOMFormData, 1.33 + public nsIXHRSendable, 1.34 + public nsFormSubmission, 1.35 + public nsWrapperCache 1.36 +{ 1.37 +public: 1.38 + nsFormData(nsISupports* aOwner = nullptr); 1.39 + 1.40 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.41 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData, 1.42 + nsIDOMFormData) 1.43 + 1.44 + NS_DECL_NSIDOMFORMDATA 1.45 + NS_DECL_NSIXHRSENDABLE 1.46 + 1.47 + // nsWrapperCache 1.48 + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.49 + 1.50 + // WebIDL 1.51 + nsISupports* 1.52 + GetParentObject() const 1.53 + { 1.54 + return mOwner; 1.55 + } 1.56 + static already_AddRefed<nsFormData> 1.57 + Constructor(const mozilla::dom::GlobalObject& aGlobal, 1.58 + const mozilla::dom::Optional<mozilla::dom::NonNull<mozilla::dom::HTMLFormElement> >& aFormElement, 1.59 + mozilla::ErrorResult& aRv); 1.60 + void Append(const nsAString& aName, const nsAString& aValue); 1.61 + void Append(const nsAString& aName, nsIDOMBlob* aBlob, 1.62 + const mozilla::dom::Optional<nsAString>& aFilename); 1.63 + 1.64 + // nsFormSubmission 1.65 + virtual nsresult GetEncodedSubmission(nsIURI* aURI, 1.66 + nsIInputStream** aPostDataStream) MOZ_OVERRIDE; 1.67 + virtual nsresult AddNameValuePair(const nsAString& aName, 1.68 + const nsAString& aValue) MOZ_OVERRIDE 1.69 + { 1.70 + FormDataTuple* data = mFormData.AppendElement(); 1.71 + data->name = aName; 1.72 + data->stringValue = aValue; 1.73 + data->valueIsFile = false; 1.74 + return NS_OK; 1.75 + } 1.76 + virtual nsresult AddNameFilePair(const nsAString& aName, 1.77 + nsIDOMBlob* aBlob, 1.78 + const nsString& aFilename) MOZ_OVERRIDE 1.79 + { 1.80 + FormDataTuple* data = mFormData.AppendElement(); 1.81 + data->name = aName; 1.82 + data->fileValue = aBlob; 1.83 + data->filename = aFilename; 1.84 + data->valueIsFile = true; 1.85 + return NS_OK; 1.86 + } 1.87 + 1.88 +private: 1.89 + nsCOMPtr<nsISupports> mOwner; 1.90 + 1.91 + struct FormDataTuple 1.92 + { 1.93 + nsString name; 1.94 + nsString stringValue; 1.95 + nsCOMPtr<nsIDOMBlob> fileValue; 1.96 + nsString filename; 1.97 + bool valueIsFile; 1.98 + }; 1.99 + 1.100 + nsTArray<FormDataTuple> mFormData; 1.101 +}; 1.102 + 1.103 +#endif // nsFormData_h__