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 "MessageReceiver.h" |
31 | #include "MessageSender.h" |
32 | #include "ServiceWorkerFetchTask.h" |
33 | #include <WebCore/SWServerToContextConnection.h> |
34 | |
35 | namespace WebCore { |
36 | struct FetchOptions; |
37 | class ResourceRequest; |
38 | } |
39 | |
40 | namespace IPC { |
41 | class FormDataReference; |
42 | } |
43 | |
44 | namespace PAL { |
45 | class SessionID; |
46 | } |
47 | |
48 | namespace WebKit { |
49 | |
50 | class NetworkProcess; |
51 | |
52 | class WebSWServerToContextConnection : public WebCore::SWServerToContextConnection, public IPC::MessageSender, public IPC::MessageReceiver { |
53 | public: |
54 | template <typename... Args> static Ref<WebSWServerToContextConnection> create(Args&&... args) |
55 | { |
56 | return adoptRef(*new WebSWServerToContextConnection(std::forward<Args>(args)...)); |
57 | } |
58 | |
59 | void connectionClosed(); |
60 | |
61 | IPC::Connection* ipcConnection() const { return m_ipcConnection.ptr(); } |
62 | |
63 | // IPC::MessageReceiver |
64 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final; |
65 | |
66 | void terminate(); |
67 | |
68 | void startFetch(PAL::SessionID, Ref<IPC::Connection>&&, WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, WebCore::ServiceWorkerIdentifier, const WebCore::ResourceRequest&, const WebCore::FetchOptions&, const IPC::FormDataReference&, const String&); |
69 | void cancelFetch(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, WebCore::ServiceWorkerIdentifier); |
70 | void continueDidReceiveFetchResponse(WebCore::SWServerConnectionIdentifier, WebCore::FetchIdentifier, WebCore::ServiceWorkerIdentifier); |
71 | |
72 | void didReceiveFetchTaskMessage(IPC::Connection&, IPC::Decoder&); |
73 | |
74 | void setThrottleState(bool isThrottleable); |
75 | bool isThrottleable() const { return m_isThrottleable; } |
76 | |
77 | private: |
78 | WebSWServerToContextConnection(NetworkProcess&, const WebCore::RegistrableDomain&, Ref<IPC::Connection>&&); |
79 | ~WebSWServerToContextConnection(); |
80 | |
81 | // IPC::MessageSender |
82 | IPC::Connection* messageSenderConnection() const final; |
83 | uint64_t messageSenderDestinationID() const final; |
84 | |
85 | // Messages to the SW host WebProcess |
86 | void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&, PAL::SessionID, const String& userAgent) final; |
87 | void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final; |
88 | void fireActivateEvent(WebCore::ServiceWorkerIdentifier) final; |
89 | void terminateWorker(WebCore::ServiceWorkerIdentifier) final; |
90 | void syncTerminateWorker(WebCore::ServiceWorkerIdentifier) final; |
91 | void findClientByIdentifierCompleted(uint64_t requestIdentifier, const Optional<WebCore::ServiceWorkerClientData>&, bool hasSecurityError) final; |
92 | void matchAllCompleted(uint64_t requestIdentifier, const Vector<WebCore::ServiceWorkerClientData>&) final; |
93 | void claimCompleted(uint64_t requestIdentifier) final; |
94 | void didFinishSkipWaiting(uint64_t callbackID) final; |
95 | |
96 | void connectionMayNoLongerBeNeeded() final; |
97 | |
98 | Ref<IPC::Connection> m_ipcConnection; |
99 | Ref<NetworkProcess> m_networkProcess; |
100 | |
101 | HashMap<ServiceWorkerFetchTask::Identifier, WebCore::FetchIdentifier> m_ongoingFetchIdentifiers; |
102 | HashMap<WebCore::FetchIdentifier, Ref<ServiceWorkerFetchTask>> m_ongoingFetches; |
103 | bool m_isThrottleable { true }; |
104 | }; // class WebSWServerToContextConnection |
105 | |
106 | } // namespace WebKit |
107 | |
108 | #endif // ENABLE(SERVICE_WORKER) |
109 | |
110 | |