/work/obj-fuzz/dist/include/mozilla/plugins/BrowserStreamChild.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef mozilla_plugins_BrowserStreamChild_h |
7 | | #define mozilla_plugins_BrowserStreamChild_h 1 |
8 | | |
9 | | #include "mozilla/plugins/PBrowserStreamChild.h" |
10 | | #include "mozilla/plugins/AStream.h" |
11 | | #include "base/task.h" |
12 | | #include "base/timer.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace plugins { |
16 | | |
17 | | class PluginInstanceChild; |
18 | | class StreamNotifyChild; |
19 | | |
20 | | class BrowserStreamChild : public PBrowserStreamChild, public AStream |
21 | | { |
22 | | public: |
23 | | BrowserStreamChild(PluginInstanceChild* instance, |
24 | | const nsCString& url, |
25 | | const uint32_t& length, |
26 | | const uint32_t& lastmodified, |
27 | | StreamNotifyChild* notifyData, |
28 | | const nsCString& headers); |
29 | | virtual ~BrowserStreamChild(); |
30 | | |
31 | 0 | virtual bool IsBrowserStream() override { return true; } |
32 | | |
33 | | NPError StreamConstructed( |
34 | | const nsCString& mimeType, |
35 | | const bool& seekable, |
36 | | uint16_t* stype); |
37 | | |
38 | | virtual mozilla::ipc::IPCResult RecvWrite(const int32_t& offset, |
39 | | const uint32_t& newsize, |
40 | | const Buffer& data) override; |
41 | | virtual mozilla::ipc::IPCResult RecvNPP_DestroyStream(const NPReason& reason) override; |
42 | | virtual mozilla::ipc::IPCResult Recv__delete__() override; |
43 | | |
44 | | void EnsureCorrectInstance(PluginInstanceChild* i) |
45 | | { |
46 | | if (i != mInstance) |
47 | | MOZ_CRASH("Incorrect stream instance"); |
48 | | } |
49 | | void EnsureCorrectStream(NPStream* s) |
50 | | { |
51 | | if (s != &mStream) |
52 | | MOZ_CRASH("Incorrect stream data"); |
53 | | } |
54 | | |
55 | | void NotifyPending() { |
56 | | NS_ASSERTION(!mNotifyPending, "Pending twice?"); |
57 | | mNotifyPending = true; |
58 | | EnsureDeliveryPending(); |
59 | | } |
60 | | |
61 | | /** |
62 | | * During instance destruction, artificially cancel all outstanding streams. |
63 | | * |
64 | | * @return false if we are already in the DELETING state. |
65 | | */ |
66 | | bool InstanceDying() { |
67 | | if (DELETING == mState) |
68 | | return false; |
69 | | |
70 | | mInstanceDying = true; |
71 | | return true; |
72 | | } |
73 | | |
74 | | void FinishDelivery() { |
75 | | NS_ASSERTION(mInstanceDying, "Should only be called after InstanceDying"); |
76 | | NS_ASSERTION(DELETING != mState, "InstanceDying didn't work?"); |
77 | | mStreamStatus = NPRES_USER_BREAK; |
78 | | Deliver(); |
79 | | NS_ASSERTION(!mStreamNotify, "Didn't deliver NPN_URLNotify?"); |
80 | | } |
81 | | |
82 | | private: |
83 | | friend class StreamNotifyChild; |
84 | | |
85 | | /** |
86 | | * Post an event to ensure delivery of pending data/destroy/urlnotify events |
87 | | * outside of the current RPC stack. |
88 | | */ |
89 | | void EnsureDeliveryPending(); |
90 | | |
91 | | /** |
92 | | * Deliver data, destruction, notify scheduling |
93 | | * or cancelling the suspended timer as needed. |
94 | | */ |
95 | | void Deliver(); |
96 | | |
97 | | /** |
98 | | * Deliver one chunk of pending data. |
99 | | * @return true if the plugin indicated a pause was necessary |
100 | | */ |
101 | | bool DeliverPendingData(); |
102 | | |
103 | | void SetSuspendedTimer(); |
104 | | void ClearSuspendedTimer(); |
105 | | |
106 | | PluginInstanceChild* mInstance; |
107 | | NPStream mStream; |
108 | | |
109 | | static const NPReason kStreamOpen = -1; |
110 | | |
111 | | /** |
112 | | * The plugin's notion of whether a stream has been "closed" (no more |
113 | | * data delivery) differs from the plugin host due to asynchronous delivery |
114 | | * of data and stream destruction. While the plugin-visible stream is open, |
115 | | * mStreamStatus should be kStreamOpen (-1). mStreamStatus will be a |
116 | | * failure code if either the parent or child indicates stream failure. |
117 | | */ |
118 | | NPReason mStreamStatus; |
119 | | |
120 | | /** |
121 | | * Delivery of NPP_DestroyStream and NPP_URLNotify must be postponed until |
122 | | * all data has been delivered. |
123 | | */ |
124 | | enum { |
125 | | NOT_DESTROYED, // NPP_DestroyStream not yet received |
126 | | DESTROY_PENDING, // NPP_DestroyStream received, not yet delivered |
127 | | DESTROYED // NPP_DestroyStream delivered, NPP_URLNotify may still be pending |
128 | | } mDestroyPending; |
129 | | bool mNotifyPending; |
130 | | |
131 | | // When NPP_Destroy is called for our instance (manager), this flag is set |
132 | | // cancels the stream and avoids sending StreamDestroyed. |
133 | | bool mInstanceDying; |
134 | | |
135 | | enum { |
136 | | CONSTRUCTING, |
137 | | ALIVE, |
138 | | DYING, |
139 | | DELETING |
140 | | } mState; |
141 | | nsCString mURL; |
142 | | nsCString mHeaders; |
143 | | StreamNotifyChild* mStreamNotify; |
144 | | |
145 | | struct PendingData |
146 | | { |
147 | | int32_t offset; |
148 | | Buffer data; |
149 | | int32_t curpos; |
150 | | }; |
151 | | nsTArray<PendingData> mPendingData; |
152 | | |
153 | | /** |
154 | | * Asynchronous RecvWrite messages are never delivered to the plugin |
155 | | * immediately, because that may be in the midst of an unexpected RPC |
156 | | * stack frame. It instead posts a runnable using this tracker to cancel |
157 | | * in case we are destroyed. |
158 | | */ |
159 | | ScopedRunnableMethodFactory<BrowserStreamChild> mDeliveryTracker; |
160 | | base::RepeatingTimer<BrowserStreamChild> mSuspendedTimer; |
161 | | }; |
162 | | |
163 | | } // namespace plugins |
164 | | } // namespace mozilla |
165 | | |
166 | | #endif /* mozilla_plugins_BrowserStreamChild_h */ |