From 8e22a11655fd7cd7f5c92f6d57dc86fdf6da42c9 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Mon, 18 Apr 2016 03:32:30 -0400 Subject: [PATCH] Bug 1263992 - patch 1 - Remove DirectoryType enum, r=smaug --- dom/base/StructuredCloneHolder.cpp | 25 ++++---------- dom/filesystem/CreateDirectoryTask.cpp | 4 +-- dom/filesystem/DeviceStorageFileSystem.cpp | 26 ++++++++++++-- dom/filesystem/DeviceStorageFileSystem.h | 3 +- dom/filesystem/Directory.cpp | 40 +++++----------------- dom/filesystem/Directory.h | 21 ++---------- dom/filesystem/FileSystemBase.cpp | 37 +++++++++++--------- dom/filesystem/FileSystemBase.h | 10 ++---- dom/filesystem/GetDirectoryListingTask.cpp | 21 ++---------- dom/filesystem/GetDirectoryListingTask.h | 4 --- dom/filesystem/GetFileOrDirectoryTask.cpp | 27 ++------------- dom/filesystem/GetFileOrDirectoryTask.h | 4 --- dom/filesystem/OSFileSystem.cpp | 7 ---- dom/filesystem/OSFileSystem.h | 6 ++-- dom/filesystem/PFileSystemParams.ipdlh | 3 +- dom/filesystem/tests/filesystem_commons.js | 7 ++-- dom/html/HTMLInputElement.cpp | 6 ++-- widget/nsBaseFilePicker.cpp | 3 +- widget/nsFilePickerProxy.cpp | 3 +- 19 files changed, 83 insertions(+), 174 deletions(-) diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 559761458280..e12cc9b8b05b 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -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 val(aCx); { RefPtr directory = - Directory::Create(aHolder->ParentDuringRead(), file, - (Directory::DirectoryType) directoryType); + Directory::Create(aHolder->ParentDuringRead(), file); if (!ToJSValue(aCx, directory, &val)) { return nullptr; diff --git a/dom/filesystem/CreateDirectoryTask.cpp b/dom/filesystem/CreateDirectoryTask.cpp index d032aaf7935c..d96d9d978970 100644 --- a/dom/filesystem/CreateDirectoryTask.cpp +++ b/dom/filesystem/CreateDirectoryTask.cpp @@ -119,9 +119,7 @@ CreateDirectoryTaskChild::HandlerCallback() } RefPtr dir = Directory::Create(mFileSystem->GetParentObject(), - mTargetPath, - Directory::eNotDOMRootDirectory, - mFileSystem); + mTargetPath, mFileSystem); MOZ_ASSERT(dir); mPromise->MaybeResolve(dir); diff --git a/dom/filesystem/DeviceStorageFileSystem.cpp b/dom/filesystem/DeviceStorageFileSystem.cpp index de22fc505ecb..2b138c277238 100644 --- a/dom/filesystem/DeviceStorageFileSystem.cpp +++ b/dom/filesystem/DeviceStorageFileSystem.cpp @@ -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 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 diff --git a/dom/filesystem/DeviceStorageFileSystem.h b/dom/filesystem/DeviceStorageFileSystem.h index f77e15021eee..9551040ae33f 100644 --- a/dom/filesystem/DeviceStorageFileSystem.h +++ b/dom/filesystem/DeviceStorageFileSystem.h @@ -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; diff --git a/dom/filesystem/Directory.cpp b/dom/filesystem/Directory.cpp index cbab78e0790b..8513db3920ba 100644 --- a/dom/filesystem/Directory.cpp +++ b/dom/filesystem/Directory.cpp @@ -137,8 +137,7 @@ Directory::GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv) } RefPtr 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::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 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 = - new Directory(aParent, aFile, aType, aFileSystem); + RefPtr 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 fs = GetFileSystem(aRv); - if (NS_WARN_IF(aRv.Failed())) { - return; - } - - fs->GetRootName(aRetval); + RefPtr 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 @@ -318,8 +301,7 @@ Directory::Get(const nsAString& aPath, ErrorResult& aRv) } RefPtr 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 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())) { diff --git a/dom/filesystem/Directory.h b/dom/filesystem/Directory.h index 5257977f8b9f..e3298e773385 100644 --- a/dom/filesystem/Directory.h +++ b/dom/filesystem/Directory.h @@ -59,20 +59,9 @@ public: static already_AddRefed 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 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 mParent; RefPtr mFileSystem; nsCOMPtr mFile; - DirectoryType mType; nsString mFilters; nsString mPath; diff --git a/dom/filesystem/FileSystemBase.cpp b/dom/filesystem/FileSystemBase.cpp index 64aa7bb072a9..3f24b440704c 100644 --- a/dom/filesystem/FileSystemBase.cpp +++ b/dom/filesystem/FileSystemBase.cpp @@ -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 fileSystemPath; aRv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(LocalOrDeviceStorageRootPath()), @@ -131,8 +138,6 @@ FileSystemBase::GetDOMPath(nsIFile* aFile, return; } - MOZ_ASSERT(FileSystemUtils::IsDescendantPath(fileSystemPath, aFile)); - nsCOMPtr path; aRv = aFile->Clone(getter_AddRefs(path)); if (NS_WARN_IF(aRv.Failed())) { @@ -142,6 +147,14 @@ FileSystemBase::GetDOMPath(nsIFile* aFile, nsTArray 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 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]); diff --git a/dom/filesystem/FileSystemBase.h b/dom/filesystem/FileSystemBase.h index 8330f394d6dc..ea6f03916b11 100644 --- a/dom/filesystem/FileSystemBase.h +++ b/dom/filesystem/FileSystemBase.h @@ -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. diff --git a/dom/filesystem/GetDirectoryListingTask.cpp b/dom/filesystem/GetDirectoryListingTask.cpp index e96340815d42..85c1ad12dd81 100644 --- a/dom/filesystem/GetDirectoryListingTask.cpp +++ b/dom/filesystem/GetDirectoryListingTask.cpp @@ -28,7 +28,6 @@ namespace dom { /* static */ already_AddRefed 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 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::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. diff --git a/dom/filesystem/GetDirectoryListingTask.h b/dom/filesystem/GetDirectoryListingTask.h index 50c15ec0f44d..36d19e0dc1d4 100644 --- a/dom/filesystem/GetDirectoryListingTask.h +++ b/dom/filesystem/GetDirectoryListingTask.h @@ -23,7 +23,6 @@ public: static already_AddRefed 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 mPromise; nsCOMPtr 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 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. diff --git a/dom/filesystem/GetFileOrDirectoryTask.cpp b/dom/filesystem/GetFileOrDirectoryTask.cpp index 708980a85313..b6f08e99fe5d 100644 --- a/dom/filesystem/GetFileOrDirectoryTask.cpp +++ b/dom/filesystem/GetFileOrDirectoryTask.cpp @@ -27,7 +27,6 @@ namespace dom { /* static */ already_AddRefed 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 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 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); diff --git a/dom/filesystem/GetFileOrDirectoryTask.h b/dom/filesystem/GetFileOrDirectoryTask.h index a3e58e34f88b..3d9b62023c2f 100644 --- a/dom/filesystem/GetFileOrDirectoryTask.h +++ b/dom/filesystem/GetFileOrDirectoryTask.h @@ -23,7 +23,6 @@ public: static already_AddRefed 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 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 diff --git a/dom/filesystem/OSFileSystem.cpp b/dom/filesystem/OSFileSystem.cpp index c4a1063c8cb0..e083c65cecd3 100644 --- a/dom/filesystem/OSFileSystem.cpp +++ b/dom/filesystem/OSFileSystem.cpp @@ -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 { diff --git a/dom/filesystem/OSFileSystem.h b/dom/filesystem/OSFileSystem.h index 0042f196ee0b..f4a13cf81a36 100644 --- a/dom/filesystem/OSFileSystem.h +++ b/dom/filesystem/OSFileSystem.h @@ -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."); } diff --git a/dom/filesystem/PFileSystemParams.ipdlh b/dom/filesystem/PFileSystemParams.ipdlh index 4e10380a4f96..5ddf03e12eea 100644 --- a/dom/filesystem/PFileSystemParams.ipdlh +++ b/dom/filesystem/PFileSystemParams.ipdlh @@ -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 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 diff --git a/dom/filesystem/tests/filesystem_commons.js b/dom/filesystem/tests/filesystem_commons.js index 0ce0d41a6983..6c7c529c94b5 100644 --- a/dom/filesystem/tests/filesystem_commons.js +++ b/dom/filesystem/tests/filesystem_commons.js @@ -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])); } diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 2b9bb70401ab..67b6ddf2d64a 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -272,8 +272,7 @@ class HTMLInputElementState final : public nsISupports continue; } - RefPtr directory = Directory::Create(aWindow, file, - Directory::eDOMRootDirectory); + RefPtr 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::Create(window, file, - Directory::eDOMRootDirectory); + RefPtr directory = Directory::Create(window, file); MOZ_ASSERT(directory); nsTArray array; diff --git a/widget/nsBaseFilePicker.cpp b/widget/nsBaseFilePicker.cpp index 71c00cbb1db3..22b3186e0c03 100644 --- a/widget/nsBaseFilePicker.cpp +++ b/widget/nsBaseFilePicker.cpp @@ -46,8 +46,7 @@ LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow, MOZ_ASSERT(isDir); #endif - RefPtr directory = - Directory::Create(aWindow, aFile, Directory::eDOMRootDirectory); + RefPtr directory = Directory::Create(aWindow, aFile); MOZ_ASSERT(directory); directory.forget(aResult); diff --git a/widget/nsFilePickerProxy.cpp b/widget/nsFilePickerProxy.cpp index 1dcbcf7ee5c8..cea661efe7e6 100644 --- a/widget/nsFilePickerProxy.cpp +++ b/widget/nsFilePickerProxy.cpp @@ -174,8 +174,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputData& aData, } RefPtr directory = - Directory::Create(mParent->GetCurrentInnerWindow(), file, - Directory::eDOMRootDirectory); + Directory::Create(mParent->GetCurrentInnerWindow(), file); MOZ_ASSERT(directory); OwningFileOrDirectory* element = mFilesOrDirectories.AppendElement();