| 1 | /* |
| 2 | * Copyright (C) 2012-2019 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 "NetworkConnectionToWebProcess.h" |
| 28 | |
| 29 | #include "BlobDataFileReferenceWithSandboxExtension.h" |
| 30 | #include "CacheStorageEngineConnectionMessages.h" |
| 31 | #include "DataReference.h" |
| 32 | #include "NetworkCache.h" |
| 33 | #include "NetworkMDNSRegisterMessages.h" |
| 34 | #include "NetworkProcess.h" |
| 35 | #include "NetworkProcessConnectionMessages.h" |
| 36 | #include "NetworkProcessMessages.h" |
| 37 | #include "NetworkRTCMonitorMessages.h" |
| 38 | #include "NetworkRTCProviderMessages.h" |
| 39 | #include "NetworkRTCSocketMessages.h" |
| 40 | #include "NetworkResourceLoadParameters.h" |
| 41 | #include "NetworkResourceLoader.h" |
| 42 | #include "NetworkResourceLoaderMessages.h" |
| 43 | #include "NetworkSession.h" |
| 44 | #include "NetworkSocketStream.h" |
| 45 | #include "NetworkSocketStreamMessages.h" |
| 46 | #include "PingLoad.h" |
| 47 | #include "PreconnectTask.h" |
| 48 | #include "ServiceWorkerFetchTaskMessages.h" |
| 49 | #include "WebCoreArgumentCoders.h" |
| 50 | #include "WebErrors.h" |
| 51 | #include "WebIDBConnectionToClient.h" |
| 52 | #include "WebIDBConnectionToClientMessages.h" |
| 53 | #include "WebProcessPoolMessages.h" |
| 54 | #include "WebResourceLoadStatisticsStore.h" |
| 55 | #include "WebSWServerConnection.h" |
| 56 | #include "WebSWServerConnectionMessages.h" |
| 57 | #include "WebSWServerToContextConnection.h" |
| 58 | #include "WebSWServerToContextConnectionMessages.h" |
| 59 | #include "WebsiteDataStoreParameters.h" |
| 60 | #include <WebCore/DocumentStorageAccess.h> |
| 61 | #include <WebCore/NetworkStorageSession.h> |
| 62 | #include <WebCore/ResourceLoadStatistics.h> |
| 63 | #include <WebCore/ResourceRequest.h> |
| 64 | #include <WebCore/SameSiteInfo.h> |
| 65 | #include <WebCore/SecurityPolicy.h> |
| 66 | |
| 67 | #if ENABLE(APPLE_PAY_REMOTE_UI) |
| 68 | #include "WebPaymentCoordinatorProxyMessages.h" |
| 69 | #endif |
| 70 | |
| 71 | namespace WebKit { |
| 72 | using namespace WebCore; |
| 73 | |
| 74 | Ref<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(NetworkProcess& networkProcess, IPC::Connection::Identifier connectionIdentifier) |
| 75 | { |
| 76 | return adoptRef(*new NetworkConnectionToWebProcess(networkProcess, connectionIdentifier)); |
| 77 | } |
| 78 | |
| 79 | NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(NetworkProcess& networkProcess, IPC::Connection::Identifier connectionIdentifier) |
| 80 | : m_connection(IPC::Connection::createServerConnection(connectionIdentifier, *this)) |
| 81 | , m_networkProcess(networkProcess) |
| 82 | , m_networkResourceLoaders(*this) |
| 83 | #if ENABLE(WEB_RTC) |
| 84 | , m_mdnsRegister(*this) |
| 85 | #endif |
| 86 | { |
| 87 | RELEASE_ASSERT(RunLoop::isMain()); |
| 88 | |
| 89 | // Use this flag to force synchronous messages to be treated as asynchronous messages in the WebProcess. |
| 90 | // Otherwise, the WebProcess would process incoming synchronous IPC while waiting for a synchronous IPC |
| 91 | // reply from the Network process, which would be unsafe. |
| 92 | m_connection->setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(true); |
| 93 | m_connection->open(); |
| 94 | } |
| 95 | |
| 96 | NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess() |
| 97 | { |
| 98 | RELEASE_ASSERT(RunLoop::isMain()); |
| 99 | |
| 100 | m_connection->invalidate(); |
| 101 | #if USE(LIBWEBRTC) |
| 102 | if (m_rtcProvider) |
| 103 | m_rtcProvider->close(); |
| 104 | #endif |
| 105 | |
| 106 | #if ENABLE(SERVICE_WORKER) |
| 107 | unregisterSWConnections(); |
| 108 | #endif |
| 109 | } |
| 110 | |
| 111 | void NetworkConnectionToWebProcess::didCleanupResourceLoader(NetworkResourceLoader& loader) |
| 112 | { |
| 113 | RELEASE_ASSERT(loader.identifier()); |
| 114 | RELEASE_ASSERT(RunLoop::isMain()); |
| 115 | |
| 116 | if (loader.isKeptAlive()) { |
| 117 | networkProcess().removeKeptAliveLoad(loader); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | ASSERT(m_networkResourceLoaders.get(loader.identifier()) == &loader); |
| 122 | m_networkResourceLoaders.remove(loader.identifier()); |
| 123 | } |
| 124 | |
| 125 | void NetworkConnectionToWebProcess::transferKeptAliveLoad(NetworkResourceLoader& loader) |
| 126 | { |
| 127 | RELEASE_ASSERT(RunLoop::isMain()); |
| 128 | ASSERT(loader.isKeptAlive()); |
| 129 | ASSERT(m_networkResourceLoaders.get(loader.identifier()) == &loader); |
| 130 | if (auto takenLoader = m_networkResourceLoaders.take(loader.identifier())) |
| 131 | m_networkProcess->addKeptAliveLoad(takenLoader.releaseNonNull()); |
| 132 | } |
| 133 | |
| 134 | void NetworkConnectionToWebProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
| 135 | { |
| 136 | if (decoder.messageReceiverName() == Messages::NetworkConnectionToWebProcess::messageReceiverName()) { |
| 137 | didReceiveNetworkConnectionToWebProcessMessage(connection, decoder); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | if (decoder.messageReceiverName() == Messages::NetworkResourceLoader::messageReceiverName()) { |
| 142 | RELEASE_ASSERT(RunLoop::isMain()); |
| 143 | RELEASE_ASSERT(decoder.destinationID()); |
| 144 | if (auto* loader = m_networkResourceLoaders.get(decoder.destinationID())) |
| 145 | loader->didReceiveNetworkResourceLoaderMessage(connection, decoder); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | if (decoder.messageReceiverName() == Messages::NetworkSocketStream::messageReceiverName()) { |
| 150 | if (auto* socketStream = m_networkSocketStreams.get(decoder.destinationID())) { |
| 151 | socketStream->didReceiveMessage(connection, decoder); |
| 152 | if (decoder.messageName() == Messages::NetworkSocketStream::Close::name()) |
| 153 | m_networkSocketStreams.remove(decoder.destinationID()); |
| 154 | } |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | if (decoder.messageReceiverName() == Messages::NetworkProcess::messageReceiverName()) { |
| 159 | m_networkProcess->didReceiveNetworkProcessMessage(connection, decoder); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | |
| 164 | #if USE(LIBWEBRTC) |
| 165 | if (decoder.messageReceiverName() == Messages::NetworkRTCSocket::messageReceiverName()) { |
| 166 | rtcProvider().didReceiveNetworkRTCSocketMessage(connection, decoder); |
| 167 | return; |
| 168 | } |
| 169 | if (decoder.messageReceiverName() == Messages::NetworkRTCMonitor::messageReceiverName()) { |
| 170 | rtcProvider().didReceiveNetworkRTCMonitorMessage(connection, decoder); |
| 171 | return; |
| 172 | } |
| 173 | if (decoder.messageReceiverName() == Messages::NetworkRTCProvider::messageReceiverName()) { |
| 174 | rtcProvider().didReceiveMessage(connection, decoder); |
| 175 | return; |
| 176 | } |
| 177 | #endif |
| 178 | #if ENABLE(WEB_RTC) |
| 179 | if (decoder.messageReceiverName() == Messages::NetworkMDNSRegister::messageReceiverName()) { |
| 180 | mdnsRegister().didReceiveMessage(connection, decoder); |
| 181 | return; |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | if (decoder.messageReceiverName() == Messages::CacheStorageEngineConnection::messageReceiverName()) { |
| 186 | cacheStorageConnection().didReceiveMessage(connection, decoder); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | #if ENABLE(INDEXED_DATABASE) |
| 191 | if (decoder.messageReceiverName() == Messages::WebIDBConnectionToClient::messageReceiverName()) { |
| 192 | auto iterator = m_webIDBConnections.find(decoder.destinationID()); |
| 193 | if (iterator != m_webIDBConnections.end()) |
| 194 | iterator->value->didReceiveMessage(connection, decoder); |
| 195 | return; |
| 196 | } |
| 197 | #endif |
| 198 | |
| 199 | #if ENABLE(SERVICE_WORKER) |
| 200 | if (decoder.messageReceiverName() == Messages::WebSWServerConnection::messageReceiverName()) { |
| 201 | if (auto swConnection = m_swConnections.get(makeObjectIdentifier<SWServerConnectionIdentifierType>(decoder.destinationID()))) |
| 202 | swConnection->didReceiveMessage(connection, decoder); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | if (decoder.messageReceiverName() == Messages::WebSWServerToContextConnection::messageReceiverName()) { |
| 207 | if (auto* contextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) { |
| 208 | contextConnection->didReceiveMessage(connection, decoder); |
| 209 | return; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if (decoder.messageReceiverName() == Messages::ServiceWorkerFetchTask::messageReceiverName()) { |
| 214 | if (auto* contextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) { |
| 215 | contextConnection->didReceiveFetchTaskMessage(connection, decoder); |
| 216 | return; |
| 217 | } |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | #if ENABLE(APPLE_PAY_REMOTE_UI) |
| 222 | if (decoder.messageReceiverName() == Messages::WebPaymentCoordinatorProxy::messageReceiverName()) |
| 223 | return paymentCoordinator().didReceiveMessage(connection, decoder); |
| 224 | #endif |
| 225 | |
| 226 | ASSERT_NOT_REACHED(); |
| 227 | } |
| 228 | |
| 229 | #if USE(LIBWEBRTC) |
| 230 | NetworkRTCProvider& NetworkConnectionToWebProcess::rtcProvider() |
| 231 | { |
| 232 | if (!m_rtcProvider) |
| 233 | m_rtcProvider = NetworkRTCProvider::create(*this); |
| 234 | return *m_rtcProvider; |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | CacheStorageEngineConnection& NetworkConnectionToWebProcess::cacheStorageConnection() |
| 239 | { |
| 240 | if (!m_cacheStorageConnection) |
| 241 | m_cacheStorageConnection = CacheStorageEngineConnection::create(*this); |
| 242 | return *m_cacheStorageConnection; |
| 243 | } |
| 244 | |
| 245 | void NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& reply) |
| 246 | { |
| 247 | if (decoder.messageReceiverName() == Messages::NetworkConnectionToWebProcess::messageReceiverName()) { |
| 248 | didReceiveSyncNetworkConnectionToWebProcessMessage(connection, decoder, reply); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | #if ENABLE(SERVICE_WORKER) |
| 253 | if (decoder.messageReceiverName() == Messages::WebSWServerConnection::messageReceiverName()) { |
| 254 | if (auto swConnection = m_swConnections.get(makeObjectIdentifier<SWServerConnectionIdentifierType>(decoder.destinationID()))) |
| 255 | swConnection->didReceiveSyncMessage(connection, decoder, reply); |
| 256 | return; |
| 257 | } |
| 258 | #endif |
| 259 | |
| 260 | #if ENABLE(APPLE_PAY_REMOTE_UI) |
| 261 | if (decoder.messageReceiverName() == Messages::WebPaymentCoordinatorProxy::messageReceiverName()) |
| 262 | return paymentCoordinator().didReceiveSyncMessage(connection, decoder, reply); |
| 263 | #endif |
| 264 | |
| 265 | ASSERT_NOT_REACHED(); |
| 266 | } |
| 267 | |
| 268 | void NetworkConnectionToWebProcess::didClose(IPC::Connection& connection) |
| 269 | { |
| 270 | #if ENABLE(SERVICE_WORKER) |
| 271 | if (RefPtr<WebSWServerToContextConnection> serverToContextConnection = m_networkProcess->connectionToContextProcessFromIPCConnection(connection)) { |
| 272 | // Service Worker process exited. |
| 273 | m_networkProcess->connectionToContextProcessWasClosed(serverToContextConnection.releaseNonNull()); |
| 274 | return; |
| 275 | } |
| 276 | #else |
| 277 | UNUSED_PARAM(connection); |
| 278 | #endif |
| 279 | |
| 280 | // Protect ourself as we might be otherwise be deleted during this function. |
| 281 | Ref<NetworkConnectionToWebProcess> protector(*this); |
| 282 | |
| 283 | while (!m_networkResourceLoaders.isEmpty()) |
| 284 | m_networkResourceLoaders.begin()->value->abort(); |
| 285 | |
| 286 | // All trackers of resources that were in the middle of being loaded were |
| 287 | // stopped with the abort() calls above, but we still need to sweep up the |
| 288 | // root activity trackers. |
| 289 | stopAllNetworkActivityTracking(); |
| 290 | |
| 291 | m_networkProcess->networkBlobRegistry().connectionToWebProcessDidClose(*this); |
| 292 | m_networkProcess->removeNetworkConnectionToWebProcess(*this); |
| 293 | |
| 294 | #if USE(LIBWEBRTC) |
| 295 | if (m_rtcProvider) { |
| 296 | m_rtcProvider->close(); |
| 297 | m_rtcProvider = nullptr; |
| 298 | } |
| 299 | #endif |
| 300 | |
| 301 | #if ENABLE(INDEXED_DATABASE) |
| 302 | auto idbConnections = m_webIDBConnections; |
| 303 | for (auto& connection : idbConnections.values()) |
| 304 | connection->disconnectedFromWebProcess(); |
| 305 | |
| 306 | m_webIDBConnections.clear(); |
| 307 | #endif |
| 308 | |
| 309 | #if ENABLE(SERVICE_WORKER) |
| 310 | unregisterSWConnections(); |
| 311 | #endif |
| 312 | |
| 313 | #if ENABLE(APPLE_PAY_REMOTE_UI) |
| 314 | m_paymentCoordinator = nullptr; |
| 315 | #endif |
| 316 | } |
| 317 | |
| 318 | void NetworkConnectionToWebProcess::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) |
| 319 | { |
| 320 | } |
| 321 | |
| 322 | void NetworkConnectionToWebProcess::createSocketStream(URL&& url, PAL::SessionID sessionID, String cachePartition, uint64_t identifier) |
| 323 | { |
| 324 | ASSERT(!m_networkSocketStreams.contains(identifier)); |
| 325 | WebCore::SourceApplicationAuditToken token = { }; |
| 326 | #if PLATFORM(COCOA) |
| 327 | token = { m_networkProcess->sourceApplicationAuditData() }; |
| 328 | #endif |
| 329 | m_networkSocketStreams.set(identifier, NetworkSocketStream::create(m_networkProcess.get(), WTFMove(url), sessionID, cachePartition, identifier, m_connection, WTFMove(token))); |
| 330 | } |
| 331 | |
| 332 | void NetworkConnectionToWebProcess::destroySocketStream(uint64_t identifier) |
| 333 | { |
| 334 | ASSERT(m_networkSocketStreams.get(identifier)); |
| 335 | m_networkSocketStreams.remove(identifier); |
| 336 | } |
| 337 | |
| 338 | void NetworkConnectionToWebProcess::cleanupForSuspension(Function<void()>&& completionHandler) |
| 339 | { |
| 340 | #if USE(LIBWEBRTC) |
| 341 | if (m_rtcProvider) { |
| 342 | m_rtcProvider->closeListeningSockets(WTFMove(completionHandler)); |
| 343 | return; |
| 344 | } |
| 345 | #endif |
| 346 | completionHandler(); |
| 347 | } |
| 348 | |
| 349 | void NetworkConnectionToWebProcess::endSuspension() |
| 350 | { |
| 351 | #if USE(LIBWEBRTC) |
| 352 | if (m_rtcProvider) |
| 353 | m_rtcProvider->authorizeListeningSockets(); |
| 354 | #endif |
| 355 | } |
| 356 | |
| 357 | Vector<RefPtr<WebCore::BlobDataFileReference>> NetworkConnectionToWebProcess::resolveBlobReferences(const NetworkResourceLoadParameters& parameters) |
| 358 | { |
| 359 | Vector<RefPtr<WebCore::BlobDataFileReference>> files; |
| 360 | if (auto* body = parameters.request.httpBody()) { |
| 361 | for (auto& element : body->elements()) { |
| 362 | if (auto* blobData = WTF::get_if<FormDataElement::EncodedBlobData>(element.data)) |
| 363 | files.appendVector(m_networkProcess->networkBlobRegistry().filesInBlob(*this, blobData->url)); |
| 364 | } |
| 365 | const_cast<WebCore::ResourceRequest&>(parameters.request).setHTTPBody(body->resolveBlobReferences(m_networkProcess->networkBlobRegistry().blobRegistry())); |
| 366 | } |
| 367 | |
| 368 | return files; |
| 369 | } |
| 370 | |
| 371 | void NetworkConnectionToWebProcess::scheduleResourceLoad(NetworkResourceLoadParameters&& loadParameters) |
| 372 | { |
| 373 | auto identifier = loadParameters.identifier; |
| 374 | RELEASE_ASSERT(identifier); |
| 375 | RELEASE_ASSERT(RunLoop::isMain()); |
| 376 | ASSERT(!m_networkResourceLoaders.contains(identifier)); |
| 377 | |
| 378 | auto loader = NetworkResourceLoader::create(WTFMove(loadParameters), *this); |
| 379 | m_networkResourceLoaders.add(identifier, loader.copyRef()); |
| 380 | loader->start(); |
| 381 | } |
| 382 | |
| 383 | void NetworkConnectionToWebProcess::performSynchronousLoad(NetworkResourceLoadParameters&& loadParameters, Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply&& reply) |
| 384 | { |
| 385 | auto identifier = loadParameters.identifier; |
| 386 | RELEASE_ASSERT(identifier); |
| 387 | RELEASE_ASSERT(RunLoop::isMain()); |
| 388 | ASSERT(!m_networkResourceLoaders.contains(identifier)); |
| 389 | |
| 390 | auto loader = NetworkResourceLoader::create(WTFMove(loadParameters), *this, WTFMove(reply)); |
| 391 | m_networkResourceLoaders.add(identifier, loader.copyRef()); |
| 392 | loader->start(); |
| 393 | } |
| 394 | |
| 395 | void NetworkConnectionToWebProcess::loadPing(NetworkResourceLoadParameters&& loadParameters) |
| 396 | { |
| 397 | auto completionHandler = [connection = m_connection.copyRef(), identifier = loadParameters.identifier] (const ResourceError& error, const ResourceResponse& response) { |
| 398 | connection->send(Messages::NetworkProcessConnection::DidFinishPingLoad(identifier, error, response), 0); |
| 399 | }; |
| 400 | |
| 401 | // PingLoad manages its own lifetime, deleting itself when its purpose has been fulfilled. |
| 402 | new PingLoad(*this, networkProcess(), WTFMove(loadParameters), WTFMove(completionHandler)); |
| 403 | } |
| 404 | |
| 405 | void NetworkConnectionToWebProcess::setOnLineState(bool isOnLine) |
| 406 | { |
| 407 | m_connection->send(Messages::NetworkProcessConnection::SetOnLineState(isOnLine), 0); |
| 408 | } |
| 409 | |
| 410 | void NetworkConnectionToWebProcess::removeLoadIdentifier(ResourceLoadIdentifier identifier) |
| 411 | { |
| 412 | RELEASE_ASSERT(identifier); |
| 413 | RELEASE_ASSERT(RunLoop::isMain()); |
| 414 | |
| 415 | RefPtr<NetworkResourceLoader> loader = m_networkResourceLoaders.get(identifier); |
| 416 | |
| 417 | // It's possible we have no loader for this identifier if the NetworkProcess crashed and this was a respawned NetworkProcess. |
| 418 | if (!loader) |
| 419 | return; |
| 420 | |
| 421 | // Abort the load now, as the WebProcess won't be able to respond to messages any more which might lead |
| 422 | // to leaked loader resources (connections, threads, etc). |
| 423 | loader->abort(); |
| 424 | ASSERT(!m_networkResourceLoaders.contains(identifier)); |
| 425 | } |
| 426 | |
| 427 | void NetworkConnectionToWebProcess::pageLoadCompleted(uint64_t webPageID) |
| 428 | { |
| 429 | stopAllNetworkActivityTrackingForPage(webPageID); |
| 430 | } |
| 431 | |
| 432 | void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname) |
| 433 | { |
| 434 | m_networkProcess->prefetchDNS(hostname); |
| 435 | } |
| 436 | |
| 437 | void NetworkConnectionToWebProcess::preconnectTo(uint64_t preconnectionIdentifier, NetworkResourceLoadParameters&& parameters) |
| 438 | { |
| 439 | ASSERT(!parameters.request.httpBody()); |
| 440 | |
| 441 | #if ENABLE(SERVER_PRECONNECT) |
| 442 | new PreconnectTask(networkProcess(), WTFMove(parameters), [this, protectedThis = makeRef(*this), identifier = preconnectionIdentifier] (const ResourceError& error) { |
| 443 | didFinishPreconnection(identifier, error); |
| 444 | }); |
| 445 | #else |
| 446 | UNUSED_PARAM(parameters); |
| 447 | didFinishPreconnection(preconnectionIdentifier, internalError(parameters.request.url())); |
| 448 | #endif |
| 449 | } |
| 450 | |
| 451 | void NetworkConnectionToWebProcess::didFinishPreconnection(uint64_t preconnectionIdentifier, const ResourceError& error) |
| 452 | { |
| 453 | if (!m_connection->isValid()) |
| 454 | return; |
| 455 | |
| 456 | m_connection->send(Messages::NetworkProcessConnection::DidFinishPreconnection(preconnectionIdentifier, error), 0); |
| 457 | } |
| 458 | |
| 459 | static NetworkStorageSession& storageSession(const NetworkProcess& networkProcess, PAL::SessionID sessionID) |
| 460 | { |
| 461 | ASSERT(sessionID.isValid()); |
| 462 | if (sessionID != PAL::SessionID::defaultSessionID()) { |
| 463 | if (auto* storageSession = networkProcess.storageSession(sessionID)) |
| 464 | return *storageSession; |
| 465 | |
| 466 | // Some requests with private browsing mode requested may still be coming shortly after NetworkProcess was told to destroy its session. |
| 467 | // FIXME: Find a way to track private browsing sessions more rigorously. |
| 468 | LOG_ERROR("Non-default storage session was requested, but there was no session for it. Please file a bug unless you just disabled private browsing, in which case it's an expected race." ); |
| 469 | } |
| 470 | return networkProcess.defaultStorageSession(); |
| 471 | } |
| 472 | |
| 473 | void NetworkConnectionToWebProcess::startDownload(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedName) |
| 474 | { |
| 475 | m_networkProcess->downloadManager().startDownload(sessionID, downloadID, request, suggestedName); |
| 476 | } |
| 477 | |
| 478 | void NetworkConnectionToWebProcess::convertMainResourceLoadToDownload(PAL::SessionID sessionID, uint64_t mainResourceLoadIdentifier, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response) |
| 479 | { |
| 480 | RELEASE_ASSERT(RunLoop::isMain()); |
| 481 | |
| 482 | // In case a response is served from service worker, we do not have yet the ability to convert the load. |
| 483 | if (!mainResourceLoadIdentifier || response.source() == ResourceResponse::Source::ServiceWorker) { |
| 484 | m_networkProcess->downloadManager().startDownload(sessionID, downloadID, request); |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | NetworkResourceLoader* loader = m_networkResourceLoaders.get(mainResourceLoadIdentifier); |
| 489 | if (!loader) { |
| 490 | // If we're trying to download a blob here loader can be null. |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | loader->convertToDownload(downloadID, request, response); |
| 495 | } |
| 496 | |
| 497 | void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, CompletionHandler<void(String cookieString, bool secureCookiesAccessed)>&& completionHandler) |
| 498 | { |
| 499 | auto& networkStorageSession = storageSession(networkProcess(), sessionID); |
| 500 | auto result = networkStorageSession.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies); |
| 501 | #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED |
| 502 | if (auto session = networkProcess().networkSession(sessionID)) { |
| 503 | if (session->shouldLogCookieInformation()) |
| 504 | NetworkResourceLoader::logCookieInformation(*this, "NetworkConnectionToWebProcess::cookiesForDOM" , reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, WTF::nullopt); |
| 505 | } |
| 506 | #endif |
| 507 | completionHandler(WTFMove(result.first), result.second); |
| 508 | } |
| 509 | |
| 510 | void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, const String& cookieString) |
| 511 | { |
| 512 | auto& networkStorageSession = storageSession(networkProcess(), sessionID); |
| 513 | networkStorageSession.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString); |
| 514 | #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED |
| 515 | if (auto session = networkProcess().networkSession(sessionID)) { |
| 516 | if (session->shouldLogCookieInformation()) |
| 517 | NetworkResourceLoader::logCookieInformation(*this, "NetworkConnectionToWebProcess::setCookiesFromDOM" , reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, WTF::nullopt); |
| 518 | } |
| 519 | #endif |
| 520 | } |
| 521 | |
| 522 | void NetworkConnectionToWebProcess::cookiesEnabled(PAL::SessionID sessionID, CompletionHandler<void(bool)>&& completionHandler) |
| 523 | { |
| 524 | completionHandler(storageSession(networkProcess(), sessionID).cookiesEnabled()); |
| 525 | } |
| 526 | |
| 527 | void NetworkConnectionToWebProcess::(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, CompletionHandler<void(String, bool)>&& completionHandler) |
| 528 | { |
| 529 | auto result = storageSession(networkProcess(), sessionID).cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies); |
| 530 | completionHandler(WTFMove(result.first), result.second); |
| 531 | } |
| 532 | |
| 533 | void NetworkConnectionToWebProcess::getRawCookies(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, CompletionHandler<void(Vector<WebCore::Cookie>&&)>&& completionHandler) |
| 534 | { |
| 535 | Vector<WebCore::Cookie> result; |
| 536 | storageSession(networkProcess(), sessionID).getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, result); |
| 537 | completionHandler(WTFMove(result)); |
| 538 | } |
| 539 | |
| 540 | void NetworkConnectionToWebProcess::deleteCookie(PAL::SessionID sessionID, const URL& url, const String& cookieName) |
| 541 | { |
| 542 | storageSession(networkProcess(), sessionID).deleteCookie(url, cookieName); |
| 543 | } |
| 544 | |
| 545 | void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, SandboxExtension::Handle&& extensionHandle, const String& contentType) |
| 546 | { |
| 547 | m_networkProcess->networkBlobRegistry().registerFileBlobURL(*this, url, path, SandboxExtension::create(WTFMove(extensionHandle)), contentType); |
| 548 | } |
| 549 | |
| 550 | void NetworkConnectionToWebProcess::registerBlobURL(const URL& url, Vector<BlobPart>&& blobParts, const String& contentType) |
| 551 | { |
| 552 | m_networkProcess->networkBlobRegistry().registerBlobURL(*this, url, WTFMove(blobParts), contentType); |
| 553 | } |
| 554 | |
| 555 | void NetworkConnectionToWebProcess::registerBlobURLFromURL(const URL& url, const URL& srcURL, bool shouldBypassConnectionCheck) |
| 556 | { |
| 557 | m_networkProcess->networkBlobRegistry().registerBlobURL(*this, url, srcURL, shouldBypassConnectionCheck); |
| 558 | } |
| 559 | |
| 560 | void NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, const String& fileBackedPath, const String& contentType) |
| 561 | { |
| 562 | m_networkProcess->networkBlobRegistry().registerBlobURLOptionallyFileBacked(*this, url, srcURL, fileBackedPath, contentType); |
| 563 | } |
| 564 | |
| 565 | void NetworkConnectionToWebProcess::registerBlobURLForSlice(const URL& url, const URL& srcURL, int64_t start, int64_t end) |
| 566 | { |
| 567 | m_networkProcess->networkBlobRegistry().registerBlobURLForSlice(*this, url, srcURL, start, end); |
| 568 | } |
| 569 | |
| 570 | void NetworkConnectionToWebProcess::unregisterBlobURL(const URL& url) |
| 571 | { |
| 572 | m_networkProcess->networkBlobRegistry().unregisterBlobURL(*this, url); |
| 573 | } |
| 574 | |
| 575 | void NetworkConnectionToWebProcess::blobSize(const URL& url, CompletionHandler<void(uint64_t)>&& completionHandler) |
| 576 | { |
| 577 | completionHandler(m_networkProcess->networkBlobRegistry().blobSize(*this, url)); |
| 578 | } |
| 579 | |
| 580 | void NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&&)>&& completionHandler) |
| 581 | { |
| 582 | Vector<RefPtr<BlobDataFileReference>> fileReferences; |
| 583 | for (auto& url : blobURLs) |
| 584 | fileReferences.appendVector(m_networkProcess->networkBlobRegistry().filesInBlob(*this, { { }, url })); |
| 585 | |
| 586 | for (auto& file : fileReferences) |
| 587 | file->prepareForFileAccess(); |
| 588 | |
| 589 | m_networkProcess->networkBlobRegistry().writeBlobsToTemporaryFiles(blobURLs, [fileReferences = WTFMove(fileReferences), completionHandler = WTFMove(completionHandler)](auto&& fileNames) mutable { |
| 590 | for (auto& file : fileReferences) |
| 591 | file->revokeFileAccess(); |
| 592 | completionHandler(WTFMove(fileNames)); |
| 593 | }); |
| 594 | } |
| 595 | |
| 596 | Vector<RefPtr<WebCore::BlobDataFileReference>> NetworkConnectionToWebProcess::filesInBlob(const URL& url) |
| 597 | { |
| 598 | return m_networkProcess->networkBlobRegistry().filesInBlob(*this, url); |
| 599 | } |
| 600 | |
| 601 | WebCore::BlobRegistryImpl& NetworkConnectionToWebProcess::blobRegistry() |
| 602 | { |
| 603 | return m_networkProcess->networkBlobRegistry().blobRegistry(); |
| 604 | } |
| 605 | |
| 606 | void NetworkConnectionToWebProcess::(bool enabled) |
| 607 | { |
| 608 | m_captureExtraNetworkLoadMetricsEnabled = enabled; |
| 609 | if (m_captureExtraNetworkLoadMetricsEnabled) |
| 610 | return; |
| 611 | |
| 612 | m_networkLoadInformationByID.clear(); |
| 613 | for (auto& loader : m_networkResourceLoaders.values()) |
| 614 | loader->disableExtraNetworkLoadMetricsCapture(); |
| 615 | } |
| 616 | |
| 617 | void NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession() |
| 618 | { |
| 619 | m_networkProcess->addWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters()); |
| 620 | } |
| 621 | |
| 622 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 623 | void NetworkConnectionToWebProcess::removeStorageAccessForFrame(PAL::SessionID sessionID, uint64_t frameID, uint64_t pageID) |
| 624 | { |
| 625 | if (auto* storageSession = networkProcess().storageSession(sessionID)) |
| 626 | storageSession->removeStorageAccessForFrame(frameID, pageID); |
| 627 | } |
| 628 | |
| 629 | void NetworkConnectionToWebProcess::clearPageSpecificDataForResourceLoadStatistics(PAL::SessionID sessionID, uint64_t pageID) |
| 630 | { |
| 631 | if (auto* storageSession = networkProcess().storageSession(sessionID)) |
| 632 | storageSession->clearPageSpecificDataForResourceLoadStatistics(pageID); |
| 633 | } |
| 634 | |
| 635 | void NetworkConnectionToWebProcess::logUserInteraction(PAL::SessionID sessionID, const RegistrableDomain& domain) |
| 636 | { |
| 637 | ASSERT(sessionID.isValid()); |
| 638 | if (!sessionID.isValid()) |
| 639 | return; |
| 640 | |
| 641 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 642 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) |
| 643 | resourceLoadStatistics->logUserInteraction(domain, [] { }); |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | void NetworkConnectionToWebProcess::logWebSocketLoading(PAL::SessionID sessionID, const RegistrableDomain& targetDomain, const RegistrableDomain& topFrameDomain, WallTime lastSeen) |
| 648 | { |
| 649 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 650 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) |
| 651 | resourceLoadStatistics->logWebSocketLoading(targetDomain, topFrameDomain, lastSeen, [] { }); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | void NetworkConnectionToWebProcess::logSubresourceLoading(PAL::SessionID sessionID, const RegistrableDomain& targetDomain, const RegistrableDomain& topFrameDomain, WallTime lastSeen) |
| 656 | { |
| 657 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 658 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) |
| 659 | resourceLoadStatistics->logSubresourceLoading(targetDomain, topFrameDomain, lastSeen, [] { }); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | void NetworkConnectionToWebProcess::logSubresourceRedirect(PAL::SessionID sessionID, const RegistrableDomain& sourceDomain, const RegistrableDomain& targetDomain) |
| 664 | { |
| 665 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 666 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) |
| 667 | resourceLoadStatistics->logSubresourceRedirect(sourceDomain, targetDomain, [] { }); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | void NetworkConnectionToWebProcess::resourceLoadStatisticsUpdated(Vector<WebCore::ResourceLoadStatistics>&& statistics) |
| 672 | { |
| 673 | for (auto& networkSession : networkProcess().networkSessions().values()) { |
| 674 | if (networkSession->sessionID().isEphemeral()) |
| 675 | continue; |
| 676 | |
| 677 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) |
| 678 | resourceLoadStatistics->resourceLoadStatisticsUpdated(WTFMove(statistics)); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | void NetworkConnectionToWebProcess::hasStorageAccess(PAL::SessionID sessionID, const RegistrableDomain& subFrameDomain, const RegistrableDomain& topFrameDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(bool)>&& completionHandler) |
| 683 | { |
| 684 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 685 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) { |
| 686 | resourceLoadStatistics->hasStorageAccess(subFrameDomain, topFrameDomain, frameID, pageID, WTFMove(completionHandler)); |
| 687 | return; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | completionHandler(true); |
| 692 | } |
| 693 | |
| 694 | void NetworkConnectionToWebProcess::requestStorageAccess(PAL::SessionID sessionID, const RegistrableDomain& subFrameDomain, const RegistrableDomain& topFrameDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(WebCore::StorageAccessWasGranted wasGranted, WebCore::StorageAccessPromptWasShown promptWasShown)>&& completionHandler) |
| 695 | { |
| 696 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 697 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) { |
| 698 | resourceLoadStatistics->requestStorageAccess(subFrameDomain, topFrameDomain, frameID, pageID, WTFMove(completionHandler)); |
| 699 | return; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | completionHandler(WebCore::StorageAccessWasGranted::Yes, WebCore::StorageAccessPromptWasShown::No); |
| 704 | } |
| 705 | |
| 706 | void NetworkConnectionToWebProcess::requestStorageAccessUnderOpener(PAL::SessionID sessionID, WebCore::RegistrableDomain&& domainInNeedOfStorageAccess, uint64_t openerPageID, WebCore::RegistrableDomain&& openerDomain) |
| 707 | { |
| 708 | if (auto networkSession = networkProcess().networkSession(sessionID)) { |
| 709 | if (auto* resourceLoadStatistics = networkSession->resourceLoadStatistics()) |
| 710 | resourceLoadStatistics->requestStorageAccessUnderOpener(WTFMove(domainInNeedOfStorageAccess), openerPageID, WTFMove(openerDomain)); |
| 711 | } |
| 712 | } |
| 713 | #endif |
| 714 | |
| 715 | void NetworkConnectionToWebProcess::addOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains) |
| 716 | { |
| 717 | SecurityPolicy::addOriginAccessWhitelistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains); |
| 718 | } |
| 719 | |
| 720 | void NetworkConnectionToWebProcess::removeOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains) |
| 721 | { |
| 722 | SecurityPolicy::removeOriginAccessWhitelistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains); |
| 723 | } |
| 724 | |
| 725 | void NetworkConnectionToWebProcess::resetOriginAccessWhitelists() |
| 726 | { |
| 727 | SecurityPolicy::resetOriginAccessWhitelists(); |
| 728 | } |
| 729 | |
| 730 | Optional<NetworkActivityTracker> NetworkConnectionToWebProcess::startTrackingResourceLoad(uint64_t pageID, ResourceLoadIdentifier resourceID, bool isMainResource, const PAL::SessionID& sessionID) |
| 731 | { |
| 732 | if (sessionID.isEphemeral()) |
| 733 | return WTF::nullopt; |
| 734 | |
| 735 | // Either get the existing root activity tracker for this page or create a |
| 736 | // new one if this is the main resource. |
| 737 | |
| 738 | size_t rootActivityIndex; |
| 739 | if (isMainResource) { |
| 740 | // If we're loading a page from the top, make sure any tracking of |
| 741 | // previous activity for this page is stopped. |
| 742 | |
| 743 | stopAllNetworkActivityTrackingForPage(pageID); |
| 744 | |
| 745 | rootActivityIndex = m_networkActivityTrackers.size(); |
| 746 | m_networkActivityTrackers.constructAndAppend(pageID); |
| 747 | m_networkActivityTrackers[rootActivityIndex].networkActivity.start(); |
| 748 | |
| 749 | #if HAVE(NW_ACTIVITY) |
| 750 | ASSERT(m_networkActivityTrackers[rootActivityIndex].networkActivity.getPlatformObject()); |
| 751 | #endif |
| 752 | } else { |
| 753 | rootActivityIndex = findRootNetworkActivity(pageID); |
| 754 | |
| 755 | // This could happen if the Networking process crashes, taking its |
| 756 | // previous state with it. |
| 757 | if (rootActivityIndex == notFound) |
| 758 | return WTF::nullopt; |
| 759 | |
| 760 | #if HAVE(NW_ACTIVITY) |
| 761 | ASSERT(m_networkActivityTrackers[rootActivityIndex].networkActivity.getPlatformObject()); |
| 762 | #endif |
| 763 | } |
| 764 | |
| 765 | // Create a tracker for the loading of the new resource, setting the root |
| 766 | // activity tracker as its parent. |
| 767 | |
| 768 | size_t newActivityIndex = m_networkActivityTrackers.size(); |
| 769 | m_networkActivityTrackers.constructAndAppend(pageID, resourceID); |
| 770 | #if HAVE(NW_ACTIVITY) |
| 771 | ASSERT(m_networkActivityTrackers[newActivityIndex].networkActivity.getPlatformObject()); |
| 772 | #endif |
| 773 | |
| 774 | auto& newActivityTracker = m_networkActivityTrackers[newActivityIndex]; |
| 775 | newActivityTracker.networkActivity.setParent(m_networkActivityTrackers[rootActivityIndex].networkActivity); |
| 776 | newActivityTracker.networkActivity.start(); |
| 777 | |
| 778 | return newActivityTracker.networkActivity; |
| 779 | } |
| 780 | |
| 781 | void NetworkConnectionToWebProcess::stopTrackingResourceLoad(ResourceLoadIdentifier resourceID, NetworkActivityTracker::CompletionCode code) |
| 782 | { |
| 783 | auto itemIndex = findNetworkActivityTracker(resourceID); |
| 784 | if (itemIndex == notFound) |
| 785 | return; |
| 786 | |
| 787 | m_networkActivityTrackers[itemIndex].networkActivity.complete(code); |
| 788 | m_networkActivityTrackers.remove(itemIndex); |
| 789 | } |
| 790 | |
| 791 | void NetworkConnectionToWebProcess::stopAllNetworkActivityTracking() |
| 792 | { |
| 793 | for (auto& activityTracker : m_networkActivityTrackers) |
| 794 | activityTracker.networkActivity.complete(NetworkActivityTracker::CompletionCode::None); |
| 795 | |
| 796 | m_networkActivityTrackers.clear(); |
| 797 | } |
| 798 | |
| 799 | void NetworkConnectionToWebProcess::stopAllNetworkActivityTrackingForPage(uint64_t pageID) |
| 800 | { |
| 801 | for (auto& activityTracker : m_networkActivityTrackers) { |
| 802 | if (activityTracker.pageID == pageID) |
| 803 | activityTracker.networkActivity.complete(NetworkActivityTracker::CompletionCode::None); |
| 804 | } |
| 805 | |
| 806 | m_networkActivityTrackers.removeAllMatching([&](const auto& activityTracker) { |
| 807 | return activityTracker.pageID == pageID; |
| 808 | }); |
| 809 | } |
| 810 | |
| 811 | size_t NetworkConnectionToWebProcess::findRootNetworkActivity(uint64_t pageID) |
| 812 | { |
| 813 | return m_networkActivityTrackers.findMatching([&](const auto& item) { |
| 814 | return item.isRootActivity && item.pageID == pageID; |
| 815 | }); |
| 816 | } |
| 817 | |
| 818 | size_t NetworkConnectionToWebProcess::findNetworkActivityTracker(ResourceLoadIdentifier resourceID) |
| 819 | { |
| 820 | return m_networkActivityTrackers.findMatching([&](const auto& item) { |
| 821 | return item.resourceID == resourceID; |
| 822 | }); |
| 823 | } |
| 824 | |
| 825 | #if ENABLE(INDEXED_DATABASE) |
| 826 | static uint64_t generateIDBConnectionToServerIdentifier() |
| 827 | { |
| 828 | ASSERT(RunLoop::isMain()); |
| 829 | static uint64_t identifier = 0; |
| 830 | return ++identifier; |
| 831 | } |
| 832 | |
| 833 | void NetworkConnectionToWebProcess::establishIDBConnectionToServer(PAL::SessionID sessionID, CompletionHandler<void(uint64_t)>&& completionHandler) |
| 834 | { |
| 835 | uint64_t serverConnectionIdentifier = generateIDBConnectionToServerIdentifier(); |
| 836 | LOG(IndexedDB, "NetworkConnectionToWebProcess::establishIDBConnectionToServer - %" PRIu64, serverConnectionIdentifier); |
| 837 | ASSERT(!m_webIDBConnections.contains(serverConnectionIdentifier)); |
| 838 | |
| 839 | m_webIDBConnections.set(serverConnectionIdentifier, WebIDBConnectionToClient::create(m_networkProcess, m_connection.get(), serverConnectionIdentifier, sessionID)); |
| 840 | completionHandler(serverConnectionIdentifier); |
| 841 | } |
| 842 | #endif |
| 843 | |
| 844 | #if ENABLE(SERVICE_WORKER) |
| 845 | void NetworkConnectionToWebProcess::unregisterSWConnections() |
| 846 | { |
| 847 | auto swConnections = WTFMove(m_swConnections); |
| 848 | for (auto& swConnection : swConnections.values()) { |
| 849 | if (swConnection) |
| 850 | swConnection->server().removeConnection(swConnection->identifier()); |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | void NetworkConnectionToWebProcess::establishSWServerConnection(PAL::SessionID sessionID, CompletionHandler<void(WebCore::SWServerConnectionIdentifier&&)>&& completionHandler) |
| 855 | { |
| 856 | auto& server = m_networkProcess->swServerForSession(sessionID); |
| 857 | auto connection = std::make_unique<WebSWServerConnection>(m_networkProcess, server, m_connection.get(), sessionID); |
| 858 | |
| 859 | SWServerConnectionIdentifier serverConnectionIdentifier = connection->identifier(); |
| 860 | LOG(ServiceWorker, "NetworkConnectionToWebProcess::establishSWServerConnection - %s" , serverConnectionIdentifier.loggingString().utf8().data()); |
| 861 | |
| 862 | ASSERT(!m_swConnections.contains(serverConnectionIdentifier)); |
| 863 | m_swConnections.add(serverConnectionIdentifier, makeWeakPtr(*connection)); |
| 864 | server.addConnection(WTFMove(connection)); |
| 865 | completionHandler(WTFMove(serverConnectionIdentifier)); |
| 866 | } |
| 867 | #endif |
| 868 | |
| 869 | void NetworkConnectionToWebProcess::setWebProcessIdentifier(ProcessIdentifier webProcessIdentifier) |
| 870 | { |
| 871 | m_webProcessIdentifier = webProcessIdentifier; |
| 872 | } |
| 873 | |
| 874 | void NetworkConnectionToWebProcess::setConnectionHasUploads() |
| 875 | { |
| 876 | ASSERT(!m_connectionHasUploads); |
| 877 | m_connectionHasUploads = true; |
| 878 | m_networkProcess->parentProcessConnection()->send(Messages::WebProcessPool::SetWebProcessHasUploads(m_webProcessIdentifier), 0); |
| 879 | } |
| 880 | |
| 881 | void NetworkConnectionToWebProcess::clearConnectionHasUploads() |
| 882 | { |
| 883 | ASSERT(m_connectionHasUploads); |
| 884 | m_connectionHasUploads = false; |
| 885 | m_networkProcess->parentProcessConnection()->send(Messages::WebProcessPool::ClearWebProcessHasUploads(m_webProcessIdentifier), 0); |
| 886 | } |
| 887 | |
| 888 | } // namespace WebKit |
| 889 | |