tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NeckoChild.cpp (9336B)


      1 /* vim: set sw=2 ts=8 et tw=80 : */
      2 
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "nsHttp.h"
      8 #include "mozilla/net/NeckoChild.h"
      9 #include "mozilla/dom/ContentChild.h"
     10 #include "mozilla/dom/BrowserChild.h"
     11 #include "mozilla/net/HttpChannelChild.h"
     12 #include "mozilla/net/ChildDNSService.h"
     13 #include "mozilla/net/CookieServiceChild.h"
     14 #ifdef MOZ_WIDGET_GTK
     15 #  include "mozilla/net/GIOChannelChild.h"
     16 #endif
     17 #include "mozilla/net/WebSocketChannelChild.h"
     18 #include "mozilla/net/WebSocketEventListenerChild.h"
     19 #include "mozilla/net/DNSRequestChild.h"
     20 #include "mozilla/net/IPCTransportProvider.h"
     21 #include "mozilla/dom/network/TCPSocketChild.h"
     22 #include "mozilla/dom/network/TCPServerSocketChild.h"
     23 #include "mozilla/dom/network/UDPSocketChild.h"
     24 #include "mozilla/net/AltDataOutputStreamChild.h"
     25 #include "mozilla/net/CacheEntryWriteHandleChild.h"
     26 #include "mozilla/net/SocketProcessBridgeChild.h"
     27 #ifdef MOZ_WEBRTC
     28 #  include "mozilla/net/StunAddrsRequestChild.h"
     29 #  include "mozilla/net/WebrtcTCPSocketChild.h"
     30 #endif
     31 
     32 #include "SerializedLoadContext.h"
     33 #include "nsGlobalWindowInner.h"
     34 #include "nsIOService.h"
     35 #include "nsINetworkLinkService.h"
     36 #include "nsQueryObject.h"
     37 #include "mozilla/ipc/URIUtils.h"
     38 #include "mozilla/Components.h"
     39 #include "nsNetUtil.h"
     40 #include "SimpleChannel.h"
     41 
     42 using mozilla::dom::TCPServerSocketChild;
     43 using mozilla::dom::TCPSocketChild;
     44 using mozilla::dom::UDPSocketChild;
     45 
     46 namespace mozilla {
     47 namespace net {
     48 
     49 PNeckoChild* gNeckoChild = nullptr;
     50 
     51 // C++ file contents
     52 
     53 NeckoChild::~NeckoChild() {
     54  // Send__delete__(gNeckoChild);
     55  gNeckoChild = nullptr;
     56 }
     57 
     58 void NeckoChild::InitNeckoChild() {
     59  if (!IsNeckoChild()) {
     60    MOZ_ASSERT(false, "InitNeckoChild called by non-child!");
     61    return;
     62  }
     63 
     64  if (!gNeckoChild) {
     65    mozilla::dom::ContentChild* cpc =
     66        mozilla::dom::ContentChild::GetSingleton();
     67    NS_ASSERTION(cpc, "Content Protocol is NULL!");
     68    if (NS_WARN_IF(cpc->IsShuttingDown())) {
     69      return;
     70    }
     71    RefPtr<NeckoChild> child = new NeckoChild();
     72    gNeckoChild = cpc->SendPNeckoConstructor(child);
     73    NS_ASSERTION(gNeckoChild, "PNecko Protocol init failed!");
     74  }
     75 }
     76 
     77 PStunAddrsRequestChild* NeckoChild::AllocPStunAddrsRequestChild() {
     78  // We don't allocate here: instead we always use IPDL constructor that takes
     79  // an existing object
     80  MOZ_ASSERT_UNREACHABLE(
     81      "AllocPStunAddrsRequestChild should not be called "
     82      "on child");
     83  return nullptr;
     84 }
     85 
     86 bool NeckoChild::DeallocPStunAddrsRequestChild(PStunAddrsRequestChild* aActor) {
     87 #ifdef MOZ_WEBRTC
     88  StunAddrsRequestChild* p = static_cast<StunAddrsRequestChild*>(aActor);
     89  p->ReleaseIPDLReference();
     90 #endif
     91  return true;
     92 }
     93 
     94 PWebrtcTCPSocketChild* NeckoChild::AllocPWebrtcTCPSocketChild(
     95    const Maybe<TabId>& tabId) {
     96  // We don't allocate here: instead we always use IPDL constructor that takes
     97  // an existing object
     98  MOZ_ASSERT_UNREACHABLE(
     99      "AllocPWebrtcTCPSocketChild should not be called on"
    100      " child");
    101  return nullptr;
    102 }
    103 
    104 bool NeckoChild::DeallocPWebrtcTCPSocketChild(PWebrtcTCPSocketChild* aActor) {
    105 #ifdef MOZ_WEBRTC
    106  WebrtcTCPSocketChild* child = static_cast<WebrtcTCPSocketChild*>(aActor);
    107  child->ReleaseIPDLReference();
    108 #endif
    109  return true;
    110 }
    111 
    112 PCacheEntryWriteHandleChild* NeckoChild::AllocPCacheEntryWriteHandleChild(
    113    PHttpChannelChild* channel) {
    114  // We don't allocate here: see HttpChannelChild::GetCacheEntryWriteHandle()
    115  MOZ_ASSERT_UNREACHABLE(
    116      "AllocPCacheEntryWriteHandleChild should not be called");
    117  return nullptr;
    118 }
    119 
    120 bool NeckoChild::DeallocPCacheEntryWriteHandleChild(
    121    PCacheEntryWriteHandleChild* aActor) {
    122  CacheEntryWriteHandleChild* child =
    123      static_cast<CacheEntryWriteHandleChild*>(aActor);
    124  child->ReleaseIPDLReference();
    125  return true;
    126 }
    127 
    128 PAltDataOutputStreamChild* NeckoChild::AllocPAltDataOutputStreamChild(
    129    const nsACString& type, const int64_t& predictedSize,
    130    const mozilla::Maybe<mozilla::NotNull<PHttpChannelChild*>>& channel,
    131    const mozilla::Maybe<mozilla::NotNull<PCacheEntryWriteHandleChild*>>&
    132        handle) {
    133  // We don't allocate here: see HttpChannelChild::OpenAlternativeOutputStream()
    134  MOZ_ASSERT_UNREACHABLE("AllocPAltDataOutputStreamChild should not be called");
    135  return nullptr;
    136 }
    137 
    138 bool NeckoChild::DeallocPAltDataOutputStreamChild(
    139    PAltDataOutputStreamChild* aActor) {
    140  AltDataOutputStreamChild* child =
    141      static_cast<AltDataOutputStreamChild*>(aActor);
    142  child->ReleaseIPDLReference();
    143  return true;
    144 }
    145 
    146 #ifdef MOZ_WIDGET_GTK
    147 PGIOChannelChild* NeckoChild::AllocPGIOChannelChild(
    148    PBrowserChild* aBrowser, const SerializedLoadContext& aSerialized,
    149    const GIOChannelCreationArgs& aOpenArgs) {
    150  // We don't allocate here: see GIOChannelChild::AsyncOpen()
    151  MOZ_CRASH("AllocPGIOChannelChild should not be called");
    152  return nullptr;
    153 }
    154 
    155 bool NeckoChild::DeallocPGIOChannelChild(PGIOChannelChild* channel) {
    156  MOZ_ASSERT(IsNeckoChild(), "DeallocPGIOChannelChild called by non-child!");
    157 
    158  GIOChannelChild* child = static_cast<GIOChannelChild*>(channel);
    159  child->ReleaseIPDLReference();
    160  return true;
    161 }
    162 #endif
    163 
    164 PCookieServiceChild* NeckoChild::AllocPCookieServiceChild() {
    165  // We don't allocate here: see CookieService::GetSingleton()
    166  MOZ_ASSERT_UNREACHABLE("AllocPCookieServiceChild should not be called");
    167  return nullptr;
    168 }
    169 
    170 bool NeckoChild::DeallocPCookieServiceChild(PCookieServiceChild* cs) {
    171  NS_ASSERTION(IsNeckoChild(),
    172               "DeallocPCookieServiceChild called by non-child!");
    173 
    174  CookieServiceChild* p = static_cast<CookieServiceChild*>(cs);
    175  p->Release();
    176  return true;
    177 }
    178 
    179 PWebSocketChild* NeckoChild::AllocPWebSocketChild(
    180    PBrowserChild* browser, const SerializedLoadContext& aSerialized,
    181    const uint32_t& aSerial) {
    182  MOZ_ASSERT_UNREACHABLE("AllocPWebSocketChild should not be called");
    183  return nullptr;
    184 }
    185 
    186 bool NeckoChild::DeallocPWebSocketChild(PWebSocketChild* child) {
    187  WebSocketChannelChild* p = static_cast<WebSocketChannelChild*>(child);
    188  p->ReleaseIPDLReference();
    189  return true;
    190 }
    191 
    192 PWebSocketEventListenerChild* NeckoChild::AllocPWebSocketEventListenerChild(
    193    const uint64_t& aInnerWindowID) {
    194  RefPtr<WebSocketEventListenerChild> c = new WebSocketEventListenerChild(
    195      aInnerWindowID, GetMainThreadSerialEventTarget());
    196  return c.forget().take();
    197 }
    198 
    199 bool NeckoChild::DeallocPWebSocketEventListenerChild(
    200    PWebSocketEventListenerChild* aActor) {
    201  RefPtr<WebSocketEventListenerChild> c =
    202      dont_AddRef(static_cast<WebSocketEventListenerChild*>(aActor));
    203  MOZ_ASSERT(c);
    204  return true;
    205 }
    206 
    207 PTCPSocketChild* NeckoChild::AllocPTCPSocketChild(const nsAString& host,
    208                                                  const uint16_t& port) {
    209  TCPSocketChild* p = new TCPSocketChild(host, port, nullptr);
    210  p->AddIPDLReference();
    211  return p;
    212 }
    213 
    214 bool NeckoChild::DeallocPTCPSocketChild(PTCPSocketChild* child) {
    215  TCPSocketChild* p = static_cast<TCPSocketChild*>(child);
    216  p->ReleaseIPDLReference();
    217  return true;
    218 }
    219 
    220 PTCPServerSocketChild* NeckoChild::AllocPTCPServerSocketChild(
    221    const uint16_t& aLocalPort, const uint16_t& aBacklog,
    222    const bool& aUseArrayBuffers) {
    223  MOZ_ASSERT_UNREACHABLE("AllocPTCPServerSocket should not be called");
    224  return nullptr;
    225 }
    226 
    227 bool NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child) {
    228  TCPServerSocketChild* p = static_cast<TCPServerSocketChild*>(child);
    229  p->ReleaseIPDLReference();
    230  return true;
    231 }
    232 
    233 PUDPSocketChild* NeckoChild::AllocPUDPSocketChild(nsIPrincipal* aPrincipal,
    234                                                  const nsACString& aFilter) {
    235  MOZ_ASSERT_UNREACHABLE("AllocPUDPSocket should not be called");
    236  return nullptr;
    237 }
    238 
    239 bool NeckoChild::DeallocPUDPSocketChild(PUDPSocketChild* child) {
    240  UDPSocketChild* p = static_cast<UDPSocketChild*>(child);
    241  p->ReleaseIPDLReference();
    242  return true;
    243 }
    244 
    245 PTransportProviderChild* NeckoChild::AllocPTransportProviderChild() {
    246  // This refcount is transferred to the receiver of the message that
    247  // includes the PTransportProviderChild actor.
    248  RefPtr<TransportProviderChild> res = new TransportProviderChild();
    249 
    250  return res.forget().take();
    251 }
    252 
    253 bool NeckoChild::DeallocPTransportProviderChild(
    254    PTransportProviderChild* aActor) {
    255  return true;
    256 }
    257 
    258 mozilla::ipc::IPCResult NeckoChild::RecvSpeculativeConnectRequest() {
    259  nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
    260  if (obsService) {
    261    obsService->NotifyObservers(nullptr, "speculative-connect-request",
    262                                nullptr);
    263  }
    264  return IPC_OK();
    265 }
    266 
    267 mozilla::ipc::IPCResult NeckoChild::RecvNetworkChangeNotification(
    268    nsCString const& type) {
    269  nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
    270  if (obsService) {
    271    obsService->NotifyObservers(nullptr, NS_NETWORK_LINK_TOPIC,
    272                                NS_ConvertUTF8toUTF16(type).get());
    273  }
    274  return IPC_OK();
    275 }
    276 
    277 mozilla::ipc::IPCResult NeckoChild::RecvSetTRRDomain(const nsCString& domain) {
    278  RefPtr<net::ChildDNSService> dnsServiceChild =
    279      dont_AddRef(net::ChildDNSService::GetSingleton());
    280  if (dnsServiceChild) {
    281    dnsServiceChild->SetTRRDomain(domain);
    282  }
    283  return IPC_OK();
    284 }
    285 
    286 }  // namespace net
    287 }  // namespace mozilla