Bug 1299500 - Get rid of DeviceStorage API - part 11 - FileSystem, r=ehsan a=gchang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 20:15:45 +0100
changeset 395390 e4c10d4f6b3ec4101824421749b104b17e942f0b
parent 395389 7c8fddc43c028fc26f47d653658fc3c9a6a77027
child 395391 076416de288687037559442ec1dbe2987752da66
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, gchang
bugs1299500
milestone54.0a2
Bug 1299500 - Get rid of DeviceStorage API - part 11 - FileSystem, r=ehsan a=gchang
dom/filesystem/DeviceStorageFileSystem.cpp
dom/filesystem/DeviceStorageFileSystem.h
dom/filesystem/Directory.cpp
dom/filesystem/FileSystemBase.cpp
dom/filesystem/FileSystemBase.h
dom/filesystem/FileSystemPermissionRequest.cpp
dom/filesystem/FileSystemPermissionRequest.h
dom/filesystem/FileSystemRequestParent.cpp
dom/filesystem/FileSystemRequestParent.h
dom/filesystem/FileSystemTaskBase.cpp
dom/filesystem/FileSystemTaskBase.h
dom/filesystem/GetDirectoryListingTask.cpp
dom/filesystem/GetDirectoryListingTask.h
dom/filesystem/GetFileOrDirectoryTask.cpp
dom/filesystem/GetFileOrDirectoryTask.h
dom/filesystem/GetFilesTask.cpp
dom/filesystem/GetFilesTask.h
dom/filesystem/OSFileSystem.cpp
dom/filesystem/compat/CallbackRunnables.cpp
dom/filesystem/moz.build
ipc/glue/BackgroundParentImpl.cpp
ipc/glue/BackgroundParentImpl.h
deleted file mode 100644
--- a/dom/filesystem/DeviceStorageFileSystem.cpp
+++ /dev/null
@@ -1,195 +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 "mozilla/dom/DeviceStorageFileSystem.h"
-
-#include "mozilla/Preferences.h"
-#include "mozilla/dom/Directory.h"
-#include "mozilla/dom/File.h"
-#include "mozilla/dom/FileSystemUtils.h"
-#include "mozilla/ipc/BackgroundParent.h"
-#include "mozilla/Unused.h"
-#include "nsCOMPtr.h"
-#include "nsDebug.h"
-#include "nsIFile.h"
-#include "nsPIDOMWindow.h"
-#include "nsGlobalWindow.h"
-
-using namespace mozilla::ipc;
-
-namespace mozilla {
-namespace dom {
-
-DeviceStorageFileSystem::DeviceStorageFileSystem(const nsAString& aStorageType,
-                                                 const nsAString& aStorageName)
-  : mStorageType(aStorageType)
-  , mStorageName(aStorageName)
-  , mWindowId(0)
-{
-  mPermissionCheckType = ePermissionCheckByTestingPref;
-
-  if (NS_IsMainThread()) {
-    if (mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) {
-      mPermissionCheckType = ePermissionCheckNotRequired;
-    } else {
-      mPermissionCheckType = ePermissionCheckRequired;
-    }
-  } else {
-    AssertIsOnBackgroundThread();
-  }
-}
-
-DeviceStorageFileSystem::~DeviceStorageFileSystem()
-{
-  AssertIsOnOwningThread();
-}
-
-already_AddRefed<FileSystemBase>
-DeviceStorageFileSystem::Clone()
-{
-  AssertIsOnOwningThread();
-
-  RefPtr<DeviceStorageFileSystem> fs =
-    new DeviceStorageFileSystem(mStorageType, mStorageName);
-
-  fs->mWindowId = mWindowId;
-
-  return fs.forget();
-}
-
-void
-DeviceStorageFileSystem::Init(nsDOMDeviceStorage* aDeviceStorage)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  AssertIsOnOwningThread();
-  MOZ_ASSERT(aDeviceStorage);
-
-  nsCOMPtr<nsPIDOMWindowInner> window = aDeviceStorage->GetOwner();
-  MOZ_ASSERT(window->IsInnerWindow());
-  mWindowId = window->WindowID();
-}
-
-void
-DeviceStorageFileSystem::Shutdown()
-{
-  AssertIsOnOwningThread();
-  mShutdown = true;
-}
-
-nsISupports*
-DeviceStorageFileSystem::GetParentObject() const
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  AssertIsOnOwningThread();
-
-  nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mWindowId);
-  MOZ_ASSERT_IF(!mShutdown, window);
-  return window ? window->AsInner() : nullptr;
-}
-
-void
-DeviceStorageFileSystem::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
-                                          ErrorResult& aRv) const
-{
-  AssertIsOnOwningThread();
-  MOZ_ASSERT(aFile);
-
-  nsCOMPtr<nsIFile> rootPath;
-  aRv = NS_NewLocalFile(LocalOrDeviceStorageRootPath(), false,
-                        getter_AddRefs(rootPath));
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  bool equal = false;
-  aRv = aFile->Equals(rootPath, &equal);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  if (equal) {
-    aRetval = mStorageName;
-    return;
-  }
-
-  FileSystemBase::GetDirectoryName(aFile, aRetval, aRv);
-  NS_WARNING_ASSERTION(!aRv.Failed(), "GetDirectoryName failed");
-}
-
-bool
-DeviceStorageFileSystem::IsSafeFile(nsIFile* aFile) const
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Should be on parent process!");
-  MOZ_ASSERT(!NS_IsMainThread());
-  MOZ_ASSERT(aFile);
-
-  nsCOMPtr<nsIFile> rootPath;
-  nsresult rv = NS_NewLocalFile(LocalOrDeviceStorageRootPath(), false,
-                                getter_AddRefs(rootPath));
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return false;
-  }
-
-  // Check if this file belongs to this storage.
-  if (NS_WARN_IF(!FileSystemUtils::IsDescendantPath(rootPath, aFile))) {
-    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);
-}
-
-bool
-DeviceStorageFileSystem::IsSafeDirectory(Directory* aDir) const
-{
-  AssertIsOnOwningThread();
-  MOZ_ASSERT(aDir);
-
-  ErrorResult rv;
-  RefPtr<FileSystemBase> fs = aDir->GetFileSystem(rv);
-  if (NS_WARN_IF(rv.Failed())) {
-    rv.SuppressException();
-    return false;
-  }
-
-  nsAutoString fsSerialization;
-  fs->SerializeDOMPath(fsSerialization);
-
-  nsAutoString thisSerialization;
-  SerializeDOMPath(thisSerialization);
-
-  // Check if the given directory is from this storage.
-  return fsSerialization == thisSerialization;
-}
-
-void
-DeviceStorageFileSystem::SerializeDOMPath(nsAString& aString) const
-{
-  AssertIsOnOwningThread();
-
-  // Generate the string representation of the file system.
-  aString.AssignLiteral("devicestorage-");
-  aString.Append(mStorageType);
-  aString.Append('-');
-  aString.Append(mStorageName);
-}
-
-nsresult
-DeviceStorageFileSystem::MainThreadWork()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  DebugOnly<DeviceStorageTypeChecker*> typeChecker =
-    DeviceStorageTypeChecker::CreateOrGet();
-  MOZ_ASSERT(typeChecker);
-  return NS_OK;
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/filesystem/DeviceStorageFileSystem.h
+++ /dev/null
@@ -1,74 +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_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
-  Init(nsDOMDeviceStorage* aDeviceStorage);
-
-  // Overrides FileSystemBase
-
-  virtual already_AddRefed<FileSystemBase>
-  Clone() override;
-
-  virtual bool
-  ShouldCreateDirectory() override { return true; }
-
-  virtual void
-  Shutdown() override;
-
-  virtual nsISupports*
-  GetParentObject() const override;
-
-  virtual void
-  GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
-                   ErrorResult& aRv) const override;
-
-  virtual bool
-  IsSafeFile(nsIFile* aFile) const override;
-
-  virtual bool
-  IsSafeDirectory(Directory* aDir) const override;
-
-  virtual void
-  SerializeDOMPath(nsAString& aSerializedString) const override;
-
-  virtual bool
-  NeedToGoToMainThread() const override { return true; }
-
-  virtual nsresult
-  MainThreadWork() override;
-
-private:
-  virtual
-  ~DeviceStorageFileSystem();
-
-  nsString mStorageType;
-  nsString mStorageName;
-
-  uint64_t mWindowId;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_DeviceStorageFileSystem_h
--- a/dom/filesystem/Directory.cpp
+++ b/dom/filesystem/Directory.cpp
@@ -1,17 +1,16 @@
 /* -*- 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 "mozilla/dom/Directory.h"
 
-#include "FileSystemPermissionRequest.h"
 #include "GetDirectoryListingTask.h"
 #include "GetFilesTask.h"
 #include "WorkerPrivate.h"
 
 #include "nsCharSeparatedTokenizer.h"
 #include "nsString.h"
 #include "mozilla/dom/DirectoryBinding.h"
 #include "mozilla/dom/FileSystemBase.h"
@@ -183,17 +182,18 @@ Directory::GetFilesAndDirectories(ErrorR
   }
 
   RefPtr<GetDirectoryListingTaskChild> task =
     GetDirectoryListingTaskChild::Create(fs, this, mFile, mFilters, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
-  FileSystemPermissionRequest::RequestForTask(task);
+  task->Start();
+
   return task->GetPromise();
 }
 
 already_AddRefed<Promise>
 Directory::GetFiles(bool aRecursiveFlag, ErrorResult& aRv)
 {
   ErrorResult rv;
   RefPtr<FileSystemBase> fs = GetFileSystem(rv);
@@ -204,17 +204,18 @@ Directory::GetFiles(bool aRecursiveFlag,
 
   RefPtr<GetFilesTaskChild> task =
     GetFilesTaskChild::Create(fs, this, mFile, aRecursiveFlag, rv);
   if (NS_WARN_IF(rv.Failed())) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
-  FileSystemPermissionRequest::RequestForTask(task);
+  task->Start();
+
   return task->GetPromise();
 }
 
 void
 Directory::SetContentFilters(const nsAString& aFilters)
 {
   mFilters = aFilters;
 }
--- a/dom/filesystem/FileSystemBase.cpp
+++ b/dom/filesystem/FileSystemBase.cpp
@@ -1,58 +1,24 @@
 /* -*- 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 "mozilla/dom/FileSystemBase.h"
 
-#include "DeviceStorageFileSystem.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "OSFileSystem.h"
 
 namespace mozilla {
 namespace dom {
 
-// static
-already_AddRefed<FileSystemBase>
-FileSystemBase::DeserializeDOMPath(const nsAString& aString)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-
-  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();
-    }
-
-    RefPtr<DeviceStorageFileSystem> f =
-      new DeviceStorageFileSystem(storageType, storageName);
-    return f.forget();
-  }
-
-  return RefPtr<OSFileSystemParent>(new OSFileSystemParent(aString)).forget();
-}
-
 FileSystemBase::FileSystemBase()
   : mShutdown(false)
-  , mPermissionCheckType(eNotSet)
 #ifdef DEBUG
   , mOwningThread(PR_GetCurrentThread())
 #endif
 {
 }
 
 FileSystemBase::~FileSystemBase()
 {
@@ -128,18 +94,17 @@ FileSystemBase::GetDOMPath(nsIFile* aFil
                            ErrorResult& aRv) const
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(aFile);
 
   aRetval.Truncate();
 
   nsCOMPtr<nsIFile> fileSystemPath;
-  aRv = NS_NewLocalFile(LocalOrDeviceStorageRootPath(),
-                        true, getter_AddRefs(fileSystemPath));
+  aRv = NS_NewLocalFile(LocalRootPath(), true, getter_AddRefs(fileSystemPath));
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   nsCOMPtr<nsIFile> path;
   aRv = aFile->Clone(getter_AddRefs(path));
   if (NS_WARN_IF(aRv.Failed())) {
     return;
--- a/dom/filesystem/FileSystemBase.h
+++ b/dom/filesystem/FileSystemBase.h
@@ -15,20 +15,16 @@ namespace dom {
 
 class BlobImpl;
 
 class FileSystemBase
 {
 public:
   NS_INLINE_DECL_REFCOUNTING(FileSystemBase)
 
-  // Create file system object from its string representation.
-  static already_AddRefed<FileSystemBase>
-  DeserializeDOMPath(const nsAString& aString);
-
   FileSystemBase();
 
   virtual void
   Shutdown();
 
   // SerializeDOMPath the FileSystem to string.
   virtual void
   SerializeDOMPath(nsAString& aOutput) const = 0;
@@ -51,19 +47,19 @@ public:
 
   /*
    * Return the local root path of the FileSystem implementation.
    * For OSFileSystem, this is equal to the path of the root Directory;
    * For DeviceStorageFileSystem, this is the path of the SDCard, parent
    * directory of the exposed root Directory (per type).
    */
   const nsAString&
