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 "ServiceWorkerContainerParent.h"
8
9
#include "ServiceWorkerContainerProxy.h"
10
11
namespace mozilla {
12
namespace dom {
13
14
using mozilla::ipc::IPCResult;
15
16
void ServiceWorkerContainerParent::ActorDestroy(ActorDestroyReason aReason) {
17
if (mProxy) {
18
mProxy->RevokeActor(this);
19
mProxy = nullptr;
20
}
21
}
22
23
IPCResult ServiceWorkerContainerParent::RecvTeardown() {
24
Unused << Send__delete__(this);
25
return IPC_OK();
26
}
27
28
IPCResult ServiceWorkerContainerParent::RecvRegister(
29
const IPCClientInfo& aClientInfo, const nsCString& aScopeURL,
30
const nsCString& aScriptURL,
31
const ServiceWorkerUpdateViaCache& aUpdateViaCache,
32
RegisterResolver&& aResolver) {
33
if (!mProxy) {
34
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
35
return IPC_OK();
36
}
37
38
mProxy
39
->Register(ClientInfo(aClientInfo), aScopeURL, aScriptURL,
40
aUpdateViaCache)
41
->Then(
42
GetCurrentThreadSerialEventTarget(), __func__,
43
[aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
44
aResolver(aDescriptor.ToIPC());
45
},
46
[aResolver](const CopyableErrorResult& aResult) {
47
aResolver(aResult);
48
});
49
50
return IPC_OK();
51
}
52
53
IPCResult ServiceWorkerContainerParent::RecvGetRegistration(
54
const IPCClientInfo& aClientInfo, const nsCString& aURL,
55
GetRegistrationResolver&& aResolver) {
56
if (!mProxy) {
57
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
58
return IPC_OK();
59
}
60
61
mProxy->GetRegistration(ClientInfo(aClientInfo), aURL)
62
->Then(
63
GetCurrentThreadSerialEventTarget(), __func__,
64
[aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
65
aResolver(aDescriptor.ToIPC());
66
},
67
[aResolver](const CopyableErrorResult& aResult) {
68
aResolver(aResult);
69
});
70
71
return IPC_OK();
72
}
73
74
IPCResult ServiceWorkerContainerParent::RecvGetRegistrations(
75
const IPCClientInfo& aClientInfo, GetRegistrationsResolver&& aResolver) {
76
if (!mProxy) {
77
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
78
return IPC_OK();
79
}
80
81
mProxy->GetRegistrations(ClientInfo(aClientInfo))
82
->Then(
83
GetCurrentThreadSerialEventTarget(), __func__,
84
[aResolver](
85
const nsTArray<ServiceWorkerRegistrationDescriptor>& aList) {
86
IPCServiceWorkerRegistrationDescriptorList ipcList;
87
for (auto& desc : aList) {
88
ipcList.values().AppendElement(desc.ToIPC());
89
}
90
aResolver(std::move(ipcList));
91
},
92
[aResolver](const CopyableErrorResult& aResult) {
93
aResolver(aResult);
94
});
95
96
return IPC_OK();
97
}
98
99
IPCResult ServiceWorkerContainerParent::RecvGetReady(
100
const IPCClientInfo& aClientInfo, GetReadyResolver&& aResolver) {
101
if (!mProxy) {
102
aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
103
return IPC_OK();
104
}
105
106
mProxy->GetReady(ClientInfo(aClientInfo))
107
->Then(
108
GetCurrentThreadSerialEventTarget(), __func__,
109
[aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
110
aResolver(aDescriptor.ToIPC());
111
},
112
[aResolver](const CopyableErrorResult& aResult) {
113
aResolver(aResult);
114
});
115
116
return IPC_OK();
117
}
118
119
ServiceWorkerContainerParent::ServiceWorkerContainerParent() {}
120
121
ServiceWorkerContainerParent::~ServiceWorkerContainerParent() {
122
MOZ_DIAGNOSTIC_ASSERT(!mProxy);
123
}
124
125
void ServiceWorkerContainerParent::Init() {
126
mProxy = new ServiceWorkerContainerProxy(this);
127
}
128
129
} // namespace dom
130
} // namespace mozilla