ServiceWorkerParent.cpp (1748B)
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 "ServiceWorkerParent.h" 8 9 #include "ServiceWorkerCloneData.h" 10 #include "ServiceWorkerProxy.h" 11 #include "mozilla/dom/ClientInfo.h" 12 #include "mozilla/dom/ClientState.h" 13 #include "mozilla/dom/ipc/StructuredCloneData.h" 14 15 namespace mozilla::dom { 16 17 using mozilla::dom::ipc::StructuredCloneData; 18 using mozilla::ipc::IPCResult; 19 20 void ServiceWorkerParent::ActorDestroy(ActorDestroyReason aReason) { 21 if (mProxy) { 22 mProxy->RevokeActor(this); 23 mProxy = nullptr; 24 } 25 } 26 27 IPCResult ServiceWorkerParent::RecvTeardown() { 28 MaybeSendDelete(); 29 return IPC_OK(); 30 } 31 32 IPCResult ServiceWorkerParent::RecvPostMessage( 33 const ClonedOrErrorMessageData& aClonedData, 34 const PostMessageSource& aSource) { 35 RefPtr<ServiceWorkerCloneData> data = new ServiceWorkerCloneData(); 36 data->CopyFromClonedMessageData(aClonedData); 37 38 mProxy->PostMessage(std::move(data), aSource); 39 40 return IPC_OK(); 41 } 42 43 ServiceWorkerParent::ServiceWorkerParent() : mDeleteSent(false) {} 44 45 ServiceWorkerParent::~ServiceWorkerParent() { MOZ_DIAGNOSTIC_ASSERT(!mProxy); } 46 47 void ServiceWorkerParent::Init(const IPCServiceWorkerDescriptor& aDescriptor) { 48 MOZ_DIAGNOSTIC_ASSERT(!mProxy); 49 mProxy = new ServiceWorkerProxy(ServiceWorkerDescriptor(aDescriptor)); 50 mProxy->Init(this); 51 } 52 53 void ServiceWorkerParent::MaybeSendDelete() { 54 if (mDeleteSent) { 55 return; 56 } 57 mDeleteSent = true; 58 (void)Send__delete__(this); 59 } 60 61 } // namespace mozilla::dom