-  LocalOrDeviceStorageRootPath() const
+  LocalRootPath() const
   {
-    return mLocalOrDeviceStorageRootPath;
+    return mLocalRootPath;
   }
 
   bool
   IsShutdown() const
   {
     return mShutdown;
   }
 
@@ -71,56 +67,16 @@ public:
   IsSafeFile(nsIFile* aFile) const;
 
   virtual bool
   IsSafeDirectory(Directory* aDir) const;
 
   bool
   GetRealPath(BlobImpl* aFile, nsIFile** aPath) const;
 
-  /*
-   * Get the permission name required to access this file system.
-   */
-  const nsCString&
-  GetPermission() const
-  {
-    return mPermission;
-  }
-
-  // The decision about doing or not doing the permission check cannot be done
-  // everywhere because, for some FileSystemBase implementation, this depends on
-  // a preference.
-  // This enum describes all the possible decisions. The implementation will do
-  // the check on the main-thread in the child and in the parent process when
-  // needed.
-  // Note: the permission check should not fail in PBackground because that
-  // means that the child has been compromised. If this happens the child
-  // process is killed.
-  enum ePermissionCheckType {
-    // When on the main-thread, we must check if we have
-    // device.storage.prompt.testing set to true.
-    ePermissionCheckByTestingPref,
-
-    // No permission check must be done.
-    ePermissionCheckNotRequired,
-
-    // Permission check is required.
-    ePermissionCheckRequired,
-
-    // This is the default value. We crash if this is let like this.
-    eNotSet
-  };
-
-  ePermissionCheckType
-  PermissionCheckType() const
-  {
-    MOZ_ASSERT(mPermissionCheckType != eNotSet);
-    return mPermissionCheckType;
-  }
-
   // IPC initialization
   // See how these 2 methods are used in FileSystemTaskChildBase.
 
   virtual bool
   NeedToGoToMainThread() const { return false; }
 
   virtual nsresult
   MainThreadWork() { return NS_ERROR_FAILURE; }
