diff --git a/dom/filesystem/CreateDirectoryTask.cpp b/dom/filesystem/CreateDirectoryTask.cpp deleted file mode 100644 index 36d0d9dd106a4..0000000000000 --- a/dom/filesystem/CreateDirectoryTask.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "CreateDirectoryTask.h" - -#include "mozilla/dom/Directory.h" -#include "mozilla/dom/FileSystemBase.h" -#include "mozilla/dom/FileSystemUtils.h" -#include "mozilla/dom/PFileSystemParams.h" -#include "mozilla/dom/Promise.h" -#include "mozilla/ipc/BackgroundParent.h" -#include "nsIFile.h" -#include "nsStringGlue.h" - -namespace mozilla { - -using namespace ipc; - -namespace dom { - -/** - * CreateDirectoryTaskChild - */ - -/* static */ already_AddRefed -CreateDirectoryTaskChild::Create(FileSystemBase* aFileSystem, - nsIFile* aTargetPath, - ErrorResult& aRv) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - MOZ_ASSERT(aFileSystem); - - RefPtr task = - new CreateDirectoryTaskChild(aFileSystem, aTargetPath); - - // aTargetPath can be null. In this case SetError will be called. - - nsCOMPtr globalObject = - do_QueryInterface(aFileSystem->GetParentObject()); - if (NS_WARN_IF(!globalObject)) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } - - task->mPromise = Promise::Create(globalObject, aRv); - if (NS_WARN_IF(aRv.Failed())) { - return nullptr; - } - - return task.forget(); -} - -CreateDirectoryTaskChild::CreateDirectoryTaskChild(FileSystemBase* aFileSystem, - nsIFile* aTargetPath) - : FileSystemTaskChildBase(aFileSystem) - , mTargetPath(aTargetPath) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - MOZ_ASSERT(aFileSystem); -} - -CreateDirectoryTaskChild::~CreateDirectoryTaskChild() -{ - MOZ_ASSERT(NS_IsMainThread()); -} - -already_AddRefed -CreateDirectoryTaskChild::GetPromise() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - return RefPtr(mPromise).forget(); -} - -FileSystemParams -CreateDirectoryTaskChild::GetRequestParams(const nsString& aSerializedDOMPath, - ErrorResult& aRv) const -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - - nsAutoString path; - aRv = mTargetPath->GetPath(path); - if (NS_WARN_IF(aRv.Failed())) { - return FileSystemCreateDirectoryParams(); - } - - return FileSystemCreateDirectoryParams(aSerializedDOMPath, path); -} - -void -CreateDirectoryTaskChild::SetSuccessRequestResult(const FileSystemResponseValue& aValue, - ErrorResult& aRv) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - - const FileSystemDirectoryResponse& r = - aValue.get_FileSystemDirectoryResponse(); - - aRv = NS_NewLocalFile(r.realPath(), true, getter_AddRefs(mTargetPath)); - NS_WARNING_ASSERTION(!aRv.Failed(), "NS_NewLocalFile failed"); -} - -void -CreateDirectoryTaskChild::HandlerCallback() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (mFileSystem->IsShutdown()) { - mPromise = nullptr; - return; - } - - if (HasError()) { - mPromise->MaybeReject(mErrorValue); - mPromise = nullptr; - return; - } - - RefPtr dir = Directory::Create(mFileSystem->GetParentObject(), - mTargetPath, mFileSystem); - MOZ_ASSERT(dir); - - mPromise->MaybeResolve(dir); - mPromise = nullptr; -} - -void -CreateDirectoryTaskChild::GetPermissionAccessType(nsCString& aAccess) const -{ - aAccess.AssignLiteral(DIRECTORY_CREATE_PERMISSION); -} - -/** - * CreateDirectoryTaskParent - */ - -/* static */ already_AddRefed -CreateDirectoryTaskParent::Create(FileSystemBase* aFileSystem, - const FileSystemCreateDirectoryParams& aParam, - FileSystemRequestParent* aParent, - ErrorResult& aRv) -{ - MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!"); - AssertIsOnBackgroundThread(); - MOZ_ASSERT(aFileSystem); - - RefPtr task = - new CreateDirectoryTaskParent(aFileSystem, aParam, aParent); - - aRv = NS_NewLocalFile(aParam.realPath(), true, - getter_AddRefs(task->mTargetPath)); - if (NS_WARN_IF(aRv.Failed())) { - return nullptr; - } - - return task.forget(); -} - -CreateDirectoryTaskParent::CreateDirectoryTaskParent(FileSystemBase* aFileSystem, - const FileSystemCreateDirectoryParams& aParam, - FileSystemRequestParent* aParent) - : FileSystemTaskParentBase(aFileSystem, aParam, aParent) -{ - MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!"); - AssertIsOnBackgroundThread(); - MOZ_ASSERT(aFileSystem); -} - -FileSystemResponseValue -CreateDirectoryTaskParent::GetSuccessRequestResult(ErrorResult& aRv) const -{ - AssertIsOnBackgroundThread(); - - nsAutoString path; - aRv = mTargetPath->GetPath(path); - if (NS_WARN_IF(aRv.Failed())) { - return FileSystemDirectoryResponse(); - } - - return FileSystemDirectoryResponse(path); -} - -nsresult -CreateDirectoryTaskParent::IOWork() -{ - MOZ_ASSERT(XRE_IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(!NS_IsMainThread(), "Only call on worker thread!"); - - if (mFileSystem->IsShutdown()) { - return NS_ERROR_FAILURE; - } - - bool fileExists; - nsresult rv = mTargetPath->Exists(&fileExists); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - if (fileExists) { - return NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR; - } - - rv = mTargetPath->Create(nsIFile::DIRECTORY_TYPE, 0770); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - - return NS_OK; -} - -void -CreateDirectoryTaskParent::GetPermissionAccessType(nsCString& aAccess) const -{ - aAccess.AssignLiteral(DIRECTORY_CREATE_PERMISSION); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/CreateDirectoryTask.h b/dom/filesystem/CreateDirectoryTask.h deleted file mode 100644 index f65d640622878..0000000000000 --- a/dom/filesystem/CreateDirectoryTask.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_CreateDirectoryTask_h -#define mozilla_dom_CreateDirectoryTask_h - -#include "mozilla/dom/FileSystemTaskBase.h" -#include "mozilla/ErrorResult.h" - -namespace mozilla { -namespace dom { - -class FileSystemCreateDirectoryParams; -class Promise; - -class CreateDirectoryTaskChild final : public FileSystemTaskChildBase -{ -public: - static already_AddRefed - Create(FileSystemBase* aFileSystem, - nsIFile* aTargetPath, - ErrorResult& aRv); - - virtual - ~CreateDirectoryTaskChild(); - - already_AddRefed - GetPromise(); - - virtual void - GetPermissionAccessType(nsCString& aAccess) const override; - - virtual void - HandlerCallback() override; - -protected: - virtual FileSystemParams - GetRequestParams(const nsString& aSerializedDOMPath, - ErrorResult& aRv) const override; - - virtual void - SetSuccessRequestResult(const FileSystemResponseValue& aValue, - ErrorResult& aRv) override; - - -private: - CreateDirectoryTaskChild(FileSystemBase* aFileSystem, - nsIFile* aTargetPath); - - RefPtr mPromise; - nsCOMPtr mTargetPath; -}; - -class CreateDirectoryTaskParent final : public FileSystemTaskParentBase -{ -public: - static already_AddRefed - Create(FileSystemBase* aFileSystem, - const FileSystemCreateDirectoryParams& aParam, - FileSystemRequestParent* aParent, - ErrorResult& aRv); - - virtual void - GetPermissionAccessType(nsCString& aAccess) const override; - -protected: - virtual nsresult - IOWork() override; - - virtual FileSystemResponseValue - GetSuccessRequestResult(ErrorResult& aRv) const override; - -private: - CreateDirectoryTaskParent(FileSystemBase* aFileSystem, - const FileSystemCreateDirectoryParams& aParam, - FileSystemRequestParent* aParent); - - nsCOMPtr mTargetPath; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_CreateDirectoryTask_h diff --git a/dom/filesystem/Directory.cpp b/dom/filesystem/Directory.cpp index 1b42ef59d6251..53e2984f49ac3 100644 --- a/dom/filesystem/Directory.cpp +++ b/dom/filesystem/Directory.cpp @@ -6,7 +6,6 @@ #include "mozilla/dom/Directory.h" -#include "CreateDirectoryTask.h" #include "FileSystemPermissionRequest.h" #include "GetDirectoryListingTask.h" #include "GetFileOrDirectoryTask.h" @@ -21,13 +20,6 @@ #include "mozilla/dom/FileSystemUtils.h" #include "mozilla/dom/OSFileSystem.h" -// Resolve the name collision of Microsoft's API name with macros defined in -// Windows header files. Undefine the macro of CreateDirectory to avoid -// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW. -#ifdef CreateDirectory -#undef CreateDirectory -#endif - namespace mozilla { namespace dom { @@ -188,31 +180,6 @@ Directory::GetName(nsAString& aRetval, ErrorResult& aRv) fs->GetDirectoryName(mFile, aRetval, aRv); } -already_AddRefed -Directory::CreateDirectory(const nsAString& aPath, ErrorResult& aRv) -{ - // Only exposed for DeviceStorage. - MOZ_ASSERT(NS_IsMainThread()); - - nsCOMPtr realPath; - nsresult error = DOMPathToRealPath(aPath, getter_AddRefs(realPath)); - - RefPtr fs = GetFileSystem(aRv); - if (NS_WARN_IF(aRv.Failed())) { - return nullptr; - } - - RefPtr task = - CreateDirectoryTaskChild::Create(fs, realPath, aRv); - if (NS_WARN_IF(aRv.Failed())) { - return nullptr; - } - - task->SetError(error); - FileSystemPermissionRequest::RequestForTask(task); - return task->GetPromise(); -} - already_AddRefed Directory::Get(const nsAString& aPath, ErrorResult& aRv) { diff --git a/dom/filesystem/Directory.h b/dom/filesystem/Directory.h index c9ab1d6fbb741..22110c751234d 100644 --- a/dom/filesystem/Directory.h +++ b/dom/filesystem/Directory.h @@ -14,13 +14,6 @@ #include "nsCycleCollectionParticipant.h" #include "nsWrapperCache.h" -// Resolve the name collision of Microsoft's API name with macros defined in -// Windows header files. Undefine the macro of CreateDirectory to avoid -// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW. -#ifdef CreateDirectory -#undef CreateDirectory -#endif - namespace mozilla { namespace dom { @@ -65,9 +58,6 @@ class Directory final void GetName(nsAString& aRetval, ErrorResult& aRv); - already_AddRefed - CreateDirectory(const nsAString& aPath, ErrorResult& aRv); - already_AddRefed Get(const nsAString& aPath, ErrorResult& aRv); diff --git a/dom/filesystem/FileSystemRequestParent.cpp b/dom/filesystem/FileSystemRequestParent.cpp index 19cd14924caa7..a58fd8648d858 100644 --- a/dom/filesystem/FileSystemRequestParent.cpp +++ b/dom/filesystem/FileSystemRequestParent.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/FileSystemRequestParent.h" -#include "CreateDirectoryTask.h" #include "GetDirectoryListingTask.h" #include "GetFileOrDirectoryTask.h" #include "RemoveTask.h" @@ -48,7 +47,6 @@ FileSystemRequestParent::Initialize(const FileSystemParams& aParams) switch (aParams.type()) { - FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory) FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetDirectoryListing) FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory) FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFiles) diff --git a/dom/filesystem/PFileSystemParams.ipdlh b/dom/filesystem/PFileSystemParams.ipdlh index 18bcbb7db8704..4307e33082b7e 100644 --- a/dom/filesystem/PFileSystemParams.ipdlh +++ b/dom/filesystem/PFileSystemParams.ipdlh @@ -7,12 +7,6 @@ include protocol PBlob; namespace mozilla { namespace dom { -struct FileSystemCreateDirectoryParams -{ - nsString filesystem; - nsString realPath; -}; - union FileSystemFileDataValue { uint8_t[]; @@ -61,7 +55,6 @@ struct FileSystemRemoveParams union FileSystemParams { - FileSystemCreateDirectoryParams; FileSystemGetDirectoryListingParams; FileSystemGetFilesParams; FileSystemGetFileOrDirectoryParams; diff --git a/dom/webidl/Directory.webidl b/dom/webidl/Directory.webidl index 5a676160f59e3..6cb86da04e248 100644 --- a/dom/webidl/Directory.webidl +++ b/dom/webidl/Directory.webidl @@ -26,18 +26,6 @@ interface Directory { [Throws] readonly attribute DOMString name; - /* - * Creates a descendent directory. This method will create any intermediate - * directories specified by the path segments. - * - * @param path The relative path of the new directory to current directory. - * If path exists, createDirectory must fail. - * @return If succeeds, the promise is resolved with the new created - * Directory object. Otherwise, rejected with a DOM error. - */ - [Func="mozilla::dom::Directory::DeviceStorageEnabled", NewObject] - Promise createDirectory(DOMString path); - /* * Gets a descendent file or directory with the given path. *