/src/mozilla-central/dom/file/ipc/TemporaryIPCBlobChild.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
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 | | |
7 | | #include "TemporaryIPCBlobChild.h" |
8 | | #include "mozilla/dom/MutableBlobStorage.h" |
9 | | #include <private/pprio.h> |
10 | | |
11 | | namespace mozilla { |
12 | | namespace dom { |
13 | | |
14 | | TemporaryIPCBlobChild::TemporaryIPCBlobChild(MutableBlobStorage* aStorage) |
15 | | : mMutableBlobStorage(aStorage) |
16 | | , mActive(true) |
17 | 0 | { |
18 | 0 | MOZ_ASSERT(aStorage); |
19 | 0 | } |
20 | | |
21 | | TemporaryIPCBlobChild::~TemporaryIPCBlobChild() |
22 | 0 | {} |
23 | | |
24 | | mozilla::ipc::IPCResult |
25 | | TemporaryIPCBlobChild::RecvFileDesc(const FileDescriptor& aFD) |
26 | 0 | { |
27 | 0 | MOZ_ASSERT(mActive); |
28 | 0 |
|
29 | 0 | auto rawFD = aFD.ClonePlatformHandle(); |
30 | 0 | PRFileDesc* prfile = PR_ImportFile(PROsfd(rawFD.release())); |
31 | 0 |
|
32 | 0 | mMutableBlobStorage->TemporaryFileCreated(prfile); |
33 | 0 | mMutableBlobStorage = nullptr; |
34 | 0 | return IPC_OK(); |
35 | 0 | } |
36 | | |
37 | | mozilla::ipc::IPCResult |
38 | | TemporaryIPCBlobChild::Recv__delete__(const IPCBlobOrError& aData) |
39 | 0 | { |
40 | 0 | mActive = false; |
41 | 0 | mMutableBlobStorage = nullptr; |
42 | 0 |
|
43 | 0 | if (aData.type() == IPCBlobOrError::TIPCBlob) { |
44 | 0 | // This must be always deserialized. |
45 | 0 | RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(aData.get_IPCBlob()); |
46 | 0 | MOZ_ASSERT(blobImpl); |
47 | 0 |
|
48 | 0 | if (mCallback) { |
49 | 0 | mCallback->OperationSucceeded(blobImpl); |
50 | 0 | } |
51 | 0 | } else if(mCallback) { |
52 | 0 | MOZ_ASSERT(aData.type() == IPCBlobOrError::Tnsresult); |
53 | 0 | mCallback->OperationFailed(aData.get_nsresult()); |
54 | 0 | } |
55 | 0 |
|
56 | 0 | mCallback = nullptr; |
57 | 0 |
|
58 | 0 | return IPC_OK(); |
59 | 0 | } |
60 | | |
61 | | void |
62 | | TemporaryIPCBlobChild::ActorDestroy(ActorDestroyReason aWhy) |
63 | 0 | { |
64 | 0 | mActive = false; |
65 | 0 | mMutableBlobStorage = nullptr; |
66 | 0 |
|
67 | 0 | if (mCallback) { |
68 | 0 | mCallback->OperationFailed(NS_ERROR_FAILURE); |
69 | 0 | mCallback = nullptr; |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | void |
74 | | TemporaryIPCBlobChild::AskForBlob(TemporaryIPCBlobChildCallback* aCallback, |
75 | | const nsACString& aContentType, |
76 | | PRFileDesc* aFD) |
77 | 0 | { |
78 | 0 | MOZ_ASSERT(aCallback); |
79 | 0 | MOZ_ASSERT(!mCallback); |
80 | 0 |
|
81 | 0 | if (!mActive) { |
82 | 0 | aCallback->OperationFailed(NS_ERROR_FAILURE); |
83 | 0 | return; |
84 | 0 | } |
85 | 0 | |
86 | 0 | FileDescriptor fdd = |
87 | 0 | FileDescriptor(FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(aFD))); |
88 | 0 |
|
89 | 0 | mCallback = aCallback; |
90 | 0 | SendOperationDone(nsCString(aContentType), fdd); |
91 | 0 | } |
92 | | |
93 | | } // dom namespace |
94 | | } // mozilla namespace |