@@ -142,28 +98,20 @@ protected:
   // the OS directory that acts as the root of this OSFileSystem).
   // This path must be set by the FileSystem implementation immediately
   // because it will be used for the validation of any FileSystemTaskChildBase.
   // The concept of this path is that, any task will never go out of it and this
   // must be considered the OS 'root' of the current FileSystem. Different
   // Directory object can have different OS 'root' path.
   // To be more clear, any path managed by this FileSystem implementation must
   // be discendant of this local root path.
-  // The reason why it's not just called 'localRootPath' is because for
-  // DeviceStorage this contains the path of the device storage SDCard, that is
-  // the parent directory of the exposed root path.
-  nsString mLocalOrDeviceStorageRootPath;
+  nsString mLocalRootPath;
 
   bool mShutdown;
 
-  // The permission name required to access the file system.
-  nsCString mPermission;
-
-  ePermissionCheckType mPermissionCheckType;
-
 #ifdef DEBUG
   PRThread* mOwningThread;
 #endif
 };
 
 } // namespace dom
 } // namespace mozilla
 
deleted file mode 100644
--- a/dom/filesystem/FileSystemPermissionRequest.cpp
+++ /dev/null
@@ -1,262 +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 "FileSystemPermissionRequest.h"
-
-#include "mozilla/dom/FileSystemBase.h"
-#include "mozilla/dom/FileSystemTaskBase.h"
-#include "mozilla/dom/FileSystemUtils.h"
-#include "mozilla/ipc/BackgroundChild.h"
-#include "mozilla/ipc/PBackgroundChild.h"
-#include "nsIDocument.h"
-#include "nsIIPCBackgroundChildCreateCallback.h"
-#include "nsPIDOMWindow.h"
-#include "nsContentPermissionHelper.h"
-
-namespace mozilla {
-namespace dom {
-
-namespace {
-
-// This class takes care of the PBackground initialization and, once this step
-// is completed, it starts the task.
-class PBackgroundInitializer final : public nsIIPCBackgroundChildCreateCallback
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
-
-  static void
-  ScheduleTask(FileSystemTaskChildBase* aTask)
-  {
-    MOZ_ASSERT(aTask);
-    RefPtr<PBackgroundInitializer> pb = new PBackgroundInitializer(aTask);
-  }
-
-private:
-  explicit PBackgroundInitializer(FileSystemTaskChildBase* aTask)
-    : mTask(aTask)
-  {
-    MOZ_ASSERT(aTask);
-
-    PBackgroundChild* actor =
-      mozilla::ipc::BackgroundChild::GetForCurrentThread();
-    if (actor) {
-      ActorCreated(actor);
-    } else {
-      if (NS_WARN_IF(
-          !mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread(this))) {
-        MOZ_CRASH();
-      }
-    }
-  }
-
-  ~PBackgroundInitializer()
-  {}
-
-  RefPtr<FileSystemTaskChildBase> mTask;
-};
-
-NS_IMPL_ISUPPORTS(PBackgroundInitializer,
-                  nsIIPCBackgroundChildCreateCallback)
-
-void
-PBackgroundInitializer::ActorFailed()
-{
-  MOZ_CRASH("Failed to create a PBackgroundChild actor!");
-}
-
-void
-PBackgroundInitializer::ActorCreated(mozilla::ipc::PBackgroundChild* aActor)
-{
-  mTask->Start();
-}
-
-// This must be a CancelableRunnable because it can be dispatched to a worker
-// thread. But we don't care about the Cancel() because in that case, Run() is
-// not called and the task is deleted by the DTOR.
-class AsyncStartRunnable final : public CancelableRunnable
-{
-public:
-  explicit AsyncStartRunnable(FileSystemTaskChildBase* aTask)
-    : mTask(aTask)
-  {
-    MOZ_ASSERT(aTask);
-  }
-
-  NS_IMETHOD
-  Run() override
-  {
-    PBackgroundInitializer::ScheduleTask(mTask);
-    return NS_OK;
-  }
-
-private:
-  RefPtr<FileSystemTaskChildBase> mTask;
-};
-
-} // anonymous namespace
-
-NS_IMPL_ISUPPORTS(FileSystemPermissionRequest, nsIRunnable,
-                  nsIContentPermissionRequest)
-
-/* static */ void
-FileSystemPermissionRequest::RequestForTask(FileSystemTaskChildBase* aTask)
-{
-  MOZ_ASSERT(aTask);
-
-  RefPtr<FileSystemBase> filesystem = aTask->GetFileSystem();
-  if (!filesystem) {
-    return;
-  }
-
-  if (filesystem->PermissionCheckType() == FileSystemBase::ePermissionCheckNotRequired) {
-    // Let's make the scheduling of this task asynchronous.
-    RefPtr<AsyncStartRunnable> runnable = new AsyncStartRunnable(aTask);
-    NS_DispatchToCurrentThread(runnable);
-    return;
-  }
-
-  // We don't need any permission check for the FileSystem API. If we are here
-  // it's because we are dealing with a DeviceStorage API that is main-thread
-  // only.
-  MOZ_ASSERT(NS_IsMainThread());
-
-  RefPtr<FileSystemPermissionRequest> request =
-    new FileSystemPermissionRequest(aTask);
-  NS_DispatchToCurrentThread(request);
-}
-
-FileSystemPermissionRequest::FileSystemPermissionRequest(FileSystemTaskChildBase* aTask)
-  : mTask(aTask)
-{
-  MOZ_ASSERT(mTask, "aTask should not be null!");
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mTask->GetPermissionAccessType(mPermissionAccess);
-
-  RefPtr<FileSystemBase> filesystem = mTask->GetFileSystem();
-  if (!filesystem) {
-    return;
-  }
-
-  mPermissionType = filesystem->GetPermission();
-
-  mWindow = do_QueryInterface(filesystem->GetParentObject());
-  if (NS_WARN_IF(!mWindow)) {
-    return;
-  }
-
-  nsCOMPtr<nsIDocument> doc = mWindow->GetDoc();
-  if (!doc) {
-    return;
-  }
-
-  mPrincipal = doc->NodePrincipal();
-  mRequester = new nsContentPermissionRequester(mWindow);
-}
-
-FileSystemPermissionRequest::~FileSystemPermissionRequest()
-{
-}
-
-NS_IMETHODIMP
-FileSystemPermissionRequest::GetTypes(nsIArray** aTypes)
-{
-  nsTArray<nsString> emptyOptions;
-  return nsContentPermissionUtils::CreatePermissionArray(mPermissionType,
-                                                         mPermissionAccess,
-                                                         emptyOptions,
-                                                         aTypes);
-}
-
-NS_IMETHODIMP
-FileSystemPermissionRequest::GetPrincipal(nsIPrincipal** aRequestingPrincipal)
-{
-  NS_IF_ADDREF(*aRequestingPrincipal = mPrincipal);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-FileSystemPermissionRequest::GetWindow(mozIDOMWindow** 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);
-  ScheduleTask();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-FileSystemPermissionRequest::Allow(JS::HandleValue aChoices)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aChoices.isUndefined());
-  ScheduleTask();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-FileSystemPermissionRequest::Run()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  RefPtr<FileSystemBase> filesystem = mTask->GetFileSystem();
-  if (!filesystem) {
-    Cancel();
-    return NS_OK;
-  }
-
-  if (filesystem->PermissionCheckType() == FileSystemBase::ePermissionCheckNotRequired) {
-    Allow(JS::UndefinedHandleValue);
-    return NS_OK;
-  }
-
-  if (filesystem->PermissionCheckType() == FileSystemBase::ePermissionCheckByTestingPref &&
-      mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) {
-    Allow(JS::UndefinedHandleValue);
-    return NS_OK;
-  }
-
-  if (!mWindow) {
-    Cancel();
-    return NS_OK;
-  }
-
-  nsContentPermissionUtils::AskPermission(this, mWindow);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-FileSystemPermissionRequest::GetRequester(nsIContentPermissionRequester** aRequester)
-{
-  NS_ENSURE_ARG_POINTER(aRequester);
-
-  nsCOMPtr<nsIContentPermissionRequester> requester = mRequester;
-  requester.forget(aRequester);
-  return NS_OK;
-}
-
-void
-FileSystemPermissionRequest::ScheduleTask()
-{
-  PBackgroundInitializer::ScheduleTask(mTask);
-}
-
-} /* namespace dom */
-} /* namespace mozilla */
deleted file mode 100644
--- a/dom/filesystem/FileSystemPermissionRequest.h
+++ /dev/null
@@ -1,57 +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_FileSystemPermissionRequest_h
-#define mozilla_dom_FileSystemPermissionRequest_h
-
-#include "nsIRunnable.h"
-#include "nsIContentPermissionPrompt.h"
-#include "nsString.h"
-
-class nsPIDOMWindowInner;
-
-namespace mozilla {
-namespace dom {
-
-class FileSystemTaskChildBase;
-
-class FileSystemPermissionRequest final
-  : public nsIContentPermissionRequest
-  , public nsIRunnable
-{
-public:
-  // Request permission for the given task.
-  static void
-  RequestForTask(FileSystemTaskChildBase* aTask);
-
-  NS_DECL_THREADSAFE_ISUPPORTS
-  NS_DECL_NSICONTENTPERMISSIONREQUEST
-  NS_DECL_NSIRUNNABLE
-
-private:
-  explicit FileSystemPermissionRequest(FileSystemTaskChildBase* aTask);
-
-  ~FileSystemPermissionRequest();
-
-  // Once the permission check has been done, we must run the task using IPC and
-  // PBackground. This method checks if the PBackground thread is ready to
-  // receive the task and in case waits for ActorCreated() to be called using
-  // the PBackgroundInitializer class (see FileSystemPermissionRequest.cpp).
-  void
-  ScheduleTask();
-
-  nsCString mPermissionType;
-  nsCString mPermissionAccess;
-  RefPtr<FileSystemTaskChildBase> mTask;
-  nsCOMPtr<nsPIDOMWindowInner> mWindow;
-  nsCOMPtr<nsIPrincipal> mPrincipal;
-  nsCOMPtr<nsIContentPermissionRequester> mRequester;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_FileSystemPermissionRequest_h
--- a/dom/filesystem/FileSystemRequestParent.cpp
+++ b/dom/filesystem/FileSystemRequestParent.cpp
@@ -1,19 +1,24 @@
 /* -*- 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 "mozilla/dom/FileSystemRequestParent.h"
+#include "mozilla/dom/PFileSystemParams.h"
 
 #include "GetDirectoryListingTask.h"
 #include "GetFileOrDirectoryTask.h"
 
 #include "mozilla/dom/FileSystemBase.h"
+#include "mozilla/ipc/BackgroundParent.h"
+
+using namespace mozilla::ipc;
 
 namespace mozilla {
 namespace dom {
 
 FileSystemRequestParent::FileSystemRequestParent()
   : mDestroyed(false)
 {
   AssertIsOnBackgroundThread();
@@ -22,17 +27,17 @@ FileSystemRequestParent::FileSystemReque
 FileSystemRequestParent::~FileSystemRequestParent()
 {
   AssertIsOnBackgroundThread();
 }
 
 #define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name)                         \
     case FileSystemParams::TFileSystem##name##Params: {                        \
       const FileSystem##name##Params& p = aParams;                             \
-      mFileSystem = FileSystemBase::DeserializeDOMPath(p.filesystem());        \
+      mFileSystem = new OSFileSystemParent(p.filesystem());                    \
       MOZ_ASSERT(mFileSystem);                                                 \
       mTask = name##TaskParent::Create(mFileSystem, p, this, rv);              \
       if (NS_WARN_IF(rv.Failed())) {                                           \
         rv.SuppressException();                                                \
         return false;                                                          \
       }                                                                        \
       break;                                                                   \
     }
@@ -56,25 +61,16 @@ FileSystemRequestParent::Initialize(cons
     }
   }
 
   if (NS_WARN_IF(!mTask || !mFileSystem)) {
     // Should never reach here.
     return false;
   }
 
-  if (mFileSystem->PermissionCheckType() != FileSystemBase::ePermissionCheckNotRequired) {
-    nsAutoCString access;
-    mTask->GetPermissionAccessType(access);
-
-    mPermissionName = mFileSystem->GetPermission();
-    mPermissionName.Append('-');
-    mPermissionName.Append(access);
-  }
-
   return true;
 }
 
 void
 FileSystemRequestParent::Start()
 {
   MOZ_ASSERT(!mDestroyed);
   MOZ_ASSERT(mFileSystem);
--- a/dom/filesystem/FileSystemRequestParent.h
+++ b/dom/filesystem/FileSystemRequestParent.h
@@ -18,29 +18,16 @@ class FileSystemTaskParentBase;
 
 class FileSystemRequestParent final : public PFileSystemRequestParent
 {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileSystemRequestParent)
 
 public:
   FileSystemRequestParent();
 
-  const nsCString&
-  PermissionName() const
-  {
-    return mPermissionName;
-  }
-
-  FileSystemBase::ePermissionCheckType
-  PermissionCheckType() const
-  {
-    return mFileSystem ? mFileSystem->PermissionCheckType()
-                       : FileSystemBase::eNotSet;
-  }
-
   bool
   Initialize(const FileSystemParams& aParams);
 
   void
   Start();
 
   bool Destroyed() const
   {
@@ -51,17 +38,15 @@ public:
   ActorDestroy(ActorDestroyReason why) override;
 
 private:
   ~FileSystemRequestParent();
 
   RefPtr<FileSystemBase> mFileSystem;
   RefPtr<FileSystemTaskParentBase> mTask;
 
-  nsCString mPermissionName;
-
   bool mDestroyed;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_FileSystemRequestParent_h
--- a/dom/filesystem/FileSystemTaskBase.cpp
+++ b/dom/filesystem/FileSystemTaskBase.cpp
@@ -8,17 +8,19 @@
 
 #include "nsNetCID.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/FileSystemBase.h"
 #include "mozilla/dom/FileSystemRequestParent.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ipc/BlobParent.h"
+#include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/BackgroundParent.h"
+#include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/Unused.h"
 #include "nsProxyRelease.h"
 
 namespace mozilla {
 namespace dom {
 
 namespace {
 
@@ -98,16 +100,18 @@ public:
   }
 
 private:
   RefPtr<FileSystemTaskChildBase> mTask;
 };
 
 } // anonymous namespace
 
+NS_IMPL_ISUPPORTS(FileSystemTaskChildBase, nsIIPCBackgroundChildCreateCallback)
+
 /**
  * FileSystemTaskBase class
  */
 
 FileSystemTaskChildBase::FileSystemTaskChildBase(FileSystemBase* aFileSystem)
   : mErrorValue(NS_OK)
   , mFileSystem(aFileSystem)
 {
@@ -127,16 +131,37 @@ FileSystemTaskChildBase::GetFileSystem()
   return mFileSystem.get();
 }
 
 void
 FileSystemTaskChildBase::Start()
 {
   mFileSystem->AssertIsOnOwningThread();
 
+  mozilla::ipc::PBackgroundChild* actor =
+    mozilla::ipc::BackgroundChild::GetForCurrentThread();
+  if (actor) {
+    ActorCreated(actor);
+  } else {
+    if (NS_WARN_IF(
+        !mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread(this))) {
+      MOZ_CRASH();
+    }
+  }
+}
+
+void
+FileSystemTaskChildBase::ActorFailed()
+{
+  MOZ_CRASH("Failed to create a PBackgroundChild actor!");
+}
+
+void
+FileSystemTaskChildBase::ActorCreated(mozilla::ipc::PBackgroundChild* aActor)
+{
   if (HasError()) {
     // In this case we don't want to use IPC at all.
     RefPtr<ErrorRunnable> runnable = new ErrorRunnable(this);
     DebugOnly<nsresult> rv = NS_DispatchToCurrentThread(runnable);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToCurrentThread failed");
     return;
   }
 
@@ -154,20 +179,17 @@ FileSystemTaskChildBase::Start()
     return;
   }
 
   // Retain a reference so the task object isn't deleted without IPDL's
   // knowledge. The reference will be released by
   // mozilla::ipc::BackgroundChildImpl::DeallocPFileSystemRequestChild.
   NS_ADDREF_THIS();
 
-  // If we are here, PBackground must be up and running, because Start() is
-  // called only by FileSystemPermissionRequest, and that class takes care of
-  // PBackground initialization.
-  PBackgroundChild* actor =
+  mozilla::ipc::PBackgroundChild* actor =
     mozilla::ipc::BackgroundChild::GetForCurrentThread();
   MOZ_ASSERT(actor);
 
   actor->SendPFileSystemRequestConstructor(this, params);
 }
 
 void
 FileSystemTaskChildBase::SetRequestResult(const FileSystemResponseValue& aValue)
--- a/dom/filesystem/FileSystemTaskBase.h
+++ b/dom/filesystem/FileSystemTaskBase.h
@@ -5,128 +5,111 @@
  * 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 "nsIIPCBackgroundChildCreateCallback.h"
 #include "nsThreadUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 class BlobImpl;
 class FileSystemBase;
 class FileSystemParams;
 class PBlobParent;
 
-#define DIRECTORY_READ_PERMISSION "read"
-#define DIRECTORY_WRITE_PERMISSION "write"
-#define DIRECTORY_CREATE_PERMISSION "create"
-
 /*
  * The base class to implement a Task class.
  * The file system operations can only be performed in the parent process. In
  * order to avoid duplicated code, we used PBackground for child-parent and
  * parent-parent communications.
  *
  * 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 any process loading content, while
  * the right block is the call sequence only inside the parent process.
  *
  *       Page
  *        |
  *        | (1)
- *  ______|_______________________     |     __________________________________
- * |      |                       |    |    |                                  |
+ *  ______|_________________________     |    _________________________________
+ * |      |                          |   |   |                                 |
  * |      |                          |   |   |                                 |
  * |      V                          |  IPC  | PBackground thread on           |
  * | [new FileSystemTaskChildBase()] |   |   | the parent process              |
- * |       |                         |   |   |                                 |
- * |       | (2)                     |   |   |                                 |
- * |       V                         |   |   |                                 |
- * | [FileSystemPermissionRequest------------------\                           |
- * |  ::RequestForTask()] <------------------------/                           |
- * |         |                      |    |    |                                |
- * |         | (3)                  |         |                                |
- * |         V                      |   (4)   |                                |
+ * |         |                       |   |   |                                 |
+ * |         | (2)                   |       |                                 |
+ * |         V                       |  (3)  |                                 |
  * |    [GetRequestParams]------------------->[new FileSystemTaskParentBase()] |
  * |                                 |       |          |                      |
- * |                                 |   |   |          | (5)   _____________  |
+ * |                                 |   |   |          | (4)   _____________  |
  * |                                 |   |   |          |      |             | |
  * |                                 |   |   |          |      | I/O Thread  | |
  * |                                 |   |   |          |      |             | |
  * |                                 |   |   |          ---------> [IOWork]  | |
  * |                                 |  IPC  |                 |     |       | |
- * |                                 |   |   |                 |     | (6)   | |
+ * |                                 |   |   |                 |     | (5)   | |
  * |                                 |   |   |          --------------       | |
  * |                                 |   |   |          |      |_____________| |
  * |                                 |   |   |          |                      |
  * |                                 |   |   |          V                      |
  * |                                 |   |   |     [HandleResult]              |
  * |                                 |   |   |          |                      |
- * |                                 |       |          | (7)                  |
- * |                                 |  (8)  |          V                      |
+ * |                                 |       |          | (6)                  |
+ * |                                 |  (7)  |          V                      |
  * |   [SetRequestResult]<---------------------[GetRequestResult]              |
  * |       |                         |       |                                 |
- * |       | (9)                     |   |   |                                 |
+ * |       | (8)                     |   |   |                                 |
  * |       V                         |   |   |                                 |
  * |[HandlerCallback]                |  IPC  |                                 |
  * |_______|_________________________|   |   |_________________________________|
  *         |                             |
  *         V
  *        Page
  *
  * 1. From the process that is handling the request
  * Child/Parent (it can be in any process):
  *   (1) Call FileSystem API from content page with JS. Create a task and run.
  *   The base constructor [FileSystemTaskChildBase()] of the task should be
  *   called.
- *   (2) The FileSystemTaskChildBase object is given to
- *   [FileSystemPermissionRequest::RequestForTask()] that will perform a
- *   permission check step if needed (See ePermissionCheckType enum). The real
- *   operation is done on the parent process but it's hidden by
- *   [nsContentPermissionUtils::AskPermission()]. If the permission check is not
- *   needed or if the page has the right permission, the
- *   FileSystemPermissionRequest will start the task (only once PBackground
- *   actor is fully initialized).
- *   (3) Forward the task to the parent process through the IPC and call
+ *   (2) Forward the task to the parent process through the IPC and call
  *   [GetRequestParams] to prepare the parameters of the IPC.
  * Parent:
- *   (4) The parent process receives IPC and handle it in
+ *   (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 [FileSystemTaskParentBase(aParam, aParent)]
- *   For security reasons, we do an additional permission check if needed. In
- *   the check fails, the child process will be killed.
- *   of the task should be called to set the task as an IPC task.
- *   (5) The task operation will be performed in the member function of [IOWork].
+ *   IPC task.
+ *   (4) The task operation will be performed in the member function of [IOWork].
  *   A I/O  thread will be created to run that function. If error occurs
  *   during the operation, call [SetError] to record the error and then abort.
- *   (6) After finishing the task operation, call [HandleResult] to send the
+ *   (5) After finishing the task operation, call [HandleResult] to send the
  *   result back to the child process though the IPC.
- *   (7) Call [GetRequestResult] request result to prepare the parameters of the
+ *   (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, FileSystemTaskChildBase can handle the error message without
  *   interfering.
  *   Each task only needs to implement its specific success result preparation
  *   function -[GetSuccessRequestResult].
  * Child/Parent:
- *   (8) The process receives IPC and calls [SetRequestResult] to get the
+ *   (7) The 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.
- *   (9) Call [HandlerCallback] to send the task result to the content page.
+ *   (8) Call [HandlerCallback] to send the task result to the content page.
  */
 class FileSystemTaskChildBase : public PFileSystemRequestChild
+                              , public nsIIPCBackgroundChildCreateCallback
 {
 public:
-  NS_INLINE_DECL_REFCOUNTING(FileSystemTaskChildBase)
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
 
   /*
    * Start the task. It will dispatch all the information to the parent process,
    * PBackground thread. This method must be called from the owning thread.
    */
   void
   Start();
 
@@ -136,22 +119,16 @@ public:
    */
   void
   SetError(const nsresult& aErrorCode);
 
   FileSystemBase*
   GetFileSystem() const;
 
   /*
-   * Get the type of permission access required to perform this task.
-   */
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const = 0;
-
-  /*
    * After the task is completed, this function will be called to pass the task
    * result to the content page. This method is called in the owning thread.
    * Override this function to handle the call back to the content page.
    */
   virtual void
   HandlerCallback() = 0;
 
   bool
@@ -254,22 +231,16 @@ public:
   virtual bool
   NeedToGoToMainThread() const;
 
   // This method is called only if NeedToGoToMainThread() returns true.
   // Of course, it runs on the main-thread.
   virtual nsresult
   MainThreadWork();
 
-  /*
-   * Get the type of permission access required to perform this task.
-   */
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const = 0;
-
   bool
   HasError() const { return NS_FAILED(mErrorValue); }
 
   NS_IMETHOD
   Run() override;
 
 private:
   /*
--- a/dom/filesystem/GetDirectoryListingTask.cpp
+++ b/dom/filesystem/GetDirectoryListingTask.cpp
@@ -8,19 +8,21 @@
 
 #include "HTMLSplitOnSpacesTokenizer.h"
 #include "js/Value.h"
 #include "mozilla/dom/FileBlobImpl.h"
 #include "mozilla/dom/FileSystemBase.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/PFileSystemParams.h"
 #include "mozilla/dom/Promise.h"
+#include "mozilla/dom/UnionTypes.h"
 #include "mozilla/dom/ipc/BlobChild.h"
 #include "mozilla/dom/ipc/BlobParent.h"
 #include "nsIFile.h"
+#include "nsISimpleEnumerator.h"
 #include "nsStringGlue.h"
 
 namespace mozilla {
 namespace dom {
 
 /**
  * GetDirectoryListingTaskChild
  */
@@ -171,22 +173,16 @@ GetDirectoryListingTaskChild::HandlerCal
     mPromise = nullptr;
     return;
   }
 
   mPromise->MaybeResolve(mTargetData);
   mPromise = nullptr;
 }
 
-void
-GetDirectoryListingTaskChild::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_READ_PERMISSION);
-}
-
 /**
  * GetDirectoryListingTaskParent
  */
 
 /* static */ already_AddRefed<GetDirectoryListingTaskParent>
 GetDirectoryListingTaskParent::Create(FileSystemBase* aFileSystem,
                                       const FileSystemGetDirectoryListingParams& aParam,
                                       FileSystemRequestParent* aParent,
@@ -379,16 +375,10 @@ GetDirectoryListingTaskParent::IOWork()
 
     if (!mTargetData.AppendElement(element, fallible)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
   return NS_OK;
 }
 
-void
-GetDirectoryListingTaskParent::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_READ_PERMISSION);
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/filesystem/GetDirectoryListingTask.h
+++ b/dom/filesystem/GetDirectoryListingTask.h
@@ -11,16 +11,17 @@
 #include "mozilla/dom/FileSystemTaskBase.h"
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 
 class BlobImpl;
 class FileSystemGetDirectoryListingParams;
