| 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 "ServiceWorkerData.h" |
| 31 | #include "ServiceWorkerIdentifier.h" |
| 32 | #include "ServiceWorkerRegistrationKey.h" |
| 33 | #include "ServiceWorkerTypes.h" |
| 34 | #include "ServiceWorkerUpdateViaCache.h" |
| 35 | #include <wtf/WallTime.h> |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
| 39 | enum class ServiceWorkerUpdateViaCache : uint8_t; |
| 40 | |
| 41 | struct ServiceWorkerRegistrationData { |
| 42 | ServiceWorkerRegistrationKey key; |
| 43 | ServiceWorkerRegistrationIdentifier identifier; |
| 44 | URL scopeURL; |
| 45 | ServiceWorkerUpdateViaCache updateViaCache; |
| 46 | WallTime lastUpdateTime; |
| 47 | |
| 48 | Optional<ServiceWorkerData> installingWorker; |
| 49 | Optional<ServiceWorkerData> waitingWorker; |
| 50 | Optional<ServiceWorkerData> activeWorker; |
| 51 | |
| 52 | ServiceWorkerRegistrationData isolatedCopy() const; |
| 53 | |
| 54 | template<class Encoder> void encode(Encoder&) const; |
| 55 | template<class Decoder> static Optional<ServiceWorkerRegistrationData> decode(Decoder&); |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | template<class Encoder> |
| 60 | void ServiceWorkerRegistrationData::encode(Encoder& encoder) const |
| 61 | { |
| 62 | encoder << key << identifier << scopeURL << updateViaCache << lastUpdateTime.secondsSinceEpoch().value() << installingWorker << waitingWorker << activeWorker; |
| 63 | } |
| 64 | |
| 65 | template<class Decoder> |
| 66 | Optional<ServiceWorkerRegistrationData> ServiceWorkerRegistrationData::decode(Decoder& decoder) |
| 67 | { |
| 68 | Optional<ServiceWorkerRegistrationKey> key; |
| 69 | decoder >> key; |
| 70 | if (!key) |
| 71 | return WTF::nullopt; |
| 72 | |
| 73 | Optional<ServiceWorkerRegistrationIdentifier> identifier; |
| 74 | decoder >> identifier; |
| 75 | if (!identifier) |
| 76 | return WTF::nullopt; |
| 77 | |
| 78 | Optional<URL> scopeURL; |
| 79 | decoder >> scopeURL; |
| 80 | if (!scopeURL) |
| 81 | return WTF::nullopt; |
| 82 | |
| 83 | Optional<ServiceWorkerUpdateViaCache> updateViaCache; |
| 84 | decoder >> updateViaCache; |
| 85 | if (!updateViaCache) |
| 86 | return WTF::nullopt; |
| 87 | |
| 88 | Optional<double> rawWallTime; |
| 89 | decoder >> rawWallTime; |
| 90 | if (!rawWallTime) |
| 91 | return WTF::nullopt; |
| 92 | |
| 93 | Optional<Optional<ServiceWorkerData>> installingWorker; |
| 94 | decoder >> installingWorker; |
| 95 | if (!installingWorker) |
| 96 | return WTF::nullopt; |
| 97 | |
| 98 | Optional<Optional<ServiceWorkerData>> waitingWorker; |
| 99 | decoder >> waitingWorker; |
| 100 | if (!waitingWorker) |
| 101 | return WTF::nullopt; |
| 102 | |
| 103 | Optional<Optional<ServiceWorkerData>> activeWorker; |
| 104 | decoder >> activeWorker; |
| 105 | if (!activeWorker) |
| 106 | return WTF::nullopt; |
| 107 | |
| 108 | return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*scopeURL), WTFMove(*updateViaCache), WallTime::fromRawSeconds(*rawWallTime), WTFMove(*installingWorker), WTFMove(*waitingWorker), WTFMove(*activeWorker) } }; |
| 109 | } |
| 110 | |
| 111 | } // namespace WTF |
| 112 | |
| 113 | #endif // ENABLE(SERVICE_WORKER) |
| 114 | |