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_FileList_h 8 #define mozilla_dom_FileList_h 9 10 #include <cstdint> 11 #include "js/TypeDecls.h" 12 #include "mozilla/Assertions.h" 13 #include "nsCOMPtr.h" 14 #include "nsCycleCollectionParticipant.h" 15 #include "nsISupports.h" 16 #include "nsTArray.h" 17 #include "nsWrapperCache.h" 18 19 class nsCycleCollectionTraversalCallback; 20 template <class T> 21 class RefPtr; 22 23 namespace mozilla { 24 class ErrorResult; 25 namespace dom { 26 27 class BlobImpls; 28 class File; 29 template <typename T> 30 class Sequence; 31 32 class FileList final : public nsISupports, public nsWrapperCache { 33 public: 34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileList) 36 37 explicit FileList(nsISupports* aParent); 38 39 virtual JSObject* WrapObject(JSContext* aCx, 40 JS::Handle<JSObject*> aGivenProto) override; 41 GetParentObject()42 nsISupports* GetParentObject() { return mParent; } 43 44 bool Append(File* aFile); 45 46 bool Remove(uint32_t aIndex); 47 48 void Clear(); 49 50 File* Item(uint32_t aIndex) const; 51 52 File* IndexedGetter(uint32_t aIndex, bool& aFound) const; 53 Length()54 uint32_t Length() const { return mFiles.Length(); } 55 56 void ToSequence(Sequence<RefPtr<File>>& aSequence, ErrorResult& aRv) const; 57 58 private: 59 ~FileList(); 60 61 FallibleTArray<RefPtr<File>> mFiles; 62 nsCOMPtr<nsISupports> mParent; 63 }; 64 65 } // namespace dom 66 } // namespace mozilla 67 68 #endif // mozilla_dom_FileList_h 69