|
1 |
|
2 /* vim: set sw=2 ts=8 et tw=80 : */ |
|
3 |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include "necko-config.h" |
|
9 #include "nsHttp.h" |
|
10 #include "mozilla/net/NeckoChild.h" |
|
11 #include "mozilla/dom/ContentChild.h" |
|
12 #include "mozilla/net/HttpChannelChild.h" |
|
13 #include "mozilla/net/CookieServiceChild.h" |
|
14 #include "mozilla/net/WyciwygChannelChild.h" |
|
15 #include "mozilla/net/FTPChannelChild.h" |
|
16 #include "mozilla/net/WebSocketChannelChild.h" |
|
17 #include "mozilla/net/DNSRequestChild.h" |
|
18 #include "mozilla/net/RemoteOpenFileChild.h" |
|
19 #include "mozilla/net/ChannelDiverterChild.h" |
|
20 #include "mozilla/dom/network/TCPSocketChild.h" |
|
21 #include "mozilla/dom/network/TCPServerSocketChild.h" |
|
22 #include "mozilla/dom/network/UDPSocketChild.h" |
|
23 #ifdef NECKO_PROTOCOL_rtsp |
|
24 #include "mozilla/net/RtspControllerChild.h" |
|
25 #include "mozilla/net/RtspChannelChild.h" |
|
26 #endif |
|
27 #include "SerializedLoadContext.h" |
|
28 |
|
29 using mozilla::dom::TCPSocketChild; |
|
30 using mozilla::dom::TCPServerSocketChild; |
|
31 using mozilla::dom::UDPSocketChild; |
|
32 |
|
33 namespace mozilla { |
|
34 namespace net { |
|
35 |
|
36 PNeckoChild *gNeckoChild = nullptr; |
|
37 |
|
38 // C++ file contents |
|
39 NeckoChild::NeckoChild() |
|
40 { |
|
41 } |
|
42 |
|
43 NeckoChild::~NeckoChild() |
|
44 { |
|
45 } |
|
46 |
|
47 void NeckoChild::InitNeckoChild() |
|
48 { |
|
49 NS_ABORT_IF_FALSE(IsNeckoChild(), "InitNeckoChild called by non-child!"); |
|
50 |
|
51 if (!gNeckoChild) { |
|
52 mozilla::dom::ContentChild * cpc = |
|
53 mozilla::dom::ContentChild::GetSingleton(); |
|
54 NS_ASSERTION(cpc, "Content Protocol is NULL!"); |
|
55 gNeckoChild = cpc->SendPNeckoConstructor(); |
|
56 NS_ASSERTION(gNeckoChild, "PNecko Protocol init failed!"); |
|
57 } |
|
58 } |
|
59 |
|
60 // Note: not actually called; has some lifespan as child process, so |
|
61 // automatically destroyed at exit. |
|
62 void NeckoChild::DestroyNeckoChild() |
|
63 { |
|
64 NS_ABORT_IF_FALSE(IsNeckoChild(), "DestroyNeckoChild called by non-child!"); |
|
65 static bool alreadyDestroyed = false; |
|
66 NS_ABORT_IF_FALSE(!alreadyDestroyed, "DestroyNeckoChild already called!"); |
|
67 |
|
68 if (!alreadyDestroyed) { |
|
69 Send__delete__(gNeckoChild); |
|
70 gNeckoChild = nullptr; |
|
71 alreadyDestroyed = true; |
|
72 } |
|
73 } |
|
74 |
|
75 PHttpChannelChild* |
|
76 NeckoChild::AllocPHttpChannelChild(PBrowserChild* browser, |
|
77 const SerializedLoadContext& loadContext, |
|
78 const HttpChannelCreationArgs& aOpenArgs) |
|
79 { |
|
80 // We don't allocate here: instead we always use IPDL constructor that takes |
|
81 // an existing HttpChildChannel |
|
82 NS_NOTREACHED("AllocPHttpChannelChild should not be called on child"); |
|
83 return nullptr; |
|
84 } |
|
85 |
|
86 bool |
|
87 NeckoChild::DeallocPHttpChannelChild(PHttpChannelChild* channel) |
|
88 { |
|
89 NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPHttpChannelChild called by non-child!"); |
|
90 |
|
91 HttpChannelChild* child = static_cast<HttpChannelChild*>(channel); |
|
92 child->ReleaseIPDLReference(); |
|
93 return true; |
|
94 } |
|
95 |
|
96 PFTPChannelChild* |
|
97 NeckoChild::AllocPFTPChannelChild(PBrowserChild* aBrowser, |
|
98 const SerializedLoadContext& aSerialized, |
|
99 const FTPChannelCreationArgs& aOpenArgs) |
|
100 { |
|
101 // We don't allocate here: see FTPChannelChild::AsyncOpen() |
|
102 NS_RUNTIMEABORT("AllocPFTPChannelChild should not be called"); |
|
103 return nullptr; |
|
104 } |
|
105 |
|
106 bool |
|
107 NeckoChild::DeallocPFTPChannelChild(PFTPChannelChild* channel) |
|
108 { |
|
109 NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPFTPChannelChild called by non-child!"); |
|
110 |
|
111 FTPChannelChild* child = static_cast<FTPChannelChild*>(channel); |
|
112 child->ReleaseIPDLReference(); |
|
113 return true; |
|
114 } |
|
115 |
|
116 PCookieServiceChild* |
|
117 NeckoChild::AllocPCookieServiceChild() |
|
118 { |
|
119 // We don't allocate here: see nsCookieService::GetSingleton() |
|
120 NS_NOTREACHED("AllocPCookieServiceChild should not be called"); |
|
121 return nullptr; |
|
122 } |
|
123 |
|
124 bool |
|
125 NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild* cs) |
|
126 { |
|
127 NS_ASSERTION(IsNeckoChild(), "DeallocPCookieServiceChild called by non-child!"); |
|
128 |
|
129 CookieServiceChild *p = static_cast<CookieServiceChild*>(cs); |
|
130 p->Release(); |
|
131 return true; |
|
132 } |
|
133 |
|
134 PWyciwygChannelChild* |
|
135 NeckoChild::AllocPWyciwygChannelChild() |
|
136 { |
|
137 WyciwygChannelChild *p = new WyciwygChannelChild(); |
|
138 p->AddIPDLReference(); |
|
139 return p; |
|
140 } |
|
141 |
|
142 bool |
|
143 NeckoChild::DeallocPWyciwygChannelChild(PWyciwygChannelChild* channel) |
|
144 { |
|
145 NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPWyciwygChannelChild called by non-child!"); |
|
146 |
|
147 WyciwygChannelChild *p = static_cast<WyciwygChannelChild*>(channel); |
|
148 p->ReleaseIPDLReference(); |
|
149 return true; |
|
150 } |
|
151 |
|
152 PWebSocketChild* |
|
153 NeckoChild::AllocPWebSocketChild(PBrowserChild* browser, |
|
154 const SerializedLoadContext& aSerialized) |
|
155 { |
|
156 NS_NOTREACHED("AllocPWebSocketChild should not be called"); |
|
157 return nullptr; |
|
158 } |
|
159 |
|
160 bool |
|
161 NeckoChild::DeallocPWebSocketChild(PWebSocketChild* child) |
|
162 { |
|
163 WebSocketChannelChild* p = static_cast<WebSocketChannelChild*>(child); |
|
164 p->ReleaseIPDLReference(); |
|
165 return true; |
|
166 } |
|
167 |
|
168 PRtspControllerChild* |
|
169 NeckoChild::AllocPRtspControllerChild() |
|
170 { |
|
171 NS_NOTREACHED("AllocPRtspController should not be called"); |
|
172 return nullptr; |
|
173 } |
|
174 |
|
175 bool |
|
176 NeckoChild::DeallocPRtspControllerChild(PRtspControllerChild* child) |
|
177 { |
|
178 #ifdef NECKO_PROTOCOL_rtsp |
|
179 RtspControllerChild* p = static_cast<RtspControllerChild*>(child); |
|
180 p->ReleaseIPDLReference(); |
|
181 #endif |
|
182 return true; |
|
183 } |
|
184 |
|
185 PRtspChannelChild* |
|
186 NeckoChild::AllocPRtspChannelChild(const RtspChannelConnectArgs& aArgs) |
|
187 { |
|
188 NS_NOTREACHED("AllocPRtspController should not be called"); |
|
189 return nullptr; |
|
190 } |
|
191 |
|
192 bool |
|
193 NeckoChild::DeallocPRtspChannelChild(PRtspChannelChild* child) |
|
194 { |
|
195 #ifdef NECKO_PROTOCOL_rtsp |
|
196 RtspChannelChild* p = static_cast<RtspChannelChild*>(child); |
|
197 p->ReleaseIPDLReference(); |
|
198 #endif |
|
199 return true; |
|
200 } |
|
201 |
|
202 PTCPSocketChild* |
|
203 NeckoChild::AllocPTCPSocketChild() |
|
204 { |
|
205 TCPSocketChild* p = new TCPSocketChild(); |
|
206 p->AddIPDLReference(); |
|
207 return p; |
|
208 } |
|
209 |
|
210 bool |
|
211 NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild* child) |
|
212 { |
|
213 TCPSocketChild* p = static_cast<TCPSocketChild*>(child); |
|
214 p->ReleaseIPDLReference(); |
|
215 return true; |
|
216 } |
|
217 |
|
218 PTCPServerSocketChild* |
|
219 NeckoChild::AllocPTCPServerSocketChild(const uint16_t& aLocalPort, |
|
220 const uint16_t& aBacklog, |
|
221 const nsString& aBinaryType) |
|
222 { |
|
223 NS_NOTREACHED("AllocPTCPServerSocket should not be called"); |
|
224 return nullptr; |
|
225 } |
|
226 |
|
227 bool |
|
228 NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child) |
|
229 { |
|
230 TCPServerSocketChild* p = static_cast<TCPServerSocketChild*>(child); |
|
231 p->ReleaseIPDLReference(); |
|
232 return true; |
|
233 } |
|
234 |
|
235 PUDPSocketChild* |
|
236 NeckoChild::AllocPUDPSocketChild(const nsCString& aHost, |
|
237 const uint16_t& aPort, |
|
238 const nsCString& aFilter) |
|
239 { |
|
240 NS_NOTREACHED("AllocPUDPSocket should not be called"); |
|
241 return nullptr; |
|
242 } |
|
243 |
|
244 bool |
|
245 NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child) |
|
246 { |
|
247 |
|
248 UDPSocketChild* p = static_cast<UDPSocketChild*>(child); |
|
249 p->ReleaseIPDLReference(); |
|
250 return true; |
|
251 } |
|
252 |
|
253 PDNSRequestChild* |
|
254 NeckoChild::AllocPDNSRequestChild(const nsCString& aHost, |
|
255 const uint32_t& aFlags) |
|
256 { |
|
257 // We don't allocate here: instead we always use IPDL constructor that takes |
|
258 // an existing object |
|
259 NS_NOTREACHED("AllocPDNSRequestChild should not be called on child"); |
|
260 return nullptr; |
|
261 } |
|
262 |
|
263 bool |
|
264 NeckoChild::DeallocPDNSRequestChild(PDNSRequestChild* aChild) |
|
265 { |
|
266 DNSRequestChild *p = static_cast<DNSRequestChild*>(aChild); |
|
267 p->ReleaseIPDLReference(); |
|
268 return true; |
|
269 } |
|
270 |
|
271 PRemoteOpenFileChild* |
|
272 NeckoChild::AllocPRemoteOpenFileChild(const URIParams&, const OptionalURIParams&) |
|
273 { |
|
274 // We don't allocate here: instead we always use IPDL constructor that takes |
|
275 // an existing RemoteOpenFileChild |
|
276 NS_NOTREACHED("AllocPRemoteOpenFileChild should not be called on child"); |
|
277 return nullptr; |
|
278 } |
|
279 |
|
280 bool |
|
281 NeckoChild::DeallocPRemoteOpenFileChild(PRemoteOpenFileChild* aChild) |
|
282 { |
|
283 RemoteOpenFileChild *p = static_cast<RemoteOpenFileChild*>(aChild); |
|
284 p->ReleaseIPDLReference(); |
|
285 return true; |
|
286 } |
|
287 |
|
288 PChannelDiverterChild* |
|
289 NeckoChild::AllocPChannelDiverterChild(const ChannelDiverterArgs& channel) |
|
290 { |
|
291 return new ChannelDiverterChild();; |
|
292 } |
|
293 |
|
294 bool |
|
295 NeckoChild::DeallocPChannelDiverterChild(PChannelDiverterChild* child) |
|
296 { |
|
297 delete static_cast<ChannelDiverterChild*>(child); |
|
298 return true; |
|
299 } |
|
300 |
|
301 }} // mozilla::net |
|
302 |