+class OwningFileOrDirectory;
 
 class GetDirectoryListingTaskChild final : public FileSystemTaskChildBase
 {
 public:
   static already_AddRefed<GetDirectoryListingTaskChild>
   Create(FileSystemBase* aFileSystem,
          Directory* aDirectory,
          nsIFile* aTargetPath,
@@ -28,19 +29,16 @@ public:
          ErrorResult& aRv);
 
   virtual
   ~GetDirectoryListingTaskChild();
 
   already_AddRefed<Promise>
   GetPromise();
 
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
 private:
   // If aDirectoryOnly is set, we should ensure that the target is a directory.
   GetDirectoryListingTaskChild(FileSystemBase* aFileSystem,
                                Directory* aDirectory,
                                nsIFile* aTargetPath,
                                const nsAString& aFilters);
 
   virtual FileSystemParams
@@ -66,19 +64,16 @@ class GetDirectoryListingTaskParent fina
 {
 public:
   static already_AddRefed<GetDirectoryListingTaskParent>
   Create(FileSystemBase* aFileSystem,
          const FileSystemGetDirectoryListingParams& aParam,
          FileSystemRequestParent* aParent,
          ErrorResult& aRv);
 
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
 private:
   GetDirectoryListingTaskParent(FileSystemBase* aFileSystem,
                                 const FileSystemGetDirectoryListingParams& aParam,
                                 FileSystemRequestParent* aParent);
 
   virtual FileSystemResponseValue
   GetSuccessRequestResult(ErrorResult& aRv) const override;
 
--- a/dom/filesystem/GetFileOrDirectoryTask.cpp
+++ b/dom/filesystem/GetFileOrDirectoryTask.cpp
@@ -149,22 +149,16 @@ GetFileOrDirectoryTaskChild::HandlerCall
   }
 
   MOZ_ASSERT(mResultFile);
   mPromise->MaybeResolve(mResultFile);
   mResultFile = nullptr;
   mPromise = nullptr;
 }
 
