netwerk/ipc/NeckoChild.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/ipc/NeckoChild.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,302 @@
     1.4 +
     1.5 +/* vim: set sw=2 ts=8 et tw=80 : */
     1.6 +
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "necko-config.h"
    1.12 +#include "nsHttp.h"
    1.13 +#include "mozilla/net/NeckoChild.h"
    1.14 +#include "mozilla/dom/ContentChild.h"
    1.15 +#include "mozilla/net/HttpChannelChild.h"
    1.16 +#include "mozilla/net/CookieServiceChild.h"
    1.17 +#include "mozilla/net/WyciwygChannelChild.h"
    1.18 +#include "mozilla/net/FTPChannelChild.h"
    1.19 +#include "mozilla/net/WebSocketChannelChild.h"
    1.20 +#include "mozilla/net/DNSRequestChild.h"
    1.21 +#include "mozilla/net/RemoteOpenFileChild.h"
    1.22 +#include "mozilla/net/ChannelDiverterChild.h"
    1.23 +#include "mozilla/dom/network/TCPSocketChild.h"
    1.24 +#include "mozilla/dom/network/TCPServerSocketChild.h"
    1.25 +#include "mozilla/dom/network/UDPSocketChild.h"
    1.26 +#ifdef NECKO_PROTOCOL_rtsp
    1.27 +#include "mozilla/net/RtspControllerChild.h"
    1.28 +#include "mozilla/net/RtspChannelChild.h"
    1.29 +#endif
    1.30 +#include "SerializedLoadContext.h"
    1.31 +
    1.32 +using mozilla::dom::TCPSocketChild;
    1.33 +using mozilla::dom::TCPServerSocketChild;
    1.34 +using mozilla::dom::UDPSocketChild;
    1.35 +
    1.36 +namespace mozilla {
    1.37 +namespace net {
    1.38 +
    1.39 +PNeckoChild *gNeckoChild = nullptr;
    1.40 +
    1.41 +// C++ file contents
    1.42 +NeckoChild::NeckoChild()
    1.43 +{
    1.44 +}
    1.45 +
    1.46 +NeckoChild::~NeckoChild()
    1.47 +{
    1.48 +}
    1.49 +
    1.50 +void NeckoChild::InitNeckoChild()
    1.51 +{
    1.52 +  NS_ABORT_IF_FALSE(IsNeckoChild(), "InitNeckoChild called by non-child!");
    1.53 +
    1.54 +  if (!gNeckoChild) {
    1.55 +    mozilla::dom::ContentChild * cpc = 
    1.56 +      mozilla::dom::ContentChild::GetSingleton();
    1.57 +    NS_ASSERTION(cpc, "Content Protocol is NULL!");
    1.58 +    gNeckoChild = cpc->SendPNeckoConstructor(); 
    1.59 +    NS_ASSERTION(gNeckoChild, "PNecko Protocol init failed!");
    1.60 +  }
    1.61 +}
    1.62 +
    1.63 +// Note: not actually called; has some lifespan as child process, so
    1.64 +// automatically destroyed at exit.  
    1.65 +void NeckoChild::DestroyNeckoChild()
    1.66 +{
    1.67 +  NS_ABORT_IF_FALSE(IsNeckoChild(), "DestroyNeckoChild called by non-child!");
    1.68 +  static bool alreadyDestroyed = false;
    1.69 +  NS_ABORT_IF_FALSE(!alreadyDestroyed, "DestroyNeckoChild already called!");
    1.70 +
    1.71 +  if (!alreadyDestroyed) {
    1.72 +    Send__delete__(gNeckoChild); 
    1.73 +    gNeckoChild = nullptr;
    1.74 +    alreadyDestroyed = true;
    1.75 +  }
    1.76 +}
    1.77 +
    1.78 +PHttpChannelChild*
    1.79 +NeckoChild::AllocPHttpChannelChild(PBrowserChild* browser,
    1.80 +                                   const SerializedLoadContext& loadContext,
    1.81 +                                   const HttpChannelCreationArgs& aOpenArgs)
    1.82 +{
    1.83 +  // We don't allocate here: instead we always use IPDL constructor that takes
    1.84 +  // an existing HttpChildChannel
    1.85 +  NS_NOTREACHED("AllocPHttpChannelChild should not be called on child");
    1.86 +  return nullptr;
    1.87 +}
    1.88 +
    1.89 +bool 
    1.90 +NeckoChild::DeallocPHttpChannelChild(PHttpChannelChild* channel)
    1.91 +{
    1.92 +  NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPHttpChannelChild called by non-child!");
    1.93 +
    1.94 +  HttpChannelChild* child = static_cast<HttpChannelChild*>(channel);
    1.95 +  child->ReleaseIPDLReference();
    1.96 +  return true;
    1.97 +}
    1.98 +
    1.99 +PFTPChannelChild*
   1.100 +NeckoChild::AllocPFTPChannelChild(PBrowserChild* aBrowser,
   1.101 +                                  const SerializedLoadContext& aSerialized,
   1.102 +                                  const FTPChannelCreationArgs& aOpenArgs)
   1.103 +{
   1.104 +  // We don't allocate here: see FTPChannelChild::AsyncOpen()
   1.105 +  NS_RUNTIMEABORT("AllocPFTPChannelChild should not be called");
   1.106 +  return nullptr;
   1.107 +}
   1.108 +
   1.109 +bool
   1.110 +NeckoChild::DeallocPFTPChannelChild(PFTPChannelChild* channel)
   1.111 +{
   1.112 +  NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPFTPChannelChild called by non-child!");
   1.113 +
   1.114 +  FTPChannelChild* child = static_cast<FTPChannelChild*>(channel);
   1.115 +  child->ReleaseIPDLReference();
   1.116 +  return true;
   1.117 +}
   1.118 +
   1.119 +PCookieServiceChild*
   1.120 +NeckoChild::AllocPCookieServiceChild()
   1.121 +{
   1.122 +  // We don't allocate here: see nsCookieService::GetSingleton()
   1.123 +  NS_NOTREACHED("AllocPCookieServiceChild should not be called");
   1.124 +  return nullptr;
   1.125 +}
   1.126 +
   1.127 +bool
   1.128 +NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild* cs)
   1.129 +{
   1.130 +  NS_ASSERTION(IsNeckoChild(), "DeallocPCookieServiceChild called by non-child!");
   1.131 +
   1.132 +  CookieServiceChild *p = static_cast<CookieServiceChild*>(cs);
   1.133 +  p->Release();
   1.134 +  return true;
   1.135 +}
   1.136 +
   1.137 +PWyciwygChannelChild*
   1.138 +NeckoChild::AllocPWyciwygChannelChild()
   1.139 +{
   1.140 +  WyciwygChannelChild *p = new WyciwygChannelChild();
   1.141 +  p->AddIPDLReference();
   1.142 +  return p;
   1.143 +}
   1.144 +
   1.145 +bool
   1.146 +NeckoChild::DeallocPWyciwygChannelChild(PWyciwygChannelChild* channel)
   1.147 +{
   1.148 +  NS_ABORT_IF_FALSE(IsNeckoChild(), "DeallocPWyciwygChannelChild called by non-child!");
   1.149 +
   1.150 +  WyciwygChannelChild *p = static_cast<WyciwygChannelChild*>(channel);
   1.151 +  p->ReleaseIPDLReference();
   1.152 +  return true;
   1.153 +}
   1.154 +
   1.155 +PWebSocketChild*
   1.156 +NeckoChild::AllocPWebSocketChild(PBrowserChild* browser,
   1.157 +                                 const SerializedLoadContext& aSerialized)
   1.158 +{
   1.159 +  NS_NOTREACHED("AllocPWebSocketChild should not be called");
   1.160 +  return nullptr;
   1.161 +}
   1.162 +
   1.163 +bool
   1.164 +NeckoChild::DeallocPWebSocketChild(PWebSocketChild* child)
   1.165 +{
   1.166 +  WebSocketChannelChild* p = static_cast<WebSocketChannelChild*>(child);
   1.167 +  p->ReleaseIPDLReference();
   1.168 +  return true;
   1.169 +}
   1.170 +
   1.171 +PRtspControllerChild*
   1.172 +NeckoChild::AllocPRtspControllerChild()
   1.173 +{
   1.174 +  NS_NOTREACHED("AllocPRtspController should not be called");
   1.175 +  return nullptr;
   1.176 +}
   1.177 +
   1.178 +bool
   1.179 +NeckoChild::DeallocPRtspControllerChild(PRtspControllerChild* child)
   1.180 +{
   1.181 +#ifdef NECKO_PROTOCOL_rtsp
   1.182 +  RtspControllerChild* p = static_cast<RtspControllerChild*>(child);
   1.183 +  p->ReleaseIPDLReference();
   1.184 +#endif
   1.185 +  return true;
   1.186 +}
   1.187 +
   1.188 +PRtspChannelChild*
   1.189 +NeckoChild::AllocPRtspChannelChild(const RtspChannelConnectArgs& aArgs)
   1.190 +{
   1.191 +  NS_NOTREACHED("AllocPRtspController should not be called");
   1.192 +  return nullptr;
   1.193 +}
   1.194 +
   1.195 +bool
   1.196 +NeckoChild::DeallocPRtspChannelChild(PRtspChannelChild* child)
   1.197 +{
   1.198 +#ifdef NECKO_PROTOCOL_rtsp
   1.199 +  RtspChannelChild* p = static_cast<RtspChannelChild*>(child);
   1.200 +  p->ReleaseIPDLReference();
   1.201 +#endif
   1.202 +  return true;
   1.203 +}
   1.204 +
   1.205 +PTCPSocketChild*
   1.206 +NeckoChild::AllocPTCPSocketChild()
   1.207 +{
   1.208 +  TCPSocketChild* p = new TCPSocketChild();
   1.209 +  p->AddIPDLReference();
   1.210 +  return p;
   1.211 +}
   1.212 +
   1.213 +bool
   1.214 +NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild* child)
   1.215 +{
   1.216 +  TCPSocketChild* p = static_cast<TCPSocketChild*>(child);
   1.217 +  p->ReleaseIPDLReference();
   1.218 +  return true;
   1.219 +}
   1.220 +
   1.221 +PTCPServerSocketChild*
   1.222 +NeckoChild::AllocPTCPServerSocketChild(const uint16_t& aLocalPort,
   1.223 +                                  const uint16_t& aBacklog,
   1.224 +                                  const nsString& aBinaryType)
   1.225 +{
   1.226 +  NS_NOTREACHED("AllocPTCPServerSocket should not be called");
   1.227 +  return nullptr;
   1.228 +}
   1.229 +
   1.230 +bool
   1.231 +NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child)
   1.232 +{
   1.233 +  TCPServerSocketChild* p = static_cast<TCPServerSocketChild*>(child);
   1.234 +  p->ReleaseIPDLReference();
   1.235 +  return true;
   1.236 +}
   1.237 +
   1.238 +PUDPSocketChild*
   1.239 +NeckoChild::AllocPUDPSocketChild(const nsCString& aHost,
   1.240 +                                 const uint16_t& aPort,
   1.241 +                                 const nsCString& aFilter)
   1.242 +{
   1.243 +  NS_NOTREACHED("AllocPUDPSocket should not be called");
   1.244 +  return nullptr;
   1.245 +}
   1.246 +
   1.247 +bool
   1.248 +NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child)
   1.249 +{
   1.250 +
   1.251 +  UDPSocketChild* p = static_cast<UDPSocketChild*>(child);
   1.252 +  p->ReleaseIPDLReference();
   1.253 +  return true;
   1.254 +}
   1.255 +
   1.256 +PDNSRequestChild*
   1.257 +NeckoChild::AllocPDNSRequestChild(const nsCString& aHost,
   1.258 +                                  const uint32_t& aFlags)
   1.259 +{
   1.260 +  // We don't allocate here: instead we always use IPDL constructor that takes
   1.261 +  // an existing object
   1.262 +  NS_NOTREACHED("AllocPDNSRequestChild should not be called on child");
   1.263 +  return nullptr;
   1.264 +}
   1.265 +
   1.266 +bool
   1.267 +NeckoChild::DeallocPDNSRequestChild(PDNSRequestChild* aChild)
   1.268 +{
   1.269 +  DNSRequestChild *p = static_cast<DNSRequestChild*>(aChild);
   1.270 +  p->ReleaseIPDLReference();
   1.271 +  return true;
   1.272 +}
   1.273 +
   1.274 +PRemoteOpenFileChild*
   1.275 +NeckoChild::AllocPRemoteOpenFileChild(const URIParams&, const OptionalURIParams&)
   1.276 +{
   1.277 +  // We don't allocate here: instead we always use IPDL constructor that takes
   1.278 +  // an existing RemoteOpenFileChild
   1.279 +  NS_NOTREACHED("AllocPRemoteOpenFileChild should not be called on child");
   1.280 +  return nullptr;
   1.281 +}
   1.282 +
   1.283 +bool
   1.284 +NeckoChild::DeallocPRemoteOpenFileChild(PRemoteOpenFileChild* aChild)
   1.285 +{
   1.286 +  RemoteOpenFileChild *p = static_cast<RemoteOpenFileChild*>(aChild);
   1.287 +  p->ReleaseIPDLReference();
   1.288 +  return true;
   1.289 +}
   1.290 +
   1.291 +PChannelDiverterChild*
   1.292 +NeckoChild::AllocPChannelDiverterChild(const ChannelDiverterArgs& channel)
   1.293 +{
   1.294 +  return new ChannelDiverterChild();;
   1.295 +}
   1.296 +
   1.297 +bool
   1.298 +NeckoChild::DeallocPChannelDiverterChild(PChannelDiverterChild* child)
   1.299 +{
   1.300 +  delete static_cast<ChannelDiverterChild*>(child);
   1.301 +  return true;
   1.302 +}
   1.303 +
   1.304 +}} // mozilla::net
   1.305 +

mercurial