|
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" |
|
7 |
|
8 #include "CreateDirectoryTask.h" |
|
9 #include "CreateFileTask.h" |
|
10 #include "GetFileOrDirectoryTask.h" |
|
11 #include "RemoveTask.h" |
|
12 |
|
13 #include "mozilla/AppProcessChecker.h" |
|
14 #include "mozilla/dom/FileSystemBase.h" |
|
15 |
|
16 namespace mozilla { |
|
17 namespace dom { |
|
18 |
|
19 FileSystemRequestParent::FileSystemRequestParent() |
|
20 { |
|
21 } |
|
22 |
|
23 FileSystemRequestParent::~FileSystemRequestParent() |
|
24 { |
|
25 } |
|
26 |
|
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 } |
|
34 |
|
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()) { |
|
42 |
|
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) |
|
47 |
|
48 default: { |
|
49 NS_RUNTIMEABORT("not reached"); |
|
50 break; |
|
51 } |
|
52 } |
|
53 |
|
54 if (NS_WARN_IF(!task || !mFileSystem)) { |
|
55 // Should never reach here. |
|
56 return false; |
|
57 } |
|
58 |
|
59 if (!mFileSystem->IsTesting()) { |
|
60 // Check the content process permission. |
|
61 |
|
62 nsCString access; |
|
63 task->GetPermissionAccessType(access); |
|
64 |
|
65 nsAutoCString permissionName; |
|
66 permissionName = mFileSystem->GetPermission(); |
|
67 permissionName.AppendLiteral("-"); |
|
68 permissionName.Append(access); |
|
69 |
|
70 if (!AssertAppProcessPermission(aParent, permissionName.get())) { |
|
71 return false; |
|
72 } |
|
73 } |
|
74 |
|
75 task->Start(); |
|
76 return true; |
|
77 } |
|
78 |
|
79 void |
|
80 FileSystemRequestParent::ActorDestroy(ActorDestroyReason why) |
|
81 { |
|
82 if (!mFileSystem) { |
|
83 return; |
|
84 } |
|
85 mFileSystem->Shutdown(); |
|
86 mFileSystem = nullptr; |
|
87 } |
|
88 |
|
89 } // namespace dom |
|
90 } // namespace mozilla |