From 5099e8a290de8a23a0a8ea34ac2efd145b591787 Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Tue, 11 Mar 2014 12:17:03 -0400 Subject: [PATCH] Backed out 5 changesets (bug 910412) for intermittent crash whack-a-mole. Backed out changeset e3eb9463b3e1 (bug 910412) Backed out changeset d5863d302bde (bug 910412) Backed out changeset 422b66d4b1ca (bug 910412) Backed out changeset 3431d59d752e (bug 910412) Backed out changeset b1c0310cdac1 (bug 910412) --- dom/base/domerr.msg | 8 - dom/devicestorage/DeviceStorage.h | 9 - dom/devicestorage/nsDeviceStorage.cpp | 48 +- dom/devicestorage/test/chrome.ini | 1 - dom/devicestorage/test/mochitest.ini | 5 - .../test/test_fs_app_permissions.html | 428 ------------------ dom/devicestorage/test/test_fs_basic.html | 70 --- .../test/test_fs_createDirectory.html | 105 ----- dom/devicestorage/test/test_fs_get.html | 183 -------- dom/filesystem/CreateDirectoryTask.cpp | 146 ------ dom/filesystem/CreateDirectoryTask.h | 67 --- dom/filesystem/DeviceStorageFileSystem.cpp | 137 ------ dom/filesystem/DeviceStorageFileSystem.h | 59 --- dom/filesystem/Directory.cpp | 184 -------- dom/filesystem/Directory.h | 82 ---- dom/filesystem/FileSystemBase.cpp | 67 --- dom/filesystem/FileSystemBase.h | 92 ---- .../FileSystemPermissionRequest.cpp | 190 -------- dom/filesystem/FileSystemPermissionRequest.h | 61 --- dom/filesystem/FileSystemRequestParent.cpp | 79 ---- dom/filesystem/FileSystemRequestParent.h | 44 -- dom/filesystem/FileSystemTaskBase.cpp | 208 --------- dom/filesystem/FileSystemTaskBase.h | 239 ---------- dom/filesystem/FileSystemUtils.cpp | 76 ---- dom/filesystem/FileSystemUtils.h | 53 --- dom/filesystem/GetFileOrDirectoryTask.cpp | 226 --------- dom/filesystem/GetFileOrDirectoryTask.h | 71 --- dom/filesystem/PFileSystemRequest.ipdl | 44 -- dom/filesystem/moz.build | 39 -- dom/ipc/ContentChild.cpp | 20 - dom/ipc/ContentChild.h | 3 - dom/ipc/ContentParent.cpp | 19 - dom/ipc/ContentParent.h | 6 - dom/ipc/PContent.ipdl | 22 - dom/ipc/moz.build | 1 - dom/moz.build | 1 - dom/promise/Promise.h | 16 - dom/webidl/DeviceStorage.webidl | 3 - dom/webidl/Directory.webidl | 49 -- dom/webidl/moz.build | 1 - layout/build/moz.build | 1 - xpcom/base/ErrorList.h | 12 - xpcom/base/nsError.h | 1 - 43 files changed, 25 insertions(+), 3151 deletions(-) delete mode 100644 dom/devicestorage/test/test_fs_app_permissions.html delete mode 100644 dom/devicestorage/test/test_fs_basic.html delete mode 100644 dom/devicestorage/test/test_fs_createDirectory.html delete mode 100644 dom/devicestorage/test/test_fs_get.html delete mode 100644 dom/filesystem/CreateDirectoryTask.cpp delete mode 100644 dom/filesystem/CreateDirectoryTask.h delete mode 100644 dom/filesystem/DeviceStorageFileSystem.cpp delete mode 100644 dom/filesystem/DeviceStorageFileSystem.h delete mode 100644 dom/filesystem/Directory.cpp delete mode 100644 dom/filesystem/Directory.h delete mode 100644 dom/filesystem/FileSystemBase.cpp delete mode 100644 dom/filesystem/FileSystemBase.h delete mode 100644 dom/filesystem/FileSystemPermissionRequest.cpp delete mode 100644 dom/filesystem/FileSystemPermissionRequest.h delete mode 100644 dom/filesystem/FileSystemRequestParent.cpp delete mode 100644 dom/filesystem/FileSystemRequestParent.h delete mode 100644 dom/filesystem/FileSystemTaskBase.cpp delete mode 100644 dom/filesystem/FileSystemTaskBase.h delete mode 100644 dom/filesystem/FileSystemUtils.cpp delete mode 100644 dom/filesystem/FileSystemUtils.h delete mode 100644 dom/filesystem/GetFileOrDirectoryTask.cpp delete mode 100644 dom/filesystem/GetFileOrDirectoryTask.h delete mode 100644 dom/filesystem/PFileSystemRequest.ipdl delete mode 100644 dom/filesystem/moz.build delete mode 100644 dom/webidl/Directory.webidl diff --git a/dom/base/domerr.msg b/dom/base/domerr.msg index 6cdbabd6c33..e10a29245cf 100644 --- a/dom/base/domerr.msg +++ b/dom/base/domerr.msg @@ -69,14 +69,6 @@ DOM4_MSG_DEF(QuotaExceededError, "The current transaction exceeded its quota lim DOM_MSG_DEF(NS_ERROR_DOM_INDEXEDDB_RECOVERABLE_ERR, "The operation failed because the database was prevented from taking an action. The operation might be able to succeed if the application performs some recovery steps and retries the entire transaction. For example, there was not enough remaining storage space, or the storage quota was reached and the user declined to give more space to the database.") -/* FileSystem DOM errors. */ -DOM4_MSG_DEF(InvalidAccessError, "Invalid file system path.", NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR) -DOM4_MSG_DEF(InvalidModificationError, "Failed to modify the file.", NS_ERROR_DOM_FILESYSTEM_INVALID_MODIFICATION_ERR) -DOM4_MSG_DEF(NoModificationAllowedError, "Modifications are not allowed for this file", NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR) -DOM4_MSG_DEF(AbortError, "File already exists.", NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR) -DOM4_MSG_DEF(TypeMismatchError, "The type of the file is incompatible with the expected type.", NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR) -DOM4_MSG_DEF(UnknownError, "The operation failed for reasons unrelated to the file system itself and not covered by any other error code.", NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR) - /* DOM error codes defined by us */ /* XXX string should be specified by norris */ diff --git a/dom/devicestorage/DeviceStorage.h b/dom/devicestorage/DeviceStorage.h index 566a8d587bf..606d1613851 100644 --- a/dom/devicestorage/DeviceStorage.h +++ b/dom/devicestorage/DeviceStorage.h @@ -31,8 +31,6 @@ namespace dom { class DeviceStorageEnumerationParameters; class DOMCursor; class DOMRequest; -class Promise; -class DeviceStorageFileSystem; } // namespace dom namespace ipc { class FileDescriptor; @@ -159,8 +157,6 @@ class nsDOMDeviceStorage MOZ_FINAL EnumerationParameters; typedef mozilla::dom::DOMCursor DOMCursor; typedef mozilla::dom::DOMRequest DOMRequest; - typedef mozilla::dom::Promise Promise; - typedef mozilla::dom::DeviceStorageFileSystem DeviceStorageFileSystem; public: typedef nsTArray VolumeNameArray; @@ -259,9 +255,6 @@ public: // Uses XPCOM GetStorageName - already_AddRefed - GetRoot(); - static void CreateDeviceStorageFor(nsPIDOMWindow* aWin, const nsAString& aType, @@ -339,8 +332,6 @@ private: DEVICE_STORAGE_TYPE_SHARED, DEVICE_STORAGE_TYPE_EXTERNAL }; - - nsRefPtr mFileSystem; }; #endif diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index e17bef714fa..ad32123fa41 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -11,15 +11,11 @@ #include "mozilla/DebugOnly.h" #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/DeviceStorageBinding.h" -#include "mozilla/dom/DeviceStorageFileSystem.h" #include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h" -#include "mozilla/dom/Directory.h" -#include "mozilla/dom/FileSystemUtils.h" #include "mozilla/dom/ipc/Blob.h" #include "mozilla/dom/PBrowserChild.h" #include "mozilla/dom/PContentPermissionRequestChild.h" #include "mozilla/dom/PermissionMessageUtils.h" -#include "mozilla/dom/Promise.h" #include "mozilla/LazyIdleThread.h" #include "mozilla/Preferences.h" #include "mozilla/Scoped.h" @@ -895,7 +891,14 @@ DeviceStorageFile::IsSafePath(const nsAString& aPath) void DeviceStorageFile::NormalizeFilePath() { - FileSystemUtils::LocalPathToNormalizedPath(mPath, mPath); +#if defined(XP_WIN) + char16_t* cur = mPath.BeginWriting(); + char16_t* end = mPath.EndWriting(); + for (; cur < end; ++cur) { + if (char16_t('\\') == *cur) + *cur = char16_t('/'); + } +#endif } void @@ -913,9 +916,23 @@ DeviceStorageFile::AppendRelativePath(const nsAString& aPath) { NS_WARNING(NS_LossyConvertUTF16toASCII(aPath).get()); return; } - nsString localPath; - FileSystemUtils::NormalizedPathToLocalPath(aPath, localPath); - mFile->AppendRelativePath(localPath); +#if defined(XP_WIN) + // replace forward slashes with backslashes, + // since nsLocalFileWin chokes on them + nsString temp; + temp.Assign(aPath); + + char16_t* cur = temp.BeginWriting(); + char16_t* end = temp.EndWriting(); + + for (; cur < end; ++cur) { + if (char16_t('/') == *cur) + *cur = char16_t('\\'); + } + mFile->AppendRelativePath(temp); +#else + mFile->AppendRelativePath(aPath); +#endif } nsresult @@ -3056,11 +3073,6 @@ nsDOMDeviceStorage::Shutdown() { MOZ_ASSERT(NS_IsMainThread()); - if (mFileSystem) { - mFileSystem->SetDeviceStorage(nullptr); - mFileSystem = nullptr; - } - if (!mStorageName.IsEmpty()) { UnregisterForSDCardChanges(this); } @@ -3799,16 +3811,6 @@ nsDOMDeviceStorage::Default() return mStorageName.Equals(defaultStorageName); } -already_AddRefed -nsDOMDeviceStorage::GetRoot() -{ - if (!mFileSystem) { - mFileSystem = new DeviceStorageFileSystem(mStorageType, mStorageName); - mFileSystem->SetDeviceStorage(this); - } - return mozilla::dom::Directory::GetRoot(mFileSystem); -} - NS_IMETHODIMP nsDOMDeviceStorage::GetDefault(bool* aDefault) { diff --git a/dom/devicestorage/test/chrome.ini b/dom/devicestorage/test/chrome.ini index 568a23ac75b..e1799879a86 100644 --- a/dom/devicestorage/test/chrome.ini +++ b/dom/devicestorage/test/chrome.ini @@ -1,4 +1,3 @@ [DEFAULT] [test_app_permissions.html] -[test_fs_app_permissions.html] diff --git a/dom/devicestorage/test/mochitest.ini b/dom/devicestorage/test/mochitest.ini index 1e917c5eace..69cc9b6e85e 100644 --- a/dom/devicestorage/test/mochitest.ini +++ b/dom/devicestorage/test/mochitest.ini @@ -21,8 +21,3 @@ support-files = devicestorage_common.js [test_usedSpace.html] [test_watch.html] [test_watchOther.html] - -# FileSystem API tests -[test_fs_basic.html] -[test_fs_createDirectory.html] -[test_fs_get.html] diff --git a/dom/devicestorage/test/test_fs_app_permissions.html b/dom/devicestorage/test/test_fs_app_permissions.html deleted file mode 100644 index 94486c53d4a..00000000000 --- a/dom/devicestorage/test/test_fs_app_permissions.html +++ /dev/null @@ -1,428 +0,0 @@ - - - - - - Permission test of FileSystem API for Device Storage - - - - -Mozilla Bug 910412 -

-
- -
-
-
-
- - diff --git a/dom/devicestorage/test/test_fs_basic.html b/dom/devicestorage/test/test_fs_basic.html deleted file mode 100644 index 22c5a943ab8..00000000000 --- a/dom/devicestorage/test/test_fs_basic.html +++ /dev/null @@ -1,70 +0,0 @@ - - - - - Test for the FileSystem API for device storage - - - - - - -Mozilla Bug 910412 -

- -
-
-
- - - diff --git a/dom/devicestorage/test/test_fs_createDirectory.html b/dom/devicestorage/test/test_fs_createDirectory.html deleted file mode 100644 index 59d65917806..00000000000 --- a/dom/devicestorage/test/test_fs_createDirectory.html +++ /dev/null @@ -1,105 +0,0 @@ - - - - - Test createDirectory of the FileSystem API for device storage - - - - - - -Mozilla Bug 910412 -

- -
-
-
- - - diff --git a/dom/devicestorage/test/test_fs_get.html b/dom/devicestorage/test/test_fs_get.html deleted file mode 100644 index 6db5abefb08..00000000000 --- a/dom/devicestorage/test/test_fs_get.html +++ /dev/null @@ -1,183 +0,0 @@ - - - - - Test Directory#get of the FileSystem API for device storage - - - - - - -Mozilla Bug 910412 -

- -
-
-
- - - diff --git a/dom/filesystem/CreateDirectoryTask.cpp b/dom/filesystem/CreateDirectoryTask.cpp deleted file mode 100644 index c02ded2cda9..00000000000 --- a/dom/filesystem/CreateDirectoryTask.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 "DOMError.h" -#include "mozilla/dom/Directory.h" -#include "mozilla/dom/FileSystemBase.h" -#include "mozilla/dom/FileSystemUtils.h" -#include "mozilla/dom/Promise.h" -#include "nsIFile.h" -#include "nsStringGlue.h" - -namespace mozilla { -namespace dom { - -CreateDirectoryTask::CreateDirectoryTask(FileSystemBase* aFileSystem, - const nsAString& aPath) - : FileSystemTaskBase(aFileSystem) - , mTargetRealPath(aPath) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (!aFileSystem) { - return; - } - nsCOMPtr globalObject = - do_QueryInterface(aFileSystem->GetWindow()); - if (!globalObject) { - return; - } - mPromise = new Promise(globalObject); -} - -CreateDirectoryTask::CreateDirectoryTask( - FileSystemBase* aFileSystem, - const FileSystemCreateDirectoryParams& aParam, - FileSystemRequestParent* aParent) - : FileSystemTaskBase(aFileSystem, aParam, aParent) -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - mTargetRealPath = aParam.realPath(); -} - -CreateDirectoryTask::~CreateDirectoryTask() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); -} - -already_AddRefed -CreateDirectoryTask::GetPromise() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - return nsRefPtr(mPromise).forget(); -} - -FileSystemParams -CreateDirectoryTask::GetRequestParams(const nsString& aFileSystem) const -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - return FileSystemCreateDirectoryParams(aFileSystem, mTargetRealPath); -} - -FileSystemResponseValue -CreateDirectoryTask::GetSuccessRequestResult() const -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - return FileSystemDirectoryResponse(mTargetRealPath); -} - -void -CreateDirectoryTask::SetSuccessRequestResult(const FileSystemResponseValue& aValue) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - FileSystemDirectoryResponse r = aValue; - mTargetRealPath = r.realPath(); -} - -void -CreateDirectoryTask::Work() -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(!NS_IsMainThread(), "Only call on worker thread!"); - - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - if (!filesystem) { - return; - } - - nsCOMPtr file = filesystem->GetLocalFile(mTargetRealPath); - if (!file) { - SetError(NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR); - return; - } - - bool ret; - nsresult rv = file->Exists(&ret); - if (NS_FAILED(rv)) { - SetError(rv); - return; - } - - if (ret) { - SetError(NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR); - return; - } - - rv = file->Create(nsIFile::DIRECTORY_TYPE, 0777); - if (NS_FAILED(rv)) { - SetError(rv); - return; - } -} - -void -CreateDirectoryTask::HandlerCallback() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - if (!filesystem) { - return; - } - - if (HasError()) { - nsRefPtr domError = new DOMError(filesystem->GetWindow(), - mErrorValue); - mPromise->MaybeReject(domError); - return; - } - nsRefPtr dir = new Directory(filesystem, mTargetRealPath); - mPromise->MaybeResolve(dir); -} - -void -CreateDirectoryTask::GetPermissionAccessType(nsCString& aAccess) const -{ - aAccess.AssignLiteral("create"); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/CreateDirectoryTask.h b/dom/filesystem/CreateDirectoryTask.h deleted file mode 100644 index 9e26a4d7b53..00000000000 --- a/dom/filesystem/CreateDirectoryTask.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 "nsAutoPtr.h" - -class nsCString; -class nsString; - -namespace mozilla { -namespace dom { - -class Directory; -class FileSystemBase; -class FileSystemCreateDirectoryParams; -class Promise; - -class CreateDirectoryTask MOZ_FINAL - : public FileSystemTaskBase -{ -public: - CreateDirectoryTask(FileSystemBase* aFileSystem, - const nsAString& aPath); - CreateDirectoryTask(FileSystemBase* aFileSystem, - const FileSystemCreateDirectoryParams& aParam, - FileSystemRequestParent* aParent); - - virtual - ~CreateDirectoryTask(); - - already_AddRefed - GetPromise(); - - virtual void - GetPermissionAccessType(nsCString& aAccess) const MOZ_OVERRIDE; - -protected: - virtual FileSystemParams - GetRequestParams(const nsString& aFileSystem) const MOZ_OVERRIDE; - - virtual FileSystemResponseValue - GetSuccessRequestResult() const MOZ_OVERRIDE; - - virtual void - SetSuccessRequestResult(const FileSystemResponseValue& aValue) MOZ_OVERRIDE; - - virtual void - Work() MOZ_OVERRIDE; - - virtual void - HandlerCallback() MOZ_OVERRIDE; - -private: - nsRefPtr mPromise; - nsString mTargetRealPath; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_CreateDirectoryTask_h diff --git a/dom/filesystem/DeviceStorageFileSystem.cpp b/dom/filesystem/DeviceStorageFileSystem.cpp deleted file mode 100644 index 7973832f0fb..00000000000 --- a/dom/filesystem/DeviceStorageFileSystem.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 "mozilla/dom/DeviceStorageFileSystem.h" - -#include "DeviceStorage.h" -#include "mozilla/Preferences.h" -#include "mozilla/dom/Directory.h" -#include "mozilla/dom/FileSystemUtils.h" -#include "nsCOMPtr.h" -#include "nsDebug.h" -#include "nsDeviceStorage.h" -#include "nsIFile.h" -#include "nsPIDOMWindow.h" - -namespace mozilla { -namespace dom { - -DeviceStorageFileSystem::DeviceStorageFileSystem( - const nsAString& aStorageType, - const nsAString& aStorageName) - : mDeviceStorage(nullptr) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - - mStorageType = aStorageType; - mStorageName = aStorageName; - - // Generate the string representation of the file system. - mString.AppendLiteral("devicestorage-"); - mString.Append(mStorageType); - mString.AppendLiteral("-"); - mString.Append(mStorageName); - - mIsTesting = - mozilla::Preferences::GetBool("device.storage.prompt.testing", false); - - // Get the permission name required to access the file system. - nsresult rv = - DeviceStorageTypeChecker::GetPermissionForType(mStorageType, mPermission); - NS_WARN_IF(NS_FAILED(rv)); - - // Get the local path of the file system root. - // Since the child process is not allowed to access the file system, we only - // do this from the parent process. - if (!FileSystemUtils::IsParentProcess()) { - return; - } - nsCOMPtr rootFile; - DeviceStorageFile::GetRootDirectoryForType(aStorageType, - aStorageName, - getter_AddRefs(rootFile)); - - NS_WARN_IF(!rootFile || NS_FAILED(rootFile->GetPath(mLocalRootPath))); - FileSystemUtils::LocalPathToNormalizedPath(mLocalRootPath, - mNormalizedLocalRootPath); - - // DeviceStorageTypeChecker is a singleton object and must be initialized on - // the main thread. We initialize it here so that we can use it on the worker - // thread. - DebugOnly typeChecker - = DeviceStorageTypeChecker::CreateOrGet(); - MOZ_ASSERT(typeChecker); -} - -DeviceStorageFileSystem::~DeviceStorageFileSystem() -{ -} - -void -DeviceStorageFileSystem::SetDeviceStorage(nsDOMDeviceStorage* aDeviceStorage) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - mDeviceStorage = aDeviceStorage; -} - -nsPIDOMWindow* -DeviceStorageFileSystem::GetWindow() const -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (!mDeviceStorage) { - return nullptr; - } - return mDeviceStorage->GetOwner(); -} - -already_AddRefed -DeviceStorageFileSystem::GetLocalFile(const nsAString& aRealPath) const -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Should be on parent process!"); - nsAutoString localPath; - FileSystemUtils::NormalizedPathToLocalPath(aRealPath, localPath); - localPath = mLocalRootPath + localPath; - nsCOMPtr file; - nsresult rv = NS_NewLocalFile(localPath, false, getter_AddRefs(file)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - return file.forget(); -} - -const nsAString& -DeviceStorageFileSystem::GetRootName() const -{ - return mStorageName; -} - -bool -DeviceStorageFileSystem::IsSafeFile(nsIFile* aFile) const -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Should be on parent process!"); - MOZ_ASSERT(aFile); - - // Check if this file belongs to this storage. - nsAutoString path; - if (NS_FAILED(aFile->GetPath(path))) { - return false; - } - FileSystemUtils::LocalPathToNormalizedPath(path, path); - if (!FileSystemUtils::IsDescendantPath(mNormalizedLocalRootPath, path)) { - return false; - } - - // Check if the file type is compatible with the storage type. - DeviceStorageTypeChecker* typeChecker - = DeviceStorageTypeChecker::CreateOrGet(); - MOZ_ASSERT(typeChecker); - return typeChecker->Check(mStorageType, aFile); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/DeviceStorageFileSystem.h b/dom/filesystem/DeviceStorageFileSystem.h deleted file mode 100644 index 285945b714e..00000000000 --- a/dom/filesystem/DeviceStorageFileSystem.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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_DeviceStorageFileSystem_h -#define mozilla_dom_DeviceStorageFileSystem_h - -#include "mozilla/dom/FileSystemBase.h" -#include "nsString.h" - -class nsDOMDeviceStorage; - -namespace mozilla { -namespace dom { - -class DeviceStorageFileSystem - : public FileSystemBase -{ -public: - DeviceStorageFileSystem(const nsAString& aStorageType, - const nsAString& aStorageName); - - void - SetDeviceStorage(nsDOMDeviceStorage* aDeviceStorage); - - // Overrides FileSystemBase - - virtual nsPIDOMWindow* - GetWindow() const MOZ_OVERRIDE; - - virtual already_AddRefed - GetLocalFile(const nsAString& aRealPath) const MOZ_OVERRIDE; - - virtual const nsAString& - GetRootName() const MOZ_OVERRIDE; - - virtual bool - IsSafeFile(nsIFile* aFile) const MOZ_OVERRIDE; - -private: - virtual - ~DeviceStorageFileSystem(); - - nsString mStorageType; - nsString mStorageName; - - // The local path of the root. Only available in the parent process. - // In the child process, we don't use it and its value should be empty. - nsString mLocalRootPath; - nsString mNormalizedLocalRootPath; - nsDOMDeviceStorage* mDeviceStorage; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_DeviceStorageFileSystem_h diff --git a/dom/filesystem/Directory.cpp b/dom/filesystem/Directory.cpp deleted file mode 100644 index 0540b1b2de2..00000000000 --- a/dom/filesystem/Directory.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=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 "mozilla/dom/Directory.h" - -#include "CreateDirectoryTask.h" -#include "FileSystemPermissionRequest.h" -#include "GetFileOrDirectoryTask.h" - -#include "nsCharSeparatedTokenizer.h" -#include "nsStringGlue.h" -#include "mozilla/dom/DirectoryBinding.h" -#include "mozilla/dom/FileSystemBase.h" -#include "mozilla/dom/FileSystemUtils.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 { - -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Directory) -NS_IMPL_CYCLE_COLLECTING_ADDREF(Directory) -NS_IMPL_CYCLE_COLLECTING_RELEASE(Directory) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Directory) - NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -// static -already_AddRefed -Directory::GetRoot(FileSystemBase* aFileSystem) -{ - nsRefPtr task = new GetFileOrDirectoryTask( - aFileSystem, EmptyString(), true); - FileSystemPermissionRequest::RequestForTask(task); - return task->GetPromise(); -} - -Directory::Directory(FileSystemBase* aFileSystem, - const nsAString& aPath) - : mPath(aPath) -{ - MOZ_ASSERT(aFileSystem, "aFileSystem should not be null."); - mFileSystem = do_GetWeakReference(aFileSystem); - // Remove the trailing "/". - mPath.Trim(FILESYSTEM_DOM_PATH_SEPARATOR, false, true); - - SetIsDOMBinding(); -} - -Directory::~Directory() -{ -} - -nsPIDOMWindow* -Directory::GetParentObject() const -{ - nsRefPtr fs = do_QueryReferent(mFileSystem); - if (!fs) { - return nullptr; - } - return fs->GetWindow(); -} - -JSObject* -Directory::WrapObject(JSContext* aCx, JS::Handle aScope) -{ - return DirectoryBinding::Wrap(aCx, aScope, this); -} - -void -Directory::GetName(nsString& aRetval) const -{ - aRetval.Truncate(); - - nsRefPtr fs = do_QueryReferent(mFileSystem); - if (mPath.IsEmpty() && fs) { - aRetval = fs->GetRootName(); - return; - } - - aRetval = Substring(mPath, - mPath.RFindChar(FileSystemUtils::kSeparatorChar) + 1); -} - -already_AddRefed -Directory::CreateDirectory(const nsAString& aPath) -{ - nsresult error = NS_OK; - nsString realPath; - if (!DOMPathToRealPath(aPath, realPath)) { - error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR; - } - nsRefPtr fs = do_QueryReferent(mFileSystem); - nsRefPtr task = new CreateDirectoryTask( - fs, realPath); - task->SetError(error); - FileSystemPermissionRequest::RequestForTask(task); - return task->GetPromise(); -} - -already_AddRefed -Directory::Get(const nsAString& aPath) -{ - nsresult error = NS_OK; - nsString realPath; - if (!DOMPathToRealPath(aPath, realPath)) { - error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR; - } - nsRefPtr fs = do_QueryReferent(mFileSystem); - nsRefPtr task = new GetFileOrDirectoryTask( - fs, realPath, false); - task->SetError(error); - FileSystemPermissionRequest::RequestForTask(task); - return task->GetPromise(); -} - -bool -Directory::DOMPathToRealPath(const nsAString& aPath, nsAString& aRealPath) const -{ - aRealPath.Truncate(); - - nsString relativePath; - relativePath = aPath; - - // Trim white spaces. - static const char kWhitespace[] = "\b\t\r\n "; - relativePath.Trim(kWhitespace); - - if (!IsValidRelativePath(relativePath)) { - return false; - } - - aRealPath = mPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR) + - relativePath; - - return true; -} - -// static -bool -Directory::IsValidRelativePath(const nsString& aPath) -{ - // We don't allow empty relative path to access the root. - if (aPath.IsEmpty()) { - return false; - } - - // Leading and trailing "/" are not allowed. - if (aPath.First() == FileSystemUtils::kSeparatorChar || - aPath.Last() == FileSystemUtils::kSeparatorChar) { - return false; - } - - NS_NAMED_LITERAL_STRING(kCurrentDir, "."); - NS_NAMED_LITERAL_STRING(kParentDir, ".."); - - // Split path and check each path component. - nsCharSeparatedTokenizer tokenizer(aPath, FileSystemUtils::kSeparatorChar); - while (tokenizer.hasMoreTokens()) { - nsDependentSubstring pathComponent = tokenizer.nextToken(); - // The path containing empty components, such as "foo//bar", is invalid. - // We don't allow paths, such as "../foo", "foo/./bar" and "foo/../bar", - // to walk up the directory. - if (pathComponent.IsEmpty() || - pathComponent.Equals(kCurrentDir) || - pathComponent.Equals(kParentDir)) { - return false; - } - } - - return true; -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/Directory.h b/dom/filesystem/Directory.h deleted file mode 100644 index a98fe5ab3f6..00000000000 --- a/dom/filesystem/Directory.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=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_Directory_h -#define mozilla_dom_Directory_h - -#include "mozilla/Attributes.h" -#include "mozilla/dom/BindingDeclarations.h" -#include "nsAutoPtr.h" -#include "nsCycleCollectionParticipant.h" -#include "nsPIDOMWindow.h" -#include "nsWeakReference.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 { - -class FileSystemBase; -class Promise; - -class Directory MOZ_FINAL - : public nsISupports - , public nsWrapperCache -{ -public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory) - -public: - static already_AddRefed - GetRoot(FileSystemBase* aFileSystem); - - Directory(FileSystemBase* aFileSystem, const nsAString& aPath); - ~Directory(); - - // ========= Begin WebIDL bindings. =========== - - nsPIDOMWindow* - GetParentObject() const; - - virtual JSObject* - WrapObject(JSContext* aCx, JS::Handle aScope) MOZ_OVERRIDE; - - void - GetName(nsString& aRetval) const; - - already_AddRefed - CreateDirectory(const nsAString& aPath); - - already_AddRefed - Get(const nsAString& aPath); - - // =========== End WebIDL bindings.============ -private: - static bool - IsValidRelativePath(const nsString& aPath); - - /* - * Convert relative DOM path to the absolute real path. - * @return true if succeed. false if the DOM path is invalid. - */ - bool - DOMPathToRealPath(const nsAString& aPath, nsAString& aRealPath) const; - - nsWeakPtr mFileSystem; - nsString mPath; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_Directory_h diff --git a/dom/filesystem/FileSystemBase.cpp b/dom/filesystem/FileSystemBase.cpp deleted file mode 100644 index ca5eecd6129..00000000000 --- a/dom/filesystem/FileSystemBase.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=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 "mozilla/dom/FileSystemBase.h" - -#include "DeviceStorageFileSystem.h" -#include "nsCharSeparatedTokenizer.h" - -namespace mozilla { -namespace dom { - -NS_IMPL_ISUPPORTS1(FileSystemBase, nsISupportsWeakReference) - -// static -already_AddRefed -FileSystemBase::FromString(const nsAString& aString) -{ - if (StringBeginsWith(aString, NS_LITERAL_STRING("devicestorage-"))) { - // The string representation of devicestorage file system is of the format: - // devicestorage-StorageType-StorageName - - nsCharSeparatedTokenizer tokenizer(aString, char16_t('-')); - tokenizer.nextToken(); - - nsString storageType; - if (tokenizer.hasMoreTokens()) { - storageType = tokenizer.nextToken(); - } - - nsString storageName; - if (tokenizer.hasMoreTokens()) { - storageName = tokenizer.nextToken(); - } - - nsCOMPtr f = - new DeviceStorageFileSystem(storageType, storageName); - return f.forget(); - } - return nullptr; -} - -FileSystemBase::FileSystemBase() - : mIsTesting(false) -{ -} - -FileSystemBase::~FileSystemBase() -{ -} - -nsPIDOMWindow* -FileSystemBase::GetWindow() const -{ - return nullptr; -} - -bool -FileSystemBase::IsSafeFile(nsIFile* aFile) const -{ - return true; -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/FileSystemBase.h b/dom/filesystem/FileSystemBase.h deleted file mode 100644 index 56a1195f44b..00000000000 --- a/dom/filesystem/FileSystemBase.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=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_FileSystemBase_h -#define mozilla_dom_FileSystemBase_h - -#include "nsWeakReference.h" -#include "nsAutoPtr.h" -#include "nsString.h" - -class nsPIDOMWindow; // You need |#include "nsPIDOMWindow.h"| in CPP files. - -namespace mozilla { -namespace dom { - -/* - * To make FileSystemBase as a weak reference, so that before the child window - * is closed and the FileSystemBase is destroyed, we don't need to notify the - * FileSystemTaskBase instances, which hold the FileSystemBase reference, to - * cancel and wait until the instances finish. - */ -class FileSystemBase - : public nsSupportsWeakReference -{ - NS_DECL_THREADSAFE_ISUPPORTS -public: - - // Create file system object from its string representation. - static already_AddRefed - FromString(const nsAString& aString); - - FileSystemBase(); - - // Get the string representation of the file system. - const nsString& - ToString() const - { - return mString; - } - - virtual nsPIDOMWindow* - GetWindow() const; - - /* - * Create nsIFile object with the given real path (absolute DOM path). - */ - virtual already_AddRefed - GetLocalFile(const nsAString& aRealPath) const = 0; - - /* - * Get the virtual name of the root directory. This name will be exposed to - * the content page. - */ - virtual const nsAString& - GetRootName() const = 0; - - virtual bool - IsSafeFile(nsIFile* aFile) const; - - /* - * Get the permission name required to access this file system. - */ - const nsCString& - GetPermission() const - { - return mPermission; - } - - bool - IsTesting() const - { - return mIsTesting; - } -protected: - virtual ~FileSystemBase(); - - // The string representation of the file system. - nsString mString; - - // The permission name required to access the file system. - nsCString mPermission; - - bool mIsTesting; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_FileSystemBase_h diff --git a/dom/filesystem/FileSystemPermissionRequest.cpp b/dom/filesystem/FileSystemPermissionRequest.cpp deleted file mode 100644 index 3da37e5fd8a..00000000000 --- a/dom/filesystem/FileSystemPermissionRequest.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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 "FileSystemPermissionRequest.h" - -#include "mozilla/dom/FileSystemBase.h" -#include "mozilla/dom/FileSystemTaskBase.h" -#include "mozilla/dom/FileSystemUtils.h" -#include "mozilla/dom/TabChild.h" -#include "nsIDocument.h" -#include "nsPIDOMWindow.h" -#include "nsString.h" - -namespace mozilla { -namespace dom { - -NS_IMPL_ISUPPORTS2(FileSystemPermissionRequest, nsIRunnable, nsIContentPermissionRequest) - -// static -void -FileSystemPermissionRequest::RequestForTask(FileSystemTaskBase* aTask) -{ - MOZ_ASSERT(aTask, "aTask should not be null!"); - MOZ_ASSERT(NS_IsMainThread()); - nsRefPtr request = - new FileSystemPermissionRequest(aTask); - NS_DispatchToCurrentThread(request); -} - -FileSystemPermissionRequest::FileSystemPermissionRequest( - FileSystemTaskBase* aTask) - : mTask(aTask) -{ - MOZ_ASSERT(mTask, "aTask should not be null!"); - MOZ_ASSERT(NS_IsMainThread()); - - mTask->GetPermissionAccessType(mPermissionAccess); - - nsRefPtr filesystem = mTask->GetFileSystem(); - if (!filesystem) { - return; - } - - mPermissionType = filesystem->GetPermission(); - - mWindow = filesystem->GetWindow(); - if (!mWindow) { - return; - } - - nsCOMPtr doc = mWindow->GetDoc(); - if (!doc) { - return; - } - - mPrincipal = doc->NodePrincipal(); -} - -FileSystemPermissionRequest::~FileSystemPermissionRequest() -{ -} - -bool -FileSystemPermissionRequest::Recv__delete__(const bool& aAllow, - const InfallibleTArray& aChoices) -{ - MOZ_ASSERT(aChoices.IsEmpty(), - "FileSystemPermissionRequest doesn't support permission choice"); - if (aAllow) { - Allow(JS::UndefinedHandleValue); - } else { - Cancel(); - } - return true; -} - -void -FileSystemPermissionRequest::IPDLRelease() -{ - Release(); -} - -NS_IMETHODIMP -FileSystemPermissionRequest::GetTypes(nsIArray** aTypes) -{ - nsTArray emptyOptions; - return CreatePermissionArray(mPermissionType, - mPermissionAccess, - emptyOptions, - aTypes); -} - -NS_IMETHODIMP -FileSystemPermissionRequest::GetPrincipal(nsIPrincipal** aRequestingPrincipal) -{ - NS_IF_ADDREF(*aRequestingPrincipal = mPrincipal); - return NS_OK; -} - -NS_IMETHODIMP -FileSystemPermissionRequest::GetWindow(nsIDOMWindow** aRequestingWindow) -{ - NS_IF_ADDREF(*aRequestingWindow = mWindow); - return NS_OK; -} - -NS_IMETHODIMP -FileSystemPermissionRequest::GetElement(nsIDOMElement** aRequestingElement) -{ - *aRequestingElement = nullptr; - return NS_OK; -} - -NS_IMETHODIMP -FileSystemPermissionRequest::Cancel() -{ - MOZ_ASSERT(NS_IsMainThread()); - mTask->SetError(NS_ERROR_DOM_SECURITY_ERR); - mTask->Start(); - return NS_OK; -} - -NS_IMETHODIMP -FileSystemPermissionRequest::Allow(JS::HandleValue aChoices) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aChoices.isUndefined()); - mTask->Start(); - return NS_OK; -} - -NS_IMETHODIMP -FileSystemPermissionRequest::Run() -{ - MOZ_ASSERT(NS_IsMainThread()); - - nsRefPtr filesystem = mTask->GetFileSystem(); - if (!filesystem) { - Cancel(); - return NS_OK; - } - - if (filesystem->IsTesting()) { - Allow(JS::UndefinedHandleValue); - return NS_OK; - } - - if (FileSystemUtils::IsParentProcess()) { - nsCOMPtr prompt - = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (!prompt || NS_FAILED(prompt->Prompt(this))) { - Cancel(); - } - return NS_OK; - } - - if (!mWindow) { - Cancel(); - return NS_OK; - } - - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild. - TabChild* child = TabChild::GetFrom(mWindow->GetDocShell()); - if (!child) { - Cancel(); - return NS_OK; - } - - // Retain a reference so the object isn't deleted without IPDL's - // knowledge. Corresponding release occurs in - // DeallocPContentPermissionRequest. - AddRef(); - - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest(mPermissionType, - mPermissionAccess, - emptyOptions)); - child->SendPContentPermissionRequestConstructor( - this, permArray, IPC::Principal(mPrincipal)); - - Sendprompt(); - return NS_OK; -} - -} /* namespace dom */ -} /* namespace mozilla */ diff --git a/dom/filesystem/FileSystemPermissionRequest.h b/dom/filesystem/FileSystemPermissionRequest.h deleted file mode 100644 index 6513e9b7d58..00000000000 --- a/dom/filesystem/FileSystemPermissionRequest.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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_FileSystemPermissionRequest_h -#define mozilla_dom_FileSystemPermissionRequest_h - -#include "PCOMContentPermissionRequestChild.h" -#include "nsAutoPtr.h" -#include "nsContentPermissionHelper.h" -#include "nsIRunnable.h" - -class nsCString; -class nsPIDOMWindow; - -namespace mozilla { -namespace dom { - -class FileSystemTaskBase; - -class FileSystemPermissionRequest MOZ_FINAL - : public nsIContentPermissionRequest - , public nsIRunnable - , public PCOMContentPermissionRequestChild -{ -public: - // Request permission for the given task. - static void - RequestForTask(FileSystemTaskBase* aTask); - - // Overrides PCOMContentPermissionRequestChild - - virtual void - IPDLRelease() MOZ_OVERRIDE; - - bool - Recv__delete__(const bool& aAllow, - const InfallibleTArray& aChoices) MOZ_OVERRIDE; - - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSICONTENTPERMISSIONREQUEST - NS_DECL_NSIRUNNABLE -private: - FileSystemPermissionRequest(FileSystemTaskBase* aTask); - - virtual - ~FileSystemPermissionRequest(); - - nsCString mPermissionType; - nsCString mPermissionAccess; - nsRefPtr mTask; - nsCOMPtr mWindow; - nsCOMPtr mPrincipal; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_FileSystemPermissionRequest_h diff --git a/dom/filesystem/FileSystemRequestParent.cpp b/dom/filesystem/FileSystemRequestParent.cpp deleted file mode 100644 index 4cb4b8f6832..00000000000 --- a/dom/filesystem/FileSystemRequestParent.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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 "mozilla/dom/FileSystemRequestParent.h" - -#include "CreateDirectoryTask.h" -#include "GetFileOrDirectoryTask.h" - -#include "mozilla/AppProcessChecker.h" -#include "mozilla/dom/FileSystemBase.h" - -namespace mozilla { -namespace dom { - -FileSystemRequestParent::FileSystemRequestParent() -{ -} - -FileSystemRequestParent::~FileSystemRequestParent() -{ -} - -bool -FileSystemRequestParent::Dispatch(ContentParent* aParent, - const FileSystemParams& aParams) -{ - MOZ_ASSERT(aParent, "aParent should not be null."); - nsRefPtr task; - switch (aParams.type()) { - - case FileSystemParams::TFileSystemCreateDirectoryParams: { - const FileSystemCreateDirectoryParams& p = aParams; - mFileSystem = FileSystemBase::FromString(p.filesystem()); - task = new CreateDirectoryTask(mFileSystem, p, this); - break; - } - - case FileSystemParams::TFileSystemGetFileOrDirectoryParams: { - const FileSystemGetFileOrDirectoryParams& p = aParams; - mFileSystem = FileSystemBase::FromString(p.filesystem()); - task = new GetFileOrDirectoryTask(mFileSystem, p, this); - break; - } - - default: { - NS_RUNTIMEABORT("not reached"); - break; - } - } - - if (NS_WARN_IF(!task || !mFileSystem)) { - // Should never reach here. - return false; - } - - if (!mFileSystem->IsTesting()) { - // Check the content process permission. - - nsCString access; - task->GetPermissionAccessType(access); - - nsAutoCString permissionName; - permissionName = mFileSystem->GetPermission(); - permissionName.AppendLiteral("-"); - permissionName.Append(access); - - if (!AssertAppProcessPermission(aParent, permissionName.get())) { - return false; - } - } - - task->Start(); - return true; -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/FileSystemRequestParent.h b/dom/filesystem/FileSystemRequestParent.h deleted file mode 100644 index eeebb925fc1..00000000000 --- a/dom/filesystem/FileSystemRequestParent.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et cindent: */ -/* 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_FileSystemRequestParent_h -#define mozilla_dom_FileSystemRequestParent_h - -#include "mozilla/dom/PFileSystemRequestParent.h" -#include "mozilla/dom/ContentChild.h" -#include "mozilla/dom/ContentParent.h" - -namespace mozilla { -namespace dom { - -class FileSystemBase; - -class FileSystemRequestParent - : public PFileSystemRequestParent -{ - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileSystemRequestParent) -public: - FileSystemRequestParent(); - - virtual - ~FileSystemRequestParent(); - - bool - IsRunning() - { - return state() == PFileSystemRequest::__Start; - } - - bool - Dispatch(ContentParent* aParent, const FileSystemParams& aParams); -private: - nsRefPtr mFileSystem; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_FileSystemRequestParent_h diff --git a/dom/filesystem/FileSystemTaskBase.cpp b/dom/filesystem/FileSystemTaskBase.cpp deleted file mode 100644 index 3824f06b8eb..00000000000 --- a/dom/filesystem/FileSystemTaskBase.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 "mozilla/dom/FileSystemTaskBase.h" - -#include "nsNetUtil.h" // Stream transport service. -#include "mozilla/dom/ContentChild.h" -#include "mozilla/dom/FileSystemBase.h" -#include "mozilla/dom/FileSystemRequestParent.h" -#include "mozilla/dom/FileSystemUtils.h" -#include "mozilla/dom/Promise.h" -#include "mozilla/dom/PContent.h" -#include "mozilla/unused.h" - -namespace mozilla { -namespace dom { - -FileSystemTaskBase::FileSystemTaskBase(FileSystemBase* aFileSystem) - : mErrorValue(NS_OK) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - MOZ_ASSERT(aFileSystem, "aFileSystem should not be null."); - mFileSystem = do_GetWeakReference(aFileSystem); -} - -FileSystemTaskBase::FileSystemTaskBase(FileSystemBase* aFileSystem, - const FileSystemParams& aParam, - FileSystemRequestParent* aParent) - : mErrorValue(NS_OK) - , mRequestParent(aParent) -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - MOZ_ASSERT(aFileSystem, "aFileSystem should not be null."); - mFileSystem = do_GetWeakReference(aFileSystem); -} - -FileSystemTaskBase::~FileSystemTaskBase() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); -} - -already_AddRefed -FileSystemTaskBase::GetFileSystem() -{ - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - return filesystem.forget(); -} - -void -FileSystemTaskBase::Start() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - - if (HasError()) { - HandlerCallback(); - return; - } - - if (FileSystemUtils::IsParentProcess()) { - // Run in parent process. - // Start worker thread. - nsCOMPtr target - = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); - NS_ASSERTION(target, "Must have stream transport service."); - target->Dispatch(this, NS_DISPATCH_NORMAL); - return; - } - - // Run in child process. - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - if (!filesystem) { - return; - } - - // Retain a reference so the task object isn't deleted without IPDL's - // knowledge. The reference will be released by - // mozilla::dom::ContentChild::DeallocPFileSystemRequestChild. - NS_ADDREF_THIS(); - ContentChild::GetSingleton()->SendPFileSystemRequestConstructor(this, - GetRequestParams(filesystem->ToString())); -} - -NS_IMETHODIMP -FileSystemTaskBase::Run() -{ - if (!NS_IsMainThread()) { - // Run worker thread tasks - Work(); - // Dispatch itself to main thread - NS_DispatchToMainThread(this); - return NS_OK; - } - - // Run main thread tasks - HandleResult(); - return NS_OK; -} - -void -FileSystemTaskBase::HandleResult() -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - if (!filesystem) { - return; - } - if (mRequestParent && mRequestParent->IsRunning()) { - unused << mRequestParent->Send__delete__(mRequestParent, - GetRequestResult()); - } else { - HandlerCallback(); - } -} - -FileSystemResponseValue -FileSystemTaskBase::GetRequestResult() const -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (HasError()) { - return FileSystemErrorResponse(mErrorValue); - } else { - return GetSuccessRequestResult(); - } -} - -void -FileSystemTaskBase::SetRequestResult(const FileSystemResponseValue& aValue) -{ - MOZ_ASSERT(!FileSystemUtils::IsParentProcess(), - "Only call from child process!"); - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (aValue.type() == FileSystemResponseValue::TFileSystemErrorResponse) { - FileSystemErrorResponse r = aValue; - mErrorValue = r.error(); - } else { - SetSuccessRequestResult(aValue); - } -} - -bool -FileSystemTaskBase::Recv__delete__(const FileSystemResponseValue& aValue) -{ - SetRequestResult(aValue); - HandlerCallback(); - return true; -} - -void -FileSystemTaskBase::SetError(const nsresult& aErrorValue) -{ - uint16_t module = NS_ERROR_GET_MODULE(aErrorValue); - if (module == NS_ERROR_MODULE_DOM_FILESYSTEM || - module == NS_ERROR_MODULE_DOM_FILE || - module == NS_ERROR_MODULE_DOM) { - mErrorValue = aErrorValue; - return; - } - - switch (aErrorValue) { - case NS_OK: - mErrorValue = NS_OK; - return; - - case NS_ERROR_FILE_INVALID_PATH: - case NS_ERROR_FILE_UNRECOGNIZED_PATH: - mErrorValue = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR; - return; - - case NS_ERROR_FILE_DESTINATION_NOT_DIR: - mErrorValue = NS_ERROR_DOM_FILESYSTEM_INVALID_MODIFICATION_ERR; - return; - - case NS_ERROR_FILE_ACCESS_DENIED: - case NS_ERROR_FILE_DIR_NOT_EMPTY: - mErrorValue = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR; - return; - - case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST: - case NS_ERROR_NOT_AVAILABLE: - mErrorValue = NS_ERROR_DOM_FILE_NOT_FOUND_ERR; - return; - - case NS_ERROR_FILE_ALREADY_EXISTS: - mErrorValue = NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR; - return; - - case NS_ERROR_FILE_NOT_DIRECTORY: - mErrorValue = NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR; - return; - - case NS_ERROR_UNEXPECTED: - default: - mErrorValue = NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR; - return; - } -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/FileSystemTaskBase.h b/dom/filesystem/FileSystemTaskBase.h deleted file mode 100644 index cfe98d80597..00000000000 --- a/dom/filesystem/FileSystemTaskBase.h +++ /dev/null @@ -1,239 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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_FileSystemTaskBase_h -#define mozilla_dom_FileSystemTaskBase_h - -#include "mozilla/ErrorResult.h" -#include "mozilla/dom/FileSystemRequestParent.h" -#include "mozilla/dom/PFileSystemRequestChild.h" -#include "nsWeakReference.h" - -namespace mozilla { -namespace dom { - -class FileSystemBase; -class FileSystemParams; -class Promise; - -/* - * The base class to implement a Task class. - * The task is used to handle the OOP (out of process) operations. - * The file system operations can only be performed in the parent process. When - * performing such a parent-process-only operation, a task will delivered the - * operation to the parent process if needed. - * - * The following diagram illustrates the how a API call from the content page - * starts a task and gets call back results. - * - * The left block is the call sequence inside the child process, while the - * right block is the call sequence inside the parent process. - * - * There are two types of API call. One is from the content page of the child - * process and we mark the steps as (1) to (8). The other is from the content - * page of the parent process and we mark the steps as (1') to (4'). - * - * Page Page - * | | - * | (1) | (1') - * ______|________________ | _____________________|_____________ - * | | | | | | | - * | | Task in | | | Task in | | - * | | Child Process | | | Parent Process | | - * | V | IPC | V | - * [new FileSystemTaskBase()] | | [new FileSystemTaskBase()] | - * | | | | | | | - * | | (2) | | | (2') | - * | V | (3) | | | - * | [GetRequestParams]------------->[new FileSystemTaskBase(...)] | - * | | | | | | - * | | | | | (4) | | - * | | | | | V | - * | | | | -----------> [Work] | - * | | IPC | | | - * | | | | (5) | (3') | - * | | | | V | - * | | | | --------[HandleResult] | - * | | | | | | | - * | | | | (6) | | - * | | (7) | V | | - * | [SetRequestResult]<-------------[GetRequestResult] | | - * | | | | | (4') | - * | | (8) | | | | | - * | V | | | V | - * |[HandlerCallback] | IPC | [HandlerCallback] | - * |_______|_______________| | |_________________________|_________| - * | | | - * V V - * Page Page - * - * 1. From child process page - * Child: - * (1) Call FileSystem API from content page with JS. Create a task and run. - * The base constructor [FileSystemTaskBase()] of the task should be called. - * (2) Forward the task to the parent process through the IPC and call - * [GetRequestParams] to prepare the parameters of the IPC. - * Parent: - * (3) The parent process receives IPC and handle it in - * FileystemRequestParent. - * Get the IPC parameters and create a task to run the IPC task. The base - * constructor [FileSystemTaskBase(aParam, aParent)] of the task should be - * called to set the task as an IPC task. - * (4) The task operation will be performed in the member function of [Work]. - * A worker thread will be created to run that function. If error occurs - * during the operation, call [SetError] to record the error and then abort. - * (5) After finishing the task operation, call [HandleResult] to send the - * result back to the child process though the IPC. - * (6) Call [GetRequestResult] request result to prepare the parameters of the - * IPC. Because the formats of the error result for different task are the - * same, FileSystemTaskBase can handle the error message without interfering. - * Each task only needs to implement its specific success result preparation - * function -[GetSuccessRequestResult]. - * Child: - * (7) The child process receives IPC and calls [SetRequestResult] to get the - * task result. Each task needs to implement its specific success result - * parsing function [SetSuccessRequestResult] to get the success result. - * (8) Call [HandlerCallback] to send the task result to the content page. - * 2. From parent process page - * We don't need to send the task parameters and result to other process. So - * there are less steps, but their functions are the same. The correspondence - * between the two types of steps is: - * (1') = (1), - * (2') = (4), - * (3') = (5), - * (4') = (8). - */ -class FileSystemTaskBase - : public nsRunnable - , public PFileSystemRequestChild -{ -public: - /* - * Start the task. If the task is running the child process, it will be - * forwarded to parent process by IPC, or else, creates a worker thread to - * do the task work. - */ - void - Start(); - - /* - * The error codes are defined in xpcom/base/ErrorList.h and their - * corresponding error name and message are defined in dom/base/domerr.msg. - */ - void - SetError(const nsresult& aErrorCode); - - already_AddRefed - GetFileSystem(); - - /* - * Get the type of permission access required to perform this task. - */ - virtual void - GetPermissionAccessType(nsCString& aAccess) const = 0; - - NS_DECL_NSIRUNNABLE -protected: - /* - * To create a task to handle the page content request. - */ - FileSystemTaskBase(FileSystemBase* aFileSystem); - - /* - * To create a parent process task delivered from the child process through - * IPC. - */ - FileSystemTaskBase(FileSystemBase* aFileSystem, - const FileSystemParams& aParam, - FileSystemRequestParent* aParent); - - virtual - ~FileSystemTaskBase(); - - /* - * The function to perform task operation. It will be run on the worker - * thread of the parent process. - * Overrides this function to define the task operation for individual task. - */ - virtual void - Work() = 0; - - /* - * After the task is completed, this function will be called to pass the task - * result to the content page. - * Override this function to handle the call back to the content page. - */ - virtual void - HandlerCallback() = 0; - - /* - * Wrap the task parameter to FileSystemParams for sending it through IPC. - * It will be called when we need to forward a task from the child process to - * the prarent process. - * @param filesystem The string representation of the file system. - */ - virtual FileSystemParams - GetRequestParams(const nsString& aFileSystem) const = 0; - - /* - * Wrap the task success result to FileSystemResponseValue for sending it - * through IPC. - * It will be called when the task is completed successfully and we need to - * send the task success result back to the child process. - */ - virtual FileSystemResponseValue - GetSuccessRequestResult() const = 0; - - /* - * Unwrap the IPC message to get the task success result. - * It will be called when the task is completed successfully and an IPC - * message is received in the child process and we want to get the task - * success result. - */ - virtual void - SetSuccessRequestResult(const FileSystemResponseValue& aValue) = 0; - - bool - HasError() const { return mErrorValue != NS_OK; } - - // Overrides PFileSystemRequestChild - virtual bool - Recv__delete__(const FileSystemResponseValue& value) MOZ_OVERRIDE; - - nsresult mErrorValue; - - nsWeakPtr mFileSystem; - nsRefPtr mRequestParent; -private: - /* - * After finishing the task operation, handle the task result. - * If it is an IPC task, send back the IPC result. Or else, send the result - * to the content page. - */ - void - HandleResult(); - - /* - * Wrap the task result to FileSystemResponseValue for sending it through IPC. - * It will be called when the task is completed and we need to - * send the task result back to the child process. - */ - FileSystemResponseValue - GetRequestResult() const; - - /* - * Unwrap the IPC message to get the task result. - * It will be called when the task is completed and an IPC message is received - * in the child process and we want to get the task result. - */ - void - SetRequestResult(const FileSystemResponseValue& aValue); -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_FileSystemTaskBase_h diff --git a/dom/filesystem/FileSystemUtils.cpp b/dom/filesystem/FileSystemUtils.cpp deleted file mode 100644 index fade06f8289..00000000000 --- a/dom/filesystem/FileSystemUtils.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 "mozilla/dom/FileSystemUtils.h" - -#include "nsXULAppAPI.h" - -namespace mozilla { -namespace dom { - -// static -void -FileSystemUtils::LocalPathToNormalizedPath(const nsAString& aLocal, - nsAString& aNorm) -{ - nsString result; - result = aLocal; -#if defined(XP_WIN) - char16_t* cur = result.BeginWriting(); - char16_t* end = result.EndWriting(); - for (; cur < end; ++cur) { - if (char16_t('\\') == *cur) - *cur = char16_t('/'); - } -#endif - aNorm = result; -} - -// static -void -FileSystemUtils::NormalizedPathToLocalPath(const nsAString& aNorm, - nsAString& aLocal) -{ - nsString result; - result = aNorm; -#if defined(XP_WIN) - char16_t* cur = result.BeginWriting(); - char16_t* end = result.EndWriting(); - for (; cur < end; ++cur) { - if (char16_t('/') == *cur) - *cur = char16_t('\\'); - } -#endif - aLocal = result; -} - -// static -bool -FileSystemUtils::IsDescendantPath(const nsAString& aPath, - const nsAString& aDescendantPath) -{ - // The descendant path should begin with its ancestor path. - nsAutoString prefix; - prefix = aPath + NS_LITERAL_STRING(FILESYSTEM_DOM_PATH_SEPARATOR); - - // Check the sub-directory path to see if it has the parent path as prefix. - if (aDescendantPath.Length() < prefix.Length() || - !StringBeginsWith(aDescendantPath, prefix)) { - return false; - } - - return true; -} - -// static -bool -FileSystemUtils::IsParentProcess() -{ - return XRE_GetProcessType() == GeckoProcessType_Default; -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/FileSystemUtils.h b/dom/filesystem/FileSystemUtils.h deleted file mode 100644 index 27c1cf34156..00000000000 --- a/dom/filesystem/FileSystemUtils.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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_FileSystemUtils_h -#define mozilla_dom_FileSystemUtils_h - -#include "nsStringGlue.h" - -namespace mozilla { -namespace dom { - -#define FILESYSTEM_DOM_PATH_SEPARATOR "/" - -/* - * This class is for error handling. - * All methods in this class are static. - */ -class FileSystemUtils -{ -public: - /* - * Convert the path separator to "/". - */ - static void - LocalPathToNormalizedPath(const nsAString& aLocal, nsAString& aNorm); - - /* - * Convert the normalized path separator "/" to the system dependent path - * separator, which is "/" on Mac and Linux, and "\" on Windows. - */ - static void - NormalizedPathToLocalPath(const nsAString& aNorm, nsAString& aLocal); - - /* - * Return true if aDescendantPath is a descendant of aPath. Both aPath and - * aDescendantPath are absolute DOM path. - */ - static bool - IsDescendantPath(const nsAString& aPath, const nsAString& aDescendantPath); - - static bool - IsParentProcess(); - - static const char16_t kSeparatorChar = char16_t('/'); -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_FileSystemUtils_h diff --git a/dom/filesystem/GetFileOrDirectoryTask.cpp b/dom/filesystem/GetFileOrDirectoryTask.cpp deleted file mode 100644 index 37b934c77ec..00000000000 --- a/dom/filesystem/GetFileOrDirectoryTask.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 "GetFileOrDirectoryTask.h" - -#include "js/Value.h" -#include "mozilla/dom/Directory.h" -#include "mozilla/dom/FileSystemBase.h" -#include "mozilla/dom/FileSystemUtils.h" -#include "mozilla/dom/Promise.h" -#include "nsDOMFile.h" -#include "nsIFile.h" -#include "nsStringGlue.h" - -namespace mozilla { -namespace dom { - -GetFileOrDirectoryTask::GetFileOrDirectoryTask( - FileSystemBase* aFileSystem, - const nsAString& aTargetPath, - bool aDirectoryOnly) - : FileSystemTaskBase(aFileSystem) - , mTargetRealPath(aTargetPath) - , mIsDirectory(aDirectoryOnly) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (!aFileSystem) { - return; - } - nsCOMPtr globalObject = - do_QueryInterface(aFileSystem->GetWindow()); - if (!globalObject) { - return; - } - mPromise = new Promise(globalObject); -} - -GetFileOrDirectoryTask::GetFileOrDirectoryTask( - FileSystemBase* aFileSystem, - const FileSystemGetFileOrDirectoryParams& aParam, - FileSystemRequestParent* aParent) - : FileSystemTaskBase(aFileSystem, aParam, aParent) - , mIsDirectory(false) -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - mTargetRealPath = aParam.realPath(); -} - -GetFileOrDirectoryTask::~GetFileOrDirectoryTask() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); -} - -already_AddRefed -GetFileOrDirectoryTask::GetPromise() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - return nsRefPtr(mPromise).forget(); -} - -FileSystemParams -GetFileOrDirectoryTask::GetRequestParams(const nsString& aFileSystem) const -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - return FileSystemGetFileOrDirectoryParams(aFileSystem, mTargetRealPath); -} - -FileSystemResponseValue -GetFileOrDirectoryTask::GetSuccessRequestResult() const -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - if (mIsDirectory) { - return FileSystemDirectoryResponse(mTargetRealPath); - } - - ContentParent* cp = static_cast(mRequestParent->Manager()); - BlobParent* actor = cp->GetOrCreateActorForBlob(mTargetFile); - if (!actor) { - return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR); - } - FileSystemFileResponse response; - response.blobParent() = actor; - return response; -} - -void -GetFileOrDirectoryTask::SetSuccessRequestResult(const FileSystemResponseValue& aValue) -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - switch (aValue.type()) { - case FileSystemResponseValue::TFileSystemFileResponse: { - FileSystemFileResponse r = aValue; - BlobChild* actor = static_cast(r.blobChild()); - nsCOMPtr blob = actor->GetBlob(); - mTargetFile = do_QueryInterface(blob); - mIsDirectory = false; - break; - } - case FileSystemResponseValue::TFileSystemDirectoryResponse: { - FileSystemDirectoryResponse r = aValue; - mTargetRealPath = r.realPath(); - mIsDirectory = true; - break; - } - default: { - NS_RUNTIMEABORT("not reached"); - break; - } - } -} - -void -GetFileOrDirectoryTask::Work() -{ - MOZ_ASSERT(FileSystemUtils::IsParentProcess(), - "Only call from parent process!"); - MOZ_ASSERT(!NS_IsMainThread(), "Only call on worker thread!"); - - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - if (!filesystem) { - return; - } - - // Whether we want to get the root directory. - bool getRoot = mTargetRealPath.IsEmpty(); - - nsCOMPtr file = filesystem->GetLocalFile(mTargetRealPath); - if (!file) { - SetError(NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR); - return; - } - - bool ret; - nsresult rv = file->Exists(&ret); - if (NS_FAILED(rv)) { - SetError(rv); - return; - } - - if (!ret) { - if (!getRoot) { - SetError(NS_ERROR_DOM_FILE_NOT_FOUND_ERR); - return; - } - - // If the root directory doesn't exit, create it. - rv = file->Create(nsIFile::DIRECTORY_TYPE, 0777); - if (NS_FAILED(rv)) { - SetError(rv); - return; - } - } - - // Get isDirectory. - rv = file->IsDirectory(&mIsDirectory); - if (NS_FAILED(rv)) { - SetError(rv); - return; - } - - if (!mIsDirectory) { - // Check if the root is a directory. - if (getRoot) { - SetError(NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR); - return; - } - - // Get isFile - rv = file->IsFile(&ret); - if (NS_FAILED(rv)) { - SetError(rv); - return; - } - if (!ret) { - // Neither directory or file. - SetError(NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR); - return; - } - - if (!filesystem->IsSafeFile(file)) { - SetError(NS_ERROR_DOM_SECURITY_ERR); - return; - } - - mTargetFile = new nsDOMFileFile(file); - } -} - -void -GetFileOrDirectoryTask::HandlerCallback() -{ - MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - nsRefPtr filesystem = do_QueryReferent(mFileSystem); - if (!filesystem) { - return; - } - - if (HasError()) { - nsRefPtr domError = new DOMError(filesystem->GetWindow(), - mErrorValue); - mPromise->MaybeReject(domError); - return; - } - - if (mIsDirectory) { - nsRefPtr dir = new Directory(filesystem, mTargetRealPath); - mPromise->MaybeResolve(dir); - return; - } - - mPromise->MaybeResolve(mTargetFile); -} - -void -GetFileOrDirectoryTask::GetPermissionAccessType(nsCString& aAccess) const -{ - aAccess.AssignLiteral("read"); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/GetFileOrDirectoryTask.h b/dom/filesystem/GetFileOrDirectoryTask.h deleted file mode 100644 index c5ea04a63b3..00000000000 --- a/dom/filesystem/GetFileOrDirectoryTask.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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_GetFileOrDirectory_h -#define mozilla_dom_GetFileOrDirectory_h - -#include "mozilla/dom/FileSystemTaskBase.h" -#include "nsAutoPtr.h" - -class nsIDOMFile; -class nsString; - -namespace mozilla { -namespace dom { - -class FileSystemBase; -class FileSystemFile; -class FileSystemGetFileOrDirectoryParams; -class Promise; - -class GetFileOrDirectoryTask MOZ_FINAL - : public FileSystemTaskBase -{ -public: - // If aDirectoryOnly is set, we should ensure that the target is a directory. - GetFileOrDirectoryTask(FileSystemBase* aFileSystem, - const nsAString& aTargetPath, - bool aDirectoryOnly); - GetFileOrDirectoryTask(FileSystemBase* aFileSystem, - const FileSystemGetFileOrDirectoryParams& aParam, - FileSystemRequestParent* aParent); - - virtual - ~GetFileOrDirectoryTask(); - - already_AddRefed - GetPromise(); - - virtual void - GetPermissionAccessType(nsCString& aAccess) const MOZ_OVERRIDE; -protected: - virtual FileSystemParams - GetRequestParams(const nsString& aFileSystem) const MOZ_OVERRIDE; - - virtual FileSystemResponseValue - GetSuccessRequestResult() const MOZ_OVERRIDE; - - virtual void - SetSuccessRequestResult(const FileSystemResponseValue& aValue) MOZ_OVERRIDE; - - virtual void - Work() MOZ_OVERRIDE; - - virtual void - HandlerCallback() MOZ_OVERRIDE; - -private: - nsRefPtr mPromise; - nsString mTargetRealPath; - // Whether we get a directory. - bool mIsDirectory; - nsCOMPtr mTargetFile; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_GetFileOrDirectory_h diff --git a/dom/filesystem/PFileSystemRequest.ipdl b/dom/filesystem/PFileSystemRequest.ipdl deleted file mode 100644 index b94aa59b626..00000000000 --- a/dom/filesystem/PFileSystemRequest.ipdl +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ -/* vim: set ts=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 protocol PBlob; -include protocol PContent; - -namespace mozilla { -namespace dom { - -struct FileSystemFileResponse -{ - PBlob blob; -}; - -struct FileSystemDirectoryResponse -{ - nsString realPath; -}; - -struct FileSystemErrorResponse -{ - nsresult error; -}; - -union FileSystemResponseValue -{ - FileSystemDirectoryResponse; - FileSystemFileResponse; - FileSystemErrorResponse; -}; - -sync protocol PFileSystemRequest -{ - manager PContent; - -child: - __delete__(FileSystemResponseValue response); -}; - -} // namespace dom -} // namespace mozilla diff --git a/dom/filesystem/moz.build b/dom/filesystem/moz.build deleted file mode 100644 index 34cda14970f..00000000000 --- a/dom/filesystem/moz.build +++ /dev/null @@ -1,39 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# 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/. - -EXPORTS.mozilla.dom += [ - 'DeviceStorageFileSystem.h', - 'Directory.h', - 'FileSystemBase.h', - 'FileSystemRequestParent.h', - 'FileSystemTaskBase.h', - 'FileSystemUtils.h', -] - -SOURCES += [ - 'CreateDirectoryTask.cpp', - 'DeviceStorageFileSystem.cpp', - 'Directory.cpp', - 'FileSystemBase.cpp', - 'FileSystemPermissionRequest.cpp', - 'FileSystemRequestParent.cpp', - 'FileSystemTaskBase.cpp', - 'FileSystemUtils.cpp', - 'GetFileOrDirectoryTask.cpp', -] - -FINAL_LIBRARY = 'gklayout' - -IPDL_SOURCES += [ - 'PFileSystemRequest.ipdl', -] - -include('/ipc/chromium/chromium-config.mozbuild') - -LOCAL_INCLUDES += [ - '/dom/base', -] - diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index de37ecb1dc7..effc52f34e9 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -116,8 +116,6 @@ #include "mozilla/dom/indexedDB/PIndexedDBChild.h" #include "mozilla/dom/mobilemessage/SmsChild.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h" -#include "mozilla/dom/PFileSystemRequestChild.h" -#include "mozilla/dom/FileSystemTaskBase.h" #include "mozilla/dom/bluetooth/PBluetoothChild.h" #include "mozilla/dom/PFMRadioChild.h" #include "mozilla/ipc/InputStreamUtils.h" @@ -1046,24 +1044,6 @@ ContentChild::DeallocPDeviceStorageRequestChild(PDeviceStorageRequestChild* aDev return true; } -PFileSystemRequestChild* -ContentChild::AllocPFileSystemRequestChild(const FileSystemParams& aParams) -{ - NS_NOTREACHED("Should never get here!"); - return nullptr; -} - -bool -ContentChild::DeallocPFileSystemRequestChild(PFileSystemRequestChild* aFileSystem) -{ - mozilla::dom::FileSystemTaskBase* child = - static_cast(aFileSystem); - // The reference is increased in FileSystemTaskBase::Start of - // FileSystemTaskBase.cpp. We should decrease it after IPC. - NS_RELEASE(child); - return true; -} - PNeckoChild* ContentChild::AllocPNeckoChild() { diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index bb269379057..7bd070b76c2 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -99,9 +99,6 @@ public: virtual PDeviceStorageRequestChild* AllocPDeviceStorageRequestChild(const DeviceStorageParams&); virtual bool DeallocPDeviceStorageRequestChild(PDeviceStorageRequestChild*); - virtual PFileSystemRequestChild* AllocPFileSystemRequestChild(const FileSystemParams&); - virtual bool DeallocPFileSystemRequestChild(PFileSystemRequestChild*); - virtual PBlobChild* AllocPBlobChild(const BlobConstructorParams& aParams); virtual bool DeallocPBlobChild(PBlobChild*); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 3a5f62f96c8..fd5f17656b5 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -38,7 +38,6 @@ #include "mozilla/dom/GeolocationBinding.h" #include "mozilla/dom/telephony/TelephonyParent.h" #include "mozilla/dom/time/DateCacheCleaner.h" -#include "mozilla/dom/FileSystemRequestParent.h" #include "SmsParent.h" #include "mozilla/hal_sandbox/PHalParent.h" #include "mozilla/ipc/BackgroundChild.h" @@ -2276,24 +2275,6 @@ ContentParent::DeallocPDeviceStorageRequestParent(PDeviceStorageRequestParent* d return true; } -PFileSystemRequestParent* -ContentParent::AllocPFileSystemRequestParent(const FileSystemParams& aParams) -{ - nsRefPtr result = new FileSystemRequestParent(); - if (!result->Dispatch(this, aParams)) { - return nullptr; - } - return result.forget().get(); -} - -bool -ContentParent::DeallocPFileSystemRequestParent(PFileSystemRequestParent* doomed) -{ - FileSystemRequestParent* parent = static_cast(doomed); - NS_RELEASE(parent); - return true; -} - PBlobParent* ContentParent::AllocPBlobParent(const BlobConstructorParams& aParams) { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index d75ef575f86..552f0bc306b 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -346,12 +346,6 @@ private: AllocPDeviceStorageRequestParent(const DeviceStorageParams&) MOZ_OVERRIDE; virtual bool DeallocPDeviceStorageRequestParent(PDeviceStorageRequestParent*) MOZ_OVERRIDE; - virtual PFileSystemRequestParent* - AllocPFileSystemRequestParent(const FileSystemParams&) MOZ_OVERRIDE; - - virtual bool - DeallocPFileSystemRequestParent(PFileSystemRequestParent*) MOZ_OVERRIDE; - virtual PBlobParent* AllocPBlobParent(const BlobConstructorParams& aParams) MOZ_OVERRIDE; virtual bool DeallocPBlobParent(PBlobParent*) MOZ_OVERRIDE; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 7e4c5fb0909..dfb9f5370d1 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -14,7 +14,6 @@ include protocol PCrashReporter; include protocol PExternalHelperApp; include protocol PDeviceStorageRequest; include protocol PFMRadio; -include protocol PFileSystemRequest; include protocol PHal; include protocol PImageBridge; include protocol PIndexedDB; @@ -194,24 +193,6 @@ union FMRadioRequestParams FMRadioRequestCancelSeekParams; }; -struct FileSystemCreateDirectoryParams -{ - nsString filesystem; - nsString realPath; -}; - -struct FileSystemGetFileOrDirectoryParams -{ - nsString filesystem; - nsString realPath; -}; - -union FileSystemParams -{ - FileSystemCreateDirectoryParams; - FileSystemGetFileOrDirectoryParams; -}; - union PrefValue { nsCString; int32_t; @@ -241,7 +222,6 @@ intr protocol PContent manages PBrowser; manages PCrashReporter; manages PDeviceStorageRequest; - manages PFileSystemRequest; manages PExternalHelperApp; manages PFMRadio; manages PHal; @@ -391,8 +371,6 @@ parent: PDeviceStorageRequest(DeviceStorageParams params); - PFileSystemRequest(FileSystemParams params); - sync PCrashReporter(NativeThreadId tid, uint32_t processType); sync GetRandomValues(uint32_t length) diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 84556672e20..1e7ec0fcbb8 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -98,7 +98,6 @@ LOCAL_INCLUDES += [ '/dom/bluetooth/ipc', '/dom/devicestorage', '/dom/events', - '/dom/filesystem', '/dom/fmradio/ipc', '/dom/indexedDB', '/dom/indexedDB/ipc', diff --git a/dom/moz.build b/dom/moz.build index af011ed6b4d..9ba4eb697ff 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -50,7 +50,6 @@ PARALLEL_DIRS += [ 'encoding', 'events', 'file', - 'filesystem', 'fmradio', 'asmjscache', 'media', diff --git a/dom/promise/Promise.h b/dom/promise/Promise.h index 1255911c5f2..7254bc67ad4 100644 --- a/dom/promise/Promise.h +++ b/dom/promise/Promise.h @@ -220,22 +220,6 @@ private: return true; } - // Accept objects that inherit from nsISupports but not nsWrapperCache (e.g. - // nsIDOMFile). - template - typename EnableIf::value && - IsBaseOf::value, bool>::Type - ArgumentToJSValue(T& aArgument, - JSContext* aCx, - JSObject* aScope, - JS::MutableHandle aValue) - { - JS::Rooted scope(aCx, aScope); - - nsresult rv = nsContentUtils::WrapNative(aCx, scope, &aArgument, aValue); - return NS_SUCCEEDED(rv); - } - template