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