michael@0: michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "necko-config.h" michael@0: #include "nsHttp.h" michael@0: #include "mozilla/net/NeckoChild.h" michael@0: #include "mozilla/dom/ContentChild.h" michael@0: #include "mozilla/net/HttpChannelChild.h" michael@0: #include "mozilla/net/CookieServiceChild.h" michael@0: #include "mozilla/net/WyciwygChannelChild.h" michael@0: #include "mozilla/net/FTPChannelChild.h" michael@0: #include "mozilla/net/WebSocketChannelChild.h" michael@0: #include "mozilla/net/DNSRequestChild.h" michael@0: #include "mozilla/net/RemoteOpenFileChild.h" michael@0: #include "mozilla/net/ChannelDiverterChild.h" michael@0: #include "mozilla/dom/network/TCPSocketChild.h" michael@0: #include "mozilla/dom/network/TCPServerSocketChild.h" michael@0: #include "mozilla/dom/network/UDPSocketChild.h" michael@0: #ifdef NECKO_PROTOCOL_rtsp michael@0: #include "mozilla/net/RtspControllerChild.h" michael@0: #include "mozilla/net/RtspChannelChild.h" michael@0: #endif michael@0: #include "SerializedLoadContext.h" michael@0: michael@0: using mozilla::dom::TCPSocketChild; michael@0: using mozilla::dom::TCPServerSocketChild; michael@0: using mozilla::dom::UDPSocketChild; michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: PNeckoChild *gNeckoChild = nullptr; michael@0: michael@0: // C++ file contents michael@0: NeckoChild::NeckoChild() michael@0: { michael@0: } michael@0: michael@0: NeckoChild::~NeckoChild() michael@0: { michael@0: } michael@0: michael@0: void NeckoChild::InitNeckoChild() michael@0: { michael@0: NS_ABORT_IF_FALSE(IsNeckoChild(), "InitNeckoChild called by non-child!"); michael@0: michael@0: if (!gNeckoChild) { michael@0: mozilla::dom::ContentChild * cpc = michael@0: mozilla::dom::ContentChild::GetSingleton(); michael@0: NS_ASSERTION(cpc, "Content Protocol is NULL!"); michael@0: gNeckoChild = cpc->SendPNeckoConstructor(); michael@0: NS_ASSERTION(gNeckoChild, "PNecko Protocol init failed!"); michael@0: } michael@0: } michael@0: michael@0: // Note: not actually called; has some lifespan as child process, so michael@0: // automatically destroyed at exit. michael@0: void NeckoChild::DestroyNeckoChild() michael@0: { michael@0: NS_ABORT_IF_FALSE(IsNeckoChild(), "DestroyNeckoChild called by non-child!"); michael@0: static bool alreadyDestroyed = false; michael@0: NS_ABORT_IF_FALSE(!alreadyDestroyed, "DestroyNeckoChild already called!"); michael@0: michael@0: if (!alreadyDestroyed) { michael@0: Send__delete__(gNeckoChild); michael@0: gNeckoChild = nullptr; michael@0: alreadyDestroyed = true; michael@0: } michael@0: } michael@0: michael@0: PHttpChannelChild* michael@0: NeckoChild::AllocPHttpChannelChild(PBrowserChild* browser, michael@0: const SerializedLoadContext& loadContext, michael@0: const HttpChannelCreationArgs& aOpenArgs) michael@0: { michael@0: // We don't allocate here: instead we always use IPDL constructor that takes michael@0: // an existing HttpChildChannel michael@0: NS_NOTREACHED("AllocPHttpChannelChild should not be called on child"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPHttpChannelChild(PHttpChannelChild* channel) michael@0: { michael@0: NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPHttpChannelChild called by non-child!"); michael@0: michael@0: HttpChannelChild* child = static_cast(channel); michael@0: child->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PFTPChannelChild* michael@0: NeckoChild::AllocPFTPChannelChild(PBrowserChild* aBrowser, michael@0: const SerializedLoadContext& aSerialized, michael@0: const FTPChannelCreationArgs& aOpenArgs) michael@0: { michael@0: // We don't allocate here: see FTPChannelChild::AsyncOpen() michael@0: NS_RUNTIMEABORT("AllocPFTPChannelChild should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPFTPChannelChild(PFTPChannelChild* channel) michael@0: { michael@0: NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPFTPChannelChild called by non-child!"); michael@0: michael@0: FTPChannelChild* child = static_cast(channel); michael@0: child->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PCookieServiceChild* michael@0: NeckoChild::AllocPCookieServiceChild() michael@0: { michael@0: // We don't allocate here: see nsCookieService::GetSingleton() michael@0: NS_NOTREACHED("AllocPCookieServiceChild should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild* cs) michael@0: { michael@0: NS_ASSERTION(IsNeckoChild(), "DeallocPCookieServiceChild called by non-child!"); michael@0: michael@0: CookieServiceChild *p = static_cast(cs); michael@0: p->Release(); michael@0: return true; michael@0: } michael@0: michael@0: PWyciwygChannelChild* michael@0: NeckoChild::AllocPWyciwygChannelChild() michael@0: { michael@0: WyciwygChannelChild *p = new WyciwygChannelChild(); michael@0: p->AddIPDLReference(); michael@0: return p; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPWyciwygChannelChild(PWyciwygChannelChild* channel) michael@0: { michael@0: NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPWyciwygChannelChild called by non-child!"); michael@0: michael@0: WyciwygChannelChild *p = static_cast(channel); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PWebSocketChild* michael@0: NeckoChild::AllocPWebSocketChild(PBrowserChild* browser, michael@0: const SerializedLoadContext& aSerialized) michael@0: { michael@0: NS_NOTREACHED("AllocPWebSocketChild should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPWebSocketChild(PWebSocketChild* child) michael@0: { michael@0: WebSocketChannelChild* p = static_cast(child); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PRtspControllerChild* michael@0: NeckoChild::AllocPRtspControllerChild() michael@0: { michael@0: NS_NOTREACHED("AllocPRtspController should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPRtspControllerChild(PRtspControllerChild* child) michael@0: { michael@0: #ifdef NECKO_PROTOCOL_rtsp michael@0: RtspControllerChild* p = static_cast(child); michael@0: p->ReleaseIPDLReference(); michael@0: #endif michael@0: return true; michael@0: } michael@0: michael@0: PRtspChannelChild* michael@0: NeckoChild::AllocPRtspChannelChild(const RtspChannelConnectArgs& aArgs) michael@0: { michael@0: NS_NOTREACHED("AllocPRtspController should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPRtspChannelChild(PRtspChannelChild* child) michael@0: { michael@0: #ifdef NECKO_PROTOCOL_rtsp michael@0: RtspChannelChild* p = static_cast(child); michael@0: p->ReleaseIPDLReference(); michael@0: #endif michael@0: return true; michael@0: } michael@0: michael@0: PTCPSocketChild* michael@0: NeckoChild::AllocPTCPSocketChild() michael@0: { michael@0: TCPSocketChild* p = new TCPSocketChild(); michael@0: p->AddIPDLReference(); michael@0: return p; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild* child) michael@0: { michael@0: TCPSocketChild* p = static_cast(child); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PTCPServerSocketChild* michael@0: NeckoChild::AllocPTCPServerSocketChild(const uint16_t& aLocalPort, michael@0: const uint16_t& aBacklog, michael@0: const nsString& aBinaryType) michael@0: { michael@0: NS_NOTREACHED("AllocPTCPServerSocket should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child) michael@0: { michael@0: TCPServerSocketChild* p = static_cast(child); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PUDPSocketChild* michael@0: NeckoChild::AllocPUDPSocketChild(const nsCString& aHost, michael@0: const uint16_t& aPort, michael@0: const nsCString& aFilter) michael@0: { michael@0: NS_NOTREACHED("AllocPUDPSocket should not be called"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child) michael@0: { michael@0: michael@0: UDPSocketChild* p = static_cast(child); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PDNSRequestChild* michael@0: NeckoChild::AllocPDNSRequestChild(const nsCString& aHost, michael@0: const uint32_t& aFlags) michael@0: { michael@0: // We don't allocate here: instead we always use IPDL constructor that takes michael@0: // an existing object michael@0: NS_NOTREACHED("AllocPDNSRequestChild should not be called on child"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPDNSRequestChild(PDNSRequestChild* aChild) michael@0: { michael@0: DNSRequestChild *p = static_cast(aChild); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PRemoteOpenFileChild* michael@0: NeckoChild::AllocPRemoteOpenFileChild(const URIParams&, const OptionalURIParams&) michael@0: { michael@0: // We don't allocate here: instead we always use IPDL constructor that takes michael@0: // an existing RemoteOpenFileChild michael@0: NS_NOTREACHED("AllocPRemoteOpenFileChild should not be called on child"); michael@0: return nullptr; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPRemoteOpenFileChild(PRemoteOpenFileChild* aChild) michael@0: { michael@0: RemoteOpenFileChild *p = static_cast(aChild); michael@0: p->ReleaseIPDLReference(); michael@0: return true; michael@0: } michael@0: michael@0: PChannelDiverterChild* michael@0: NeckoChild::AllocPChannelDiverterChild(const ChannelDiverterArgs& channel) michael@0: { michael@0: return new ChannelDiverterChild();; michael@0: } michael@0: michael@0: bool michael@0: NeckoChild::DeallocPChannelDiverterChild(PChannelDiverterChild* child) michael@0: { michael@0: delete static_cast(child); michael@0: return true; michael@0: } michael@0: michael@0: }} // mozilla::net michael@0: