2 * Copyright (C) 2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #if ENABLE(SERVICE_WORKER)
30 #include "SecurityOriginData.h"
31 #include "ServiceWorkerJobType.h"
32 #include "ServiceWorkerRegistrationKey.h"
33 #include "ServiceWorkerRegistrationOptions.h"
35 #include <wtf/Identified.h>
39 struct ServiceWorkerJobData : public ThreadSafeIdentified<ServiceWorkerJobData> {
41 explicit ServiceWorkerJobData(uint64_t connectionIdentifier);
42 ServiceWorkerJobData(const ServiceWorkerJobData&) = default;
43 ServiceWorkerJobData() = default;
45 uint64_t connectionIdentifier() const { return m_connectionIdentifier; }
48 URL clientCreationURL;
49 SecurityOriginData topOrigin;
51 ServiceWorkerJobType type;
53 RegistrationOptions registrationOptions;
55 ServiceWorkerRegistrationKey registrationKey() const;
56 ServiceWorkerJobData isolatedCopy() const;
58 template<class Encoder> void encode(Encoder&) const;
59 template<class Decoder> static std::optional<ServiceWorkerJobData> decode(Decoder&);
62 WEBCORE_EXPORT ServiceWorkerJobData(uint64_t jobIdentifier, uint64_t connectionIdentifier);
64 uint64_t m_connectionIdentifier { 0 };
67 template<class Encoder>
68 void ServiceWorkerJobData::encode(Encoder& encoder) const
70 encoder << identifier() << m_connectionIdentifier << scriptURL << clientCreationURL << topOrigin << scopeURL;
71 encoder.encodeEnum(type);
73 case ServiceWorkerJobType::Register:
74 encoder << registrationOptions;
79 template<class Decoder>
80 std::optional<ServiceWorkerJobData> ServiceWorkerJobData::decode(Decoder& decoder)
82 uint64_t jobIdentifier;
83 if (!decoder.decode(jobIdentifier))
86 uint64_t connectionIdentifier;
87 if (!decoder.decode(connectionIdentifier))
90 std::optional<ServiceWorkerJobData> jobData = { { jobIdentifier, connectionIdentifier } };
92 if (!decoder.decode(jobData->scriptURL))
94 if (!decoder.decode(jobData->clientCreationURL))
97 std::optional<SecurityOriginData> topOrigin;
101 jobData->topOrigin = WTFMove(*topOrigin);
103 if (!decoder.decode(jobData->scopeURL))
105 if (!decoder.decodeEnum(jobData->type))
108 switch (jobData->type) {
109 case ServiceWorkerJobType::Register:
110 if (!decoder.decode(jobData->registrationOptions))
118 } // namespace WebCore
120 #endif // ENABLE(SERVICE_WORKER)