1/*
2 * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#pragma once
26
27#if ENABLE(SERVICE_WORKER)
28
29#include "ArgumentCoders.h"
30#include "Connection.h"
31#include "SharedMemory.h"
32#include <WebCore/DocumentIdentifier.h>
33#include <WebCore/FetchOptions.h>
34#include <WebCore/ServiceWorkerData.h>
35#include <WebCore/ServiceWorkerIdentifier.h>
36#include <WebCore/ServiceWorkerRegistrationData.h>
37#include <WebCore/ServiceWorkerTypes.h>
38#include <wtf/Forward.h>
39#include <wtf/HashSet.h>
40#include <wtf/Optional.h>
41#include <wtf/ThreadSafeRefCounted.h>
42#include <wtf/Vector.h>
43#include <wtf/text/WTFString.h>
44
45namespace WebCore {
46enum class ServiceWorkerRegistrationState : uint8_t;
47class ServiceWorkerRegistrationKey;
48struct MessageWithMessagePorts;
49enum class ServiceWorkerUpdateViaCache : uint8_t;
50enum class ServiceWorkerState : uint8_t;
51struct ExceptionData;
52struct ServiceWorkerRegistrationData;
53enum class ShouldNotifyWhenResolved : bool;
54struct ServiceWorkerData;
55}
56
57namespace Messages {
58namespace WebSWClientConnection {
59
60static inline IPC::StringReference messageReceiverName()
61{
62 return IPC::StringReference("WebSWClientConnection");
63}
64
65class JobRejectedInServer {
66public:
67 typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, const WebCore::ExceptionData&> Arguments;
68
69 static IPC::StringReference receiverName() { return messageReceiverName(); }
70 static IPC::StringReference name() { return IPC::StringReference("JobRejectedInServer"); }
71 static const bool isSync = false;
72
73 JobRejectedInServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, const WebCore::ExceptionData& exception)
74 : m_arguments(jobDataIdentifier, exception)
75 {
76 }
77
78 const Arguments& arguments() const
79 {
80 return m_arguments;
81 }
82
83private:
84 Arguments m_arguments;
85};
86
87class RegistrationJobResolvedInServer {
88public:
89 typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, const WebCore::ServiceWorkerRegistrationData&, WebCore::ShouldNotifyWhenResolved> Arguments;
90
91 static IPC::StringReference receiverName() { return messageReceiverName(); }
92 static IPC::StringReference name() { return IPC::StringReference("RegistrationJobResolvedInServer"); }
93 static const bool isSync = false;
94
95 RegistrationJobResolvedInServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, const WebCore::ServiceWorkerRegistrationData& registration, WebCore::ShouldNotifyWhenResolved shouldNotifyWhenResolved)
96 : m_arguments(jobDataIdentifier, registration, shouldNotifyWhenResolved)
97 {
98 }
99
100 const Arguments& arguments() const
101 {
102 return m_arguments;
103 }
104
105private:
106 Arguments m_arguments;
107};
108
109class UnregistrationJobResolvedInServer {
110public:
111 typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, bool> Arguments;
112
113 static IPC::StringReference receiverName() { return messageReceiverName(); }
114 static IPC::StringReference name() { return IPC::StringReference("UnregistrationJobResolvedInServer"); }
115 static const bool isSync = false;
116
117 UnregistrationJobResolvedInServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, bool unregistrationResult)
118 : m_arguments(jobDataIdentifier, unregistrationResult)
119 {
120 }
121
122 const Arguments& arguments() const
123 {
124 return m_arguments;
125 }
126
127private:
128 Arguments m_arguments;
129};
130
131class StartScriptFetchForServer {
132public:
133 typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, const WebCore::ServiceWorkerRegistrationKey&, const WebCore::FetchOptions::Cache&> Arguments;
134
135 static IPC::StringReference receiverName() { return messageReceiverName(); }
136 static IPC::StringReference name() { return IPC::StringReference("StartScriptFetchForServer"); }
137 static const bool isSync = false;
138
139 StartScriptFetchForServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, const WebCore::ServiceWorkerRegistrationKey& registrationKey, const WebCore::FetchOptions::Cache& cachePolicy)
140 : m_arguments(jobDataIdentifier, registrationKey, cachePolicy)
141 {
142 }
143
144 const Arguments& arguments() const
145 {
146 return m_arguments;
147 }
148
149private:
150 Arguments m_arguments;
151};
152
153class UpdateRegistrationState {
154public:
155 typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, WebCore::ServiceWorkerRegistrationState, const Optional<WebCore::ServiceWorkerData>&> Arguments;
156
157 static IPC::StringReference receiverName() { return messageReceiverName(); }
158 static IPC::StringReference name() { return IPC::StringReference("UpdateRegistrationState"); }
159 static const bool isSync = false;
160
161 UpdateRegistrationState(const WebCore::ServiceWorkerRegistrationIdentifier& identifier, WebCore::ServiceWorkerRegistrationState state, const Optional<WebCore::ServiceWorkerData>& serviceWorkerIdentifier)
162 : m_arguments(identifier, state, serviceWorkerIdentifier)
163 {
164 }
165
166 const Arguments& arguments() const
167 {
168 return m_arguments;
169 }
170
171private:
172 Arguments m_arguments;
173};
174
175class UpdateWorkerState {
176public:
177 typedef std::tuple<const WebCore::ServiceWorkerIdentifier&, WebCore::ServiceWorkerState> Arguments;
178
179 static IPC::StringReference receiverName() { return messageReceiverName(); }
180 static IPC::StringReference name() { return IPC::StringReference("UpdateWorkerState"); }
181 static const bool isSync = false;
182
183 UpdateWorkerState(const WebCore::ServiceWorkerIdentifier& serviceWorkerIdentifier, WebCore::ServiceWorkerState state)
184 : m_arguments(serviceWorkerIdentifier, state)
185 {
186 }
187
188 const Arguments& arguments() const
189 {
190 return m_arguments;
191 }
192
193private:
194 Arguments m_arguments;
195};
196
197class FireUpdateFoundEvent {
198public:
199 typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&> Arguments;
200
201 static IPC::StringReference receiverName() { return messageReceiverName(); }
202 static IPC::StringReference name() { return IPC::StringReference("FireUpdateFoundEvent"); }
203 static const bool isSync = false;
204
205 explicit FireUpdateFoundEvent(const WebCore::ServiceWorkerRegistrationIdentifier& identifier)
206 : m_arguments(identifier)
207 {
208 }
209
210 const Arguments& arguments() const
211 {
212 return m_arguments;
213 }
214
215private:
216 Arguments m_arguments;
217};
218
219class SetRegistrationLastUpdateTime {
220public:
221 typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, const WallTime&> Arguments;
222
223 static IPC::StringReference receiverName() { return messageReceiverName(); }
224 static IPC::StringReference name() { return IPC::StringReference("SetRegistrationLastUpdateTime"); }
225 static const bool isSync = false;
226
227 SetRegistrationLastUpdateTime(const WebCore::ServiceWorkerRegistrationIdentifier& identifier, const WallTime& lastUpdateTime)
228 : m_arguments(identifier, lastUpdateTime)
229 {
230 }
231
232 const Arguments& arguments() const
233 {
234 return m_arguments;
235 }
236
237private:
238 Arguments m_arguments;
239};
240
241class SetRegistrationUpdateViaCache {
242public:
243 typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, WebCore::ServiceWorkerUpdateViaCache> Arguments;
244
245 static IPC::StringReference receiverName() { return messageReceiverName(); }
246 static IPC::StringReference name() { return IPC::StringReference("SetRegistrationUpdateViaCache"); }
247 static const bool isSync = false;
248
249 SetRegistrationUpdateViaCache(const WebCore::ServiceWorkerRegistrationIdentifier& identifier, WebCore::ServiceWorkerUpdateViaCache updateViaCache)
250 : m_arguments(identifier, updateViaCache)
251 {
252 }
253
254 const Arguments& arguments() const
255 {
256 return m_arguments;
257 }
258
259private:
260 Arguments m_arguments;
261};
262
263class NotifyClientsOfControllerChange {
264public:
265 typedef std::tuple<const HashSet<WebCore::DocumentIdentifier>&, const WebCore::ServiceWorkerData&> Arguments;
266
267 static IPC::StringReference receiverName() { return messageReceiverName(); }
268 static IPC::StringReference name() { return IPC::StringReference("NotifyClientsOfControllerChange"); }
269 static const bool isSync = false;
270
271 NotifyClientsOfControllerChange(const HashSet<WebCore::DocumentIdentifier>& contextIdentifiers, const WebCore::ServiceWorkerData& newController)
272 : m_arguments(contextIdentifiers, newController)
273 {
274 }
275
276 const Arguments& arguments() const
277 {
278 return m_arguments;
279 }
280
281private:
282 Arguments m_arguments;
283};
284
285class SetSWOriginTableIsImported {
286public:
287 typedef std::tuple<> Arguments;
288
289 static IPC::StringReference receiverName() { return messageReceiverName(); }
290 static IPC::StringReference name() { return IPC::StringReference("SetSWOriginTableIsImported"); }
291 static const bool isSync = false;
292
293 const Arguments& arguments() const
294 {
295 return m_arguments;
296 }
297
298private:
299 Arguments m_arguments;
300};
301
302class SetSWOriginTableSharedMemory {
303public:
304 typedef std::tuple<const WebKit::SharedMemory::Handle&> Arguments;
305
306 static IPC::StringReference receiverName() { return messageReceiverName(); }
307 static IPC::StringReference name() { return IPC::StringReference("SetSWOriginTableSharedMemory"); }
308 static const bool isSync = false;
309
310 explicit SetSWOriginTableSharedMemory(const WebKit::SharedMemory::Handle& handle)
311 : m_arguments(handle)
312 {
313 }
314
315 const Arguments& arguments() const
316 {
317 return m_arguments;
318 }
319
320private:
321 Arguments m_arguments;
322};
323
324class PostMessageToServiceWorkerClient {
325public:
326 typedef std::tuple<const WebCore::DocumentIdentifier&, const WebCore::MessageWithMessagePorts&, const WebCore::ServiceWorkerData&, const String&> Arguments;
327
328 static IPC::StringReference receiverName() { return messageReceiverName(); }
329 static IPC::StringReference name() { return IPC::StringReference("PostMessageToServiceWorkerClient"); }
330 static const bool isSync = false;
331
332 PostMessageToServiceWorkerClient(const WebCore::DocumentIdentifier& destinationContextIdentifier, const WebCore::MessageWithMessagePorts& message, const WebCore::ServiceWorkerData& source, const String& sourceOrigin)
333 : m_arguments(destinationContextIdentifier, message, source, sourceOrigin)
334 {
335 }
336
337 const Arguments& arguments() const
338 {
339 return m_arguments;
340 }
341
342private:
343 Arguments m_arguments;
344};
345
346class DidMatchRegistration {
347public:
348 typedef std::tuple<uint64_t, const Optional<WebCore::ServiceWorkerRegistrationData>&> Arguments;
349
350 static IPC::StringReference receiverName() { return messageReceiverName(); }
351 static IPC::StringReference name() { return IPC::StringReference("DidMatchRegistration"); }
352 static const bool isSync = false;
353
354 DidMatchRegistration(uint64_t matchRequestIdentifier, const Optional<WebCore::ServiceWorkerRegistrationData>& data)
355 : m_arguments(matchRequestIdentifier, data)
356 {
357 }
358
359 const Arguments& arguments() const
360 {
361 return m_arguments;
362 }
363
364private:
365 Arguments m_arguments;
366};
367
368class DidGetRegistrations {
369public:
370 typedef std::tuple<uint64_t, const Vector<WebCore::ServiceWorkerRegistrationData>&> Arguments;
371
372 static IPC::StringReference receiverName() { return messageReceiverName(); }
373 static IPC::StringReference name() { return IPC::StringReference("DidGetRegistrations"); }
374 static const bool isSync = false;
375
376 DidGetRegistrations(uint64_t matchRequestIdentifier, const Vector<WebCore::ServiceWorkerRegistrationData>& registrations)
377 : m_arguments(matchRequestIdentifier, registrations)
378 {
379 }
380
381 const Arguments& arguments() const
382 {
383 return m_arguments;
384 }
385
386private:
387 Arguments m_arguments;
388};
389
390class RegistrationReady {
391public:
392 typedef std::tuple<uint64_t, const WebCore::ServiceWorkerRegistrationData&> Arguments;
393
394 static IPC::StringReference receiverName() { return messageReceiverName(); }
395 static IPC::StringReference name() { return IPC::StringReference("RegistrationReady"); }
396 static const bool isSync = false;
397
398 RegistrationReady(uint64_t registrationReadyRequestIdentifier, const WebCore::ServiceWorkerRegistrationData& data)
399 : m_arguments(registrationReadyRequestIdentifier, data)
400 {
401 }
402
403 const Arguments& arguments() const
404 {
405 return m_arguments;
406 }
407
408private:
409 Arguments m_arguments;
410};
411
412} // namespace WebSWClientConnection
413} // namespace Messages
414
415#endif // ENABLE(SERVICE_WORKER)
416