/src/mozilla-central/dom/filesystem/compat/FileSystemDirectoryEntry.cpp
Line | Count | Source (jump to first uncovered line) |
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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "FileSystemDirectoryEntry.h" |
8 | | #include "CallbackRunnables.h" |
9 | | #include "FileSystemDirectoryReader.h" |
10 | | #include "mozilla/dom/Directory.h" |
11 | | #include "mozilla/dom/FileSystemDirectoryEntryBinding.h" |
12 | | #include "mozilla/dom/FileSystemUtils.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemDirectoryEntry, FileSystemEntry, |
18 | | mDirectory) |
19 | | |
20 | | NS_IMPL_ADDREF_INHERITED(FileSystemDirectoryEntry, FileSystemEntry) |
21 | | NS_IMPL_RELEASE_INHERITED(FileSystemDirectoryEntry, FileSystemEntry) |
22 | | |
23 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemDirectoryEntry) |
24 | 0 | NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry) |
25 | | |
26 | | FileSystemDirectoryEntry::FileSystemDirectoryEntry(nsIGlobalObject* aGlobal, |
27 | | Directory* aDirectory, |
28 | | FileSystemDirectoryEntry* aParentEntry, |
29 | | FileSystem* aFileSystem) |
30 | | : FileSystemEntry(aGlobal, aParentEntry, aFileSystem) |
31 | | , mDirectory(aDirectory) |
32 | 0 | { |
33 | 0 | MOZ_ASSERT(aGlobal); |
34 | 0 | } |
35 | | |
36 | | FileSystemDirectoryEntry::~FileSystemDirectoryEntry() |
37 | 0 | {} |
38 | | |
39 | | JSObject* |
40 | | FileSystemDirectoryEntry::WrapObject(JSContext* aCx, |
41 | | JS::Handle<JSObject*> aGivenProto) |
42 | 0 | { |
43 | 0 | return FileSystemDirectoryEntry_Binding::Wrap(aCx, this, aGivenProto); |
44 | 0 | } |
45 | | |
46 | | void |
47 | | FileSystemDirectoryEntry::GetName(nsAString& aName, ErrorResult& aRv) const |
48 | 0 | { |
49 | 0 | MOZ_ASSERT(mDirectory); |
50 | 0 | mDirectory->GetName(aName, aRv); |
51 | 0 | } |
52 | | |
53 | | void |
54 | | FileSystemDirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const |
55 | 0 | { |
56 | 0 | MOZ_ASSERT(mDirectory); |
57 | 0 | mDirectory->GetPath(aPath, aRv); |
58 | 0 | } |
59 | | |
60 | | already_AddRefed<FileSystemDirectoryReader> |
61 | | FileSystemDirectoryEntry::CreateReader() |
62 | 0 | { |
63 | 0 | MOZ_ASSERT(mDirectory); |
64 | 0 |
|
65 | 0 | RefPtr<FileSystemDirectoryReader> reader = |
66 | 0 | new FileSystemDirectoryReader(this, Filesystem(), mDirectory); |
67 | 0 | return reader.forget(); |
68 | 0 | } |
69 | | |
70 | | void |
71 | | FileSystemDirectoryEntry::GetInternal(const nsAString& aPath, |
72 | | const FileSystemFlags& aFlag, |
73 | | const Optional<OwningNonNull<FileSystemEntryCallback>>& aSuccessCallback, |
74 | | const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback, |
75 | | GetInternalType aType) |
76 | 0 | { |
77 | 0 | MOZ_ASSERT(mDirectory); |
78 | 0 |
|
79 | 0 | if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) { |
80 | 0 | return; |
81 | 0 | } |
82 | 0 | |
83 | 0 | if (aFlag.mCreate) { |
84 | 0 | ErrorCallbackHelper::Call(GetParentObject(), aErrorCallback, |
85 | 0 | NS_ERROR_DOM_SECURITY_ERR); |
86 | 0 | return; |
87 | 0 | } |
88 | 0 | |
89 | 0 | nsTArray<nsString> parts; |
90 | 0 | if (!FileSystemUtils::IsValidRelativeDOMPath(aPath, parts)) { |
91 | 0 | ErrorCallbackHelper::Call(GetParentObject(), aErrorCallback, |
92 | 0 | NS_ERROR_DOM_NOT_FOUND_ERR); |
93 | 0 | return; |
94 | 0 | } |
95 | 0 | |
96 | 0 | RefPtr<GetEntryHelper> helper = |
97 | 0 | new GetEntryHelper(this, mDirectory, parts, Filesystem(), |
98 | 0 | aSuccessCallback.WasPassed() |
99 | 0 | ? &aSuccessCallback.Value() : nullptr, |
100 | 0 | aErrorCallback.WasPassed() |
101 | 0 | ? &aErrorCallback.Value() : nullptr, |
102 | 0 | aType); |
103 | 0 | helper->Run(); |
104 | 0 | } |
105 | | |
106 | | } // dom namespace |
107 | | } // mozilla namespace |