-void
-GetFileOrDirectoryTaskChild::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_READ_PERMISSION);
-}
-
 /**
  * GetFileOrDirectoryTaskParent
  */
 
 /* static */ already_AddRefed<GetFileOrDirectoryTaskParent>
 GetFileOrDirectoryTaskParent::Create(FileSystemBase* aFileSystem,
                                      const FileSystemGetFileOrDirectoryParams& aParam,
                                      FileSystemRequestParent* aParent,
@@ -271,16 +265,10 @@ GetFileOrDirectoryTaskParent::IOWork()
 
   if (!mFileSystem->IsSafeFile(mTargetPath)) {
     return NS_ERROR_DOM_SECURITY_ERR;
   }
 
   return NS_OK;
 }
 
-void
-GetFileOrDirectoryTaskParent::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_READ_PERMISSION);
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/filesystem/GetFileOrDirectoryTask.h
+++ b/dom/filesystem/GetFileOrDirectoryTask.h
@@ -26,19 +26,16 @@ public:
          ErrorResult& aRv);
 
   virtual
   ~GetFileOrDirectoryTaskChild();
 
   already_AddRefed<Promise>
   GetPromise();
 
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
 protected:
   virtual FileSystemParams
   GetRequestParams(const nsString& aSerializedDOMPath,
                    ErrorResult& aRv) const override;
 
   virtual void
   SetSuccessRequestResult(const FileSystemResponseValue& aValue,
                           ErrorResult& aRv) override;
