2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 03:25:40 +00:00
|
|
|
/* 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"
|
2014-03-05 08:40:48 +00:00
|
|
|
#include "CreateFileTask.h"
|
2015-06-22 23:31:32 +00:00
|
|
|
#include "GetDirectoryListingTask.h"
|
2014-03-05 03:25:40 +00:00
|
|
|
#include "GetFileOrDirectoryTask.h"
|
2014-03-12 06:30:21 +00:00
|
|
|
#include "RemoveTask.h"
|
2014-03-05 03:25:40 +00:00
|
|
|
|
2014-03-05 03:24:19 +00:00
|
|
|
#include "mozilla/AppProcessChecker.h"
|
2014-03-05 03:25:40 +00:00
|
|
|
#include "mozilla/dom/FileSystemBase.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
FileSystemRequestParent::FileSystemRequestParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSystemRequestParent::~FileSystemRequestParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name) \
|
|
|
|
case FileSystemParams::TFileSystem##name##Params: { \
|
|
|
|
const FileSystem##name##Params& p = aParams; \
|
|
|
|
mFileSystem = FileSystemBase::FromString(p.filesystem()); \
|
|
|
|
task = new name##Task(mFileSystem, p, this); \
|
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FileSystemRequestParent::Dispatch(ContentParent* aParent,
|
|
|
|
const FileSystemParams& aParams)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aParent, "aParent should not be null.");
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<FileSystemTaskBase> task;
|
2014-03-05 03:25:40 +00:00
|
|
|
switch (aParams.type()) {
|
|
|
|
|
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory)
|
2014-03-05 08:40:48 +00:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateFile)
|
2015-06-22 23:31:32 +00:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetDirectoryListing)
|
2014-03-05 03:25:40 +00:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory)
|
2014-03-12 06:30:21 +00:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(Remove)
|
2014-03-05 03:25:40 +00:00
|
|
|
|
|
|
|
default: {
|
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!task || !mFileSystem)) {
|
|
|
|
// Should never reach here.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-10 17:54:26 +00:00
|
|
|
if (mFileSystem->RequiresPermissionChecks()) {
|
2014-03-05 03:24:19 +00:00
|
|
|
// Check the content process permission.
|
|
|
|
|
|
|
|
nsCString access;
|
|
|
|
task->GetPermissionAccessType(access);
|
|
|
|
|
|
|
|
nsAutoCString permissionName;
|
|
|
|
permissionName = mFileSystem->GetPermission();
|
2014-05-22 03:48:51 +00:00
|
|
|
permissionName.Append('-');
|
2014-03-05 03:24:19 +00:00
|
|
|
permissionName.Append(access);
|
|
|
|
|
|
|
|
if (!AssertAppProcessPermission(aParent, permissionName.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
task->Start();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FileSystemRequestParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
if (!mFileSystem) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mFileSystem->Shutdown();
|
|
|
|
mFileSystem = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|