2 /* vim: set sw=2 ts=8 et tw=80 : */
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/. */
8 #include "necko-config.h"
10 #include "mozilla/net/NeckoChild.h"
11 #include "mozilla/dom/ContentChild.h"
12 #include "mozilla/dom/TabChild.h"
13 #include "mozilla/net/HttpChannelChild.h"
14 #include "mozilla/net/CookieServiceChild.h"
15 #include "mozilla/net/WyciwygChannelChild.h"
16 #include "mozilla/net/FTPChannelChild.h"
17 #include "mozilla/net/WebSocketChannelChild.h"
18 #include "mozilla/net/DNSRequestChild.h"
19 #include "mozilla/net/RemoteOpenFileChild.h"
20 #include "mozilla/net/ChannelDiverterChild.h"
21 #include "mozilla/dom/network/TCPSocketChild.h"
22 #include "mozilla/dom/network/TCPServerSocketChild.h"
23 #include "mozilla/dom/network/UDPSocketChild.h"
24 #ifdef NECKO_PROTOCOL_rtsp
25 #include "mozilla/net/RtspControllerChild.h"
26 #include "mozilla/net/RtspChannelChild.h"
28 #include "SerializedLoadContext.h"
30 using mozilla::dom::TCPSocketChild
;
31 using mozilla::dom::TCPServerSocketChild
;
32 using mozilla::dom::UDPSocketChild
;
37 PNeckoChild
*gNeckoChild
= nullptr;
40 NeckoChild::NeckoChild()
44 NeckoChild::~NeckoChild()
48 void NeckoChild::InitNeckoChild()
50 NS_ABORT_IF_FALSE(IsNeckoChild(), "InitNeckoChild called by non-child!");
53 mozilla::dom::ContentChild
* cpc
=
54 mozilla::dom::ContentChild::GetSingleton();
55 NS_ASSERTION(cpc
, "Content Protocol is NULL!");
56 gNeckoChild
= cpc
->SendPNeckoConstructor();
57 NS_ASSERTION(gNeckoChild
, "PNecko Protocol init failed!");
61 // Note: not actually called; has some lifespan as child process, so
62 // automatically destroyed at exit.
63 void NeckoChild::DestroyNeckoChild()
65 NS_ABORT_IF_FALSE(IsNeckoChild(), "DestroyNeckoChild called by non-child!");
66 static bool alreadyDestroyed
= false;
67 NS_ABORT_IF_FALSE(!alreadyDestroyed
, "DestroyNeckoChild already called!");
69 if (!alreadyDestroyed
) {
70 Send__delete__(gNeckoChild
);
71 gNeckoChild
= nullptr;
72 alreadyDestroyed
= true;
77 NeckoChild::AllocPHttpChannelChild(const PBrowserOrId
& browser
,
78 const SerializedLoadContext
& loadContext
,
79 const HttpChannelCreationArgs
& aOpenArgs
)
81 // We don't allocate here: instead we always use IPDL constructor that takes
82 // an existing HttpChildChannel
83 NS_NOTREACHED("AllocPHttpChannelChild should not be called on child");
88 NeckoChild::DeallocPHttpChannelChild(PHttpChannelChild
* channel
)
90 NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPHttpChannelChild called by non-child!");
92 HttpChannelChild
* child
= static_cast<HttpChannelChild
*>(channel
);
93 child
->ReleaseIPDLReference();
98 NeckoChild::AllocPFTPChannelChild(const PBrowserOrId
& aBrowser
,
99 const SerializedLoadContext
& aSerialized
,
100 const FTPChannelCreationArgs
& aOpenArgs
)
102 // We don't allocate here: see FTPChannelChild::AsyncOpen()
103 NS_RUNTIMEABORT("AllocPFTPChannelChild should not be called");
108 NeckoChild::DeallocPFTPChannelChild(PFTPChannelChild
* channel
)
110 NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPFTPChannelChild called by non-child!");
112 FTPChannelChild
* child
= static_cast<FTPChannelChild
*>(channel
);
113 child
->ReleaseIPDLReference();
118 NeckoChild::AllocPCookieServiceChild()
120 // We don't allocate here: see nsCookieService::GetSingleton()
121 NS_NOTREACHED("AllocPCookieServiceChild should not be called");
126 NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild
* cs
)
128 NS_ASSERTION(IsNeckoChild(), "DeallocPCookieServiceChild called by non-child!");
130 CookieServiceChild
*p
= static_cast<CookieServiceChild
*>(cs
);
135 PWyciwygChannelChild
*
136 NeckoChild::AllocPWyciwygChannelChild()
138 WyciwygChannelChild
*p
= new WyciwygChannelChild();
139 p
->AddIPDLReference();
144 NeckoChild::DeallocPWyciwygChannelChild(PWyciwygChannelChild
* channel
)
146 NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPWyciwygChannelChild called by non-child!");
148 WyciwygChannelChild
*p
= static_cast<WyciwygChannelChild
*>(channel
);
149 p
->ReleaseIPDLReference();
154 NeckoChild::AllocPWebSocketChild(const PBrowserOrId
& browser
,
155 const SerializedLoadContext
& aSerialized
)
157 NS_NOTREACHED("AllocPWebSocketChild should not be called");
162 NeckoChild::DeallocPWebSocketChild(PWebSocketChild
* child
)
164 WebSocketChannelChild
* p
= static_cast<WebSocketChannelChild
*>(child
);
165 p
->ReleaseIPDLReference();
169 PRtspControllerChild
*
170 NeckoChild::AllocPRtspControllerChild()
172 NS_NOTREACHED("AllocPRtspController should not be called");
177 NeckoChild::DeallocPRtspControllerChild(PRtspControllerChild
* child
)
179 #ifdef NECKO_PROTOCOL_rtsp
180 RtspControllerChild
* p
= static_cast<RtspControllerChild
*>(child
);
181 p
->ReleaseIPDLReference();
187 NeckoChild::AllocPRtspChannelChild(const RtspChannelConnectArgs
& aArgs
)
189 NS_NOTREACHED("AllocPRtspController should not be called");
194 NeckoChild::DeallocPRtspChannelChild(PRtspChannelChild
* child
)
196 #ifdef NECKO_PROTOCOL_rtsp
197 RtspChannelChild
* p
= static_cast<RtspChannelChild
*>(child
);
198 p
->ReleaseIPDLReference();
204 NeckoChild::AllocPTCPSocketChild(const nsString
& host
,
205 const uint16_t& port
)
207 TCPSocketChild
* p
= new TCPSocketChild();
209 p
->AddIPDLReference();
214 NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild
* child
)
216 TCPSocketChild
* p
= static_cast<TCPSocketChild
*>(child
);
217 p
->ReleaseIPDLReference();
221 PTCPServerSocketChild
*
222 NeckoChild::AllocPTCPServerSocketChild(const uint16_t& aLocalPort
,
223 const uint16_t& aBacklog
,
224 const nsString
& aBinaryType
)
226 NS_NOTREACHED("AllocPTCPServerSocket should not be called");
231 NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild
* child
)
233 TCPServerSocketChild
* p
= static_cast<TCPServerSocketChild
*>(child
);
234 p
->ReleaseIPDLReference();
239 NeckoChild::AllocPUDPSocketChild(const nsCString
& aFilter
)
241 NS_NOTREACHED("AllocPUDPSocket should not be called");
246 NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild
* child
)
249 UDPSocketChild
* p
= static_cast<UDPSocketChild
*>(child
);
250 p
->ReleaseIPDLReference();
255 NeckoChild::AllocPDNSRequestChild(const nsCString
& aHost
,
256 const uint32_t& aFlags
)
258 // We don't allocate here: instead we always use IPDL constructor that takes
259 // an existing object
260 NS_NOTREACHED("AllocPDNSRequestChild should not be called on child");
265 NeckoChild::DeallocPDNSRequestChild(PDNSRequestChild
* aChild
)
267 DNSRequestChild
*p
= static_cast<DNSRequestChild
*>(aChild
);
268 p
->ReleaseIPDLReference();
272 PRemoteOpenFileChild
*
273 NeckoChild::AllocPRemoteOpenFileChild(const SerializedLoadContext
& aSerialized
,
275 const OptionalURIParams
&)
277 // We don't allocate here: instead we always use IPDL constructor that takes
278 // an existing RemoteOpenFileChild
279 NS_NOTREACHED("AllocPRemoteOpenFileChild should not be called on child");
284 NeckoChild::DeallocPRemoteOpenFileChild(PRemoteOpenFileChild
* aChild
)
286 RemoteOpenFileChild
*p
= static_cast<RemoteOpenFileChild
*>(aChild
);
287 p
->ReleaseIPDLReference();
291 PChannelDiverterChild
*
292 NeckoChild::AllocPChannelDiverterChild(const ChannelDiverterArgs
& channel
)
294 return new ChannelDiverterChild();;
298 NeckoChild::DeallocPChannelDiverterChild(PChannelDiverterChild
* child
)
300 delete static_cast<ChannelDiverterChild
*>(child
);
305 NeckoChild::RecvAsyncAuthPromptForNestedFrame(const uint64_t& aNestedFrameId
,
306 const nsCString
& aUri
,
307 const nsString
& aRealm
,
308 const uint64_t& aCallbackId
)
310 auto iter
= dom::TabChild::NestedTabChildMap().find(aNestedFrameId
);
311 if (iter
== dom::TabChild::NestedTabChildMap().end()) {
315 dom::TabChild
* tabChild
= iter
->second
;
316 tabChild
->SendAsyncAuthPrompt(aUri
, aRealm
, aCallbackId
);