| 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 "SharedMemory.h" |
| 32 | #include <WebCore/DocumentIdentifier.h> |
| 33 | #include <WebCore/FetchOptions.h> |
| 34 | #include <WebCore/ServiceWorkerData.h> |
| 35 | #include <WebCore/ServiceWorkerIdentifier.h> |
| 36 | #include <WebCore/ServiceWorkerRegistrationData.h> |
| 37 | #include <WebCore/ServiceWorkerTypes.h> |
| 38 | #include <wtf/Forward.h> |
| 39 | #include <wtf/HashSet.h> |
| 40 | #include <wtf/Optional.h> |
| 41 | #include <wtf/ThreadSafeRefCounted.h> |
| 42 | #include <wtf/Vector.h> |
| 43 | #include <wtf/text/WTFString.h> |
| 44 | |
| 45 | namespace WebCore { |
| 46 | enum class ServiceWorkerRegistrationState : uint8_t; |
| 47 | class ServiceWorkerRegistrationKey; |
| 48 | struct MessageWithMessagePorts; |
| 49 | enum class ServiceWorkerUpdateViaCache : uint8_t; |
| 50 | enum class ServiceWorkerState : uint8_t; |
| 51 | struct ExceptionData; |
| 52 | struct ServiceWorkerRegistrationData; |
| 53 | enum class ShouldNotifyWhenResolved : bool; |
| 54 | struct ServiceWorkerData; |
| 55 | } |
| 56 | |
| 57 | namespace Messages { |
| 58 | namespace WebSWClientConnection { |
| 59 | |
| 60 | static inline IPC::StringReference messageReceiverName() |
| 61 | { |
| 62 | return IPC::StringReference("WebSWClientConnection" ); |
| 63 | } |
| 64 | |
| 65 | class JobRejectedInServer { |
| 66 | public: |
| 67 | typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, const WebCore::ExceptionData&> Arguments; |
| 68 | |
| 69 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 70 | static IPC::StringReference name() { return IPC::StringReference("JobRejectedInServer" ); } |
| 71 | static const bool isSync = false; |
| 72 | |
| 73 | JobRejectedInServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, const WebCore::ExceptionData& exception) |
| 74 | : m_arguments(jobDataIdentifier, exception) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | const Arguments& arguments() const |
| 79 | { |
| 80 | return m_arguments; |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | Arguments m_arguments; |
| 85 | }; |
| 86 | |
| 87 | class RegistrationJobResolvedInServer { |
| 88 | public: |
| 89 | typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, const WebCore::ServiceWorkerRegistrationData&, WebCore::ShouldNotifyWhenResolved> Arguments; |
| 90 | |
| 91 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 92 | static IPC::StringReference name() { return IPC::StringReference("RegistrationJobResolvedInServer" ); } |
| 93 | static const bool isSync = false; |
| 94 | |
| 95 | RegistrationJobResolvedInServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, const WebCore::ServiceWorkerRegistrationData& registration, WebCore::ShouldNotifyWhenResolved shouldNotifyWhenResolved) |
| 96 | : m_arguments(jobDataIdentifier, registration, shouldNotifyWhenResolved) |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | const Arguments& arguments() const |
| 101 | { |
| 102 | return m_arguments; |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | Arguments m_arguments; |
| 107 | }; |
| 108 | |
| 109 | class UnregistrationJobResolvedInServer { |
| 110 | public: |
| 111 | typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, bool> Arguments; |
| 112 | |
| 113 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 114 | static IPC::StringReference name() { return IPC::StringReference("UnregistrationJobResolvedInServer" ); } |
| 115 | static const bool isSync = false; |
| 116 | |
| 117 | UnregistrationJobResolvedInServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, bool unregistrationResult) |
| 118 | : m_arguments(jobDataIdentifier, unregistrationResult) |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | const Arguments& arguments() const |
| 123 | { |
| 124 | return m_arguments; |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | Arguments m_arguments; |
| 129 | }; |
| 130 | |
| 131 | class StartScriptFetchForServer { |
| 132 | public: |
| 133 | typedef std::tuple<const WebCore::ServiceWorkerJobIdentifier&, const WebCore::ServiceWorkerRegistrationKey&, const WebCore::FetchOptions::Cache&> Arguments; |
| 134 | |
| 135 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 136 | static IPC::StringReference name() { return IPC::StringReference("StartScriptFetchForServer" ); } |
| 137 | static const bool isSync = false; |
| 138 | |
| 139 | StartScriptFetchForServer(const WebCore::ServiceWorkerJobIdentifier& jobDataIdentifier, const WebCore::ServiceWorkerRegistrationKey& registrationKey, const WebCore::FetchOptions::Cache& cachePolicy) |
| 140 | : m_arguments(jobDataIdentifier, registrationKey, cachePolicy) |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | const Arguments& arguments() const |
| 145 | { |
| 146 | return m_arguments; |
| 147 | } |
| 148 | |
| 149 | private: |
| 150 | Arguments m_arguments; |
| 151 | }; |
| 152 | |
| 153 | class UpdateRegistrationState { |
| 154 | public: |
| 155 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, WebCore::ServiceWorkerRegistrationState, const Optional<WebCore::ServiceWorkerData>&> Arguments; |
| 156 | |
| 157 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 158 | static IPC::StringReference name() { return IPC::StringReference("UpdateRegistrationState" ); } |
| 159 | static const bool isSync = false; |
| 160 | |
| 161 | UpdateRegistrationState(const WebCore::ServiceWorkerRegistrationIdentifier& identifier, WebCore::ServiceWorkerRegistrationState state, const Optional<WebCore::ServiceWorkerData>& serviceWorkerIdentifier) |
| 162 | : m_arguments(identifier, state, serviceWorkerIdentifier) |
| 163 | { |
| 164 | } |
| 165 | |
| 166 | const Arguments& arguments() const |
| 167 | { |
| 168 | return m_arguments; |
| 169 | } |
| 170 | |
| 171 | private: |
| 172 | Arguments m_arguments; |
| 173 | }; |
| 174 | |
| 175 | class UpdateWorkerState { |
| 176 | public: |
| 177 | typedef std::tuple<const WebCore::ServiceWorkerIdentifier&, WebCore::ServiceWorkerState> Arguments; |
| 178 | |
| 179 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 180 | static IPC::StringReference name() { return IPC::StringReference("UpdateWorkerState" ); } |
| 181 | static const bool isSync = false; |
| 182 | |
| 183 | UpdateWorkerState(const WebCore::ServiceWorkerIdentifier& serviceWorkerIdentifier, WebCore::ServiceWorkerState state) |
| 184 | : m_arguments(serviceWorkerIdentifier, state) |
| 185 | { |
| 186 | } |
| 187 | |
| 188 | const Arguments& arguments() const |
| 189 | { |
| 190 | return m_arguments; |
| 191 | } |
| 192 | |
| 193 | private: |
| 194 | Arguments m_arguments; |
| 195 | }; |
| 196 | |
| 197 | class FireUpdateFoundEvent { |
| 198 | public: |
| 199 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&> Arguments; |
| 200 | |
| 201 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 202 | static IPC::StringReference name() { return IPC::StringReference("FireUpdateFoundEvent" ); } |
| 203 | static const bool isSync = false; |
| 204 | |
| 205 | explicit FireUpdateFoundEvent(const WebCore::ServiceWorkerRegistrationIdentifier& identifier) |
| 206 | : m_arguments(identifier) |
| 207 | { |
| 208 | } |
| 209 | |
| 210 | const Arguments& arguments() const |
| 211 | { |
| 212 | return m_arguments; |
| 213 | } |
| 214 | |
| 215 | private: |
| 216 | Arguments m_arguments; |
| 217 | }; |
| 218 | |
| 219 | class SetRegistrationLastUpdateTime { |
| 220 | public: |
| 221 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, const WallTime&> Arguments; |
| 222 | |
| 223 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 224 | static IPC::StringReference name() { return IPC::StringReference("SetRegistrationLastUpdateTime" ); } |
| 225 | static const bool isSync = false; |
| 226 | |
| 227 | SetRegistrationLastUpdateTime(const WebCore::ServiceWorkerRegistrationIdentifier& identifier, const WallTime& lastUpdateTime) |
| 228 | : m_arguments(identifier, lastUpdateTime) |
| 229 | { |
| 230 | } |
| 231 | |
| 232 | const Arguments& arguments() const |
| 233 | { |
| 234 | return m_arguments; |
| 235 | } |
| 236 | |
| 237 | private: |
| 238 | Arguments m_arguments; |
| 239 | }; |
| 240 | |
| 241 | class SetRegistrationUpdateViaCache { |
| 242 | public: |
| 243 | typedef std::tuple<const WebCore::ServiceWorkerRegistrationIdentifier&, WebCore::ServiceWorkerUpdateViaCache> Arguments; |
| 244 | |
| 245 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 246 | static IPC::StringReference name() { return IPC::StringReference("SetRegistrationUpdateViaCache" ); } |
| 247 | static const bool isSync = false; |
| 248 | |
| 249 | SetRegistrationUpdateViaCache(const WebCore::ServiceWorkerRegistrationIdentifier& identifier, WebCore::ServiceWorkerUpdateViaCache updateViaCache) |
| 250 | : m_arguments(identifier, updateViaCache) |
| 251 | { |
| 252 | } |
| 253 | |
| 254 | const Arguments& arguments() const |
| 255 | { |
| 256 | return m_arguments; |
| 257 | } |
| 258 | |
| 259 | private: |
| 260 | Arguments m_arguments; |
| 261 | }; |
| 262 | |
| 263 | class NotifyClientsOfControllerChange { |
| 264 | public: |
| 265 | typedef std::tuple<const HashSet<WebCore::DocumentIdentifier>&, const WebCore::ServiceWorkerData&> Arguments; |
| 266 | |
| 267 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 268 | static IPC::StringReference name() { return IPC::StringReference("NotifyClientsOfControllerChange" ); } |
| 269 | static const bool isSync = false; |
| 270 | |
| 271 | NotifyClientsOfControllerChange(const HashSet<WebCore::DocumentIdentifier>& contextIdentifiers, const WebCore::ServiceWorkerData& newController) |
| 272 | : m_arguments(contextIdentifiers, newController) |
| 273 | { |
| 274 | } |
| 275 | |
| 276 | const Arguments& arguments() const |
| 277 | { |
| 278 | return m_arguments; |
| 279 | } |
| 280 | |
| 281 | private: |
| 282 | Arguments m_arguments; |
| 283 | }; |
| 284 | |
| 285 | class SetSWOriginTableIsImported { |
| 286 | public: |
| 287 | typedef std::tuple<> Arguments; |
| 288 | |
| 289 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 290 | static IPC::StringReference name() { return IPC::StringReference("SetSWOriginTableIsImported" ); } |
| 291 | static const bool isSync = false; |
| 292 | |
| 293 | const Arguments& arguments() const |
| 294 | { |
| 295 | return m_arguments; |
| 296 | } |
| 297 | |
| 298 | private: |
| 299 | Arguments m_arguments; |
| 300 | }; |
| 301 | |
| 302 | class SetSWOriginTableSharedMemory { |
| 303 | public: |
| 304 | typedef std::tuple<const WebKit::SharedMemory::Handle&> Arguments; |
| 305 | |
| 306 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 307 | static IPC::StringReference name() { return IPC::StringReference("SetSWOriginTableSharedMemory" ); } |
| 308 | static const bool isSync = false; |
| 309 | |
| 310 | explicit SetSWOriginTableSharedMemory(const WebKit::SharedMemory::Handle& handle) |
| 311 | : m_arguments(handle) |
| 312 | { |
| 313 | } |
| 314 | |
| 315 | const Arguments& arguments() const |
| 316 | { |
| 317 | return m_arguments; |
| 318 | } |
| 319 | |
| 320 | private: |
| 321 | Arguments m_arguments; |
| 322 | }; |
| 323 | |
| 324 | class PostMessageToServiceWorkerClient { |
| 325 | public: |
| 326 | typedef std::tuple<const WebCore::DocumentIdentifier&, const WebCore::MessageWithMessagePorts&, const WebCore::ServiceWorkerData&, const String&> Arguments; |
| 327 | |
| 328 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 329 | static IPC::StringReference name() { return IPC::StringReference("PostMessageToServiceWorkerClient" ); } |
| 330 | static const bool isSync = false; |
| 331 | |
| 332 | PostMessageToServiceWorkerClient(const WebCore::DocumentIdentifier& destinationContextIdentifier, const WebCore::MessageWithMessagePorts& message, const WebCore::ServiceWorkerData& source, const String& sourceOrigin) |
| 333 | : m_arguments(destinationContextIdentifier, message, source, sourceOrigin) |
| 334 | { |
| 335 | } |
| 336 | |
| 337 | const Arguments& arguments() const |
| 338 | { |
| 339 | return m_arguments; |
| 340 | } |
| 341 | |
| 342 | private: |
| 343 | Arguments m_arguments; |
| 344 | }; |
| 345 | |
| 346 | class DidMatchRegistration { |
| 347 | public: |
| 348 | typedef std::tuple<uint64_t, const Optional<WebCore::ServiceWorkerRegistrationData>&> Arguments; |
| 349 | |
| 350 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 351 | static IPC::StringReference name() { return IPC::StringReference("DidMatchRegistration" ); } |
| 352 | static const bool isSync = false; |
| 353 | |
| 354 | DidMatchRegistration(uint64_t matchRequestIdentifier, const Optional<WebCore::ServiceWorkerRegistrationData>& data) |
| 355 | : m_arguments(matchRequestIdentifier, data) |
| 356 | { |
| 357 | } |
| 358 | |
| 359 | const Arguments& arguments() const |
| 360 | { |
| 361 | return m_arguments; |
| 362 | } |
| 363 | |
| 364 | private: |
| 365 | Arguments m_arguments; |
| 366 | }; |
| 367 | |
| 368 | class DidGetRegistrations { |
| 369 | public: |
| 370 | typedef std::tuple<uint64_t, const Vector<WebCore::ServiceWorkerRegistrationData>&> Arguments; |
| 371 | |
| 372 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 373 | static IPC::StringReference name() { return IPC::StringReference("DidGetRegistrations" ); } |
| 374 | static const bool isSync = false; |
| 375 | |
| 376 | DidGetRegistrations(uint64_t matchRequestIdentifier, const Vector<WebCore::ServiceWorkerRegistrationData>& registrations) |
| 377 | : m_arguments(matchRequestIdentifier, registrations) |
| 378 | { |
| 379 | } |
| 380 | |
| 381 | const Arguments& arguments() const |
| 382 | { |
| 383 | return m_arguments; |
| 384 | } |
| 385 | |
| 386 | private: |
| 387 | Arguments m_arguments; |
| 388 | }; |
| 389 | |
| 390 | class RegistrationReady { |
| 391 | public: |
| 392 | typedef std::tuple<uint64_t, const WebCore::ServiceWorkerRegistrationData&> Arguments; |
| 393 | |
| 394 | static IPC::StringReference receiverName() { return messageReceiverName(); } |
| 395 | static IPC::StringReference name() { return IPC::StringReference("RegistrationReady" ); } |
| 396 | static const bool isSync = false; |
| 397 | |
| 398 | RegistrationReady(uint64_t registrationReadyRequestIdentifier, const WebCore::ServiceWorkerRegistrationData& data) |
| 399 | : m_arguments(registrationReadyRequestIdentifier, data) |
| 400 | { |
| 401 | } |
| 402 | |
| 403 | const Arguments& arguments() const |
| 404 | { |
| 405 | return m_arguments; |
| 406 | } |
| 407 | |
| 408 | private: |
| 409 | Arguments m_arguments; |
| 410 | }; |
| 411 | |
| 412 | } // namespace WebSWClientConnection |
| 413 | } // namespace Messages |
| 414 | |
| 415 | #endif // ENABLE(SERVICE_WORKER) |
| 416 | |