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 : #include "mozilla/dom/Directory.h"
8 : #include "mozilla/dom/FileList.h"
9 : #include "mozilla/dom/FileListBinding.h"
10 : #include "mozilla/dom/File.h"
11 :
12 : namespace mozilla {
13 : namespace dom {
14 :
15 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileList, mFiles, mParent)
16 :
17 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileList)
18 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
19 0 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFileList)
20 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMFileList)
21 0 : NS_INTERFACE_MAP_END
22 :
23 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(FileList)
24 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(FileList)
25 :
26 : JSObject*
27 0 : FileList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
28 : {
29 0 : return mozilla::dom::FileListBinding::Wrap(aCx, this, aGivenProto);
30 : }
31 :
32 : NS_IMETHODIMP
33 0 : FileList::GetLength(uint32_t* aLength)
34 : {
35 0 : *aLength = Length();
36 :
37 0 : return NS_OK;
38 : }
39 :
40 : NS_IMETHODIMP
41 0 : FileList::Item(uint32_t aIndex, nsISupports** aValue)
42 : {
43 0 : nsCOMPtr<nsIDOMBlob> file = Item(aIndex);
44 0 : file.forget(aValue);
45 0 : return NS_OK;
46 : }
47 :
48 : File*
49 0 : FileList::Item(uint32_t aIndex) const
50 : {
51 0 : if (aIndex >= mFiles.Length()) {
52 0 : return nullptr;
53 : }
54 :
55 0 : return mFiles[aIndex];
56 : }
57 :
58 : File*
59 0 : FileList::IndexedGetter(uint32_t aIndex, bool& aFound) const
60 : {
61 0 : aFound = aIndex < mFiles.Length();
62 0 : return Item(aIndex);
63 : }
64 :
65 : void
66 0 : FileList::ToSequence(Sequence<RefPtr<File>>& aSequence,
67 : ErrorResult& aRv) const
68 : {
69 0 : MOZ_ASSERT(aSequence.IsEmpty());
70 0 : if (mFiles.IsEmpty()) {
71 0 : return;
72 : }
73 :
74 0 : if (!aSequence.SetLength(mFiles.Length(),
75 0 : mozilla::fallible_t())) {
76 0 : aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
77 0 : return;
78 : }
79 :
80 0 : for (uint32_t i = 0; i < mFiles.Length(); ++i) {
81 0 : aSequence[i] = mFiles[i];
82 : }
83 : }
84 :
85 : } // namespace dom
86 : } // namespace mozilla
|