1/*
2 * Copyright (C) 2010-2018 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'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include "config.h"
26
27#if ENABLE(SERVICE_WORKER)
28
29#include "WebSWServerConnection.h"
30
31#include "ArgumentCoders.h"
32#include "Decoder.h"
33#include "FormDataReference.h"
34#include "HandleMessage.h"
35#include "WebCoreArgumentCoders.h"
36#include "WebSWServerConnectionMessages.h"
37#include <WebCore/FetchIdentifier.h>
38#include <WebCore/FetchOptions.h>
39#include <WebCore/MessageWithMessagePorts.h>
40#include <WebCore/ResourceRequest.h>
41#include <WebCore/SecurityOriginData.h>
42#include <WebCore/ServiceWorkerClientData.h>
43#include <WebCore/ServiceWorkerClientIdentifier.h>
44#include <WebCore/ServiceWorkerFetchResult.h>
45#include <WebCore/ServiceWorkerIdentifier.h>
46#include <WebCore/ServiceWorkerJobData.h>
47#include <WebCore/ServiceWorkerRegistrationKey.h>
48#include <WebCore/ServiceWorkerTypes.h>
49#include <wtf/Optional.h>
50#include <wtf/text/WTFString.h>
51
52namespace Messages {
53
54namespace WebSWServerConnection {
55
56void SyncTerminateWorkerFromClient::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection)
57{
58 connection.sendSyncReply(WTFMove(encoder));
59}
60
61void StoreRegistrationsOnDisk::callReply(IPC::Decoder& decoder, CompletionHandler<void()>&& completionHandler)
62{
63 completionHandler();
64}
65
66void StoreRegistrationsOnDisk::cancelReply(CompletionHandler<void()>&& completionHandler)
67{
68 completionHandler();
69}
70
71void StoreRegistrationsOnDisk::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection)
72{
73 connection.sendSyncReply(WTFMove(encoder));
74}
75
76} // namespace WebSWServerConnection
77
78} // namespace Messages
79
80namespace WebKit {
81
82void WebSWServerConnection::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
83{
84 if (decoder.messageName() == Messages::WebSWServerConnection::ScheduleJobInServer::name()) {
85 IPC::handleMessage<Messages::WebSWServerConnection::ScheduleJobInServer>(decoder, this, &WebSWServerConnection::scheduleJobInServer);
86 return;
87 }
88 if (decoder.messageName() == Messages::WebSWServerConnection::FinishFetchingScriptInServer::name()) {
89 IPC::handleMessage<Messages::WebSWServerConnection::FinishFetchingScriptInServer>(decoder, this, &WebSWServerConnection::finishFetchingScriptInServer);
90 return;
91 }
92 if (decoder.messageName() == Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer::name()) {
93 IPC::handleMessage<Messages::WebSWServerConnection::AddServiceWorkerRegistrationInServer>(decoder, this, &WebSWServerConnection::addServiceWorkerRegistrationInServer);
94 return;
95 }
96 if (decoder.messageName() == Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer::name()) {
97 IPC::handleMessage<Messages::WebSWServerConnection::RemoveServiceWorkerRegistrationInServer>(decoder, this, &WebSWServerConnection::removeServiceWorkerRegistrationInServer);
98 return;
99 }
100 if (decoder.messageName() == Messages::WebSWServerConnection::StartFetch::name()) {
101 IPC::handleMessage<Messages::WebSWServerConnection::StartFetch>(decoder, this, &WebSWServerConnection::startFetch);
102 return;
103 }
104 if (decoder.messageName() == Messages::WebSWServerConnection::CancelFetch::name()) {
105 IPC::handleMessage<Messages::WebSWServerConnection::CancelFetch>(decoder, this, &WebSWServerConnection::cancelFetch);
106 return;
107 }
108 if (decoder.messageName() == Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse::name()) {
109 IPC::handleMessage<Messages::WebSWServerConnection::ContinueDidReceiveFetchResponse>(decoder, this, &WebSWServerConnection::continueDidReceiveFetchResponse);
110 return;
111 }
112 if (decoder.messageName() == Messages::WebSWServerConnection::PostMessageToServiceWorker::name()) {
113 IPC::handleMessage<Messages::WebSWServerConnection::PostMessageToServiceWorker>(decoder, this, &WebSWServerConnection::postMessageToServiceWorker);
114 return;
115 }
116 if (decoder.messageName() == Messages::WebSWServerConnection::DidResolveRegistrationPromise::name()) {
117 IPC::handleMessage<Messages::WebSWServerConnection::DidResolveRegistrationPromise>(decoder, this, &WebSWServerConnection::didResolveRegistrationPromise);
118 return;
119 }
120 if (decoder.messageName() == Messages::WebSWServerConnection::MatchRegistration::name()) {
121 IPC::handleMessage<Messages::WebSWServerConnection::MatchRegistration>(decoder, this, &WebSWServerConnection::matchRegistration);
122 return;
123 }
124 if (decoder.messageName() == Messages::WebSWServerConnection::WhenRegistrationReady::name()) {
125 IPC::handleMessage<Messages::WebSWServerConnection::WhenRegistrationReady>(decoder, this, &WebSWServerConnection::whenRegistrationReady);
126 return;
127 }
128 if (decoder.messageName() == Messages::WebSWServerConnection::GetRegistrations::name()) {
129 IPC::handleMessage<Messages::WebSWServerConnection::GetRegistrations>(decoder, this, &WebSWServerConnection::getRegistrations);
130 return;
131 }
132 if (decoder.messageName() == Messages::WebSWServerConnection::RegisterServiceWorkerClient::name()) {
133 IPC::handleMessage<Messages::WebSWServerConnection::RegisterServiceWorkerClient>(decoder, this, &WebSWServerConnection::registerServiceWorkerClient);
134 return;
135 }
136 if (decoder.messageName() == Messages::WebSWServerConnection::UnregisterServiceWorkerClient::name()) {
137 IPC::handleMessage<Messages::WebSWServerConnection::UnregisterServiceWorkerClient>(decoder, this, &WebSWServerConnection::unregisterServiceWorkerClient);
138 return;
139 }
140 if (decoder.messageName() == Messages::WebSWServerConnection::SetThrottleState::name()) {
141 IPC::handleMessage<Messages::WebSWServerConnection::SetThrottleState>(decoder, this, &WebSWServerConnection::setThrottleState);
142 return;
143 }
144 if (decoder.messageName() == Messages::WebSWServerConnection::StoreRegistrationsOnDisk::name()) {
145 IPC::handleMessageAsync<Messages::WebSWServerConnection::StoreRegistrationsOnDisk>(connection, decoder, this, &WebSWServerConnection::storeRegistrationsOnDisk);
146 return;
147 }
148 UNUSED_PARAM(connection);
149 UNUSED_PARAM(decoder);
150 ASSERT_NOT_REACHED();
151}
152
153void WebSWServerConnection::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)
154{
155 if (decoder.messageName() == Messages::WebSWServerConnection::SyncTerminateWorkerFromClient::name()) {
156 IPC::handleMessageSynchronous<Messages::WebSWServerConnection::SyncTerminateWorkerFromClient>(connection, decoder, replyEncoder, this, &WebSWServerConnection::syncTerminateWorkerFromClient);
157 return;
158 }
159 UNUSED_PARAM(connection);
160 UNUSED_PARAM(decoder);
161 UNUSED_PARAM(replyEncoder);
162 ASSERT_NOT_REACHED();
163}
164
165} // namespace WebKit
166
167
168#endif // ENABLE(SERVICE_WORKER)
169