content/base/src/nsFormData.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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/. */
     5 #ifndef nsFormData_h__
     6 #define nsFormData_h__
     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"
    18 class nsIDOMFile;
    20 namespace mozilla {
    21 class ErrorResult;
    23 namespace dom {
    24 class HTMLFormElement;
    25 class GlobalObject;
    26 } // namespace dom
    27 } // namespace mozilla
    29 class nsFormData : public nsIDOMFormData,
    30                    public nsIXHRSendable,
    31                    public nsFormSubmission,
    32                    public nsWrapperCache
    33 {
    34 public:
    35   nsFormData(nsISupports* aOwner = nullptr);
    37   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    38   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFormData,
    39                                                          nsIDOMFormData)
    41   NS_DECL_NSIDOMFORMDATA
    42   NS_DECL_NSIXHRSENDABLE
    44   // nsWrapperCache
    45   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    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);
    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   }
    85 private:
    86   nsCOMPtr<nsISupports> mOwner;
    88   struct FormDataTuple
    89   {
    90     nsString name;
    91     nsString stringValue;
    92     nsCOMPtr<nsIDOMBlob> fileValue;
    93     nsString filename;
    94     bool valueIsFile;
    95   };
    97   nsTArray<FormDataTuple> mFormData;
    98 };
   100 #endif // nsFormData_h__

mercurial