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 "RegistrableDomain.h" |
31 | #include "ServiceWorkerClientQueryOptions.h" |
32 | #include "ServiceWorkerContextData.h" |
33 | #include "ServiceWorkerIdentifier.h" |
34 | #include "ServiceWorkerTypes.h" |
35 | #include <wtf/RefCounted.h> |
36 | |
37 | namespace PAL { |
38 | class SessionID; |
39 | } |
40 | |
41 | namespace WebCore { |
42 | |
43 | class SWServer; |
44 | struct ServiceWorkerClientData; |
45 | struct ServiceWorkerClientIdentifier; |
46 | struct ServiceWorkerContextData; |
47 | struct ServiceWorkerJobDataIdentifier; |
48 | |
49 | class SWServerToContextConnection : public RefCounted<SWServerToContextConnection> { |
50 | public: |
51 | WEBCORE_EXPORT virtual ~SWServerToContextConnection(); |
52 | |
53 | SWServerToContextConnectionIdentifier identifier() const { return m_identifier; } |
54 | |
55 | // Messages to the SW host process |
56 | virtual void installServiceWorkerContext(const ServiceWorkerContextData&, PAL::SessionID, const String& userAgent) = 0; |
57 | virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0; |
58 | virtual void fireActivateEvent(ServiceWorkerIdentifier) = 0; |
59 | virtual void terminateWorker(ServiceWorkerIdentifier) = 0; |
60 | virtual void syncTerminateWorker(ServiceWorkerIdentifier) = 0; |
61 | virtual void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<ServiceWorkerClientData>&, bool hasSecurityError) = 0; |
62 | virtual void matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>&) = 0; |
63 | virtual void claimCompleted(uint64_t requestIdentifier) = 0; |
64 | virtual void didFinishSkipWaiting(uint64_t callbackID) = 0; |
65 | |
66 | // Messages back from the SW host process |
67 | WEBCORE_EXPORT void scriptContextFailedToStart(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, const String& message); |
68 | WEBCORE_EXPORT void scriptContextStarted(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier); |
69 | WEBCORE_EXPORT void didFinishInstall(const Optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, bool wasSuccessful); |
70 | WEBCORE_EXPORT void didFinishActivation(ServiceWorkerIdentifier); |
71 | WEBCORE_EXPORT void setServiceWorkerHasPendingEvents(ServiceWorkerIdentifier, bool hasPendingEvents); |
72 | WEBCORE_EXPORT void skipWaiting(ServiceWorkerIdentifier, uint64_t callbackID); |
73 | WEBCORE_EXPORT void workerTerminated(ServiceWorkerIdentifier); |
74 | WEBCORE_EXPORT void findClientByIdentifier(uint64_t clientIdRequestIdentifier, ServiceWorkerIdentifier, ServiceWorkerClientIdentifier); |
75 | WEBCORE_EXPORT void matchAll(uint64_t requestIdentifier, ServiceWorkerIdentifier, const ServiceWorkerClientQueryOptions&); |
76 | WEBCORE_EXPORT void claim(uint64_t requestIdentifier, ServiceWorkerIdentifier); |
77 | WEBCORE_EXPORT void setScriptResource(ServiceWorkerIdentifier, URL&& scriptURL, String&& script, URL&& responseURL, String&& mimeType); |
78 | |
79 | WEBCORE_EXPORT static SWServerToContextConnection* connectionForRegistrableDomain(const RegistrableDomain&); |
80 | |
81 | const RegistrableDomain& registrableDomain() const { return m_registrableDomain; } |
82 | |
83 | virtual void connectionMayNoLongerBeNeeded() = 0; |
84 | |
85 | protected: |
86 | WEBCORE_EXPORT explicit SWServerToContextConnection(const RegistrableDomain&); |
87 | |
88 | private: |
89 | SWServerToContextConnectionIdentifier m_identifier; |
90 | RegistrableDomain m_registrableDomain; |
91 | }; |
92 | |
93 | } // namespace WebCore |
94 | |
95 | #endif // ENABLE(SERVICE_WORKER) |
96 | |