RemoteWorkerParent.cpp (3863B)
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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "RemoteWorkerParent.h" 8 9 #include "RemoteWorkerController.h" 10 #include "RemoteWorkerServiceParent.h" 11 #include "mozilla/dom/ContentParent.h" 12 #include "mozilla/dom/PFetchEventOpProxyParent.h" 13 #include "mozilla/ipc/BackgroundParent.h" 14 15 namespace mozilla { 16 17 using namespace ipc; 18 19 namespace dom { 20 21 RemoteWorkerParent::RemoteWorkerParent( 22 UniqueThreadsafeContentParentKeepAlive&& aKeepAlive) 23 : mContentParentKeepAlive(std::move(aKeepAlive)) { 24 AssertIsOnBackgroundThread(); 25 MOZ_ASSERT(XRE_IsParentProcess()); 26 } 27 28 RemoteWorkerParent::~RemoteWorkerParent() { 29 AssertIsOnBackgroundThread(); 30 MOZ_ASSERT(XRE_IsParentProcess()); 31 } 32 33 RemoteWorkerServiceParent* RemoteWorkerParent::Manager() const { 34 return static_cast<RemoteWorkerServiceParent*>( 35 PRemoteWorkerParent::Manager()); 36 } 37 38 already_AddRefed<PFetchEventOpProxyParent> 39 RemoteWorkerParent::AllocPFetchEventOpProxyParent( 40 const ParentToChildServiceWorkerFetchEventOpArgs& aArgs) { 41 MOZ_CRASH("PFetchEventOpProxyParent actors must be manually constructed!"); 42 return nullptr; 43 } 44 45 void RemoteWorkerParent::ActorDestroy(IProtocol::ActorDestroyReason) { 46 AssertIsOnBackgroundThread(); 47 MOZ_ASSERT(XRE_IsParentProcess()); 48 49 mContentParentKeepAlive = nullptr; 50 51 if (mController) { 52 mController->NoteDeadWorkerActor(); 53 mController = nullptr; 54 } 55 } 56 57 IPCResult RemoteWorkerParent::RecvCreated(const bool& aStatus) { 58 AssertIsOnBackgroundThread(); 59 MOZ_ASSERT(XRE_IsParentProcess()); 60 61 if (!mController) { 62 return IPC_OK(); 63 } 64 65 if (aStatus) { 66 mController->CreationSucceeded(); 67 } else { 68 mController->CreationFailed(); 69 } 70 71 return IPC_OK(); 72 } 73 74 IPCResult RemoteWorkerParent::RecvError(const ErrorValue& aValue) { 75 AssertIsOnBackgroundThread(); 76 MOZ_ASSERT(XRE_IsParentProcess()); 77 78 if (mController) { 79 mController->ErrorPropagation(aValue); 80 } 81 82 return IPC_OK(); 83 } 84 85 IPCResult RemoteWorkerParent::RecvNotifyLock(const bool& aCreated) { 86 AssertIsOnBackgroundThread(); 87 MOZ_ASSERT(XRE_IsParentProcess()); 88 89 if (mController) { 90 mController->NotifyLock(aCreated); 91 } 92 93 return IPC_OK(); 94 } 95 96 IPCResult RemoteWorkerParent::RecvNotifyWebTransport(const bool& aCreated) { 97 AssertIsOnBackgroundThread(); 98 MOZ_ASSERT(XRE_IsParentProcess()); 99 100 if (mController) { 101 mController->NotifyWebTransport(aCreated); 102 } 103 104 return IPC_OK(); 105 } 106 107 void RemoteWorkerParent::MaybeSendDelete() { 108 if (mDeleteSent) { 109 return; 110 } 111 112 // For some reason, if the following two lines are swapped, ASan says there's 113 // a UAF... 114 mDeleteSent = true; 115 (void)Send__delete__(this); 116 } 117 118 IPCResult RemoteWorkerParent::RecvClose() { 119 AssertIsOnBackgroundThread(); 120 MOZ_ASSERT(XRE_IsParentProcess()); 121 122 if (mController) { 123 mController->WorkerTerminated(); 124 } 125 126 MaybeSendDelete(); 127 128 return IPC_OK(); 129 } 130 131 void RemoteWorkerParent::SetController(RemoteWorkerController* aController) { 132 AssertIsOnBackgroundThread(); 133 MOZ_ASSERT(XRE_IsParentProcess()); 134 135 mController = aController; 136 } 137 138 IPCResult RemoteWorkerParent::RecvSetServiceWorkerSkipWaitingFlag( 139 SetServiceWorkerSkipWaitingFlagResolver&& aResolve) { 140 AssertIsOnBackgroundThread(); 141 MOZ_ASSERT(XRE_IsParentProcess()); 142 143 if (mController) { 144 mController->SetServiceWorkerSkipWaitingFlag()->Then( 145 GetCurrentSerialEventTarget(), __func__, 146 [resolve = aResolve](bool /* unused */) { resolve(true); }, 147 [resolve = aResolve](nsresult /* unused */) { resolve(false); }); 148 } else { 149 aResolve(false); 150 } 151 152 return IPC_OK(); 153 } 154 155 } // namespace dom 156 } // namespace mozilla