@@ -60,19 +57,16 @@ class GetFileOrDirectoryTaskParent final
 {
 public:
   static already_AddRefed<GetFileOrDirectoryTaskParent>
   Create(FileSystemBase* aFileSystem,
          const FileSystemGetFileOrDirectoryParams& aParam,
          FileSystemRequestParent* aParent,
          ErrorResult& aRv);
 
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
 protected:
   virtual FileSystemResponseValue
   GetSuccessRequestResult(ErrorResult& aRv) const override;
 
   virtual nsresult
   IOWork() override;
 
 private:
--- a/dom/filesystem/GetFilesTask.cpp
+++ b/dom/filesystem/GetFilesTask.cpp
@@ -144,22 +144,16 @@ GetFilesTaskChild::HandlerCallback()
     mPromise = nullptr;
     return;
   }
 
   mPromise->MaybeResolve(mTargetData);
   mPromise = nullptr;
 }
 
-void
-GetFilesTaskChild::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral("read");
-}
-
 /**
  * GetFilesTaskParent
  */
 
 /* static */ already_AddRefed<GetFilesTaskParent>
 GetFilesTaskParent::Create(FileSystemBase* aFileSystem,
                            const FileSystemGetFilesParams& aParam,
                            FileSystemRequestParent* aParent,
@@ -254,16 +248,10 @@ GetFilesTaskParent::IOWork()
   rv = ExploreDirectory(mDirectoryDOMPath, mTargetPath);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   return NS_OK;
 }
 
