1 | /* |
2 | * Copyright (C) 2017 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'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(SERVICE_WORKER) |
29 | |
30 | #include "ServiceWorkerClientIdentifier.h" |
31 | #include "ServiceWorkerClientType.h" |
32 | #include "ServiceWorkerTypes.h" |
33 | #include <wtf/URL.h> |
34 | |
35 | namespace WebCore { |
36 | |
37 | class SWClientConnection; |
38 | class ScriptExecutionContext; |
39 | |
40 | struct ServiceWorkerClientData { |
41 | ServiceWorkerClientIdentifier identifier; |
42 | ServiceWorkerClientType type; |
43 | ServiceWorkerClientFrameType frameType; |
44 | URL url; |
45 | |
46 | ServiceWorkerClientData isolatedCopy() const; |
47 | |
48 | static ServiceWorkerClientData from(ScriptExecutionContext&, SWClientConnection&); |
49 | |
50 | template<class Encoder> void encode(Encoder&) const; |
51 | template<class Decoder> static Optional<ServiceWorkerClientData> decode(Decoder&); |
52 | }; |
53 | |
54 | template<class Encoder> |
55 | void ServiceWorkerClientData::encode(Encoder& encoder) const |
56 | { |
57 | encoder << identifier << type << frameType << url; |
58 | } |
59 | |
60 | template<class Decoder> |
61 | Optional<ServiceWorkerClientData> ServiceWorkerClientData::decode(Decoder& decoder) |
62 | { |
63 | Optional<ServiceWorkerClientIdentifier> identifier; |
64 | decoder >> identifier; |
65 | if (!identifier) |
66 | return WTF::nullopt; |
67 | |
68 | Optional<ServiceWorkerClientType> type; |
69 | decoder >> type; |
70 | if (!type) |
71 | return WTF::nullopt; |
72 | |
73 | Optional<ServiceWorkerClientFrameType> frameType; |
74 | decoder >> frameType; |
75 | if (!frameType) |
76 | return WTF::nullopt; |
77 | |
78 | Optional<URL> url; |
79 | decoder >> url; |
80 | if (!url) |
81 | return WTF::nullopt; |
82 | |
83 | return { { WTFMove(*identifier), WTFMove(*type), WTFMove(*frameType), WTFMove(*url) } }; |
84 | } |
85 | |
86 | using ServiceWorkerClientsMatchAllCallback = WTF::CompletionHandler<void(Vector<ServiceWorkerClientData>&&)>; |
87 | |
88 | } // namespace WebCore |
89 | |
90 | #endif // ENABLE(SERVICE_WORKER) |
91 | |