/src/mozilla-central/dom/file/ipc/IPCBlobInputStreamParent.h
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 | | #ifndef mozilla_dom_ipc_IPCBlobInputStreamParent_h |
8 | | #define mozilla_dom_ipc_IPCBlobInputStreamParent_h |
9 | | |
10 | | #include "mozilla/ipc/PIPCBlobInputStreamParent.h" |
11 | | |
12 | | class nsIInputStream; |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | class NS_NO_VTABLE IPCBlobInputStreamParentCallback |
18 | | { |
19 | | public: |
20 | | virtual void |
21 | | ActorDestroyed(const nsID& aID) = 0; |
22 | | |
23 | | NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING |
24 | | |
25 | | protected: |
26 | | virtual ~IPCBlobInputStreamParentCallback() |
27 | | { } |
28 | | }; |
29 | | |
30 | | class IPCBlobInputStreamParent final |
31 | | : public mozilla::ipc::PIPCBlobInputStreamParent |
32 | | { |
33 | | public: |
34 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IPCBlobInputStreamParent) |
35 | | |
36 | | // The size of the inputStream must be passed as argument in order to avoid |
37 | | // the use of nsIInputStream::Available() which could open a fileDescriptor in |
38 | | // case the stream is a nsFileStream. |
39 | | template<typename M> |
40 | | static already_AddRefed<IPCBlobInputStreamParent> |
41 | | Create(nsIInputStream* aInputStream, uint64_t aSize, |
42 | | uint64_t aChildID, nsresult* aRv, M* aManager); |
43 | | |
44 | | static already_AddRefed<IPCBlobInputStreamParent> |
45 | | Create(const nsID& aID, uint64_t aSize, |
46 | | mozilla::ipc::PBackgroundParent* aManager); |
47 | | |
48 | | void |
49 | | ActorDestroy(IProtocol::ActorDestroyReason aReason) override; |
50 | | |
51 | | const nsID& |
52 | | ID() const |
53 | 0 | { |
54 | 0 | return mID; |
55 | 0 | } |
56 | | |
57 | | uint64_t |
58 | | Size() const |
59 | 0 | { |
60 | 0 | return mSize; |
61 | 0 | } |
62 | | |
63 | | void |
64 | | SetCallback(IPCBlobInputStreamParentCallback* aCallback); |
65 | | |
66 | | mozilla::ipc::IPCResult |
67 | | RecvStreamNeeded() override; |
68 | | |
69 | | mozilla::ipc::IPCResult |
70 | | RecvLengthNeeded() override; |
71 | | |
72 | | mozilla::ipc::IPCResult |
73 | | RecvClose() override; |
74 | | |
75 | | mozilla::ipc::IPCResult |
76 | | Recv__delete__() override; |
77 | | |
78 | | bool |
79 | | HasValidStream() const; |
80 | | |
81 | | private: |
82 | | IPCBlobInputStreamParent(const nsID& aID, uint64_t aSize, |
83 | | nsIContentParent* aManager); |
84 | | |
85 | | IPCBlobInputStreamParent(const nsID& aID, uint64_t aSize, |
86 | | mozilla::ipc::PBackgroundParent* aManager); |
87 | | |
88 | 0 | ~IPCBlobInputStreamParent() = default; |
89 | | |
90 | | const nsID mID; |
91 | | const uint64_t mSize; |
92 | | |
93 | | // Only 1 of these 2 is set. Raw pointer because these 2 managers are keeping |
94 | | // the parent actor alive. The pointers will be nullified in ActorDestroyed. |
95 | | nsIContentParent* mContentManager; |
96 | | mozilla::ipc::PBackgroundParent* mPBackgroundManager; |
97 | | |
98 | | RefPtr<IPCBlobInputStreamParentCallback> mCallback; |
99 | | |
100 | | bool mMigrating; |
101 | | }; |
102 | | |
103 | | } // namespace dom |
104 | | } // namespace mozilla |
105 | | |
106 | | #endif // mozilla_dom_ipc_IPCBlobInputStreamParent_h |