b9cab73531cafaead24bee94a5b49991f44526dd
[WebKit-https.git] / Source / WebCore / workers / service / ServiceWorkerTypes.h
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 "DocumentIdentifier.h"
31 #include "ServiceWorkerIdentifier.h"
32 #include <wtf/EnumTraits.h>
33 #include <wtf/ObjectIdentifier.h>
34 #include <wtf/Variant.h>
35
36 namespace WebCore {
37
38 struct ServiceWorkerData;
39 struct ServiceWorkerClientData;
40
41 enum class ServiceWorkerRegistrationState {
42     Installing = 0,
43     Waiting = 1,
44     Active = 2,
45 };
46
47 enum class ServiceWorkerState {
48     Installing,
49     Installed,
50     Activating,
51     Activated,
52     Redundant,
53 };
54
55 enum class ServiceWorkerClientFrameType {
56     Auxiliary,
57     TopLevel,
58     Nested,
59     None
60 };
61
62 enum class ShouldNotifyWhenResolved { No, Yes };
63
64 enum ServiceWorkerRegistrationIdentifierType { };
65 using ServiceWorkerRegistrationIdentifier = ObjectIdentifier<ServiceWorkerRegistrationIdentifierType>;
66
67 enum ServiceWorkerJobIdentifierType { };
68 using ServiceWorkerJobIdentifier = ObjectIdentifier<ServiceWorkerJobIdentifierType>;
69
70 enum SWServerToContextConnectionIdentifierType { };
71 using SWServerToContextConnectionIdentifier = ObjectIdentifier<SWServerToContextConnectionIdentifierType>;
72
73 enum SWServerConnectionIdentifierType { };
74 using SWServerConnectionIdentifier = ObjectIdentifier<SWServerConnectionIdentifierType>;
75
76 using DocumentOrWorkerIdentifier = Variant<DocumentIdentifier, ServiceWorkerIdentifier>;
77
78 using ServiceWorkerOrClientData = Variant<ServiceWorkerData, ServiceWorkerClientData>;
79
80 } // namespace WebCore
81
82 namespace WTF {
83
84 template <> struct EnumTraits<WebCore::ServiceWorkerClientFrameType> {
85     using values = EnumValues<
86         WebCore::ServiceWorkerClientFrameType,
87         WebCore::ServiceWorkerClientFrameType::Auxiliary,
88         WebCore::ServiceWorkerClientFrameType::TopLevel,
89         WebCore::ServiceWorkerClientFrameType::Nested,
90         WebCore::ServiceWorkerClientFrameType::None
91     >;
92 };
93
94 template <> struct EnumTraits<WebCore::ServiceWorkerRegistrationState> {
95     using values = EnumValues<
96         WebCore::ServiceWorkerRegistrationState,
97         WebCore::ServiceWorkerRegistrationState::Installing,
98         WebCore::ServiceWorkerRegistrationState::Waiting,
99         WebCore::ServiceWorkerRegistrationState::Active
100     >;
101 };
102
103 template <> struct EnumTraits<WebCore::ServiceWorkerState> {
104     using values = EnumValues<
105         WebCore::ServiceWorkerState,
106         WebCore::ServiceWorkerState::Installing,
107         WebCore::ServiceWorkerState::Installed,
108         WebCore::ServiceWorkerState::Activating,
109         WebCore::ServiceWorkerState::Activated,
110         WebCore::ServiceWorkerState::Redundant
111     >;
112 };
113
114 template <> struct EnumTraits<WebCore::ShouldNotifyWhenResolved> {
115     using values = EnumValues<
116         WebCore::ShouldNotifyWhenResolved,
117         WebCore::ShouldNotifyWhenResolved::No,
118         WebCore::ShouldNotifyWhenResolved::Yes
119     >;
120 };
121
122 } // namespace WTF
123
124 #endif // ENABLE(SERVICE_WORKER)