Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | #include "mozilla/dom/FileSystemRequestParent.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "CreateDirectoryTask.h" |
michael@0 | 9 | #include "CreateFileTask.h" |
michael@0 | 10 | #include "GetFileOrDirectoryTask.h" |
michael@0 | 11 | #include "RemoveTask.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "mozilla/AppProcessChecker.h" |
michael@0 | 14 | #include "mozilla/dom/FileSystemBase.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace dom { |
michael@0 | 18 | |
michael@0 | 19 | FileSystemRequestParent::FileSystemRequestParent() |
michael@0 | 20 | { |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | FileSystemRequestParent::~FileSystemRequestParent() |
michael@0 | 24 | { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | #define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name) \ |
michael@0 | 28 | case FileSystemParams::TFileSystem##name##Params: { \ |
michael@0 | 29 | const FileSystem##name##Params& p = aParams; \ |
michael@0 | 30 | mFileSystem = FileSystemBase::FromString(p.filesystem()); \ |
michael@0 | 31 | task = new name##Task(mFileSystem, p, this); \ |
michael@0 | 32 | break; \ |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | bool |
michael@0 | 36 | FileSystemRequestParent::Dispatch(ContentParent* aParent, |
michael@0 | 37 | const FileSystemParams& aParams) |
michael@0 | 38 | { |
michael@0 | 39 | MOZ_ASSERT(aParent, "aParent should not be null."); |
michael@0 | 40 | nsRefPtr<FileSystemTaskBase> task; |
michael@0 | 41 | switch (aParams.type()) { |
michael@0 | 42 | |
michael@0 | 43 | FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory) |
michael@0 | 44 | FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateFile) |
michael@0 | 45 | FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory) |
michael@0 | 46 | FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(Remove) |
michael@0 | 47 | |
michael@0 | 48 | default: { |
michael@0 | 49 | NS_RUNTIMEABORT("not reached"); |
michael@0 | 50 | break; |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | if (NS_WARN_IF(!task || !mFileSystem)) { |
michael@0 | 55 | // Should never reach here. |
michael@0 | 56 | return false; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | if (!mFileSystem->IsTesting()) { |
michael@0 | 60 | // Check the content process permission. |
michael@0 | 61 | |
michael@0 | 62 | nsCString access; |
michael@0 | 63 | task->GetPermissionAccessType(access); |
michael@0 | 64 | |
michael@0 | 65 | nsAutoCString permissionName; |
michael@0 | 66 | permissionName = mFileSystem->GetPermission(); |
michael@0 | 67 | permissionName.AppendLiteral("-"); |
michael@0 | 68 | permissionName.Append(access); |
michael@0 | 69 | |
michael@0 | 70 | if (!AssertAppProcessPermission(aParent, permissionName.get())) { |
michael@0 | 71 | return false; |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | task->Start(); |
michael@0 | 76 | return true; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void |
michael@0 | 80 | FileSystemRequestParent::ActorDestroy(ActorDestroyReason why) |
michael@0 | 81 | { |
michael@0 | 82 | if (!mFileSystem) { |
michael@0 | 83 | return; |
michael@0 | 84 | } |
michael@0 | 85 | mFileSystem->Shutdown(); |
michael@0 | 86 | mFileSystem = nullptr; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | } // namespace dom |
michael@0 | 90 | } // namespace mozilla |