From 3a9551a834118765fa9f77e46b847fc8804543e9 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 3 Nov 2016 07:55:30 +0100 Subject: [PATCH] Bug 1284987 - Entries API - part 2 - FileSystemEntry.getParent, r=smaug --- dom/events/DataTransferItem.cpp | 4 +- dom/filesystem/compat/CallbackRunnables.cpp | 30 +++++++++++--- dom/filesystem/compat/CallbackRunnables.h | 12 +++++- .../compat/FileSystemDirectoryEntry.cpp | 11 ++--- .../compat/FileSystemDirectoryEntry.h | 10 ++--- .../compat/FileSystemDirectoryReader.cpp | 28 +++++++------ .../compat/FileSystemDirectoryReader.h | 8 ++-- dom/filesystem/compat/FileSystemEntry.cpp | 23 ++++++++++- dom/filesystem/compat/FileSystemEntry.h | 7 ++++ dom/filesystem/compat/FileSystemFileEntry.cpp | 3 +- dom/filesystem/compat/FileSystemFileEntry.h | 4 +- .../compat/FileSystemRootDirectoryEntry.cpp | 9 ++--- .../compat/FileSystemRootDirectoryEntry.h | 4 +- .../compat/FileSystemRootDirectoryReader.cpp | 6 +-- .../compat/FileSystemRootDirectoryReader.h | 2 +- dom/filesystem/compat/tests/test_basic.html | 40 +++++++++++++++++-- dom/webidl/FileSystemEntry.webidl | 6 +-- 17 files changed, 147 insertions(+), 60 deletions(-) diff --git a/dom/events/DataTransferItem.cpp b/dom/events/DataTransferItem.cpp index 3c5563c06f58..ebd13a867dd4 100644 --- a/dom/events/DataTransferItem.cpp +++ b/dom/events/DataTransferItem.cpp @@ -326,9 +326,9 @@ DataTransferItem::GetAsEntry(nsIPrincipal& aSubjectPrincipal, } RefPtr directory = Directory::Create(global, directoryFile); - entry = new FileSystemDirectoryEntry(global, directory, fs); + entry = new FileSystemDirectoryEntry(global, directory, nullptr, fs); } else { - entry = new FileSystemFileEntry(global, file, fs); + entry = new FileSystemFileEntry(global, file, nullptr, fs); } Sequence> entries; diff --git a/dom/filesystem/compat/CallbackRunnables.cpp b/dom/filesystem/compat/CallbackRunnables.cpp index 03f80a3693ae..1cd2b85b4889 100644 --- a/dom/filesystem/compat/CallbackRunnables.cpp +++ b/dom/filesystem/compat/CallbackRunnables.cpp @@ -74,18 +74,18 @@ EmptyEntriesCallbackRunnable::Run() return NS_OK; } -GetEntryHelper::GetEntryHelper(nsIGlobalObject* aGlobalObject, +GetEntryHelper::GetEntryHelper(FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem, FileSystemEntryCallback* aSuccessCallback, ErrorCallback* aErrorCallback, FileSystemDirectoryEntry::GetInternalType aType) - : mGlobal(aGlobalObject) + : mParentEntry(aParentEntry) , mFileSystem(aFileSystem) , mSuccessCallback(aSuccessCallback) , mErrorCallback(aErrorCallback) , mType(aType) { - MOZ_ASSERT(aGlobalObject); + MOZ_ASSERT(aParentEntry); MOZ_ASSERT(aFileSystem); MOZ_ASSERT(aSuccessCallback || aErrorCallback); } @@ -110,7 +110,8 @@ GetEntryHelper::ResolvedCallback(JSContext* aCx, JS::Handle aValue) } RefPtr entry = - new FileSystemFileEntry(mGlobal, file, mFileSystem); + new FileSystemFileEntry(mParentEntry->GetParentObject(), file, + mParentEntry, mFileSystem); mSuccessCallback->HandleEvent(*entry); return; } @@ -124,7 +125,8 @@ GetEntryHelper::ResolvedCallback(JSContext* aCx, JS::Handle aValue) } RefPtr entry = - new FileSystemDirectoryEntry(mGlobal, directory, mFileSystem); + new FileSystemDirectoryEntry(mParentEntry->GetParentObject(), directory, + mParentEntry, mFileSystem); mSuccessCallback->HandleEvent(*entry); } @@ -141,7 +143,8 @@ GetEntryHelper::Error(nsresult aError) if (mErrorCallback) { RefPtr runnable = - new ErrorCallbackRunnable(mGlobal, mErrorCallback, aError); + new ErrorCallbackRunnable(mParentEntry->GetParentObject(), + mErrorCallback, aError); DebugOnly rv = NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); } @@ -149,6 +152,21 @@ GetEntryHelper::Error(nsresult aError) NS_IMPL_ISUPPORTS0(GetEntryHelper); +/* static */ void +FileSystemEntryCallbackHelper::Call(const Optional>& aEntryCallback, + FileSystemEntry* aEntry) +{ + MOZ_ASSERT(aEntry); + + if (aEntryCallback.WasPassed()) { + RefPtr runnable = + new EntryCallbackRunnable(&aEntryCallback.Value(), aEntry); + + DebugOnly rv = NS_DispatchToMainThread(runnable); + NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); + } +} + /* static */ void ErrorCallbackHelper::Call(nsIGlobalObject* aGlobal, const Optional>& aErrorCallback, diff --git a/dom/filesystem/compat/CallbackRunnables.h b/dom/filesystem/compat/CallbackRunnables.h index c24e2e08172f..3e4e3ceac2e9 100644 --- a/dom/filesystem/compat/CallbackRunnables.h +++ b/dom/filesystem/compat/CallbackRunnables.h @@ -65,7 +65,7 @@ class GetEntryHelper final : public PromiseNativeHandler public: NS_DECL_ISUPPORTS - GetEntryHelper(nsIGlobalObject* aGlobalObject, + GetEntryHelper(FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem, FileSystemEntryCallback* aSuccessCallback, ErrorCallback* aErrorCallback, @@ -83,13 +83,21 @@ private: void Error(nsresult aError); - nsCOMPtr mGlobal; + RefPtr mParentEntry; RefPtr mFileSystem; RefPtr mSuccessCallback; RefPtr mErrorCallback; FileSystemDirectoryEntry::GetInternalType mType; }; +class FileSystemEntryCallbackHelper +{ +public: + static void + Call(const Optional>& aEntryCallback, + FileSystemEntry* aEntry); +}; + class ErrorCallbackHelper { public: diff --git a/dom/filesystem/compat/FileSystemDirectoryEntry.cpp b/dom/filesystem/compat/FileSystemDirectoryEntry.cpp index 49a956e0a750..c2b7285fe5de 100644 --- a/dom/filesystem/compat/FileSystemDirectoryEntry.cpp +++ b/dom/filesystem/compat/FileSystemDirectoryEntry.cpp @@ -25,8 +25,9 @@ NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry) FileSystemDirectoryEntry::FileSystemDirectoryEntry(nsIGlobalObject* aGlobal, Directory* aDirectory, + FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem) - : FileSystemEntry(aGlobal, aFileSystem) + : FileSystemEntry(aGlobal, aParentEntry, aFileSystem) , mDirectory(aDirectory) { MOZ_ASSERT(aGlobal); @@ -57,12 +58,12 @@ FileSystemDirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) const } already_AddRefed -FileSystemDirectoryEntry::CreateReader() const +FileSystemDirectoryEntry::CreateReader() { MOZ_ASSERT(mDirectory); RefPtr reader = - new FileSystemDirectoryReader(GetParentObject(), Filesystem(), mDirectory); + new FileSystemDirectoryReader(this, Filesystem(), mDirectory); return reader.forget(); } @@ -71,7 +72,7 @@ FileSystemDirectoryEntry::GetInternal(const nsAString& aPath, const FileSystemFlags& aFlag, const Optional>& aSuccessCallback, const Optional>& aErrorCallback, - GetInternalType aType) const + GetInternalType aType) { MOZ_ASSERT(mDirectory); @@ -101,7 +102,7 @@ FileSystemDirectoryEntry::GetInternal(const nsAString& aPath, } RefPtr handler = - new GetEntryHelper(GetParentObject(), Filesystem(), + new GetEntryHelper(this, Filesystem(), aSuccessCallback.WasPassed() ? &aSuccessCallback.Value() : nullptr, aErrorCallback.WasPassed() diff --git a/dom/filesystem/compat/FileSystemDirectoryEntry.h b/dom/filesystem/compat/FileSystemDirectoryEntry.h index e5567d91814d..67d80cab5877 100644 --- a/dom/filesystem/compat/FileSystemDirectoryEntry.h +++ b/dom/filesystem/compat/FileSystemDirectoryEntry.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_FileSystemDirectoryEntry_h #define mozilla_dom_FileSystemDirectoryEntry_h -#include "mozilla/dom/FileSystemBinding.h" #include "mozilla/dom/FileSystemEntry.h" namespace mozilla { @@ -25,6 +24,7 @@ public: FileSystemDirectoryEntry(nsIGlobalObject* aGlobalObject, Directory* aDirectory, + FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem); virtual JSObject* @@ -43,12 +43,12 @@ public: GetFullPath(nsAString& aFullPath, ErrorResult& aRv) const override; virtual already_AddRefed - CreateReader() const; + CreateReader(); void GetFile(const Optional& aPath, const FileSystemFlags& aFlag, const Optional>& aSuccessCallback, - const Optional>& aErrorCallback) const + const Optional>& aErrorCallback) { GetInternal(aPath.WasPassed() ? aPath.Value() : EmptyString(), aFlag, aSuccessCallback, aErrorCallback, eGetFile); @@ -57,7 +57,7 @@ public: void GetDirectory(const Optional& aPath, const FileSystemFlags& aFlag, const Optional>& aSuccessCallback, - const Optional>& aErrorCallback) const + const Optional>& aErrorCallback) { GetInternal(aPath.WasPassed() ? aPath.Value() : EmptyString(), aFlag, aSuccessCallback, aErrorCallback, eGetDirectory); @@ -73,7 +73,7 @@ public: GetInternal(const nsAString& aPath, const FileSystemFlags& aFlag, const Optional>& aSuccessCallback, const Optional>& aErrorCallback, - GetInternalType aType) const; + GetInternalType aType); protected: virtual ~FileSystemDirectoryEntry(); diff --git a/dom/filesystem/compat/FileSystemDirectoryReader.cpp b/dom/filesystem/compat/FileSystemDirectoryReader.cpp index 1969cb2b073a..1374373783d5 100644 --- a/dom/filesystem/compat/FileSystemDirectoryReader.cpp +++ b/dom/filesystem/compat/FileSystemDirectoryReader.cpp @@ -12,7 +12,6 @@ #include "mozilla/dom/DirectoryBinding.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseNativeHandler.h" -#include "nsIGlobalObject.h" namespace mozilla { namespace dom { @@ -24,16 +23,16 @@ class PromiseHandler final : public PromiseNativeHandler public: NS_DECL_ISUPPORTS - PromiseHandler(nsIGlobalObject* aGlobalObject, + PromiseHandler(FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem, FileSystemEntriesCallback* aSuccessCallback, ErrorCallback* aErrorCallback) - : mGlobal(aGlobalObject) + : mParentEntry(aParentEntry) , mFileSystem(aFileSystem) , mSuccessCallback(aSuccessCallback) , mErrorCallback(aErrorCallback) { - MOZ_ASSERT(aGlobalObject); + MOZ_ASSERT(aParentEntry); MOZ_ASSERT(aFileSystem); MOZ_ASSERT(aSuccessCallback); } @@ -72,7 +71,8 @@ public: RefPtr file; if (NS_SUCCEEDED(UNWRAP_OBJECT(File, valueObj, file))) { RefPtr entry = - new FileSystemFileEntry(mGlobal, file, mFileSystem); + new FileSystemFileEntry(mParentEntry->GetParentObject(), file, + mParentEntry, mFileSystem); sequence[i] = entry; continue; } @@ -84,7 +84,8 @@ public: } RefPtr entry = - new FileSystemDirectoryEntry(mGlobal, directory, mFileSystem); + new FileSystemDirectoryEntry(mParentEntry->GetParentObject(), directory, + mParentEntry, mFileSystem); sequence[i] = entry; } @@ -96,7 +97,8 @@ public: { if (mErrorCallback) { RefPtr runnable = - new ErrorCallbackRunnable(mGlobal, mErrorCallback, + new ErrorCallbackRunnable(mParentEntry->GetParentObject(), + mErrorCallback, NS_ERROR_DOM_INVALID_STATE_ERR); DebugOnly rv = NS_DispatchToMainThread(runnable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed"); @@ -106,7 +108,7 @@ public: private: ~PromiseHandler() {} - nsCOMPtr mGlobal; + RefPtr mParentEntry; RefPtr mFileSystem; RefPtr mSuccessCallback; RefPtr mErrorCallback; @@ -116,7 +118,7 @@ NS_IMPL_ISUPPORTS0(PromiseHandler); } // anonymous namespace -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemDirectoryReader, mParent, +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemDirectoryReader, mParentEntry, mDirectory, mFileSystem) NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemDirectoryReader) @@ -127,15 +129,15 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileSystemDirectoryReader) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -FileSystemDirectoryReader::FileSystemDirectoryReader(nsIGlobalObject* aGlobal, +FileSystemDirectoryReader::FileSystemDirectoryReader(FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem, Directory* aDirectory) - : mParent(aGlobal) + : mParentEntry(aParentEntry) , mFileSystem(aFileSystem) , mDirectory(aDirectory) , mAlreadyRead(false) { - MOZ_ASSERT(aGlobal); + MOZ_ASSERT(aParentEntry); MOZ_ASSERT(aFileSystem); } @@ -176,7 +178,7 @@ FileSystemDirectoryReader::ReadEntries(FileSystemEntriesCallback& aSuccessCallba } RefPtr handler = - new PromiseHandler(GetParentObject(), mFileSystem, &aSuccessCallback, + new PromiseHandler(mParentEntry, mFileSystem, &aSuccessCallback, aErrorCallback.WasPassed() ? &aErrorCallback.Value() : nullptr); promise->AppendNativeHandler(handler); diff --git a/dom/filesystem/compat/FileSystemDirectoryReader.h b/dom/filesystem/compat/FileSystemDirectoryReader.h index ac3a543acc87..d568990f6a46 100644 --- a/dom/filesystem/compat/FileSystemDirectoryReader.h +++ b/dom/filesystem/compat/FileSystemDirectoryReader.h @@ -13,8 +13,6 @@ #include "nsCycleCollectionParticipant.h" #include "nsWrapperCache.h" -class nsIGlobalObject; - namespace mozilla { namespace dom { @@ -30,14 +28,14 @@ public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileSystemDirectoryReader) - explicit FileSystemDirectoryReader(nsIGlobalObject* aGlobalObject, + explicit FileSystemDirectoryReader(FileSystemDirectoryEntry* aDirectoryEntry, FileSystem* aFileSystem, Directory* aDirectory); nsIGlobalObject* GetParentObject() const { - return mParent; + return mParentEntry->GetParentObject(); } virtual JSObject* @@ -52,7 +50,7 @@ protected: virtual ~FileSystemDirectoryReader(); private: - nsCOMPtr mParent; + RefPtr mParentEntry; RefPtr mFileSystem; RefPtr mDirectory; diff --git a/dom/filesystem/compat/FileSystemEntry.cpp b/dom/filesystem/compat/FileSystemEntry.cpp index 6f93f15d28e3..638c2c6db9b0 100644 --- a/dom/filesystem/compat/FileSystemEntry.cpp +++ b/dom/filesystem/compat/FileSystemEntry.cpp @@ -13,7 +13,8 @@ namespace mozilla { namespace dom { -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemEntry, mParent, mFileSystem) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileSystemEntry, mParent, mParentEntry, + mFileSystem) NS_IMPL_CYCLE_COLLECTING_ADDREF(FileSystemEntry) NS_IMPL_CYCLE_COLLECTING_RELEASE(FileSystemEntry) @@ -35,11 +36,13 @@ FileSystemEntry::Create(nsIGlobalObject* aGlobalObject, if (aFileOrDirectory.IsFile()) { entry = new FileSystemFileEntry(aGlobalObject, aFileOrDirectory.GetAsFile(), + nullptr, aFileSystem); } else { MOZ_ASSERT(aFileOrDirectory.IsDirectory()); entry = new FileSystemDirectoryEntry(aGlobalObject, aFileOrDirectory.GetAsDirectory(), + nullptr, aFileSystem); } @@ -47,8 +50,10 @@ FileSystemEntry::Create(nsIGlobalObject* aGlobalObject, } FileSystemEntry::FileSystemEntry(nsIGlobalObject* aGlobal, + FileSystemEntry* aParentEntry, FileSystem* aFileSystem) : mParent(aGlobal) + , mParentEntry(aParentEntry) , mFileSystem(aFileSystem) { MOZ_ASSERT(aGlobal); @@ -64,5 +69,21 @@ FileSystemEntry::WrapObject(JSContext* aCx, JS::Handle aGivenProto) return FileSystemEntryBinding::Wrap(aCx, this, aGivenProto); } +void +FileSystemEntry::GetParent(const Optional>& aSuccessCallback, + const Optional>& aErrorCallback) +{ + if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) { + return; + } + + if (mParentEntry) { + FileSystemEntryCallbackHelper::Call(aSuccessCallback, mParentEntry); + return; + } + + FileSystemEntryCallbackHelper::Call(aSuccessCallback, this); +} + } // dom namespace } // mozilla namespace diff --git a/dom/filesystem/compat/FileSystemEntry.h b/dom/filesystem/compat/FileSystemEntry.h index 38ee9fd98c52..769fb8f3f95f 100644 --- a/dom/filesystem/compat/FileSystemEntry.h +++ b/dom/filesystem/compat/FileSystemEntry.h @@ -10,6 +10,7 @@ #include "mozilla/Attributes.h" #include "mozilla/ErrorResult.h" #include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/FileSystemBinding.h" #include "nsCycleCollectionParticipant.h" #include "nsIGlobalObject.h" #include "nsWrapperCache.h" @@ -60,6 +61,10 @@ public: virtual void GetFullPath(nsAString& aFullPath, ErrorResult& aRv) const = 0; + void + GetParent(const Optional>& aSuccessCallback, + const Optional>& aErrorCallback); + FileSystem* Filesystem() const { @@ -68,11 +73,13 @@ public: protected: FileSystemEntry(nsIGlobalObject* aGlobalObject, + FileSystemEntry* aParentEntry, FileSystem* aFileSystem); virtual ~FileSystemEntry(); private: nsCOMPtr mParent; + RefPtr mParentEntry; RefPtr mFileSystem; }; diff --git a/dom/filesystem/compat/FileSystemFileEntry.cpp b/dom/filesystem/compat/FileSystemFileEntry.cpp index 56e5fe056946..03747fe4e317 100644 --- a/dom/filesystem/compat/FileSystemFileEntry.cpp +++ b/dom/filesystem/compat/FileSystemFileEntry.cpp @@ -49,8 +49,9 @@ NS_INTERFACE_MAP_END_INHERITING(FileSystemEntry) FileSystemFileEntry::FileSystemFileEntry(nsIGlobalObject* aGlobal, File* aFile, + FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem) - : FileSystemEntry(aGlobal, aFileSystem) + : FileSystemEntry(aGlobal, aParentEntry, aFileSystem) , mFile(aFile) { MOZ_ASSERT(aGlobal); diff --git a/dom/filesystem/compat/FileSystemFileEntry.h b/dom/filesystem/compat/FileSystemFileEntry.h index eb214496ff11..b1e1251a48b2 100644 --- a/dom/filesystem/compat/FileSystemFileEntry.h +++ b/dom/filesystem/compat/FileSystemFileEntry.h @@ -12,8 +12,9 @@ namespace mozilla { namespace dom { -class File; class BlobCallback; +class File; +class FileSystemDirectoryEntry; class FileSystemFileEntry final : public FileSystemEntry { @@ -22,6 +23,7 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemFileEntry, FileSystemEntry) FileSystemFileEntry(nsIGlobalObject* aGlobalObject, File* aFile, + FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem); virtual JSObject* diff --git a/dom/filesystem/compat/FileSystemRootDirectoryEntry.cpp b/dom/filesystem/compat/FileSystemRootDirectoryEntry.cpp index 417df7e15f37..68ce62aa291c 100644 --- a/dom/filesystem/compat/FileSystemRootDirectoryEntry.cpp +++ b/dom/filesystem/compat/FileSystemRootDirectoryEntry.cpp @@ -23,7 +23,7 @@ NS_INTERFACE_MAP_END_INHERITING(FileSystemDirectoryEntry) FileSystemRootDirectoryEntry::FileSystemRootDirectoryEntry(nsIGlobalObject* aGlobal, const Sequence>& aEntries, FileSystem* aFileSystem) - : FileSystemDirectoryEntry(aGlobal, nullptr, aFileSystem) + : FileSystemDirectoryEntry(aGlobal, nullptr, nullptr, aFileSystem) , mEntries(aEntries) { MOZ_ASSERT(aGlobal); @@ -45,11 +45,10 @@ FileSystemRootDirectoryEntry::GetFullPath(nsAString& aPath, ErrorResult& aRv) co } already_AddRefed -FileSystemRootDirectoryEntry::CreateReader() const +FileSystemRootDirectoryEntry::CreateReader() { RefPtr reader = - new FileSystemRootDirectoryReader(GetParentObject(), Filesystem(), - mEntries); + new FileSystemRootDirectoryReader(this, Filesystem(), mEntries); return reader.forget(); } @@ -58,7 +57,7 @@ FileSystemRootDirectoryEntry::GetInternal(const nsAString& aPath, const FileSystemFlags& aFlag, const Optional>& aSuccessCallback, const Optional>& aErrorCallback, - GetInternalType aType) const + GetInternalType aType) { if (!aSuccessCallback.WasPassed() && !aErrorCallback.WasPassed()) { return; diff --git a/dom/filesystem/compat/FileSystemRootDirectoryEntry.h b/dom/filesystem/compat/FileSystemRootDirectoryEntry.h index 0af6384a3e65..28c151ea2452 100644 --- a/dom/filesystem/compat/FileSystemRootDirectoryEntry.h +++ b/dom/filesystem/compat/FileSystemRootDirectoryEntry.h @@ -29,7 +29,7 @@ public: GetFullPath(nsAString& aFullPath, ErrorResult& aRv) const override; virtual already_AddRefed - CreateReader() const override; + CreateReader() override; private: ~FileSystemRootDirectoryEntry(); @@ -38,7 +38,7 @@ private: GetInternal(const nsAString& aPath, const FileSystemFlags& aFlag, const Optional>& aSuccessCallback, const Optional>& aErrorCallback, - GetInternalType aType) const override; + GetInternalType aType) override; void Error(const Optional>& aErrorCallback, diff --git a/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp b/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp index 16b3417f5364..5b4a417527de 100644 --- a/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp +++ b/dom/filesystem/compat/FileSystemRootDirectoryReader.cpp @@ -56,14 +56,14 @@ NS_IMPL_RELEASE_INHERITED(FileSystemRootDirectoryReader, NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FileSystemRootDirectoryReader) NS_INTERFACE_MAP_END_INHERITING(FileSystemDirectoryReader) -FileSystemRootDirectoryReader::FileSystemRootDirectoryReader(nsIGlobalObject* aGlobal, +FileSystemRootDirectoryReader::FileSystemRootDirectoryReader(FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem, const Sequence>& aEntries) - : FileSystemDirectoryReader(aGlobal, aFileSystem, nullptr) + : FileSystemDirectoryReader(aParentEntry, aFileSystem, nullptr) , mEntries(aEntries) , mAlreadyRead(false) { - MOZ_ASSERT(aGlobal); + MOZ_ASSERT(aParentEntry); MOZ_ASSERT(aFileSystem); } diff --git a/dom/filesystem/compat/FileSystemRootDirectoryReader.h b/dom/filesystem/compat/FileSystemRootDirectoryReader.h index 790aabd84899..54bca7726fd6 100644 --- a/dom/filesystem/compat/FileSystemRootDirectoryReader.h +++ b/dom/filesystem/compat/FileSystemRootDirectoryReader.h @@ -19,7 +19,7 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileSystemRootDirectoryReader, FileSystemDirectoryReader) - explicit FileSystemRootDirectoryReader(nsIGlobalObject* aGlobalObject, + explicit FileSystemRootDirectoryReader(FileSystemDirectoryEntry* aParentEntry, FileSystem* aFileSystem, const Sequence>& aEntries); diff --git a/dom/filesystem/compat/tests/test_basic.html b/dom/filesystem/compat/tests/test_basic.html index 50ef3bf53ea7..085878162d8e 100644 --- a/dom/filesystem/compat/tests/test_basic.html +++ b/dom/filesystem/compat/tests/test_basic.html @@ -80,6 +80,15 @@ function test_fileEntry_createWriter() { }); } +function test_fileEntry_getParent() { + fileEntry.getParent(function(entry) { + is(fileEntry.fullPath, entry.fullPath, "Top level FileEntry should return itself as parent."); + next(); + }, function() { + ok(false, "This is wrong."); + }); +} + function test_directoryEntry() { ok("name" in directoryEntry, "We have a name."); ok("fullPath" in directoryEntry, "We have a fullPath."); @@ -115,6 +124,15 @@ function test_directoryEntry_createReader() { }); } +function test_directoryEntry_getParent() { + directoryEntry.getParent(function(entry) { + is(directoryEntry.fullPath, entry.fullPath, "Top level FileEntry should return itself as parent."); + next(); + }, function() { + ok(false, "This is wrong."); + }); +} + function test_directoryEntry_getFile_securityError() { directoryEntry.getFile("foo", { create: true }, function() { @@ -159,7 +177,7 @@ function test_directoryEntry_getFile_simple() { directoryEntry.getFile("foo.txt", {}, function(e) { is(e.name, "foo.txt", "We have the right FileEntry."); - next(); + test_getParent(e, directoryEntry); }, function(e) { ok(false, "This should not happen."); }); @@ -169,7 +187,7 @@ function test_directoryEntry_getFile_deep() { directoryEntry.getFile("subdir/bar.txt", {}, function(e) { is(e.name, "bar.txt", "We have the right FileEntry."); - next(); + test_getParent(e, null); }, function(e) { ok(false, "This should not happen."); }); @@ -219,7 +237,7 @@ function test_directoryEntry_getDirectory_simple() { directoryEntry.getDirectory("subdir", {}, function(e) { is(e.name, "subdir", "We have the right DirectoryEntry."); - next(); + test_getParent(e, directoryEntry); }, function(e) { ok(false, "This should not happen."); }); @@ -229,7 +247,7 @@ function test_directoryEntry_getDirectory_deep() { directoryEntry.getDirectory("subdir/subsubdir", {}, function(e) { is(e.name, "subsubdir", "We have the right DirectoryEntry."); - next(); + test_getParent(e, directoryEntry); }, function(e) { ok(false, "This should not happen."); }); @@ -385,6 +403,18 @@ function cleanUpTestingFiles() { script.sendAsyncMessage("entries.delete"); } +function test_getParent(entry, parentEntry) { + entry.getParent(function(e) { + ok(e, "We have a parent Entry."); + if (parentEntry) { + is (e, parentEntry, "Parent entry matches"); + } + next(); + }, function(e) { + ok(false, "This should not happen."); + }); +} + var tests = [ setup_tests, populate_entries, @@ -394,9 +424,11 @@ var tests = [ test_fileEntry, test_fileEntry_file, test_fileEntry_createWriter, + test_fileEntry_getParent, test_directoryEntry, test_directoryEntry_createReader, + test_directoryEntry_getParent, test_directoryEntry_getFile_securityError, test_directoryEntry_getFile_typeMismatchError, diff --git a/dom/webidl/FileSystemEntry.webidl b/dom/webidl/FileSystemEntry.webidl index 98197174e47c..af112282d2b0 100644 --- a/dom/webidl/FileSystemEntry.webidl +++ b/dom/webidl/FileSystemEntry.webidl @@ -16,8 +16,6 @@ interface FileSystemEntry { readonly attribute FileSystem filesystem; -/** Not implemented: - * void getParent(optional FileSystemEntryCallback successCallback, - * optional ErrorCallback errorCallback); - */ + void getParent(optional FileSystemEntryCallback successCallback, + optional ErrorCallback errorCallback); };