Use SecurityOriginData more consistently in Service Worker code
[WebKit-https.git] / Source / WebKit / StorageProcess / ServiceWorker / WebSWServerToContextConnection.cpp
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 #include "config.h"
27 #include "WebSWServerToContextConnection.h"
28
29 #if ENABLE(SERVICE_WORKER)
30
31 #include "StorageProcess.h"
32 #include "WebCoreArgumentCoders.h"
33 #include "WebSWContextManagerConnectionMessages.h"
34 #include <WebCore/ServiceWorkerContextData.h>
35
36 using namespace WebCore;
37
38 namespace WebKit {
39
40 WebSWServerToContextConnection::WebSWServerToContextConnection(const SecurityOriginData& securityOrigin, Ref<IPC::Connection>&& connection)
41     : SWServerToContextConnection(securityOrigin)
42     , m_ipcConnection(WTFMove(connection))
43 {
44 }
45
46 IPC::Connection* WebSWServerToContextConnection::messageSenderConnection()
47 {
48     return m_ipcConnection.ptr();
49 }
50
51 uint64_t WebSWServerToContextConnection::messageSenderDestinationID()
52 {
53     return 0;
54 }
55
56 void WebSWServerToContextConnection::connectionClosed()
57 {
58     // FIXME: Do what here...?
59 }
60
61 void WebSWServerToContextConnection::installServiceWorkerContext(const ServiceWorkerContextData& data, PAL::SessionID sessionID)
62 {
63     send(Messages::WebSWContextManagerConnection::InstallServiceWorker { data, sessionID });
64 }
65
66 void WebSWServerToContextConnection::fireInstallEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)
67 {
68     send(Messages::WebSWContextManagerConnection::FireInstallEvent(serviceWorkerIdentifier));
69 }
70
71 void WebSWServerToContextConnection::fireActivateEvent(ServiceWorkerIdentifier serviceWorkerIdentifier)
72 {
73     send(Messages::WebSWContextManagerConnection::FireActivateEvent(serviceWorkerIdentifier));
74 }
75
76 void WebSWServerToContextConnection::terminateWorker(ServiceWorkerIdentifier serviceWorkerIdentifier)
77 {
78     send(Messages::WebSWContextManagerConnection::TerminateWorker(serviceWorkerIdentifier));
79 }
80
81 void WebSWServerToContextConnection::syncTerminateWorker(ServiceWorkerIdentifier serviceWorkerIdentifier)
82 {
83     sendSync(Messages::WebSWContextManagerConnection::SyncTerminateWorker(serviceWorkerIdentifier), Messages::WebSWContextManagerConnection::SyncTerminateWorker::Reply());
84 }
85
86 void WebSWServerToContextConnection::findClientByIdentifierCompleted(uint64_t requestIdentifier, const std::optional<ServiceWorkerClientData>& data, bool hasSecurityError)
87 {
88     send(Messages::WebSWContextManagerConnection::FindClientByIdentifierCompleted { requestIdentifier, data, hasSecurityError });
89 }
90
91 void WebSWServerToContextConnection::matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>& clientsData)
92 {
93     send(Messages::WebSWContextManagerConnection::MatchAllCompleted { requestIdentifier, clientsData });
94 }
95
96 void WebSWServerToContextConnection::claimCompleted(uint64_t requestIdentifier)
97 {
98     send(Messages::WebSWContextManagerConnection::ClaimCompleted { requestIdentifier });
99 }
100
101 void WebSWServerToContextConnection::didFinishSkipWaiting(uint64_t callbackID)
102 {
103     send(Messages::WebSWContextManagerConnection::DidFinishSkipWaiting { callbackID });
104 }
105
106 void WebSWServerToContextConnection::connectionMayNoLongerBeNeeded()
107 {
108     StorageProcess::singleton().swContextConnectionMayNoLongerBeNeeded(*this);
109 }
110
111 void WebSWServerToContextConnection::terminate()
112 {
113     send(Messages::WebSWContextManagerConnection::TerminateProcess());
114 }
115
116 } // namespace WebKit
117
118 #endif // ENABLE(SERVICE_WORKER)