1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/filesystem/FileSystemRequestParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#include "mozilla/dom/FileSystemRequestParent.h" 1.10 + 1.11 +#include "CreateDirectoryTask.h" 1.12 +#include "CreateFileTask.h" 1.13 +#include "GetFileOrDirectoryTask.h" 1.14 +#include "RemoveTask.h" 1.15 + 1.16 +#include "mozilla/AppProcessChecker.h" 1.17 +#include "mozilla/dom/FileSystemBase.h" 1.18 + 1.19 +namespace mozilla { 1.20 +namespace dom { 1.21 + 1.22 +FileSystemRequestParent::FileSystemRequestParent() 1.23 +{ 1.24 +} 1.25 + 1.26 +FileSystemRequestParent::~FileSystemRequestParent() 1.27 +{ 1.28 +} 1.29 + 1.30 +#define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name) \ 1.31 + case FileSystemParams::TFileSystem##name##Params: { \ 1.32 + const FileSystem##name##Params& p = aParams; \ 1.33 + mFileSystem = FileSystemBase::FromString(p.filesystem()); \ 1.34 + task = new name##Task(mFileSystem, p, this); \ 1.35 + break; \ 1.36 + } 1.37 + 1.38 +bool 1.39 +FileSystemRequestParent::Dispatch(ContentParent* aParent, 1.40 + const FileSystemParams& aParams) 1.41 +{ 1.42 + MOZ_ASSERT(aParent, "aParent should not be null."); 1.43 + nsRefPtr<FileSystemTaskBase> task; 1.44 + switch (aParams.type()) { 1.45 + 1.46 + FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory) 1.47 + FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateFile) 1.48 + FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory) 1.49 + FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(Remove) 1.50 + 1.51 + default: { 1.52 + NS_RUNTIMEABORT("not reached"); 1.53 + break; 1.54 + } 1.55 + } 1.56 + 1.57 + if (NS_WARN_IF(!task || !mFileSystem)) { 1.58 + // Should never reach here. 1.59 + return false; 1.60 + } 1.61 + 1.62 + if (!mFileSystem->IsTesting()) { 1.63 + // Check the content process permission. 1.64 + 1.65 + nsCString access; 1.66 + task->GetPermissionAccessType(access); 1.67 + 1.68 + nsAutoCString permissionName; 1.69 + permissionName = mFileSystem->GetPermission(); 1.70 + permissionName.AppendLiteral("-"); 1.71 + permissionName.Append(access); 1.72 + 1.73 + if (!AssertAppProcessPermission(aParent, permissionName.get())) { 1.74 + return false; 1.75 + } 1.76 + } 1.77 + 1.78 + task->Start(); 1.79 + return true; 1.80 +} 1.81 + 1.82 +void 1.83 +FileSystemRequestParent::ActorDestroy(ActorDestroyReason why) 1.84 +{ 1.85 + if (!mFileSystem) { 1.86 + return; 1.87 + } 1.88 + mFileSystem->Shutdown(); 1.89 + mFileSystem = nullptr; 1.90 +} 1.91 + 1.92 +} // namespace dom 1.93 +} // namespace mozilla