-void
-GetFilesTaskParent::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_READ_PERMISSION);
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/filesystem/GetFilesTask.h
+++ b/dom/filesystem/GetFilesTask.h
@@ -29,19 +29,16 @@ public:
          ErrorResult& aRv);
 
   virtual
   ~GetFilesTaskChild();
 
   already_AddRefed<Promise>
   GetPromise();
 
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
 private:
   // If aDirectoryOnly is set, we should ensure that the target is a directory.
   GetFilesTaskChild(FileSystemBase* aFileSystem,
                     Directory* aDirectory,
                     nsIFile* aTargetPath,
                     bool aRecursiveFlag);
 
   virtual FileSystemParams
@@ -69,19 +66,16 @@ class GetFilesTaskParent final : public 
 {
 public:
   static already_AddRefed<GetFilesTaskParent>
   Create(FileSystemBase* aFileSystem,
          const FileSystemGetFilesParams& aParam,
          FileSystemRequestParent* aParent,
          ErrorResult& aRv);
 
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
 private:
   GetFilesTaskParent(FileSystemBase* aFileSystem,
                      const FileSystemGetFilesParams& aParam,
                      FileSystemRequestParent* aParent);
 
   virtual FileSystemResponseValue
   GetSuccessRequestResult(ErrorResult& aRv) const override;
 
--- a/dom/filesystem/OSFileSystem.cpp
+++ b/dom/filesystem/OSFileSystem.cpp
@@ -14,30 +14,25 @@
 #include "nsDebug.h"
 #include "nsIFile.h"
 
 namespace mozilla {
 namespace dom {
 
 OSFileSystem::OSFileSystem(const nsAString& aRootDir)
 {
-  mLocalOrDeviceStorageRootPath = aRootDir;
-  mPermissionCheckType = ePermissionCheckNotRequired;
-
-#ifdef DEBUG
-  mPermission.AssignLiteral("never-used");
-#endif
+  mLocalRootPath = aRootDir;
 }
 
 already_AddRefed<FileSystemBase>
 OSFileSystem::Clone()
 {
   AssertIsOnOwningThread();
 
-  RefPtr<OSFileSystem> fs = new OSFileSystem(mLocalOrDeviceStorageRootPath);
+  RefPtr<OSFileSystem> fs = new OSFileSystem(mLocalRootPath);
   if (mParent) {
     fs->Init(mParent);
   }
 
   return fs.forget();
 }
 
 void
@@ -97,27 +92,22 @@ OSFileSystem::Traverse(nsCycleCollection
   OSFileSystem* tmp = this;
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent);
 }
 
 void
 OSFileSystem::SerializeDOMPath(nsAString& aOutput) const
 {
   AssertIsOnOwningThread();
-  aOutput = mLocalOrDeviceStorageRootPath;
+  aOutput = mLocalRootPath;
 }
 
 /**
  * OSFileSystemParent
  */
 
 OSFileSystemParent::OSFileSystemParent(const nsAString& aRootDir)
 {
-  mLocalOrDeviceStorageRootPath = aRootDir;
-  mPermissionCheckType = ePermissionCheckNotRequired;
-
-#ifdef DEBUG
-  mPermission.AssignLiteral("never-used");
-#endif
+  mLocalRootPath = aRootDir;
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/filesystem/compat/CallbackRunnables.cpp
+++ b/dom/filesystem/compat/CallbackRunnables.cpp
@@ -15,17 +15,16 @@
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/Unused.h"
 #include "nsIGlobalObject.h"
 #include "nsIFile.h"
 #include "nsPIDOMWindow.h"
 
 #include "../GetFileOrDirectoryTask.h"
-#include "../FileSystemPermissionRequest.h"
 
 namespace mozilla {
 namespace dom {
 
 EntryCallbackRunnable::EntryCallbackRunnable(FileSystemEntryCallback* aCallback,
                                              FileSystemEntry* aEntry)
   : mCallback(aCallback)
   , mEntry(aEntry)
@@ -158,17 +157,18 @@ GetEntryHelper::Run()
     GetFileOrDirectoryTaskChild::Create(fs, realPath, rv);
   if (NS_WARN_IF(rv.Failed())) {
     rv.SuppressException();
     Error(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
   task->SetError(error);
-  FileSystemPermissionRequest::RequestForTask(task);
+  task->Start();
+
   RefPtr<Promise> promise = task->GetPromise();
 
   mParts.RemoveElementAt(0);
   promise->AppendNativeHandler(this);
 }
 
 void
 GetEntryHelper::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
--- a/dom/filesystem/moz.build
+++ b/dom/filesystem/moz.build
@@ -7,31 +7,28 @@
 with Files("**"):
     BUG_COMPONENT = ("Core", "DOM")
 
 DIRS += ['compat']
 
 TEST_DIRS += ['tests']
 
 EXPORTS.mozilla.dom += [
-    'DeviceStorageFileSystem.h',
     'Directory.h',
     'FileSystemBase.h',
     'FileSystemRequestParent.h',
     'FileSystemTaskBase.h',
     'FileSystemUtils.h',
     'GetFilesHelper.h',
     'OSFileSystem.h',
 ]
 
 UNIFIED_SOURCES += [
-    'DeviceStorageFileSystem.cpp',
     'Directory.cpp',
     'FileSystemBase.cpp',
-    'FileSystemPermissionRequest.cpp',
     'FileSystemRequestParent.cpp',
     'FileSystemTaskBase.cpp',
     'FileSystemUtils.cpp',
     'GetDirectoryListingTask.cpp',
     'GetFileOrDirectoryTask.cpp',
     'GetFilesHelper.cpp',
     'GetFilesTask.cpp',
     'OSFileSystem.cpp',
--- a/ipc/glue/BackgroundParentImpl.cpp
+++ b/ipc/glue/BackgroundParentImpl.cpp
@@ -535,91 +535,16 @@ public:
   }
 
 private:
   RefPtr<ContentParent> mContentParent;
   PrincipalInfo mPrincipalInfo;
   nsCString mOrigin;
 };
 
-class CheckPermissionRunnable final : public Runnable
-{
-public:
-  CheckPermissionRunnable(already_AddRefed<ContentParent> aParent,
-                          FileSystemRequestParent* aActor,
-                          FileSystemBase::ePermissionCheckType aPermissionCheckType,
-                          const nsCString& aPermissionName)
-    : mContentParent(aParent)
-    , mActor(aActor)
-    , mPermissionCheckType(aPermissionCheckType)
-    , mPermissionName(aPermissionName)
-    , mBackgroundEventTarget(NS_GetCurrentThread())
-  {
-    AssertIsInMainProcess();
-    AssertIsOnBackgroundThread();
-
-    MOZ_ASSERT(mContentParent);
-    MOZ_ASSERT(mBackgroundEventTarget);
-    MOZ_ASSERT(mPermissionCheckType == FileSystemBase::ePermissionCheckRequired ||
-               mPermissionCheckType == FileSystemBase::ePermissionCheckByTestingPref);
-  }
-
-  NS_IMETHOD
-  Run() override
-  {
-    if (NS_IsMainThread()) {
-      NullifyContentParentRAII raii(mContentParent);
-
-      // If the permission is granted, we go back to the background thread to
-      // dispatch this task.
-      if (CheckPermission()) {
-        return mBackgroundEventTarget->Dispatch(this, NS_DISPATCH_NORMAL);
-      }
-
-      return NS_OK;
-    }
-
-    AssertIsOnBackgroundThread();
-
-    // It can happen that this actor has been destroyed in the meantime we were
-    // on the main-thread.
-    if (!mActor->Destroyed()) {
-      mActor->Start();
-    }
-
-    return NS_OK;
-  }
-
-private:
-  ~CheckPermissionRunnable() override
-  {
-     NS_ProxyRelease(mBackgroundEventTarget, mActor.forget());
-  }
-
-  bool
-  CheckPermission()
-  {
-    if (mPermissionCheckType == FileSystemBase::ePermissionCheckByTestingPref &&
-        mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) {
-      return true;
-    }
-
-    return true;
-  }
-
-  RefPtr<ContentParent> mContentParent;
-
-  RefPtr<FileSystemRequestParent> mActor;
-
-  FileSystemBase::ePermissionCheckType mPermissionCheckType;
-  nsCString mPermissionName;
-
-  nsCOMPtr<nsIEventTarget> mBackgroundEventTarget;
-};
-
 } // namespace
 
 mozilla::ipc::IPCResult
 BackgroundParentImpl::RecvPBroadcastChannelConstructor(
                                             PBroadcastChannelParent* actor,
                                             const PrincipalInfo& aPrincipalInfo,
                                             const nsCString& aOrigin,
                                             const nsString& aChannel)
@@ -841,56 +766,19 @@ BackgroundParentImpl::AllocPFileSystemRe
   AssertIsOnBackgroundThread();
 
   RefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
 
   if (NS_WARN_IF(!result->Initialize(aParams))) {
     return nullptr;
   }
 
-  return result.forget().take();
-}
-
-mozilla::ipc::IPCResult
-BackgroundParentImpl::RecvPFileSystemRequestConstructor(
-                                               PFileSystemRequestParent* aActor,
-                                               const FileSystemParams& aParams)
-{
-  AssertIsInMainProcess();
-  AssertIsOnBackgroundThread();
-
-  RefPtr<FileSystemRequestParent> actor = static_cast<FileSystemRequestParent*>(aActor);
-
-  if (actor->PermissionCheckType() == FileSystemBase::ePermissionCheckNotRequired) {
-    actor->Start();
-    return IPC_OK();
-  }
-
-  RefPtr<ContentParent> parent = BackgroundParent::GetContentParent(this);
+  result->Start();
 
-  // If the ContentParent is null we are dealing with a same-process actor.
-  if (!parent) {
-    actor->Start();
-    return IPC_OK();
-  }
-
-  const nsCString& permissionName = actor->PermissionName();
-  MOZ_ASSERT(!permissionName.IsEmpty());
-
-  // At this point we should have the right permission but we do the last check
-  // with this runnable. If the app doesn't have the permission, we kill the
-  // child process.
-  RefPtr<CheckPermissionRunnable> runnable =
-    new CheckPermissionRunnable(parent.forget(), actor,
-                                actor->PermissionCheckType(), permissionName);
-
-  nsresult rv = NS_DispatchToMainThread(runnable);
-  MOZ_ALWAYS_TRUE(NS_SUCCEEDED(rv));
-
-  return IPC_OK();
+  return result.forget().take();
 }
 
 bool
 BackgroundParentImpl::DeallocPFileSystemRequestParent(
                                               PFileSystemRequestParent* aDoomed)
 {
   AssertIsInMainProcess();
   AssertIsOnBackgroundThread();
--- a/ipc/glue/BackgroundParentImpl.h
+++ b/ipc/glue/BackgroundParentImpl.h
@@ -182,20 +182,16 @@ protected:
   AllocPQuotaParent() override;
 
   virtual bool
   DeallocPQuotaParent(PQuotaParent* aActor) override;
 
   virtual PFileSystemRequestParent*
   AllocPFileSystemRequestParent(const FileSystemParams&) override;
 
-  virtual mozilla::ipc::IPCResult
-  RecvPFileSystemRequestConstructor(PFileSystemRequestParent* aActor,
-                                    const FileSystemParams& aParams) override;
-
   virtual bool
   DeallocPFileSystemRequestParent(PFileSystemRequestParent*) override;
 
   // Gamepad API Background IPC
   virtual PGamepadEventChannelParent*
   AllocPGamepadEventChannelParent() override;
 
   virtual bool