Source code

Revision control

Other Tools

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