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