зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1263992 - patch 1 - Remove DirectoryType enum, r=smaug
This commit is contained in:
Родитель
136af0a4d8
Коммит
8e22a11655
|
@ -707,8 +707,7 @@ WriteBlob(JSStructuredCloneWriter* aWriter,
|
|||
}
|
||||
|
||||
// A directory is serialized as:
|
||||
// - pair of ints: SCTAG_DOM_DIRECTORY, 0
|
||||
// - pair of ints: type (eDOMRootDirectory/eDOMNotRootDirectory) - path length
|
||||
// - pair of ints: SCTAG_DOM_DIRECTORY, path length
|
||||
// - path as string
|
||||
bool
|
||||
WriteDirectory(JSStructuredCloneWriter* aWriter,
|
||||
|
@ -721,36 +720,25 @@ WriteDirectory(JSStructuredCloneWriter* aWriter,
|
|||
aDirectory->GetFullRealPath(path);
|
||||
|
||||
size_t charSize = sizeof(nsString::char_type);
|
||||
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_DIRECTORY, 0) &&
|
||||
JS_WriteUint32Pair(aWriter, (uint32_t)aDirectory->Type(),
|
||||
path.Length()) &&
|
||||
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_DIRECTORY, path.Length()) &&
|
||||
JS_WriteBytes(aWriter, path.get(), path.Length() * charSize);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
ReadDirectory(JSContext* aCx,
|
||||
JSStructuredCloneReader* aReader,
|
||||
uint32_t aZero,
|
||||
uint32_t aPathLength,
|
||||
StructuredCloneHolder* aHolder)
|
||||
{
|
||||
MOZ_ASSERT(aCx);
|
||||
MOZ_ASSERT(aReader);
|
||||
MOZ_ASSERT(aHolder);
|
||||
MOZ_ASSERT(aZero == 0);
|
||||
|
||||
uint32_t directoryType, lengthOfString;
|
||||
if (!JS_ReadUint32Pair(aReader, &directoryType, &lengthOfString)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(directoryType == Directory::eDOMRootDirectory ||
|
||||
directoryType == Directory::eNotDOMRootDirectory);
|
||||
|
||||
nsAutoString path;
|
||||
path.SetLength(lengthOfString);
|
||||
path.SetLength(aPathLength);
|
||||
size_t charSize = sizeof(nsString::char_type);
|
||||
if (!JS_ReadBytes(aReader, (void*) path.BeginWriting(),
|
||||
lengthOfString * charSize)) {
|
||||
aPathLength * charSize)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -769,8 +757,7 @@ ReadDirectory(JSContext* aCx,
|
|||
JS::Rooted<JS::Value> val(aCx);
|
||||
{
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(aHolder->ParentDuringRead(), file,
|
||||
(Directory::DirectoryType) directoryType);
|
||||
Directory::Create(aHolder->ParentDuringRead(), file);
|
||||
|
||||
if (!ToJSValue(aCx, directory, &val)) {
|
||||
return nullptr;
|
||||
|
|
|
@ -119,9 +119,7 @@ CreateDirectoryTaskChild::HandlerCallback()
|
|||
}
|
||||
|
||||
RefPtr<Directory> dir = Directory::Create(mFileSystem->GetParentObject(),
|
||||
mTargetPath,
|
||||
Directory::eNotDOMRootDirectory,
|
||||
mFileSystem);
|
||||
mTargetPath, mFileSystem);
|
||||
MOZ_ASSERT(dir);
|
||||
|
||||
mPromise->MaybeResolve(dir);
|
||||
|
|
|
@ -115,10 +115,32 @@ DeviceStorageFileSystem::GetParentObject() const
|
|||
}
|
||||
|
||||
void
|
||||
DeviceStorageFileSystem::GetRootName(nsAString& aRetval) const
|
||||
DeviceStorageFileSystem::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
aRetval = mStorageName;
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
nsCOMPtr<nsIFile> rootPath;
|
||||
aRv = NS_NewLocalFile(LocalOrDeviceStorageRootPath(), false,
|
||||
getter_AddRefs(rootPath));
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool equal = false;
|
||||
aRv = aFile->Equals(rootPath, &equal);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (equal) {
|
||||
aRetval = mStorageName;
|
||||
return;
|
||||
}
|
||||
|
||||
FileSystemBase::GetDirectoryName(aFile, aRetval, aRv);
|
||||
NS_WARN_IF(aRv.Failed());
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -37,7 +37,8 @@ public:
|
|||
GetParentObject() const override;
|
||||
|
||||
virtual void
|
||||
GetRootName(nsAString& aRetval) const override;
|
||||
GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
||||
ErrorResult& aRv) const override;
|
||||
|
||||
virtual bool
|
||||
IsSafeFile(nsIFile* aFile) const override;
|
||||
|
|
|
@ -137,8 +137,7 @@ Directory::GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
RefPtr<GetFileOrDirectoryTaskChild> task =
|
||||
GetFileOrDirectoryTaskChild::Create(aFileSystem, path, eDOMRootDirectory,
|
||||
true, aRv);
|
||||
GetFileOrDirectoryTaskChild::Create(aFileSystem, path, true, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -149,7 +148,7 @@ Directory::GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv)
|
|||
|
||||
/* static */ already_AddRefed<Directory>
|
||||
Directory::Create(nsISupports* aParent, nsIFile* aFile,
|
||||
DirectoryType aType, FileSystemBase* aFileSystem)
|
||||
FileSystemBase* aFileSystem)
|
||||
{
|
||||
MOZ_ASSERT(aParent);
|
||||
MOZ_ASSERT(aFile);
|
||||
|
@ -158,27 +157,17 @@ Directory::Create(nsISupports* aParent, nsIFile* aFile,
|
|||
bool isDir;
|
||||
nsresult rv = aFile->IsDirectory(&isDir);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv) && isDir);
|
||||
|
||||
if (aType == eNotDOMRootDirectory) {
|
||||
RefPtr<nsIFile> parent;
|
||||
rv = aFile->GetParent(getter_AddRefs(parent));
|
||||
// We must have a parent if this is not the root directory.
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv) && parent);
|
||||
}
|
||||
#endif
|
||||
|
||||
RefPtr<Directory> directory =
|
||||
new Directory(aParent, aFile, aType, aFileSystem);
|
||||
RefPtr<Directory> directory = new Directory(aParent, aFile, aFileSystem);
|
||||
return directory.forget();
|
||||
}
|
||||
|
||||
Directory::Directory(nsISupports* aParent,
|
||||
nsIFile* aFile,
|
||||
DirectoryType aType,
|
||||
FileSystemBase* aFileSystem)
|
||||
: mParent(aParent)
|
||||
, mFile(aFile)
|
||||
, mType(aType)
|
||||
{
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
|
@ -213,18 +202,12 @@ Directory::GetName(nsAString& aRetval, ErrorResult& aRv)
|
|||
{
|
||||
aRetval.Truncate();
|
||||
|
||||
if (mType == eDOMRootDirectory) {
|
||||
RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
fs->GetRootName(aRetval);
|
||||
RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
aRv = mFile->GetLeafName(aRetval);
|
||||
NS_WARN_IF(aRv.Failed());
|
||||
fs->GetDirectoryName(mFile, aRetval, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
|
@ -318,8 +301,7 @@ Directory::Get(const nsAString& aPath, ErrorResult& aRv)
|
|||
}
|
||||
|
||||
RefPtr<GetFileOrDirectoryTaskChild> task =
|
||||
GetFileOrDirectoryTaskChild::Create(fs, realPath, eNotDOMRootDirectory,
|
||||
false, aRv);
|
||||
GetFileOrDirectoryTaskChild::Create(fs, realPath, false, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -409,7 +391,7 @@ Directory::GetPath(nsAString& aRetval, ErrorResult& aRv)
|
|||
return;
|
||||
}
|
||||
|
||||
fs->GetDOMPath(mFile, mType, mPath, aRv);
|
||||
fs->GetDOMPath(mFile, mPath, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
@ -438,7 +420,7 @@ Directory::GetFilesAndDirectories(ErrorResult& aRv)
|
|||
}
|
||||
|
||||
RefPtr<GetDirectoryListingTaskChild> task =
|
||||
GetDirectoryListingTaskChild::Create(fs, mFile, mType, mFilters, aRv);
|
||||
GetDirectoryListingTaskChild::Create(fs, mFile, mFilters, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -478,10 +460,6 @@ FileSystemBase*
|
|||
Directory::GetFileSystem(ErrorResult& aRv)
|
||||
{
|
||||
if (!mFileSystem) {
|
||||
// Any subdir inherits the FileSystem of the parent Directory. If we are
|
||||
// here it's because we are dealing with the DOM root.
|
||||
MOZ_ASSERT(mType == eDOMRootDirectory);
|
||||
|
||||
nsAutoString path;
|
||||
aRv = mFile->GetPath(path);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
|
|
|
@ -59,20 +59,9 @@ public:
|
|||
static already_AddRefed<Promise>
|
||||
GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv);
|
||||
|
||||
enum DirectoryType {
|
||||
// When a directory is selected using a HTMLInputElement, that will be the
|
||||
// DOM root directory and its name will be '/'. All the sub directory will
|
||||
// be called with they real name. We use this enum to mark what we must
|
||||
// consider the '/' of this DOM filesystem.
|
||||
eDOMRootDirectory,
|
||||
|
||||
// All the sub directories of the '/' will be marked using this other value.
|
||||
eNotDOMRootDirectory
|
||||
};
|
||||
|
||||
static already_AddRefed<Directory>
|
||||
Create(nsISupports* aParent, nsIFile* aDirectory,
|
||||
DirectoryType aType, FileSystemBase* aFileSystem = 0);
|
||||
FileSystemBase* aFileSystem = 0);
|
||||
|
||||
// ========= Begin WebIDL bindings. ===========
|
||||
|
||||
|
@ -145,17 +134,12 @@ public:
|
|||
FileSystemBase*
|
||||
GetFileSystem(ErrorResult& aRv);
|
||||
|
||||
DirectoryType Type() const
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
bool
|
||||
ClonableToDifferentThreadOrProcess() const;
|
||||
|
||||
private:
|
||||
Directory(nsISupports* aParent,
|
||||
nsIFile* aFile, DirectoryType aType,
|
||||
nsIFile* aFile,
|
||||
FileSystemBase* aFileSystem = nullptr);
|
||||
~Directory();
|
||||
|
||||
|
@ -172,7 +156,6 @@ private:
|
|||
nsCOMPtr<nsISupports> mParent;
|
||||
RefPtr<FileSystemBase> mFileSystem;
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
DirectoryType mType;
|
||||
|
||||
nsString mFilters;
|
||||
nsString mPath;
|
||||
|
|
|
@ -110,19 +110,26 @@ FileSystemBase::IsSafeDirectory(Directory* aDir) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
FileSystemBase::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
aRv = aFile->GetLeafName(aRetval);
|
||||
NS_WARN_IF(aRv.Failed());
|
||||
}
|
||||
|
||||
void
|
||||
FileSystemBase::GetDOMPath(nsIFile* aFile,
|
||||
Directory::DirectoryType aType,
|
||||
nsAString& aRetval,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
if (aType == Directory::eDOMRootDirectory) {
|
||||
aRetval.AssignLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
|
||||
return;
|
||||
}
|
||||
aRetval.Truncate();
|
||||
|
||||
nsCOMPtr<nsIFile> fileSystemPath;
|
||||
aRv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(LocalOrDeviceStorageRootPath()),
|
||||
|
@ -131,8 +138,6 @@ FileSystemBase::GetDOMPath(nsIFile* aFile,
|
|||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(FileSystemUtils::IsDescendantPath(fileSystemPath, aFile));
|
||||
|
||||
nsCOMPtr<nsIFile> path;
|
||||
aRv = aFile->Clone(getter_AddRefs(path));
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
|
@ -142,6 +147,14 @@ FileSystemBase::GetDOMPath(nsIFile* aFile,
|
|||
nsTArray<nsString> parts;
|
||||
|
||||
while (true) {
|
||||
nsAutoString leafName;
|
||||
aRv = path->GetLeafName(leafName);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
parts.AppendElement(leafName);
|
||||
|
||||
bool equal = false;
|
||||
aRv = fileSystemPath->Equals(path, &equal);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
|
@ -152,14 +165,6 @@ FileSystemBase::GetDOMPath(nsIFile* aFile,
|
|||
break;
|
||||
}
|
||||
|
||||
nsAutoString leafName;
|
||||
aRv = path->GetLeafName(leafName);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
parts.AppendElement(leafName);
|
||||
|
||||
nsCOMPtr<nsIFile> parentPath;
|
||||
aRv = path->GetParent(getter_AddRefs(parentPath));
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
|
@ -176,8 +181,6 @@ FileSystemBase::GetDOMPath(nsIFile* aFile,
|
|||
|
||||
MOZ_ASSERT(!parts.IsEmpty());
|
||||
|
||||
aRetval.Truncate();
|
||||
|
||||
for (int32_t i = parts.Length() - 1; i >= 0; --i) {
|
||||
aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
|
||||
aRetval.Append(parts[i]);
|
||||
|
|
|
@ -40,16 +40,12 @@ public:
|
|||
virtual nsISupports*
|
||||
GetParentObject() const;
|
||||
|
||||
/*
|
||||
* Get the virtual name of the root directory. This name will be exposed to
|
||||
* the content page.
|
||||
*/
|
||||
virtual void
|
||||
GetRootName(nsAString& aRetval) const = 0;
|
||||
GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
||||
ErrorResult& aRv) const;
|
||||
|
||||
void
|
||||
GetDOMPath(nsIFile* aFile, Directory::DirectoryType aType,
|
||||
nsAString& aRetval, ErrorResult& aRv) const;
|
||||
GetDOMPath(nsIFile* aFile, nsAString& aRetval, ErrorResult& aRv) const;
|
||||
|
||||
/*
|
||||
* Return the local root path of the FileSystem implementation.
|
||||
|
|
|
@ -28,7 +28,6 @@ namespace dom {
|
|||
/* static */ already_AddRefed<GetDirectoryListingTaskChild>
|
||||
GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
const nsAString& aFilters,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
|
@ -36,7 +35,7 @@ GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
|
|||
aFileSystem->AssertIsOnOwningThread();
|
||||
|
||||
RefPtr<GetDirectoryListingTaskChild> task =
|
||||
new GetDirectoryListingTaskChild(aFileSystem, aTargetPath, aType, aFilters);
|
||||
new GetDirectoryListingTaskChild(aFileSystem, aTargetPath, aFilters);
|
||||
|
||||
// aTargetPath can be null. In this case SetError will be called.
|
||||
|
||||
|
@ -57,12 +56,10 @@ GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
|
|||
|
||||
GetDirectoryListingTaskChild::GetDirectoryListingTaskChild(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
const nsAString& aFilters)
|
||||
: FileSystemTaskChildBase(aFileSystem)
|
||||
, mTargetPath(aTargetPath)
|
||||
, mFilters(aFilters)
|
||||
, mType(aType)
|
||||
{
|
||||
MOZ_ASSERT(aFileSystem);
|
||||
aFileSystem->AssertIsOnOwningThread();
|
||||
|
@ -93,7 +90,6 @@ GetDirectoryListingTaskChild::GetRequestParams(const nsString& aSerializedDOMPat
|
|||
}
|
||||
|
||||
return FileSystemGetDirectoryListingParams(aSerializedDOMPath, path,
|
||||
mType == Directory::eDOMRootDirectory,
|
||||
mFilters);
|
||||
}
|
||||
|
||||
|
@ -179,8 +175,7 @@ GetDirectoryListingTaskChild::HandlerCallback()
|
|||
|
||||
if (mTargetData[i].mType == Directory::FileOrDirectoryPath::eDirectoryPath) {
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(mFileSystem->GetParentObject(), path,
|
||||
Directory::eNotDOMRootDirectory, mFileSystem);
|
||||
Directory::Create(mFileSystem->GetParentObject(), path, mFileSystem);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
// Propogate mFilter onto sub-Directory object:
|
||||
|
@ -230,8 +225,6 @@ GetDirectoryListingTaskParent::Create(FileSystemBase* aFileSystem,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
task->mType = aParam.isRoot()
|
||||
? Directory::eDOMRootDirectory : Directory::eNotDOMRootDirectory;
|
||||
return task.forget();
|
||||
}
|
||||
|
||||
|
@ -291,15 +284,7 @@ GetDirectoryListingTaskParent::IOWork()
|
|||
}
|
||||
|
||||
if (!exists) {
|
||||
if (mType == Directory::eNotDOMRootDirectory) {
|
||||
return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
// If the root directory doesn't exit, create it.
|
||||
rv = mTargetPath->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
// Get isDirectory.
|
||||
|
|
|
@ -23,7 +23,6 @@ public:
|
|||
static already_AddRefed<GetDirectoryListingTaskChild>
|
||||
Create(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
const nsAString& aFilters,
|
||||
ErrorResult& aRv);
|
||||
|
||||
|
@ -40,7 +39,6 @@ private:
|
|||
// If aDirectoryOnly is set, we should ensure that the target is a directory.
|
||||
GetDirectoryListingTaskChild(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
const nsAString& aFilters);
|
||||
|
||||
virtual FileSystemParams
|
||||
|
@ -57,7 +55,6 @@ private:
|
|||
RefPtr<Promise> mPromise;
|
||||
nsCOMPtr<nsIFile> mTargetPath;
|
||||
nsString mFilters;
|
||||
Directory::DirectoryType mType;
|
||||
|
||||
// We cannot store File or Directory objects bacause this object is created
|
||||
// on a different thread and File and Directory are not thread-safe.
|
||||
|
@ -89,7 +86,6 @@ private:
|
|||
|
||||
nsCOMPtr<nsIFile> mTargetPath;
|
||||
nsString mFilters;
|
||||
Directory::DirectoryType mType;
|
||||
|
||||
// We cannot store File or Directory objects bacause this object is created
|
||||
// on a different thread and File and Directory are not thread-safe.
|
||||
|
|
|
@ -27,7 +27,6 @@ namespace dom {
|
|||
/* static */ already_AddRefed<GetFileOrDirectoryTaskChild>
|
||||
GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
bool aDirectoryOnly,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
|
@ -35,8 +34,7 @@ GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
|
|||
MOZ_ASSERT(aFileSystem);
|
||||
|
||||
RefPtr<GetFileOrDirectoryTaskChild> task =
|
||||
new GetFileOrDirectoryTaskChild(aFileSystem, aTargetPath, aType,
|
||||
aDirectoryOnly);
|
||||
new GetFileOrDirectoryTaskChild(aFileSystem, aTargetPath, aDirectoryOnly);
|
||||
|
||||
// aTargetPath can be null. In this case SetError will be called.
|
||||
|
||||
|
@ -57,12 +55,10 @@ GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
|
|||
|
||||
GetFileOrDirectoryTaskChild::GetFileOrDirectoryTaskChild(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
bool aDirectoryOnly)
|
||||
: FileSystemTaskChildBase(aFileSystem)
|
||||
, mTargetPath(aTargetPath)
|
||||
, mIsDirectory(aDirectoryOnly)
|
||||
, mType(aType)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
|
||||
MOZ_ASSERT(aFileSystem);
|
||||
|
@ -92,8 +88,7 @@ GetFileOrDirectoryTaskChild::GetRequestParams(const nsString& aSerializedDOMPath
|
|||
return FileSystemGetFileOrDirectoryParams();
|
||||
}
|
||||
|
||||
return FileSystemGetFileOrDirectoryParams(aSerializedDOMPath, path,
|
||||
mType == Directory::eDOMRootDirectory);
|
||||
return FileSystemGetFileOrDirectoryParams(aSerializedDOMPath, path);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -151,7 +146,6 @@ GetFileOrDirectoryTaskChild::HandlerCallback()
|
|||
if (mIsDirectory) {
|
||||
RefPtr<Directory> dir = Directory::Create(mFileSystem->GetParentObject(),
|
||||
mTargetPath,
|
||||
mType,
|
||||
mFileSystem);
|
||||
MOZ_ASSERT(dir);
|
||||
|
||||
|
@ -195,8 +189,6 @@ GetFileOrDirectoryTaskParent::Create(FileSystemBase* aFileSystem,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
task->mType = aParam.isRoot()
|
||||
? Directory::eDOMRootDirectory : Directory::eNotDOMRootDirectory;
|
||||
return task.forget();
|
||||
}
|
||||
|
||||
|
@ -248,15 +240,7 @@ GetFileOrDirectoryTaskParent::IOWork()
|
|||
}
|
||||
|
||||
if (!exists) {
|
||||
if (mType == Directory::eNotDOMRootDirectory) {
|
||||
return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
// If the root directory doesn't exit, create it.
|
||||
rv = mTargetPath->Create(nsIFile::DIRECTORY_TYPE, 0777);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
|
||||
}
|
||||
|
||||
// Get isDirectory.
|
||||
|
@ -269,11 +253,6 @@ GetFileOrDirectoryTaskParent::IOWork()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// Check if the root is a directory.
|
||||
if (mType == Directory::eDOMRootDirectory) {
|
||||
return NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR;
|
||||
}
|
||||
|
||||
bool isFile;
|
||||
// Get isFile
|
||||
rv = mTargetPath->IsFile(&isFile);
|
||||
|
|
|
@ -23,7 +23,6 @@ public:
|
|||
static already_AddRefed<GetFileOrDirectoryTaskChild>
|
||||
Create(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
bool aDirectoryOnly,
|
||||
ErrorResult& aRv);
|
||||
|
||||
|
@ -51,7 +50,6 @@ private:
|
|||
// If aDirectoryOnly is set, we should ensure that the target is a directory.
|
||||
GetFileOrDirectoryTaskChild(FileSystemBase* aFileSystem,
|
||||
nsIFile* aTargetPath,
|
||||
Directory::DirectoryType aType,
|
||||
bool aDirectoryOnly);
|
||||
|
||||
RefPtr<Promise> mPromise;
|
||||
|
@ -59,7 +57,6 @@ private:
|
|||
|
||||
// Whether we get a directory.
|
||||
bool mIsDirectory;
|
||||
Directory::DirectoryType mType;
|
||||
};
|
||||
|
||||
class GetFileOrDirectoryTaskParent final : public FileSystemTaskParentBase
|
||||
|
@ -90,7 +87,6 @@ private:
|
|||
|
||||
// Whether we get a directory.
|
||||
bool mIsDirectory;
|
||||
Directory::DirectoryType mType;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -62,13 +62,6 @@ OSFileSystem::GetParentObject() const
|
|||
return mParent;
|
||||
}
|
||||
|
||||
void
|
||||
OSFileSystem::GetRootName(nsAString& aRetval) const
|
||||
{
|
||||
AssertIsOnOwningThread();
|
||||
aRetval.AssignLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
|
||||
}
|
||||
|
||||
bool
|
||||
OSFileSystem::IsSafeFile(nsIFile* aFile) const
|
||||
{
|
||||
|
|
|
@ -28,9 +28,6 @@ public:
|
|||
virtual nsISupports*
|
||||
GetParentObject() const override;
|
||||
|
||||
virtual void
|
||||
GetRootName(nsAString& aRetval) const override;
|
||||
|
||||
virtual bool
|
||||
IsSafeFile(nsIFile* aFile) const override;
|
||||
|
||||
|
@ -75,7 +72,8 @@ public:
|
|||
}
|
||||
|
||||
virtual void
|
||||
GetRootName(nsAString& aRetval) const override
|
||||
GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
||||
ErrorResult& aRv) const override
|
||||
{
|
||||
MOZ_CRASH("This should not be called on the PBackground thread.");
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ struct FileSystemGetDirectoryListingParams
|
|||
{
|
||||
nsString filesystem;
|
||||
nsString realPath;
|
||||
bool isRoot;
|
||||
|
||||
// 'filters' could be an array rather than a semicolon separated string
|
||||
// (we'd then use InfallibleTArray<nsString> internally), but that is
|
||||
// wasteful. E10s requires us to pass the filters over as a string anyway,
|
||||
|
@ -55,7 +55,6 @@ struct FileSystemGetFileOrDirectoryParams
|
|||
{
|
||||
nsString filesystem;
|
||||
nsString realPath;
|
||||
bool isRoot;
|
||||
};
|
||||
|
||||
struct FileSystemRemoveParams
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
function test_basic(aDirectory, aNext) {
|
||||
ok(aDirectory, "Directory exists.");
|
||||
ok(aDirectory instanceof Directory, "We have a directory.");
|
||||
is(aDirectory.name, '/', "directory.name must be '/'");
|
||||
is(aDirectory.path, '/', "directory.path must be '/'");
|
||||
is(aDirectory.path, '/' + aDirectory.name, "directory.path must be '/'+name");
|
||||
aNext();
|
||||
}
|
||||
|
||||
|
@ -16,7 +15,7 @@ function test_getFilesAndDirectories(aDirectory, aRecursive, aNext) {
|
|||
isnot(data[i].name, '/', "Subdirectory should be called with the leafname");
|
||||
isnot(data[i].path, '/', "Subdirectory path should be called with the leafname");
|
||||
isnot(data[i].path, dir.path, "Subdirectory path should contain the parent path.");
|
||||
is(data[i].path,dir.path + '/' + data[i].name, "Subdirectory path should be called parentdir.path + '/' + leafname");
|
||||
is(data[i].path, dir.path + '/' + data[i].name, "Subdirectory path should be called parentdir.path + '/' + leafname");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +30,7 @@ function test_getFilesAndDirectories(aDirectory, aRecursive, aNext) {
|
|||
ok (data[i] instanceof File || data[i] instanceof Directory, "Just Files or Directories: " + data[i].name);
|
||||
if (data[i] instanceof Directory) {
|
||||
isnot(data[i].name, '/', "Subdirectory should be called with the leafname");
|
||||
is(data[i].path, '/' + data[i].name, "Subdirectory path should be called '/' + leafname");
|
||||
is(data[i].path, aDirectory.path + '/' + data[i].name, "Subdirectory path should be called parentdir.path + '/' + leafname");
|
||||
if (aRecursive) {
|
||||
promises.push(checkSubDir(data[i]));
|
||||
}
|
||||
|
|
|
@ -272,8 +272,7 @@ class HTMLInputElementState final : public nsISupports
|
|||
continue;
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory = Directory::Create(aWindow, file,
|
||||
Directory::eDOMRootDirectory);
|
||||
RefPtr<Directory> directory = Directory::Create(aWindow, file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
OwningFileOrDirectory* element = aResult.AppendElement();
|
||||
|
@ -2311,8 +2310,7 @@ HTMLInputElement::MozSetDirectory(const nsAString& aDirectoryPath,
|
|||
return;
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory = Directory::Create(window, file,
|
||||
Directory::eDOMRootDirectory);
|
||||
RefPtr<Directory> directory = Directory::Create(window, file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
nsTArray<OwningFileOrDirectory> array;
|
||||
|
|
|
@ -46,8 +46,7 @@ LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow,
|
|||
MOZ_ASSERT(isDir);
|
||||
#endif
|
||||
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(aWindow, aFile, Directory::eDOMRootDirectory);
|
||||
RefPtr<Directory> directory = Directory::Create(aWindow, aFile);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
directory.forget(aResult);
|
||||
|
|
|
@ -174,8 +174,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputData& aData,
|
|||
}
|
||||
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(mParent->GetCurrentInnerWindow(), file,
|
||||
Directory::eDOMRootDirectory);
|
||||
Directory::Create(mParent->GetCurrentInnerWindow(), file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
OwningFileOrDirectory* element = mFilesOrDirectories.AppendElement();
|
||||
|
|
Загрузка…
Ссылка в новой задаче