LCOV - code coverage report
Current view: top level - dom/base - FormData.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 17 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef mozilla_dom_FormData_h
       8             : #define mozilla_dom_FormData_h
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : #include "mozilla/ErrorResult.h"
      12             : #include "mozilla/dom/BindingDeclarations.h"
      13             : #include "mozilla/dom/HTMLFormSubmission.h"
      14             : #include "mozilla/dom/File.h"
      15             : #include "mozilla/dom/FormDataBinding.h"
      16             : #include "nsIDOMFormData.h"
      17             : #include "nsIXMLHttpRequest.h"
      18             : #include "nsTArray.h"
      19             : #include "nsWrapperCache.h"
      20             : 
      21             : namespace mozilla {
      22             : namespace dom {
      23             : 
      24             : class HTMLFormElement;
      25             : class GlobalObject;
      26             : 
      27             : class FormData final : public nsIDOMFormData,
      28             :                        public nsIXHRSendable,
      29             :                        public HTMLFormSubmission,
      30             :                        public nsWrapperCache
      31             : {
      32             : private:
      33           0 :   ~FormData() {}
      34             : 
      35           0 :   struct FormDataTuple
      36             :   {
      37             :     nsString name;
      38             :     bool wasNullBlob;
      39             :     OwningBlobOrDirectoryOrUSVString value;
      40             :   };
      41             : 
      42             :   // Returns the FormDataTuple to modify. This may be null, in which case
      43             :   // no element with aName was found.
      44             :   FormDataTuple*
      45             :   RemoveAllOthersAndGetFirstFormDataTuple(const nsAString& aName);
      46             : 
      47             :   void SetNameValuePair(FormDataTuple* aData,
      48             :                         const nsAString& aName,
      49             :                         const nsAString& aValue,
      50             :                         bool aWasNullBlob = false);
      51             : 
      52             :   void SetNameFilePair(FormDataTuple* aData,
      53             :                        const nsAString& aName,
      54             :                        File* aFile);
      55             : 
      56             :   void SetNameDirectoryPair(FormDataTuple* aData,
      57             :                             const nsAString& aName,
      58             :                             Directory* aDirectory);
      59             : 
      60             : public:
      61             :   explicit FormData(nsISupports* aOwner = nullptr);
      62             : 
      63             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      64           0 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(FormData,
      65             :                                                          nsIDOMFormData)
      66             : 
      67             :   NS_DECL_NSIDOMFORMDATA
      68             :   NS_DECL_NSIXHRSENDABLE
      69             : 
      70             :   // nsWrapperCache
      71             :   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
      72             : 
      73             :   // WebIDL
      74             :   nsISupports*
      75           0 :   GetParentObject() const
      76             :   {
      77           0 :     return mOwner;
      78             :   }
      79             : 
      80             :   static already_AddRefed<FormData>
      81             :   Constructor(const GlobalObject& aGlobal,
      82             :               const Optional<NonNull<HTMLFormElement> >& aFormElement,
      83             :               ErrorResult& aRv);
      84             : 
      85             :   void Append(const nsAString& aName, const nsAString& aValue,
      86             :               ErrorResult& aRv);
      87             : 
      88             :   void Append(const nsAString& aName, Blob& aBlob,
      89             :               const Optional<nsAString>& aFilename,
      90             :               ErrorResult& aRv);
      91             : 
      92             :   void Append(const nsAString& aName, Directory* aDirectory);
      93             : 
      94             :   void Delete(const nsAString& aName);
      95             : 
      96             :   void Get(const nsAString& aName, Nullable<OwningBlobOrDirectoryOrUSVString>& aOutValue);
      97             : 
      98             :   void GetAll(const nsAString& aName, nsTArray<OwningBlobOrDirectoryOrUSVString>& aValues);
      99             : 
     100             :   bool Has(const nsAString& aName);
     101             : 
     102             :   void Set(const nsAString& aName, Blob& aBlob,
     103             :            const Optional<nsAString>& aFilename,
     104             :            ErrorResult& aRv);
     105             :   void Set(const nsAString& aName, const nsAString& aValue,
     106             :            ErrorResult& aRv);
     107             : 
     108             :   uint32_t GetIterableLength() const;
     109             : 
     110             :   const nsAString& GetKeyAtIndex(uint32_t aIndex) const;
     111             : 
     112             :   const OwningBlobOrDirectoryOrUSVString& GetValueAtIndex(uint32_t aIndex) const;
     113             : 
     114             :   // HTMLFormSubmission
     115             :   virtual nsresult
     116             :   GetEncodedSubmission(nsIURI* aURI, nsIInputStream** aPostDataStream) override;
     117             : 
     118           0 :   virtual nsresult AddNameValuePair(const nsAString& aName,
     119             :                                     const nsAString& aValue) override
     120             :   {
     121           0 :     FormDataTuple* data = mFormData.AppendElement();
     122           0 :     SetNameValuePair(data, aName, aValue);
     123           0 :     return NS_OK;
     124             :   }
     125             : 
     126             :   virtual nsresult AddNameBlobOrNullPair(const nsAString& aName,
     127             :                                          Blob* aBlob) override;
     128             : 
     129             :   virtual nsresult AddNameDirectoryPair(const nsAString& aName,
     130             :                                         Directory* aDirectory) override;
     131             : 
     132             :   typedef bool (*FormDataEntryCallback)(const nsString& aName,
     133             :                                         const OwningBlobOrDirectoryOrUSVString& aValue,
     134             :                                         void* aClosure);
     135             : 
     136             :   uint32_t
     137           0 :   Length() const
     138             :   {
     139           0 :     return mFormData.Length();
     140             :   }
     141             : 
     142             :   // Stops iteration and returns false if any invocation of callback returns
     143             :   // false. Returns true otherwise.
     144             :   bool
     145           0 :   ForEach(FormDataEntryCallback aFunc, void* aClosure)
     146             :   {
     147           0 :     for (uint32_t i = 0; i < mFormData.Length(); ++i) {
     148           0 :       FormDataTuple& tuple = mFormData[i];
     149           0 :       if (!aFunc(tuple.name, tuple.value, aClosure)) {
     150           0 :         return false;
     151             :       }
     152             :     }
     153             : 
     154           0 :     return true;
     155             :   }
     156             : 
     157             : private:
     158             :   nsCOMPtr<nsISupports> mOwner;
     159             : 
     160             :   nsTArray<FormDataTuple> mFormData;
     161             : };
     162             : 
     163             : } // dom namespace
     164             : } // mozilla namepsace
     165             : 
     166             : #endif // mozilla_dom_FormData_h

Generated by: LCOV version 1.13