|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef nsFormData_h__ |
|
6 #define nsFormData_h__ |
|
7 |
|
8 #include "mozilla/Attributes.h" |
|
9 #include "nsIDOMFile.h" |
|
10 #include "nsIDOMFormData.h" |
|
11 #include "nsIXMLHttpRequest.h" |
|
12 #include "nsFormSubmission.h" |
|
13 #include "nsWrapperCache.h" |
|
14 #include "nsTArray.h" |
|
15 #include "mozilla/ErrorResult.h" |
|
16 #include "mozilla/dom/BindingDeclarations.h" |
|
17 |
|
18 class nsIDOMFile; |
|
19 |
|
20 namespace mozilla { |
|
21 class ErrorResult; |
|
22 |
|
23 namespace dom { |
|
24 class HTMLFormElement; |
|
25 class GlobalObject; |
|
26 } // namespace dom |
|
27 } // namespace mozilla |
|
28 |
|
29 class nsFormData : public nsIDOMFormData, |
|
30 public nsIXHRSendable, |
|
31 public nsFormSubmission, |
|
32 public nsWrapperCache |
|
33 { |
|
34 public: |
|
35 nsFormData(nsISupports* aOwner = nullptr); |
|
36 |
|
37 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
38 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData, |
|
39 nsIDOMFormData) |
|
40 |
|
41 NS_DECL_NSIDOMFORMDATA |
|
42 NS_DECL_NSIXHRSENDABLE |
|
43 |
|
44 // nsWrapperCache |
|
45 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
46 |
|
47 // WebIDL |
|
48 nsISupports* |
|
49 GetParentObject() const |
|
50 { |
|
51 return mOwner; |
|
52 } |
|
53 static already_AddRefed<nsFormData> |
|
54 Constructor(const mozilla::dom::GlobalObject& aGlobal, |
|
55 const mozilla::dom::Optional<mozilla::dom::NonNull<mozilla::dom::HTMLFormElement> >& aFormElement, |
|
56 mozilla::ErrorResult& aRv); |
|
57 void Append(const nsAString& aName, const nsAString& aValue); |
|
58 void Append(const nsAString& aName, nsIDOMBlob* aBlob, |
|
59 const mozilla::dom::Optional<nsAString>& aFilename); |
|
60 |
|
61 // nsFormSubmission |
|
62 virtual nsresult GetEncodedSubmission(nsIURI* aURI, |
|
63 nsIInputStream** aPostDataStream) MOZ_OVERRIDE; |
|
64 virtual nsresult AddNameValuePair(const nsAString& aName, |
|
65 const nsAString& aValue) MOZ_OVERRIDE |
|
66 { |
|
67 FormDataTuple* data = mFormData.AppendElement(); |
|
68 data->name = aName; |
|
69 data->stringValue = aValue; |
|
70 data->valueIsFile = false; |
|
71 return NS_OK; |
|
72 } |
|
73 virtual nsresult AddNameFilePair(const nsAString& aName, |
|
74 nsIDOMBlob* aBlob, |
|
75 const nsString& aFilename) MOZ_OVERRIDE |
|
76 { |
|
77 FormDataTuple* data = mFormData.AppendElement(); |
|
78 data->name = aName; |
|
79 data->fileValue = aBlob; |
|
80 data->filename = aFilename; |
|
81 data->valueIsFile = true; |
|
82 return NS_OK; |
|
83 } |
|
84 |
|
85 private: |
|
86 nsCOMPtr<nsISupports> mOwner; |
|
87 |
|
88 struct FormDataTuple |
|
89 { |
|
90 nsString name; |
|
91 nsString stringValue; |
|
92 nsCOMPtr<nsIDOMBlob> fileValue; |
|
93 nsString filename; |
|
94 bool valueIsFile; |
|
95 }; |
|
96 |
|
97 nsTArray<FormDataTuple> mFormData; |
|
98 }; |
|
99 |
|
100 #endif // nsFormData_h__ |