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/. */
9 #include "mozilla/net/NeckoChild.h"
10 #include "mozilla/dom/ContentChild.h"
11 #include "mozilla/dom/BrowserChild.h"
12 #include "mozilla/net/HttpChannelChild.h"
13 #include "mozilla/net/ChildDNSService.h"
14 #include "mozilla/net/CookieServiceChild.h"
15 #include "mozilla/net/DataChannelChild.h"
17 # include "mozilla/net/GIOChannelChild.h"
19 #include "mozilla/net/FileChannelChild.h"
20 #include "mozilla/net/WebSocketChannelChild.h"
21 #include "mozilla/net/WebSocketEventListenerChild.h"
22 #include "mozilla/net/DNSRequestChild.h"
23 #include "mozilla/net/IPCTransportProvider.h"
24 #include "mozilla/dom/network/TCPSocketChild.h"
25 #include "mozilla/dom/network/TCPServerSocketChild.h"
26 #include "mozilla/dom/network/UDPSocketChild.h"
27 #include "mozilla/net/AltDataOutputStreamChild.h"
28 #include "mozilla/net/SocketProcessBridgeChild.h"
30 # include "mozilla/net/StunAddrsRequestChild.h"
31 # include "mozilla/net/WebrtcTCPSocketChild.h"
34 #include "SerializedLoadContext.h"
35 #include "nsGlobalWindowInner.h"
36 #include "nsIOService.h"
37 #include "nsINetworkPredictor.h"
38 #include "nsINetworkPredictorVerifier.h"
39 #include "nsINetworkLinkService.h"
40 #include "nsQueryObject.h"
41 #include "mozilla/ipc/URIUtils.h"
42 #include "nsNetUtil.h"
43 #include "SimpleChannel.h"
45 using mozilla::dom::TCPServerSocketChild
;
46 using mozilla::dom::TCPSocketChild
;
47 using mozilla::dom::UDPSocketChild
;
52 PNeckoChild
* gNeckoChild
= nullptr;
56 NeckoChild::~NeckoChild() {
57 // Send__delete__(gNeckoChild);
58 gNeckoChild
= nullptr;
61 void NeckoChild::InitNeckoChild() {
62 if (!IsNeckoChild()) {
63 MOZ_ASSERT(false, "InitNeckoChild called by non-child!");
68 mozilla::dom::ContentChild
* cpc
=
69 mozilla::dom::ContentChild::GetSingleton();
70 NS_ASSERTION(cpc
, "Content Protocol is NULL!");
71 if (NS_WARN_IF(cpc
->IsShuttingDown())) {
74 RefPtr
<NeckoChild
> child
= new NeckoChild();
75 gNeckoChild
= cpc
->SendPNeckoConstructor(child
);
76 NS_ASSERTION(gNeckoChild
, "PNecko Protocol init failed!");
80 PStunAddrsRequestChild
* NeckoChild::AllocPStunAddrsRequestChild() {
81 // We don't allocate here: instead we always use IPDL constructor that takes
83 MOZ_ASSERT_UNREACHABLE(
84 "AllocPStunAddrsRequestChild should not be called "
89 bool NeckoChild::DeallocPStunAddrsRequestChild(PStunAddrsRequestChild
* aActor
) {
91 StunAddrsRequestChild
* p
= static_cast<StunAddrsRequestChild
*>(aActor
);
92 p
->ReleaseIPDLReference();
97 PWebrtcTCPSocketChild
* NeckoChild::AllocPWebrtcTCPSocketChild(
98 const Maybe
<TabId
>& tabId
) {
99 // We don't allocate here: instead we always use IPDL constructor that takes
100 // an existing object
101 MOZ_ASSERT_UNREACHABLE(
102 "AllocPWebrtcTCPSocketChild should not be called on"
107 bool NeckoChild::DeallocPWebrtcTCPSocketChild(PWebrtcTCPSocketChild
* aActor
) {
109 WebrtcTCPSocketChild
* child
= static_cast<WebrtcTCPSocketChild
*>(aActor
);
110 child
->ReleaseIPDLReference();
115 PAltDataOutputStreamChild
* NeckoChild::AllocPAltDataOutputStreamChild(
116 const nsACString
& type
, const int64_t& predictedSize
,
117 PHttpChannelChild
* channel
) {
118 // We don't allocate here: see HttpChannelChild::OpenAlternativeOutputStream()
119 MOZ_ASSERT_UNREACHABLE("AllocPAltDataOutputStreamChild should not be called");
123 bool NeckoChild::DeallocPAltDataOutputStreamChild(
124 PAltDataOutputStreamChild
* aActor
) {
125 AltDataOutputStreamChild
* child
=
126 static_cast<AltDataOutputStreamChild
*>(aActor
);
127 child
->ReleaseIPDLReference();
131 #ifdef MOZ_WIDGET_GTK
132 PGIOChannelChild
* NeckoChild::AllocPGIOChannelChild(
133 PBrowserChild
* aBrowser
, const SerializedLoadContext
& aSerialized
,
134 const GIOChannelCreationArgs
& aOpenArgs
) {
135 // We don't allocate here: see GIOChannelChild::AsyncOpen()
136 MOZ_CRASH("AllocPGIOChannelChild should not be called");
140 bool NeckoChild::DeallocPGIOChannelChild(PGIOChannelChild
* channel
) {
141 MOZ_ASSERT(IsNeckoChild(), "DeallocPGIOChannelChild called by non-child!");
143 GIOChannelChild
* child
= static_cast<GIOChannelChild
*>(channel
);
144 child
->ReleaseIPDLReference();
149 PCookieServiceChild
* NeckoChild::AllocPCookieServiceChild() {
150 // We don't allocate here: see CookieService::GetSingleton()
151 MOZ_ASSERT_UNREACHABLE("AllocPCookieServiceChild should not be called");
155 bool NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild
* cs
) {
156 NS_ASSERTION(IsNeckoChild(),
157 "DeallocPCookieServiceChild called by non-child!");
159 CookieServiceChild
* p
= static_cast<CookieServiceChild
*>(cs
);
164 PWebSocketChild
* NeckoChild::AllocPWebSocketChild(
165 PBrowserChild
* browser
, const SerializedLoadContext
& aSerialized
,
166 const uint32_t& aSerial
) {
167 MOZ_ASSERT_UNREACHABLE("AllocPWebSocketChild should not be called");
171 bool NeckoChild::DeallocPWebSocketChild(PWebSocketChild
* child
) {
172 WebSocketChannelChild
* p
= static_cast<WebSocketChannelChild
*>(child
);
173 p
->ReleaseIPDLReference();
177 PWebSocketEventListenerChild
* NeckoChild::AllocPWebSocketEventListenerChild(
178 const uint64_t& aInnerWindowID
) {
179 RefPtr
<WebSocketEventListenerChild
> c
= new WebSocketEventListenerChild(
180 aInnerWindowID
, GetMainThreadSerialEventTarget());
181 return c
.forget().take();
184 bool NeckoChild::DeallocPWebSocketEventListenerChild(
185 PWebSocketEventListenerChild
* aActor
) {
186 RefPtr
<WebSocketEventListenerChild
> c
=
187 dont_AddRef(static_cast<WebSocketEventListenerChild
*>(aActor
));
192 PSimpleChannelChild
* NeckoChild::AllocPSimpleChannelChild(
193 const uint32_t& channelId
) {
194 MOZ_ASSERT_UNREACHABLE("Should never get here");
198 bool NeckoChild::DeallocPSimpleChannelChild(PSimpleChannelChild
* child
) {
199 static_cast<SimpleChannelChild
*>(child
)->Release();
203 PTCPSocketChild
* NeckoChild::AllocPTCPSocketChild(const nsAString
& host
,
204 const uint16_t& port
) {
205 TCPSocketChild
* p
= new TCPSocketChild(host
, port
, nullptr);
206 p
->AddIPDLReference();
210 bool NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild
* child
) {
211 TCPSocketChild
* p
= static_cast<TCPSocketChild
*>(child
);
212 p
->ReleaseIPDLReference();
216 PTCPServerSocketChild
* NeckoChild::AllocPTCPServerSocketChild(
217 const uint16_t& aLocalPort
, const uint16_t& aBacklog
,
218 const bool& aUseArrayBuffers
) {
219 MOZ_ASSERT_UNREACHABLE("AllocPTCPServerSocket should not be called");
223 bool NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild
* child
) {
224 TCPServerSocketChild
* p
= static_cast<TCPServerSocketChild
*>(child
);
225 p
->ReleaseIPDLReference();
229 PUDPSocketChild
* NeckoChild::AllocPUDPSocketChild(nsIPrincipal
* aPrincipal
,
230 const nsACString
& aFilter
) {
231 MOZ_ASSERT_UNREACHABLE("AllocPUDPSocket should not be called");
235 bool NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild
* child
) {
236 UDPSocketChild
* p
= static_cast<UDPSocketChild
*>(child
);
237 p
->ReleaseIPDLReference();
241 PTransportProviderChild
* NeckoChild::AllocPTransportProviderChild() {
242 // This refcount is transferred to the receiver of the message that
243 // includes the PTransportProviderChild actor.
244 RefPtr
<TransportProviderChild
> res
= new TransportProviderChild();
246 return res
.forget().take();
249 bool NeckoChild::DeallocPTransportProviderChild(
250 PTransportProviderChild
* aActor
) {
254 /* Predictor Messages */
255 mozilla::ipc::IPCResult
NeckoChild::RecvPredOnPredictPrefetch(
256 nsIURI
* aURI
, const uint32_t& aHttpStatus
) {
257 MOZ_ASSERT(NS_IsMainThread(),
258 "PredictorChild::RecvOnPredictPrefetch "
261 return IPC_FAIL(this, "aURI is null");
264 // Get the current predictor
266 nsCOMPtr
<nsINetworkPredictorVerifier
> predictor
=
267 do_GetService("@mozilla.org/network/predictor;1", &rv
);
268 NS_ENSURE_SUCCESS(rv
, IPC_FAIL_NO_REASON(this));
270 predictor
->OnPredictPrefetch(aURI
, aHttpStatus
);
274 mozilla::ipc::IPCResult
NeckoChild::RecvPredOnPredictPreconnect(nsIURI
* aURI
) {
275 MOZ_ASSERT(NS_IsMainThread(),
276 "PredictorChild::RecvOnPredictPreconnect "
279 return IPC_FAIL(this, "aURI is null");
281 // Get the current predictor
283 nsCOMPtr
<nsINetworkPredictorVerifier
> predictor
=
284 do_GetService("@mozilla.org/network/predictor;1", &rv
);
285 NS_ENSURE_SUCCESS(rv
, IPC_FAIL_NO_REASON(this));
287 predictor
->OnPredictPreconnect(aURI
);
291 mozilla::ipc::IPCResult
NeckoChild::RecvPredOnPredictDNS(nsIURI
* aURI
) {
292 MOZ_ASSERT(NS_IsMainThread(),
293 "PredictorChild::RecvOnPredictDNS off "
296 return IPC_FAIL(this, "aURI is null");
298 // Get the current predictor
300 nsCOMPtr
<nsINetworkPredictorVerifier
> predictor
=
301 do_GetService("@mozilla.org/network/predictor;1", &rv
);
302 NS_ENSURE_SUCCESS(rv
, IPC_FAIL_NO_REASON(this));
304 predictor
->OnPredictDNS(aURI
);
308 mozilla::ipc::IPCResult
NeckoChild::RecvSpeculativeConnectRequest() {
309 nsCOMPtr
<nsIObserverService
> obsService
= services::GetObserverService();
311 obsService
->NotifyObservers(nullptr, "speculative-connect-request",
317 mozilla::ipc::IPCResult
NeckoChild::RecvNetworkChangeNotification(
318 nsCString
const& type
) {
319 nsCOMPtr
<nsIObserverService
> obsService
= services::GetObserverService();
321 obsService
->NotifyObservers(nullptr, NS_NETWORK_LINK_TOPIC
,
322 NS_ConvertUTF8toUTF16(type
).get());
327 mozilla::ipc::IPCResult
NeckoChild::RecvSetTRRDomain(const nsCString
& domain
) {
328 RefPtr
<net::ChildDNSService
> dnsServiceChild
=
329 dont_AddRef(net::ChildDNSService::GetSingleton());
330 if (dnsServiceChild
) {
331 dnsServiceChild
->SetTRRDomain(domain
);
337 } // namespace mozilla