Bumping manifests a=b2g-bump
[gecko.git] / netwerk / ipc / NeckoChild.cpp
blob6fd1d1694b2d5b5f56457001b0a8db18b266e0fb
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"
9 #include "nsHttp.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"
27 #endif
28 #include "SerializedLoadContext.h"
30 using mozilla::dom::TCPSocketChild;
31 using mozilla::dom::TCPServerSocketChild;
32 using mozilla::dom::UDPSocketChild;
34 namespace mozilla {
35 namespace net {
37 PNeckoChild *gNeckoChild = nullptr;
39 // C++ file contents
40 NeckoChild::NeckoChild()
44 NeckoChild::~NeckoChild()
48 void NeckoChild::InitNeckoChild()
50 NS_ABORT_IF_FALSE(IsNeckoChild(), "InitNeckoChild called by non-child!");
52 if (!gNeckoChild) {
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;
76 PHttpChannelChild*
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");
84 return nullptr;
87 bool
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();
94 return true;
97 PFTPChannelChild*
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");
104 return nullptr;
107 bool
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();
114 return true;
117 PCookieServiceChild*
118 NeckoChild::AllocPCookieServiceChild()
120 // We don't allocate here: see nsCookieService::GetSingleton()
121 NS_NOTREACHED("AllocPCookieServiceChild should not be called");
122 return nullptr;
125 bool
126 NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild* cs)
128 NS_ASSERTION(IsNeckoChild(), "DeallocPCookieServiceChild called by non-child!");
130 CookieServiceChild *p = static_cast<CookieServiceChild*>(cs);
131 p->Release();
132 return true;
135 PWyciwygChannelChild*
136 NeckoChild::AllocPWyciwygChannelChild()
138 WyciwygChannelChild *p = new WyciwygChannelChild();
139 p->AddIPDLReference();
140 return p;
143 bool
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();
150 return true;
153 PWebSocketChild*
154 NeckoChild::AllocPWebSocketChild(const PBrowserOrId& browser,
155 const SerializedLoadContext& aSerialized)
157 NS_NOTREACHED("AllocPWebSocketChild should not be called");
158 return nullptr;
161 bool
162 NeckoChild::DeallocPWebSocketChild(PWebSocketChild* child)
164 WebSocketChannelChild* p = static_cast<WebSocketChannelChild*>(child);
165 p->ReleaseIPDLReference();
166 return true;
169 PRtspControllerChild*
170 NeckoChild::AllocPRtspControllerChild()
172 NS_NOTREACHED("AllocPRtspController should not be called");
173 return nullptr;
176 bool
177 NeckoChild::DeallocPRtspControllerChild(PRtspControllerChild* child)
179 #ifdef NECKO_PROTOCOL_rtsp
180 RtspControllerChild* p = static_cast<RtspControllerChild*>(child);
181 p->ReleaseIPDLReference();
182 #endif
183 return true;
186 PRtspChannelChild*
187 NeckoChild::AllocPRtspChannelChild(const RtspChannelConnectArgs& aArgs)
189 NS_NOTREACHED("AllocPRtspController should not be called");
190 return nullptr;
193 bool
194 NeckoChild::DeallocPRtspChannelChild(PRtspChannelChild* child)
196 #ifdef NECKO_PROTOCOL_rtsp
197 RtspChannelChild* p = static_cast<RtspChannelChild*>(child);
198 p->ReleaseIPDLReference();
199 #endif
200 return true;
203 PTCPSocketChild*
204 NeckoChild::AllocPTCPSocketChild(const nsString& host,
205 const uint16_t& port)
207 TCPSocketChild* p = new TCPSocketChild();
208 p->Init(host, port);
209 p->AddIPDLReference();
210 return p;
213 bool
214 NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild* child)
216 TCPSocketChild* p = static_cast<TCPSocketChild*>(child);
217 p->ReleaseIPDLReference();
218 return true;
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");
227 return nullptr;
230 bool
231 NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child)
233 TCPServerSocketChild* p = static_cast<TCPServerSocketChild*>(child);
234 p->ReleaseIPDLReference();
235 return true;
238 PUDPSocketChild*
239 NeckoChild::AllocPUDPSocketChild(const nsCString& aFilter)
241 NS_NOTREACHED("AllocPUDPSocket should not be called");
242 return nullptr;
245 bool
246 NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child)
249 UDPSocketChild* p = static_cast<UDPSocketChild*>(child);
250 p->ReleaseIPDLReference();
251 return true;
254 PDNSRequestChild*
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");
261 return nullptr;
264 bool
265 NeckoChild::DeallocPDNSRequestChild(PDNSRequestChild* aChild)
267 DNSRequestChild *p = static_cast<DNSRequestChild*>(aChild);
268 p->ReleaseIPDLReference();
269 return true;
272 PRemoteOpenFileChild*
273 NeckoChild::AllocPRemoteOpenFileChild(const SerializedLoadContext& aSerialized,
274 const URIParams&,
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");
280 return nullptr;
283 bool
284 NeckoChild::DeallocPRemoteOpenFileChild(PRemoteOpenFileChild* aChild)
286 RemoteOpenFileChild *p = static_cast<RemoteOpenFileChild*>(aChild);
287 p->ReleaseIPDLReference();
288 return true;
291 PChannelDiverterChild*
292 NeckoChild::AllocPChannelDiverterChild(const ChannelDiverterArgs& channel)
294 return new ChannelDiverterChild();;
297 bool
298 NeckoChild::DeallocPChannelDiverterChild(PChannelDiverterChild* child)
300 delete static_cast<ChannelDiverterChild*>(child);
301 return true;
304 bool
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()) {
312 MOZ_CRASH();
313 return false;
315 dom::TabChild* tabChild = iter->second;
316 tabChild->SendAsyncAuthPrompt(aUri, aRealm, aCallbackId);
317 return true;
320 }} // mozilla::net