Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/filesystem/compat/FileSystemFileEntry.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 "FileSystemFileEntry.h"
8
#include "CallbackRunnables.h"
9
#include "mozilla/dom/File.h"
10
#include "mozilla/dom/FileSystemUtils.h"
11
#include "mozilla/dom/MultipartBlobImpl.h"
12
#include "mozilla/dom/FileSystemFileEntryBinding.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
namespace {
18
19
class FileCallbackRunnable final : public Runnable
20
{
21
public:
22
  FileCallbackRunnable(FileCallback* aCallback, File* aFile)
23
    : Runnable("FileCallbackRunnable")
24
    , mCallback(aCallback)
25
    , mFile(aFile)
26
0
  {
27
0
    MOZ_ASSERT(aCallback);
28
0
    MOZ_ASSERT(aFile);
29
0
  }
30
31
  NS_IMETHOD
32
  Run() override
33
0
  {
34
0
    // Here we clone the File object.
35
0
36
0
    RefPtr<File> file = File::Create(mFile->GetParentObject(), mFile->Impl());
37
0
    MOZ_ASSERT(file);
38
0
39
0
    mCallback->HandleEvent(*file);
40
0
    return NS_OK;
41
0
  }
42
43
private:
44
  RefPtr<FileCallback> mCallback;
45
  RefPtr<File> mFile;
46
};
47
48
} // anonymous namespace
49
50
NS_IMPL_CYCLE_COLLECTION_INHERITED(FileSystemFileEntry, FileSystemEntry, mFile)
51
52
NS_IMPL_ADDREF_INHERITED(FileSystemFileEntry, FileSystemEntry)
53
NS_IMPL_RELEASE_INHERITED(FileSystemFileEntry, FileSystemEntry)
54
55
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemFileEntry)
56
0
NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry)
57
58
FileSystemFileEntry::FileSystemFileEntry(nsIGlobalObject* aGlobal,
59
                                         File* aFile,
60
                                         FileSystemDirectoryEntry* aParentEntry,
61
                                         FileSystem* aFileSystem)
62
  : FileSystemEntry(aGlobal, aParentEntry, aFileSystem)
63
  , mFile(aFile)
64
0
{
65
0
  MOZ_ASSERT(aGlobal);
66
0
  MOZ_ASSERT(mFile);
67
0
}
68
69
FileSystemFileEntry::~FileSystemFileEntry()
70
0
{}
71
72
JSObject*
73
FileSystemFileEntry::WrapObject(JSContext* aCx,
74
                                JS::Handle<JSObject*> aGivenProto)
75
0
{
76
0
  return FileSystemFileEntry_Binding::Wrap(aCx, this, aGivenProto);
77
0
}
78
79
void
80
FileSystemFileEntry::GetName(nsAString& aName, ErrorResult& aRv) const
81
0
{
82
0
  mFile->GetName(aName);
83
0
}
84
85
void
86
FileSystemFileEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const
87
0
{
88
0
  mFile->Impl()->GetDOMPath(aPath);
89
0
  if (aPath.IsEmpty()) {
90
0
    // We're under the root directory. webkitRelativePath
91
0
    // (implemented as GetPath) is for cases when file is selected because its
92
0
    // ancestor directory is selected. But that is not the case here, so need to
93
0
    // manually prepend '/'.
94
0
    nsAutoString name;
95
0
    mFile->GetName(name);
96
0
    aPath.AssignLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
97
0
    aPath.Append(name);
98
0
  }
99
0
}
100
101
void
102
FileSystemFileEntry::GetFile(FileCallback& aSuccessCallback,
103
                             const Optional<OwningNonNull<ErrorCallback>>& aErrorCallback) const
104
0
{
105
0
  RefPtr<FileCallbackRunnable> runnable =
106
0
    new FileCallbackRunnable(&aSuccessCallback, mFile);
107
0
108
0
  FileSystemUtils::DispatchRunnable(GetParentObject(), runnable.forget());
109
0
}
110
111
} // dom namespace
112
} // mozilla namespace