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 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 0 : NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemDirectoryEntry, FileSystemEntry,
18 : mDirectory)
19 :
20 0 : NS_IMPL_ADDREF_INHERITED(FileSystemDirectoryEntry, FileSystemEntry)
21 0 : NS_IMPL_RELEASE_INHERITED(FileSystemDirectoryEntry, FileSystemEntry)
22 :
23 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileSystemDirectoryEntry)
24 0 : NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry)
25 :
26 0 : FileSystemDirectoryEntry::FileSystemDirectoryEntry(nsIGlobalObject* aGlobal,
27 : Directory* aDirectory,
28 : FileSystemDirectoryEntry* aParentEntry,
29 0 : FileSystem* aFileSystem)
30 : : FileSystemEntry(aGlobal, aParentEntry, aFileSystem)
31 0 : , mDirectory(aDirectory)
32 : {
33 0 : MOZ_ASSERT(aGlobal);
34 0 : }
35 :
36 0 : FileSystemDirectoryEntry::~FileSystemDirectoryEntry()
37 0 : {}
38 :
39 : JSObject*
40 0 : FileSystemDirectoryEntry::WrapObject(JSContext* aCx,
41 : JS::Handle<JSObject*> aGivenProto)
42 : {
43 0 : return FileSystemDirectoryEntryBinding::Wrap(aCx, this, aGivenProto);
44 : }
45 :
46 : void
47 0 : FileSystemDirectoryEntry::GetName(nsAString& aName, ErrorResult& aRv) const
48 : {
49 0 : MOZ_ASSERT(mDirectory);
50 0 : mDirectory->GetName(aName, aRv);
51 0 : }
52 :
53 : void
54 0 : FileSystemDirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const
55 : {
56 0 : MOZ_ASSERT(mDirectory);
57 0 : mDirectory->GetPath(aPath, aRv);
58 0 : }
59 :
60 : already_AddRefed<FileSystemDirectoryReader>
61 0 : FileSystemDirectoryEntry::CreateReader()
62 : {
63 0 : MOZ_ASSERT(mDirectory);
64 :
65 : RefPtr<FileSystemDirectoryReader> reader =
66 0 : new FileSystemDirectoryReader(this, Filesystem(), mDirectory);
67 0 : return reader.forget();
68 : }
69 :
70 : void
71 0 : 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 : {
77 0 : MOZ_ASSERT(mDirectory);
78 :
79 0 : if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) {
80 0 : return;
81 : }
82 :
83 0 : if (aFlag.mCreate) {
84 0 : ErrorCallbackHelper::Call(GetParentObject(), aErrorCallback,
85 0 : NS_ERROR_DOM_SECURITY_ERR);
86 0 : return;
87 : }
88 :
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 : }
95 :
96 : 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 : }
105 :
106 : } // dom namespace
107 : } // mozilla namespace
|