LCOV - code coverage report
Current view: top level - ipc/glue - BackgroundParentImpl.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 36 341 10.6 %
Date: 2017-07-14 16:53:18 Functions: 7 74 9.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       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 file,
       5             :  * You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "BackgroundParentImpl.h"
       8             : 
       9             : #include "BroadcastChannelParent.h"
      10             : #include "FileDescriptorSetParent.h"
      11             : #ifdef MOZ_WEBRTC
      12             : #include "CamerasParent.h"
      13             : #endif
      14             : #include "mozilla/media/MediaParent.h"
      15             : #include "mozilla/Assertions.h"
      16             : #include "mozilla/dom/ContentParent.h"
      17             : #include "mozilla/dom/DOMTypes.h"
      18             : #include "mozilla/dom/FileSystemBase.h"
      19             : #include "mozilla/dom/FileSystemRequestParent.h"
      20             : #include "mozilla/dom/GamepadEventChannelParent.h"
      21             : #include "mozilla/dom/GamepadTestChannelParent.h"
      22             : #include "mozilla/dom/PGamepadEventChannelParent.h"
      23             : #include "mozilla/dom/PGamepadTestChannelParent.h"
      24             : #include "mozilla/dom/MessagePortParent.h"
      25             : #include "mozilla/dom/ServiceWorkerRegistrar.h"
      26             : #include "mozilla/dom/asmjscache/AsmJSCache.h"
      27             : #include "mozilla/dom/cache/ActorUtils.h"
      28             : #include "mozilla/dom/indexedDB/ActorsParent.h"
      29             : #include "mozilla/dom/ipc/IPCBlobInputStreamParent.h"
      30             : #include "mozilla/dom/ipc/PendingIPCBlobParent.h"
      31             : #include "mozilla/dom/quota/ActorsParent.h"
      32             : #include "mozilla/ipc/BackgroundParent.h"
      33             : #include "mozilla/ipc/BackgroundUtils.h"
      34             : #include "mozilla/ipc/IPCStreamAlloc.h"
      35             : #include "mozilla/ipc/PBackgroundSharedTypes.h"
      36             : #include "mozilla/ipc/PBackgroundTestParent.h"
      37             : #include "mozilla/ipc/PChildToParentStreamParent.h"
      38             : #include "mozilla/ipc/PParentToChildStreamParent.h"
      39             : #include "mozilla/layout/VsyncParent.h"
      40             : #include "mozilla/net/HttpBackgroundChannelParent.h"
      41             : #include "mozilla/dom/network/UDPSocketParent.h"
      42             : #include "mozilla/dom/WebAuthnTransactionParent.h"
      43             : #include "mozilla/Preferences.h"
      44             : #include "nsNetUtil.h"
      45             : #include "nsIScriptSecurityManager.h"
      46             : #include "nsProxyRelease.h"
      47             : #include "mozilla/RefPtr.h"
      48             : #include "nsThreadUtils.h"
      49             : #include "nsTraceRefcnt.h"
      50             : #include "nsXULAppAPI.h"
      51             : #include "ServiceWorkerManagerParent.h"
      52             : 
      53             : #ifdef DISABLE_ASSERTS_FOR_FUZZING
      54             : #define ASSERT_UNLESS_FUZZING(...) do { } while (0)
      55             : #else
      56             : #define ASSERT_UNLESS_FUZZING(...) MOZ_ASSERT(false)
      57             : #endif
      58             : 
      59             : using mozilla::ipc::AssertIsOnBackgroundThread;
      60             : using mozilla::dom::asmjscache::PAsmJSCacheEntryParent;
      61             : using mozilla::dom::cache::PCacheParent;
      62             : using mozilla::dom::cache::PCacheStorageParent;
      63             : using mozilla::dom::cache::PCacheStreamControlParent;
      64             : using mozilla::dom::FileSystemBase;
      65             : using mozilla::dom::FileSystemRequestParent;
      66             : using mozilla::dom::MessagePortParent;
      67             : using mozilla::dom::PMessagePortParent;
      68             : using mozilla::dom::UDPSocketParent;
      69             : using mozilla::dom::WebAuthnTransactionParent;
      70             : 
      71             : namespace {
      72             : 
      73             : void
      74           4 : AssertIsOnMainThread()
      75             : {
      76           4 :   MOZ_ASSERT(NS_IsMainThread());
      77           4 : }
      78             : 
      79             : class TestParent final : public mozilla::ipc::PBackgroundTestParent
      80             : {
      81             :   friend class mozilla::ipc::BackgroundParentImpl;
      82             : 
      83           0 :   TestParent()
      84           0 :   {
      85           0 :     MOZ_COUNT_CTOR(TestParent);
      86           0 :   }
      87             : 
      88             : protected:
      89           0 :   ~TestParent() override
      90           0 :   {
      91           0 :     MOZ_COUNT_DTOR(TestParent);
      92           0 :   }
      93             : 
      94             : public:
      95             :   void
      96             :   ActorDestroy(ActorDestroyReason aWhy) override;
      97             : };
      98             : 
      99             : } // namespace
     100             : 
     101             : namespace mozilla {
     102             : namespace ipc {
     103             : 
     104             : using mozilla::dom::ContentParent;
     105             : using mozilla::dom::BroadcastChannelParent;
     106             : using mozilla::dom::ServiceWorkerRegistrationData;
     107             : using mozilla::dom::workers::ServiceWorkerManagerParent;
     108             : 
     109           4 : BackgroundParentImpl::BackgroundParentImpl()
     110             : {
     111           4 :   AssertIsInMainProcess();
     112           4 :   AssertIsOnMainThread();
     113             : 
     114           4 :   MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl);
     115           4 : }
     116             : 
     117           0 : BackgroundParentImpl::~BackgroundParentImpl()
     118             : {
     119           0 :   AssertIsInMainProcess();
     120           0 :   AssertIsOnMainThread();
     121             : 
     122           0 :   MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl);
     123           0 : }
     124             : 
     125             : void
     126           0 : BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy)
     127             : {
     128           0 :   AssertIsInMainProcess();
     129           0 :   AssertIsOnBackgroundThread();
     130           0 : }
     131             : 
     132             : BackgroundParentImpl::PBackgroundTestParent*
     133           0 : BackgroundParentImpl::AllocPBackgroundTestParent(const nsCString& aTestArg)
     134             : {
     135           0 :   AssertIsInMainProcess();
     136           0 :   AssertIsOnBackgroundThread();
     137             : 
     138           0 :   return new TestParent();
     139             : }
     140             : 
     141             : mozilla::ipc::IPCResult
     142           0 : BackgroundParentImpl::RecvPBackgroundTestConstructor(
     143             :                                                   PBackgroundTestParent* aActor,
     144             :                                                   const nsCString& aTestArg)
     145             : {
     146           0 :   AssertIsInMainProcess();
     147           0 :   AssertIsOnBackgroundThread();
     148           0 :   MOZ_ASSERT(aActor);
     149             : 
     150           0 :   if (!PBackgroundTestParent::Send__delete__(aActor, aTestArg)) {
     151           0 :     return IPC_FAIL_NO_REASON(this);
     152             :   }
     153           0 :   return IPC_OK();
     154             : }
     155             : 
     156             : bool
     157           0 : BackgroundParentImpl::DeallocPBackgroundTestParent(
     158             :                                                   PBackgroundTestParent* aActor)
     159             : {
     160           0 :   AssertIsInMainProcess();
     161           0 :   AssertIsOnBackgroundThread();
     162           0 :   MOZ_ASSERT(aActor);
     163             : 
     164           0 :   delete static_cast<TestParent*>(aActor);
     165           0 :   return true;
     166             : }
     167             : 
     168             : auto
     169           0 : BackgroundParentImpl::AllocPBackgroundIDBFactoryParent(
     170             :                                                 const LoggingInfo& aLoggingInfo)
     171             :   -> PBackgroundIDBFactoryParent*
     172             : {
     173             :   using mozilla::dom::indexedDB::AllocPBackgroundIDBFactoryParent;
     174             : 
     175           0 :   AssertIsInMainProcess();
     176           0 :   AssertIsOnBackgroundThread();
     177             : 
     178           0 :   return AllocPBackgroundIDBFactoryParent(aLoggingInfo);
     179             : }
     180             : 
     181             : mozilla::ipc::IPCResult
     182           0 : BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor(
     183             :                                             PBackgroundIDBFactoryParent* aActor,
     184             :                                             const LoggingInfo& aLoggingInfo)
     185             : {
     186             :   using mozilla::dom::indexedDB::RecvPBackgroundIDBFactoryConstructor;
     187             : 
     188           0 :   AssertIsInMainProcess();
     189           0 :   AssertIsOnBackgroundThread();
     190           0 :   MOZ_ASSERT(aActor);
     191             : 
     192           0 :   if (!RecvPBackgroundIDBFactoryConstructor(aActor, aLoggingInfo)) {
     193           0 :     return IPC_FAIL_NO_REASON(this);
     194             :   }
     195           0 :   return IPC_OK();
     196             : }
     197             : 
     198             : bool
     199           0 : BackgroundParentImpl::DeallocPBackgroundIDBFactoryParent(
     200             :                                             PBackgroundIDBFactoryParent* aActor)
     201             : {
     202             :   using mozilla::dom::indexedDB::DeallocPBackgroundIDBFactoryParent;
     203             : 
     204           0 :   AssertIsInMainProcess();
     205           0 :   AssertIsOnBackgroundThread();
     206           0 :   MOZ_ASSERT(aActor);
     207             : 
     208           0 :   return DeallocPBackgroundIDBFactoryParent(aActor);
     209             : }
     210             : 
     211             : auto
     212           0 : BackgroundParentImpl::AllocPBackgroundIndexedDBUtilsParent()
     213             :   -> PBackgroundIndexedDBUtilsParent*
     214             : {
     215           0 :   AssertIsInMainProcess();
     216           0 :   AssertIsOnBackgroundThread();
     217             : 
     218           0 :   return mozilla::dom::indexedDB::AllocPBackgroundIndexedDBUtilsParent();
     219             : }
     220             : 
     221             : bool
     222           0 : BackgroundParentImpl::DeallocPBackgroundIndexedDBUtilsParent(
     223             :                                         PBackgroundIndexedDBUtilsParent* aActor)
     224             : {
     225           0 :   AssertIsInMainProcess();
     226           0 :   AssertIsOnBackgroundThread();
     227           0 :   MOZ_ASSERT(aActor);
     228             : 
     229             :   return
     230           0 :     mozilla::dom::indexedDB::DeallocPBackgroundIndexedDBUtilsParent(aActor);
     231             : }
     232             : 
     233             : mozilla::ipc::IPCResult
     234           0 : BackgroundParentImpl::RecvFlushPendingFileDeletions()
     235             : {
     236           0 :   AssertIsInMainProcess();
     237           0 :   AssertIsOnBackgroundThread();
     238             : 
     239           0 :   if (!mozilla::dom::indexedDB::RecvFlushPendingFileDeletions()) {
     240           0 :     return IPC_FAIL_NO_REASON(this);
     241             :   }
     242           0 :   return IPC_OK();
     243             : }
     244             : 
     245             : PPendingIPCBlobParent*
     246           0 : BackgroundParentImpl::AllocPPendingIPCBlobParent(const IPCBlob& aBlob)
     247             : {
     248           0 :   MOZ_CRASH("PPendingIPCBlobParent actors should be manually constructed!");
     249             : }
     250             : 
     251             : bool
     252           0 : BackgroundParentImpl::DeallocPPendingIPCBlobParent(PPendingIPCBlobParent* aActor)
     253             : {
     254           0 :   AssertIsInMainProcess();
     255           0 :   AssertIsOnBackgroundThread();
     256           0 :   MOZ_ASSERT(aActor);
     257             : 
     258           0 :   delete aActor;
     259           0 :   return true;
     260             : }
     261             : 
     262             : PIPCBlobInputStreamParent*
     263           0 : BackgroundParentImpl::AllocPIPCBlobInputStreamParent(const nsID& aID,
     264             :                                                      const uint64_t& aSize)
     265             : {
     266           0 :   AssertIsInMainProcess();
     267           0 :   AssertIsOnBackgroundThread();
     268             : 
     269           0 :   return mozilla::dom::IPCBlobInputStreamParent::Create(aID, aSize, this);
     270             : }
     271             : 
     272             : mozilla::ipc::IPCResult
     273           0 : BackgroundParentImpl::RecvPIPCBlobInputStreamConstructor(PIPCBlobInputStreamParent* aActor,
     274             :                                                          const nsID& aID,
     275             :                                                          const uint64_t& aSize)
     276             : {
     277           0 :   if (!static_cast<mozilla::dom::IPCBlobInputStreamParent*>(aActor)->HasValidStream()) {
     278           0 :     return IPC_FAIL_NO_REASON(this);
     279             :   }
     280             : 
     281           0 :   return IPC_OK();
     282             : }
     283             : 
     284             : bool
     285           0 : BackgroundParentImpl::DeallocPIPCBlobInputStreamParent(PIPCBlobInputStreamParent* aActor)
     286             : {
     287           0 :   AssertIsInMainProcess();
     288           0 :   AssertIsOnBackgroundThread();
     289           0 :   MOZ_ASSERT(aActor);
     290             : 
     291           0 :   delete aActor;
     292           0 :   return true;
     293             : }
     294             : 
     295             : PFileDescriptorSetParent*
     296           0 : BackgroundParentImpl::AllocPFileDescriptorSetParent(
     297             :                                           const FileDescriptor& aFileDescriptor)
     298             : {
     299           0 :   AssertIsInMainProcess();
     300           0 :   AssertIsOnBackgroundThread();
     301             : 
     302           0 :   return new FileDescriptorSetParent(aFileDescriptor);
     303             : }
     304             : 
     305             : bool
     306           0 : BackgroundParentImpl::DeallocPFileDescriptorSetParent(
     307             :                                                PFileDescriptorSetParent* aActor)
     308             : {
     309           0 :   AssertIsInMainProcess();
     310           0 :   AssertIsOnBackgroundThread();
     311           0 :   MOZ_ASSERT(aActor);
     312             : 
     313           0 :   delete static_cast<FileDescriptorSetParent*>(aActor);
     314           0 :   return true;
     315             : }
     316             : 
     317             : PChildToParentStreamParent*
     318           0 : BackgroundParentImpl::AllocPChildToParentStreamParent()
     319             : {
     320           0 :   return mozilla::ipc::AllocPChildToParentStreamParent();
     321             : }
     322             : 
     323             : bool
     324           0 : BackgroundParentImpl::DeallocPChildToParentStreamParent(
     325             :                                              PChildToParentStreamParent* aActor)
     326             : {
     327           0 :   delete aActor;
     328           0 :   return true;
     329             : }
     330             : 
     331             : PParentToChildStreamParent*
     332           0 : BackgroundParentImpl::AllocPParentToChildStreamParent()
     333             : {
     334           0 :   MOZ_CRASH("PParentToChildStreamParent actors should be manually constructed!");
     335             : }
     336             : 
     337             : bool
     338           0 : BackgroundParentImpl::DeallocPParentToChildStreamParent(
     339             :                                              PParentToChildStreamParent* aActor)
     340             : {
     341           0 :   delete aActor;
     342           0 :   return true;
     343             : }
     344             : 
     345             : BackgroundParentImpl::PVsyncParent*
     346           1 : BackgroundParentImpl::AllocPVsyncParent()
     347             : {
     348           1 :   AssertIsInMainProcess();
     349           1 :   AssertIsOnBackgroundThread();
     350             : 
     351             :   RefPtr<mozilla::layout::VsyncParent> actor =
     352           2 :       mozilla::layout::VsyncParent::Create();
     353             :   // There still has one ref-count after return, and it will be released in
     354             :   // DeallocPVsyncParent().
     355           2 :   return actor.forget().take();
     356             : }
     357             : 
     358             : bool
     359           0 : BackgroundParentImpl::DeallocPVsyncParent(PVsyncParent* aActor)
     360             : {
     361           0 :   AssertIsInMainProcess();
     362           0 :   AssertIsOnBackgroundThread();
     363           0 :   MOZ_ASSERT(aActor);
     364             : 
     365             :   // This actor already has one ref-count. Please check AllocPVsyncParent().
     366             :   RefPtr<mozilla::layout::VsyncParent> actor =
     367           0 :       dont_AddRef(static_cast<mozilla::layout::VsyncParent*>(aActor));
     368           0 :   return true;
     369             : }
     370             : 
     371             : camera::PCamerasParent*
     372           0 : BackgroundParentImpl::AllocPCamerasParent()
     373             : {
     374           0 :   AssertIsInMainProcess();
     375           0 :   AssertIsOnBackgroundThread();
     376             : 
     377             : #ifdef MOZ_WEBRTC
     378             :   RefPtr<mozilla::camera::CamerasParent> actor =
     379           0 :       mozilla::camera::CamerasParent::Create();
     380           0 :   return actor.forget().take();
     381             : #else
     382             :   return nullptr;
     383             : #endif
     384             : }
     385             : 
     386             : bool
     387           0 : BackgroundParentImpl::DeallocPCamerasParent(camera::PCamerasParent *aActor)
     388             : {
     389           0 :   AssertIsInMainProcess();
     390           0 :   AssertIsOnBackgroundThread();
     391           0 :   MOZ_ASSERT(aActor);
     392             : 
     393             : #ifdef MOZ_WEBRTC
     394             :   RefPtr<mozilla::camera::CamerasParent> actor =
     395           0 :       dont_AddRef(static_cast<mozilla::camera::CamerasParent*>(aActor));
     396             : #endif
     397           0 :   return true;
     398             : }
     399             : 
     400             : auto
     401           0 : BackgroundParentImpl::AllocPUDPSocketParent(const OptionalPrincipalInfo& /* unused */,
     402             :                                             const nsCString& /* unused */)
     403             :   -> PUDPSocketParent*
     404             : {
     405           0 :   RefPtr<UDPSocketParent> p = new UDPSocketParent(this);
     406             : 
     407           0 :   return p.forget().take();
     408             : }
     409             : 
     410             : mozilla::ipc::IPCResult
     411           0 : BackgroundParentImpl::RecvPUDPSocketConstructor(PUDPSocketParent* aActor,
     412             :                                                 const OptionalPrincipalInfo& aOptionalPrincipal,
     413             :                                                 const nsCString& aFilter)
     414             : {
     415           0 :   AssertIsInMainProcess();
     416           0 :   AssertIsOnBackgroundThread();
     417             : 
     418           0 :   if (aOptionalPrincipal.type() == OptionalPrincipalInfo::TPrincipalInfo) {
     419             :     // Support for checking principals (for non-mtransport use) will be handled in
     420             :     // bug 1167039
     421           0 :     return IPC_FAIL_NO_REASON(this);
     422             :   }
     423             :   // No principal - This must be from mtransport (WebRTC/ICE) - We'd want
     424             :   // to DispatchToMainThread() here, but if we do we must block RecvBind()
     425             :   // until Init() gets run.  Since we don't have a principal, and we verify
     426             :   // we have a filter, we can safely skip the Dispatch and just invoke Init()
     427             :   // to install the filter.
     428             : 
     429             :   // For mtransport, this will always be "stun", which doesn't allow outbound
     430             :   // packets if they aren't STUN packets until a STUN response is seen.
     431           0 :   if (!aFilter.EqualsASCII(NS_NETWORK_SOCKET_FILTER_HANDLER_STUN_SUFFIX)) {
     432           0 :     return IPC_FAIL_NO_REASON(this);
     433             :   }
     434             : 
     435           0 :   IPC::Principal principal;
     436           0 :   if (!static_cast<UDPSocketParent*>(aActor)->Init(principal, aFilter)) {
     437           0 :     MOZ_CRASH("UDPSocketCallback - failed init");
     438             :   }
     439             : 
     440           0 :   return IPC_OK();
     441             : }
     442             : 
     443             : bool
     444           0 : BackgroundParentImpl::DeallocPUDPSocketParent(PUDPSocketParent* actor)
     445             : {
     446           0 :   UDPSocketParent* p = static_cast<UDPSocketParent*>(actor);
     447           0 :   p->Release();
     448           0 :   return true;
     449             : }
     450             : 
     451             : mozilla::dom::PBroadcastChannelParent*
     452           0 : BackgroundParentImpl::AllocPBroadcastChannelParent(
     453             :                                             const PrincipalInfo& aPrincipalInfo,
     454             :                                             const nsCString& aOrigin,
     455             :                                             const nsString& aChannel)
     456             : {
     457           0 :   AssertIsInMainProcess();
     458           0 :   AssertIsOnBackgroundThread();
     459             : 
     460           0 :   nsString originChannelKey;
     461             : 
     462             :   // The format of originChannelKey is:
     463             :   //  <channelName>|<origin+OriginAttributes>
     464             : 
     465           0 :   originChannelKey.Assign(aChannel);
     466             : 
     467           0 :   originChannelKey.AppendLiteral("|");
     468             : 
     469           0 :   originChannelKey.Append(NS_ConvertUTF8toUTF16(aOrigin));
     470             : 
     471           0 :   return new BroadcastChannelParent(originChannelKey);
     472             : }
     473             : 
     474             : namespace {
     475             : 
     476             : struct MOZ_STACK_CLASS NullifyContentParentRAII
     477             : {
     478           0 :   explicit NullifyContentParentRAII(RefPtr<ContentParent>& aContentParent)
     479           0 :     : mContentParent(aContentParent)
     480           0 :   {}
     481             : 
     482           0 :   ~NullifyContentParentRAII()
     483           0 :   {
     484           0 :     mContentParent = nullptr;
     485           0 :   }
     486             : 
     487             :   RefPtr<ContentParent>& mContentParent;
     488             : };
     489             : 
     490           0 : class CheckPrincipalRunnable final : public Runnable
     491             : {
     492             : public:
     493           0 :   CheckPrincipalRunnable(already_AddRefed<ContentParent> aParent,
     494             :                          const PrincipalInfo& aPrincipalInfo,
     495             :                          const nsCString& aOrigin)
     496           0 :     : Runnable("ipc::CheckPrincipalRunnable")
     497             :     , mContentParent(aParent)
     498             :     , mPrincipalInfo(aPrincipalInfo)
     499           0 :     , mOrigin(aOrigin)
     500             :   {
     501           0 :     AssertIsInMainProcess();
     502           0 :     AssertIsOnBackgroundThread();
     503             : 
     504           0 :     MOZ_ASSERT(mContentParent);
     505           0 :   }
     506             : 
     507           0 :   NS_IMETHOD Run() override
     508             :   {
     509           0 :     MOZ_ASSERT(NS_IsMainThread());
     510             : 
     511           0 :     NullifyContentParentRAII raii(mContentParent);
     512             : 
     513           0 :     nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(mPrincipalInfo);
     514             : 
     515           0 :     nsAutoCString origin;
     516           0 :     nsresult rv = principal->GetOrigin(origin);
     517           0 :     if (NS_FAILED(rv)) {
     518           0 :       mContentParent->KillHard("BroadcastChannel killed: principal::GetOrigin failed.");
     519           0 :       return NS_OK;
     520             :     }
     521             : 
     522           0 :     if (NS_WARN_IF(!mOrigin.Equals(origin))) {
     523           0 :       mContentParent->KillHard("BroadcastChannel killed: origins do not match.");
     524           0 :       return NS_OK;
     525             :     }
     526             : 
     527           0 :     return NS_OK;
     528             :   }
     529             : 
     530             : private:
     531             :   RefPtr<ContentParent> mContentParent;
     532             :   PrincipalInfo mPrincipalInfo;
     533             :   nsCString mOrigin;
     534             : };
     535             : 
     536             : } // namespace
     537             : 
     538             : mozilla::ipc::IPCResult
     539           0 : BackgroundParentImpl::RecvPBroadcastChannelConstructor(
     540             :                                             PBroadcastChannelParent* actor,
     541             :                                             const PrincipalInfo& aPrincipalInfo,
     542             :                                             const nsCString& aOrigin,
     543             :                                             const nsString& aChannel)
     544             : {
     545           0 :   AssertIsInMainProcess();
     546           0 :   AssertIsOnBackgroundThread();
     547             : 
     548           0 :   RefPtr<ContentParent> parent = BackgroundParent::GetContentParent(this);
     549             : 
     550             :   // If the ContentParent is null we are dealing with a same-process actor.
     551           0 :   if (!parent) {
     552           0 :     return IPC_OK();
     553             :   }
     554             : 
     555             :   RefPtr<CheckPrincipalRunnable> runnable =
     556           0 :     new CheckPrincipalRunnable(parent.forget(), aPrincipalInfo, aOrigin);
     557           0 :   MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
     558             : 
     559           0 :   return IPC_OK();
     560             : }
     561             : 
     562             : bool
     563           0 : BackgroundParentImpl::DeallocPBroadcastChannelParent(
     564             :                                                 PBroadcastChannelParent* aActor)
     565             : {
     566           0 :   AssertIsInMainProcess();
     567           0 :   AssertIsOnBackgroundThread();
     568           0 :   MOZ_ASSERT(aActor);
     569             : 
     570           0 :   delete static_cast<BroadcastChannelParent*>(aActor);
     571           0 :   return true;
     572             : }
     573             : 
     574             : mozilla::dom::PServiceWorkerManagerParent*
     575           2 : BackgroundParentImpl::AllocPServiceWorkerManagerParent()
     576             : {
     577           2 :   AssertIsInMainProcess();
     578           2 :   AssertIsOnBackgroundThread();
     579             : 
     580             :   RefPtr<dom::workers::ServiceWorkerManagerParent> agent =
     581           4 :     new dom::workers::ServiceWorkerManagerParent();
     582           4 :   return agent.forget().take();
     583             : }
     584             : 
     585             : bool
     586           0 : BackgroundParentImpl::DeallocPServiceWorkerManagerParent(
     587             :                                             PServiceWorkerManagerParent* aActor)
     588             : {
     589           0 :   AssertIsInMainProcess();
     590           0 :   AssertIsOnBackgroundThread();
     591           0 :   MOZ_ASSERT(aActor);
     592             : 
     593             :   RefPtr<dom::workers::ServiceWorkerManagerParent> parent =
     594           0 :     dont_AddRef(static_cast<dom::workers::ServiceWorkerManagerParent*>(aActor));
     595           0 :   MOZ_ASSERT(parent);
     596           0 :   return true;
     597             : }
     598             : 
     599             : mozilla::ipc::IPCResult
     600           0 : BackgroundParentImpl::RecvShutdownServiceWorkerRegistrar()
     601             : {
     602           0 :   AssertIsInMainProcess();
     603           0 :   AssertIsOnBackgroundThread();
     604             : 
     605           0 :   if (BackgroundParent::IsOtherProcessActor(this)) {
     606           0 :     return IPC_FAIL_NO_REASON(this);
     607             :   }
     608             : 
     609             :   RefPtr<dom::ServiceWorkerRegistrar> service =
     610           0 :     dom::ServiceWorkerRegistrar::Get();
     611           0 :   MOZ_ASSERT(service);
     612             : 
     613           0 :   service->Shutdown();
     614           0 :   return IPC_OK();
     615             : }
     616             : 
     617             : PCacheStorageParent*
     618           0 : BackgroundParentImpl::AllocPCacheStorageParent(const Namespace& aNamespace,
     619             :                                                const PrincipalInfo& aPrincipalInfo)
     620             : {
     621           0 :   return dom::cache::AllocPCacheStorageParent(this, aNamespace, aPrincipalInfo);
     622             : }
     623             : 
     624             : bool
     625           0 : BackgroundParentImpl::DeallocPCacheStorageParent(PCacheStorageParent* aActor)
     626             : {
     627           0 :   dom::cache::DeallocPCacheStorageParent(aActor);
     628           0 :   return true;
     629             : }
     630             : 
     631             : PCacheParent*
     632           0 : BackgroundParentImpl::AllocPCacheParent()
     633             : {
     634           0 :   MOZ_CRASH("CacheParent actor must be provided to PBackground manager");
     635             :   return nullptr;
     636             : }
     637             : 
     638             : bool
     639           0 : BackgroundParentImpl::DeallocPCacheParent(PCacheParent* aActor)
     640             : {
     641           0 :   dom::cache::DeallocPCacheParent(aActor);
     642           0 :   return true;
     643             : }
     644             : 
     645             : PCacheStreamControlParent*
     646           0 : BackgroundParentImpl::AllocPCacheStreamControlParent()
     647             : {
     648           0 :   MOZ_CRASH("CacheStreamControlParent actor must be provided to PBackground manager");
     649             :   return nullptr;
     650             : }
     651             : 
     652             : bool
     653           0 : BackgroundParentImpl::DeallocPCacheStreamControlParent(PCacheStreamControlParent* aActor)
     654             : {
     655           0 :   dom::cache::DeallocPCacheStreamControlParent(aActor);
     656           0 :   return true;
     657             : }
     658             : 
     659             : PMessagePortParent*
     660           0 : BackgroundParentImpl::AllocPMessagePortParent(const nsID& aUUID,
     661             :                                               const nsID& aDestinationUUID,
     662             :                                               const uint32_t& aSequenceID)
     663             : {
     664           0 :   AssertIsInMainProcess();
     665           0 :   AssertIsOnBackgroundThread();
     666             : 
     667           0 :   return new MessagePortParent(aUUID);
     668             : }
     669             : 
     670             : mozilla::ipc::IPCResult
     671           0 : BackgroundParentImpl::RecvPMessagePortConstructor(PMessagePortParent* aActor,
     672             :                                                   const nsID& aUUID,
     673             :                                                   const nsID& aDestinationUUID,
     674             :                                                   const uint32_t& aSequenceID)
     675             : {
     676           0 :   AssertIsInMainProcess();
     677           0 :   AssertIsOnBackgroundThread();
     678             : 
     679           0 :   MessagePortParent* mp = static_cast<MessagePortParent*>(aActor);
     680           0 :   if (!mp->Entangle(aDestinationUUID, aSequenceID)) {
     681           0 :     return IPC_FAIL_NO_REASON(this);
     682             :   }
     683           0 :   return IPC_OK();
     684             : }
     685             : 
     686             : bool
     687           0 : BackgroundParentImpl::DeallocPMessagePortParent(PMessagePortParent* aActor)
     688             : {
     689           0 :   AssertIsInMainProcess();
     690           0 :   AssertIsOnBackgroundThread();
     691           0 :   MOZ_ASSERT(aActor);
     692             : 
     693           0 :   delete static_cast<MessagePortParent*>(aActor);
     694           0 :   return true;
     695             : }
     696             : 
     697             : mozilla::ipc::IPCResult
     698           0 : BackgroundParentImpl::RecvMessagePortForceClose(const nsID& aUUID,
     699             :                                                 const nsID& aDestinationUUID,
     700             :                                                 const uint32_t& aSequenceID)
     701             : {
     702           0 :   AssertIsInMainProcess();
     703           0 :   AssertIsOnBackgroundThread();
     704             : 
     705           0 :   if (!MessagePortParent::ForceClose(aUUID, aDestinationUUID, aSequenceID)) {
     706           0 :     return IPC_FAIL_NO_REASON(this);
     707             :   }
     708           0 :   return IPC_OK();
     709             : }
     710             : 
     711             : PAsmJSCacheEntryParent*
     712           0 : BackgroundParentImpl::AllocPAsmJSCacheEntryParent(
     713             :                                const dom::asmjscache::OpenMode& aOpenMode,
     714             :                                const dom::asmjscache::WriteParams& aWriteParams,
     715             :                                const PrincipalInfo& aPrincipalInfo)
     716             : {
     717           0 :   AssertIsInMainProcess();
     718           0 :   AssertIsOnBackgroundThread();
     719             : 
     720             :   return
     721           0 :     dom::asmjscache::AllocEntryParent(aOpenMode, aWriteParams, aPrincipalInfo);
     722             : }
     723             : 
     724             : bool
     725           0 : BackgroundParentImpl::DeallocPAsmJSCacheEntryParent(
     726             :                                                  PAsmJSCacheEntryParent* aActor)
     727             : {
     728           0 :   AssertIsInMainProcess();
     729           0 :   AssertIsOnBackgroundThread();
     730             : 
     731           0 :   dom::asmjscache::DeallocEntryParent(aActor);
     732           0 :   return true;
     733             : }
     734             : 
     735             : BackgroundParentImpl::PQuotaParent*
     736           0 : BackgroundParentImpl::AllocPQuotaParent()
     737             : {
     738           0 :   AssertIsInMainProcess();
     739           0 :   AssertIsOnBackgroundThread();
     740             : 
     741           0 :   return mozilla::dom::quota::AllocPQuotaParent();
     742             : }
     743             : 
     744             : bool
     745           0 : BackgroundParentImpl::DeallocPQuotaParent(PQuotaParent* aActor)
     746             : {
     747           0 :   AssertIsInMainProcess();
     748           0 :   AssertIsOnBackgroundThread();
     749           0 :   MOZ_ASSERT(aActor);
     750             : 
     751           0 :   return mozilla::dom::quota::DeallocPQuotaParent(aActor);
     752             : }
     753             : 
     754             : dom::PFileSystemRequestParent*
     755           0 : BackgroundParentImpl::AllocPFileSystemRequestParent(
     756             :                                                 const FileSystemParams& aParams)
     757             : {
     758           0 :   AssertIsInMainProcess();
     759           0 :   AssertIsOnBackgroundThread();
     760             : 
     761           0 :   RefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
     762             : 
     763           0 :   if (NS_WARN_IF(!result->Initialize(aParams))) {
     764           0 :     return nullptr;
     765             :   }
     766             : 
     767           0 :   return result.forget().take();
     768             : }
     769             : 
     770             : mozilla::ipc::IPCResult
     771           0 : BackgroundParentImpl::RecvPFileSystemRequestConstructor(
     772             :                                                PFileSystemRequestParent* aActor,
     773             :                                                const FileSystemParams& params)
     774             : {
     775           0 :   static_cast<FileSystemRequestParent*>(aActor)->Start();
     776           0 :   return IPC_OK();
     777             : }
     778             : 
     779             : bool
     780           0 : BackgroundParentImpl::DeallocPFileSystemRequestParent(
     781             :                                               PFileSystemRequestParent* aDoomed)
     782             : {
     783           0 :   AssertIsInMainProcess();
     784           0 :   AssertIsOnBackgroundThread();
     785             : 
     786             :   RefPtr<FileSystemRequestParent> parent =
     787           0 :     dont_AddRef(static_cast<FileSystemRequestParent*>(aDoomed));
     788           0 :   return true;
     789             : }
     790             : 
     791             : // Gamepad API Background IPC
     792             : dom::PGamepadEventChannelParent*
     793           0 : BackgroundParentImpl::AllocPGamepadEventChannelParent()
     794             : {
     795             :   RefPtr<dom::GamepadEventChannelParent> parent =
     796           0 :     new dom::GamepadEventChannelParent();
     797             : 
     798           0 :   return parent.forget().take();
     799             : }
     800             : 
     801             : bool
     802           0 : BackgroundParentImpl::DeallocPGamepadEventChannelParent(dom::PGamepadEventChannelParent *aActor)
     803             : {
     804           0 :   MOZ_ASSERT(aActor);
     805             :   RefPtr<dom::GamepadEventChannelParent> parent =
     806           0 :     dont_AddRef(static_cast<dom::GamepadEventChannelParent*>(aActor));
     807           0 :   return true;
     808             : }
     809             : 
     810             : dom::PGamepadTestChannelParent*
     811           0 : BackgroundParentImpl::AllocPGamepadTestChannelParent()
     812             : {
     813             :   RefPtr<dom::GamepadTestChannelParent> parent =
     814           0 :     new dom::GamepadTestChannelParent();
     815             : 
     816           0 :   return parent.forget().take();
     817             : }
     818             : 
     819             : bool
     820           0 : BackgroundParentImpl::DeallocPGamepadTestChannelParent(dom::PGamepadTestChannelParent *aActor)
     821             : {
     822           0 :   MOZ_ASSERT(aActor);
     823             :   RefPtr<dom::GamepadTestChannelParent> parent =
     824           0 :     dont_AddRef(static_cast<dom::GamepadTestChannelParent*>(aActor));
     825           0 :   return true;
     826             : }
     827             : 
     828             : dom::PWebAuthnTransactionParent*
     829           0 : BackgroundParentImpl::AllocPWebAuthnTransactionParent()
     830             : {
     831           0 :   return new dom::WebAuthnTransactionParent();
     832             : }
     833             : 
     834             : bool
     835           0 : BackgroundParentImpl::DeallocPWebAuthnTransactionParent(dom::PWebAuthnTransactionParent *aActor)
     836             : {
     837           0 :   MOZ_ASSERT(aActor);
     838           0 :   delete aActor;
     839           0 :   return true;
     840             : }
     841             : 
     842             : net::PHttpBackgroundChannelParent*
     843           3 : BackgroundParentImpl::AllocPHttpBackgroundChannelParent(const uint64_t& aChannelId)
     844             : {
     845           3 :   AssertIsInMainProcess();
     846           3 :   AssertIsOnBackgroundThread();
     847             : 
     848             :   RefPtr<net::HttpBackgroundChannelParent> actor =
     849           6 :     new net::HttpBackgroundChannelParent();
     850             : 
     851             :   // hold extra refcount for IPDL
     852           6 :   return actor.forget().take();
     853             : }
     854             : 
     855             : mozilla::ipc::IPCResult
     856           3 : BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
     857             :                                       net::PHttpBackgroundChannelParent *aActor,
     858             :                                       const uint64_t& aChannelId)
     859             : {
     860           3 :   MOZ_ASSERT(aActor);
     861           3 :   AssertIsInMainProcess();
     862           3 :   AssertIsOnBackgroundThread();
     863             : 
     864             :   net::HttpBackgroundChannelParent* aParent =
     865           3 :     static_cast<net::HttpBackgroundChannelParent*>(aActor);
     866             : 
     867           3 :   if (NS_WARN_IF(NS_FAILED(aParent->Init(aChannelId)))) {
     868           0 :     return IPC_FAIL_NO_REASON(this);
     869             :   }
     870             : 
     871           3 :   return IPC_OK();
     872             : }
     873             : 
     874             : bool
     875           3 : BackgroundParentImpl::DeallocPHttpBackgroundChannelParent(
     876             :                                       net::PHttpBackgroundChannelParent *aActor)
     877             : {
     878           3 :   MOZ_ASSERT(aActor);
     879           3 :   AssertIsInMainProcess();
     880           3 :   AssertIsOnBackgroundThread();
     881             : 
     882             :   // release extra refcount hold by AllocPHttpBackgroundChannelParent
     883             :   RefPtr<net::HttpBackgroundChannelParent> actor =
     884           6 :     dont_AddRef(static_cast<net::HttpBackgroundChannelParent*>(aActor));
     885             : 
     886           6 :   return true;
     887             : }
     888             : 
     889             : } // namespace ipc
     890             : } // namespace mozilla
     891             : 
     892             : void
     893           0 : TestParent::ActorDestroy(ActorDestroyReason aWhy)
     894             : {
     895           0 :   mozilla::ipc::AssertIsInMainProcess();
     896           0 :   AssertIsOnBackgroundThread();
     897           0 : }

Generated by: LCOV version 1.13