| 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 | #pragma once |
| 26 | |
| 27 | #if ENABLE(SERVICE_WORKER) |
| 28 | |
| 29 | #include "ArgumentCoders.h" |
| 30 | #include "Connection.h" |
| 31 | #include <WebCore/FetchIdentifier.h> |
| 32 | #include <WebCore/ServiceWorkerClientIdentifier.h> |
| 33 | #include <WebCore/ServiceWorkerIdentifier.h> |
| 34 | #include <WebCore/ServiceWorkerTypes.h> |
| 35 | #include <wtf/Forward.h> |
| 36 | #include <wtf/Optional.h> |
| 37 | #include <wtf/ThreadSafeRefCounted.h> |
| 38 | #include <wtf/text/WTFString.h> |
| 39 | |
| 40 | namespace IPC { |
| 41 | class FormDataReference; |
| 42 | } |
| 43 | |
| 44 | namespace WebCore { |
| 45 | struct ServiceWorkerClientIdentifier; |
| 46 | struct MessageWithMessagePorts; |
| 47 | class ServiceWorkerRegistrationKey; |
| 48 | struct FetchOptions; |
| 49 | struct SecurityOriginData; |
| 50 | struct ServiceWorkerClientData; |
| 51 | struct ServiceWorkerJobData; |
| 52 | struct ServiceWorkerFetchResult; |
| 53 | class ResourceRequest; |
| 54 | } |
| 55 | |
| 56 | namespace Messages { |
| 57 | namespace WebSWServerConnection { |
| 58 | |
| 59 | static inline IPC::StringReference messageReceiverName() |
| 60 | { |
| 61 | return IPC::StringReference("WebSWServerConnection" ); |
| 62 | } |
| 63 | |
| 64 | class ScheduleJobInServer { |
| 65 | public: |
| 66 | typedef std::tuple<const WebCore::ServiceWorkerJobData&> Arguments; |
| 67 | |
| 68 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 69 | static IPC::StringReference name() { return IPC::StringReference("ScheduleJobInServer" ); } |
| 70 | static const bool isSync = false; |
| 71 | |
| 72 | explicit ScheduleJobInServer(const WebCore::ServiceWorkerJobData& jobData) |
| 73 | : m_arguments(jobData) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | const Arguments& arguments() const |
| 78 | { |
| 79 | return m_arguments; |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | Arguments m_arguments; |
| 84 | }; |
| 85 | |
| 86 | class FinishFetchingScriptInServer { |
| 87 | public: |
| 88 | typedef std::tuple<const WebCore::ServiceWorkerFetchResult&> Arguments; |
| 89 | |
| 90 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 91 | static IPC::StringReference name() { return IPC::StringReference("FinishFetchingScriptInServer" ); } |
| 92 | static const bool isSync = false; |
| 93 | |
| 94 | explicit FinishFetchingScriptInServer(const WebCore::ServiceWorkerFetchResult& result) |
| 95 | : m_arguments(result) |
| 96 | { |
| 97 | } |
| 98 | |
| 99 | const Arguments& arguments() const |
| 100 | { |
| 101 | return m_arguments; |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | Arguments m_arguments; |
| 106 | }; |
| 107 | |
| 108 | class AddServiceWorkerRegistrationInServer { |
| 109 | public: |
| 110 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&> Arguments; |
| 111 | |
| 112 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 113 | static IPC::StringReference name() { return IPC::StringReference("AddServiceWorkerRegistrationInServer" ); } |
| 114 | static const bool isSync = false; |
| 115 | |
| 116 | explicit AddServiceWorkerRegistrationInServer(const WebCore::ServiceWorkerRegistrationIdentifier& identifier) |
| 117 | : m_arguments(identifier) |
| 118 | { |
| 119 | } |
| 120 | |
| 121 | const Arguments& arguments() const |
| 122 | { |
| 123 | return m_arguments; |
| 124 | } |
| 125 | |
| 126 | private: |
| 127 | Arguments m_arguments; |
| 128 | }; |
| 129 | |
| 130 | class RemoveServiceWorkerRegistrationInServer { |
| 131 | public: |
| 132 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&> Arguments; |
| 133 | |
| 134 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 135 | static IPC::StringReference name() { return IPC::StringReference("RemoveServiceWorkerRegistrationInServer" ); } |
| 136 | static const bool isSync = false; |
| 137 | |
| 138 | explicit RemoveServiceWorkerRegistrationInServer(const WebCore::ServiceWorkerRegistrationIdentifier& identifier) |
| 139 | : m_arguments(identifier) |
| 140 | { |
| 141 | } |
| 142 | |
| 143 | const Arguments& arguments() const |
| 144 | { |
| 145 | return m_arguments; |
| 146 | } |
| 147 | |
| 148 | private: |
| 149 | Arguments m_arguments; |
| 150 | }; |
| 151 | |
| 152 | class StartFetch { |
| 153 | public: |
| 154 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, const WebCore::FetchIdentifier&, const WebCore::ResourceRequest&, const WebCore::FetchOptions&, const IPC::FormDataReference&, const String&> Arguments; |
| 155 | |
| 156 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 157 | static IPC::StringReference name() { return IPC::StringReference("StartFetch" ); } |
| 158 | static const bool isSync = false; |
| 159 | |
| 160 | StartFetch(const WebCore::ServiceWorkerRegistrationIdentifier& serviceWorkerRegistrationIdentifier, const WebCore::FetchIdentifier& fetchIdentifier, const WebCore::ResourceRequest& request, const WebCore::FetchOptions& options, const IPC::FormDataReference& requestBody, const String& referrer) |
| 161 | : m_arguments(serviceWorkerRegistrationIdentifier, fetchIdentifier, request, options, requestBody, referrer) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | const Arguments& arguments() const |
| 166 | { |
| 167 | return m_arguments; |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | Arguments m_arguments; |
| 172 | }; |
| 173 | |
| 174 | class CancelFetch { |
| 175 | public: |
| 176 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, const WebCore::FetchIdentifier&> Arguments; |
| 177 | |
| 178 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 179 | static IPC::StringReference name() { return IPC::StringReference("CancelFetch" ); } |
| 180 | static const bool isSync = false; |
| 181 | |
| 182 | CancelFetch(const WebCore::ServiceWorkerRegistrationIdentifier& serviceWorkerRegistrationIdentifier, const WebCore::FetchIdentifier& fetchIdentifier) |
| 183 | : m_arguments(serviceWorkerRegistrationIdentifier, fetchIdentifier) |
| 184 | { |
| 185 | } |
| 186 | |
| 187 | const Arguments& arguments() const |
| 188 | { |
| 189 | return m_arguments; |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | Arguments m_arguments; |
| 194 | }; |
| 195 | |
| 196 | class ContinueDidReceiveFetchResponse { |
| 197 | public: |
| 198 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, const WebCore::FetchIdentifier&> Arguments; |
| 199 | |
| 200 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 201 | static IPC::StringReference name() { return IPC::StringReference("ContinueDidReceiveFetchResponse" ); } |
| 202 | static const bool isSync = false; |
| 203 | |
| 204 | ContinueDidReceiveFetchResponse(const WebCore::ServiceWorkerRegistrationIdentifier& serviceWorkerRegistrationIdentifier, const WebCore::FetchIdentifier& fetchIdentifier) |
| 205 | : m_arguments(serviceWorkerRegistrationIdentifier, fetchIdentifier) |
| 206 | { |
| 207 | } |
| 208 | |
| 209 | const Arguments& arguments() const |
| 210 | { |
| 211 | return m_arguments; |
| 212 | } |
| 213 | |
| 214 | private: |
| 215 | Arguments m_arguments; |
| 216 | }; |
| 217 | |
| 218 | class PostMessageToServiceWorker { |
| 219 | public: |
| 220 | typedef std::tuple<const WebCore::ServiceWorkerIdentifier&, const WebCore::MessageWithMessagePorts&, const WebCore::ServiceWorkerOrClientIdentifier&> Arguments; |
| 221 | |
| 222 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 223 | static IPC::StringReference name() { return IPC::StringReference("PostMessageToServiceWorker" ); } |
| 224 | static const bool isSync = false; |
| 225 | |
| 226 | PostMessageToServiceWorker(const WebCore::ServiceWorkerIdentifier& destination, const WebCore::MessageWithMessagePorts& message, const WebCore::ServiceWorkerOrClientIdentifier& source) |
| 227 | : m_arguments(destination, message, source) |
| 228 | { |
| 229 | } |
| 230 | |
| 231 | const Arguments& arguments() const |
| 232 | { |
| 233 | return m_arguments; |
| 234 | } |
| 235 | |
| 236 | private: |
| 237 | Arguments m_arguments; |
| 238 | }; |
| 239 | |
| 240 | class DidResolveRegistrationPromise { |
| 241 | public: |
| 242 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationKey&> Arguments; |
| 243 | |
| 244 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 245 | static IPC::StringReference name() { return IPC::StringReference("DidResolveRegistrationPromise" ); } |
| 246 | static const bool isSync = false; |
| 247 | |
| 248 | explicit DidResolveRegistrationPromise(const WebCore::ServiceWorkerRegistrationKey& key) |
| 249 | : m_arguments(key) |
| 250 | { |
| 251 | } |
| 252 | |
| 253 | const Arguments& arguments() const |
| 254 | { |
| 255 | return m_arguments; |
| 256 | } |
| 257 | |
| 258 | private: |
| 259 | Arguments m_arguments; |
| 260 | }; |
| 261 | |
| 262 | class MatchRegistration { |
| 263 | public: |
| 264 | typedef std::tuple<uint64_t, const WebCore::SecurityOriginData&, const URL&> Arguments; |
| 265 | |
| 266 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 267 | static IPC::StringReference name() { return IPC::StringReference("MatchRegistration" ); } |
| 268 | static const bool isSync = false; |
| 269 | |
| 270 | MatchRegistration(uint64_t serviceRegistrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL) |
| 271 | : m_arguments(serviceRegistrationMatchRequestIdentifier, topOrigin, clientURL) |
| 272 | { |
| 273 | } |
| 274 | |
| 275 | const Arguments& arguments() const |
| 276 | { |
| 277 | return m_arguments; |
| 278 | } |
| 279 | |
| 280 | private: |
| 281 | Arguments m_arguments; |
| 282 | }; |
| 283 | |
| 284 | class WhenRegistrationReady { |
| 285 | public: |
| 286 | typedef std::tuple<uint64_t, const WebCore::SecurityOriginData&, const URL&> Arguments; |
| 287 | |
| 288 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 289 | static IPC::StringReference name() { return IPC::StringReference("WhenRegistrationReady" ); } |
| 290 | static const bool isSync = false; |
| 291 | |
| 292 | WhenRegistrationReady(uint64_t serviceRegistrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL) |
| 293 | : m_arguments(serviceRegistrationMatchRequestIdentifier, topOrigin, clientURL) |
| 294 | { |
| 295 | } |
| 296 | |
| 297 | const Arguments& arguments() const |
| 298 | { |
| 299 | return m_arguments; |
| 300 | } |
| 301 | |
| 302 | private: |
| 303 | Arguments m_arguments; |
| 304 | }; |
| 305 | |
| 306 | class GetRegistrations { |
| 307 | public: |
| 308 | typedef std::tuple<uint64_t, const WebCore::SecurityOriginData&, const URL&> Arguments; |
| 309 | |
| 310 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 311 | static IPC::StringReference name() { return IPC::StringReference("GetRegistrations" ); } |
| 312 | static const bool isSync = false; |
| 313 | |
| 314 | GetRegistrations(uint64_t serviceRegistrationMatchRequestIdentifier, const WebCore::SecurityOriginData& topOrigin, const URL& clientURL) |
| 315 | : m_arguments(serviceRegistrationMatchRequestIdentifier, topOrigin, clientURL) |
| 316 | { |
| 317 | } |
| 318 | |
| 319 | const Arguments& arguments() const |
| 320 | { |
| 321 | return m_arguments; |
| 322 | } |
| 323 | |
| 324 | private: |
| 325 | Arguments m_arguments; |
| 326 | }; |
| 327 | |
| 328 | class RegisterServiceWorkerClient { |
| 329 | public: |
| 330 | typedef std::tuple<const WebCore::SecurityOriginData&, const WebCore::ServiceWorkerClientData&, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>&, const String&> Arguments; |
| 331 | |
| 332 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 333 | static IPC::StringReference name() { return IPC::StringReference("RegisterServiceWorkerClient" ); } |
| 334 | static const bool isSync = false; |
| 335 | |
| 336 | RegisterServiceWorkerClient(const WebCore::SecurityOriginData& topOrigin, const WebCore::ServiceWorkerClientData& data, const Optional<WebCore::ServiceWorkerRegistrationIdentifier>& controllingServiceWorkerRegistrationIdentifier, const String& userAgent) |
| 337 | : m_arguments(topOrigin, data, controllingServiceWorkerRegistrationIdentifier, userAgent) |
| 338 | { |
| 339 | } |
| 340 | |
| 341 | const Arguments& arguments() const |
| 342 | { |
| 343 | return m_arguments; |
| 344 | } |
| 345 | |
| 346 | private: |
| 347 | Arguments m_arguments; |
| 348 | }; |
| 349 | |
| 350 | class UnregisterServiceWorkerClient { |
| 351 | public: |
| 352 | typedef std::tuple<const WebCore::ServiceWorkerClientIdentifier&> Arguments; |
| 353 | |
| 354 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 355 | static IPC::StringReference name() { return IPC::StringReference("UnregisterServiceWorkerClient" ); } |
| 356 | static const bool isSync = false; |
| 357 | |
| 358 | explicit UnregisterServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& identifier) |
| 359 | : m_arguments(identifier) |
| 360 | { |
| 361 | } |
| 362 | |
| 363 | const Arguments& arguments() const |
| 364 | { |
| 365 | return m_arguments; |
| 366 | } |
| 367 | |
| 368 | private: |
| 369 | Arguments m_arguments; |
| 370 | }; |
| 371 | |
| 372 | class SyncTerminateWorkerFromClient { |
| 373 | public: |
| 374 | typedef std::tuple<const WebCore::ServiceWorkerIdentifier&> Arguments; |
| 375 | |
| 376 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 377 | static IPC::StringReference name() { return IPC::StringReference("SyncTerminateWorkerFromClient" ); } |
| 378 | static const bool isSync = true; |
| 379 | |
| 380 | using DelayedReply = CompletionHandler<void()>; |
| 381 | static void send(std::unique_ptr<IPC::Encoder>&&, IPC::Connection&); |
| 382 | using Reply = std::tuple<>; |
| 383 | using ReplyArguments = std::tuple<>; |
| 384 | explicit SyncTerminateWorkerFromClient(const WebCore::ServiceWorkerIdentifier& workerIdentifier) |
| 385 | : m_arguments(workerIdentifier) |
| 386 | { |
| 387 | } |
| 388 | |
| 389 | const Arguments& arguments() const |
| 390 | { |
| 391 | return m_arguments; |
| 392 | } |
| 393 | |
| 394 | private: |
| 395 | Arguments m_arguments; |
| 396 | }; |
| 397 | |
| 398 | class SetThrottleState { |
| 399 | public: |
| 400 | typedef std::tuple<bool> Arguments; |
| 401 | |
| 402 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 403 | static IPC::StringReference name() { return IPC::StringReference("SetThrottleState" ); } |
| 404 | static const bool isSync = false; |
| 405 | |
| 406 | explicit SetThrottleState(bool isThrottleable) |
| 407 | : m_arguments(isThrottleable) |
| 408 | { |
| 409 | } |
| 410 | |
| 411 | const Arguments& arguments() const |
| 412 | { |
| 413 | return m_arguments; |
| 414 | } |
| 415 | |
| 416 | private: |
| 417 | Arguments m_arguments; |
| 418 | }; |
| 419 | |
| 420 | } // namespace WebSWServerConnection |
| 421 | } // namespace Messages |
| 422 | |
| 423 | #endif // ENABLE(SERVICE_WORKER) |
| 424 | |