c13903df9183c8cbf9a6d89d8001560d8a1b8444
[WebKit-https.git] / Source / WebKit / NetworkProcess / NetworkConnectionToWebProcess.cpp
1 /*
2  * Copyright (C) 2012-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''
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 "NetworkBlobRegistry.h"
33 #include "NetworkCache.h"
34 #include "NetworkConnectionToWebProcessMessages.h"
35 #include "NetworkLoad.h"
36 #include "NetworkMDNSRegisterMessages.h"
37 #include "NetworkProcess.h"
38 #include "NetworkProcessConnectionMessages.h"
39 #include "NetworkRTCMonitorMessages.h"
40 #include "NetworkRTCProviderMessages.h"
41 #include "NetworkRTCSocketMessages.h"
42 #include "NetworkResourceLoadParameters.h"
43 #include "NetworkResourceLoader.h"
44 #include "NetworkResourceLoaderMessages.h"
45 #include "NetworkSocketStream.h"
46 #include "NetworkSocketStreamMessages.h"
47 #include "PingLoad.h"
48 #include "PreconnectTask.h"
49 #include "SessionTracker.h"
50 #include "WebCoreArgumentCoders.h"
51 #include "WebErrors.h"
52 #include "WebsiteDataStore.h"
53 #include "WebsiteDataStoreParameters.h"
54 #include <WebCore/NetworkStorageSession.h>
55 #include <WebCore/PlatformCookieJar.h>
56 #include <WebCore/ResourceLoaderOptions.h>
57 #include <WebCore/ResourceRequest.h>
58 #include <WebCore/SameSiteInfo.h>
59 #include <WebCore/SecurityPolicy.h>
60 #include <pal/SessionID.h>
61
62 using namespace WebCore;
63
64 namespace WebKit {
65
66 Ref<NetworkConnectionToWebProcess> NetworkConnectionToWebProcess::create(IPC::Connection::Identifier connectionIdentifier)
67 {
68     return adoptRef(*new NetworkConnectionToWebProcess(connectionIdentifier));
69 }
70
71 NetworkConnectionToWebProcess::NetworkConnectionToWebProcess(IPC::Connection::Identifier connectionIdentifier)
72     : m_connection(IPC::Connection::createServerConnection(connectionIdentifier, *this))
73 #if ENABLE(WEB_RTC)
74     , m_mdnsRegister(*this)
75 #endif
76 {
77     m_connection->open();
78 }
79
80 NetworkConnectionToWebProcess::~NetworkConnectionToWebProcess()
81 {
82     m_connection->invalidate();
83 #if USE(LIBWEBRTC)
84     if (m_rtcProvider)
85         m_rtcProvider->close();
86 #endif
87 }
88
89 void NetworkConnectionToWebProcess::didCleanupResourceLoader(NetworkResourceLoader& loader)
90 {
91     ASSERT(m_networkResourceLoaders.get(loader.identifier()) == &loader);
92
93     m_networkResourceLoaders.remove(loader.identifier());
94 }
95
96 void NetworkConnectionToWebProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
97 {
98     if (decoder.messageReceiverName() == Messages::NetworkConnectionToWebProcess::messageReceiverName()) {
99         didReceiveNetworkConnectionToWebProcessMessage(connection, decoder);
100         return;
101     }
102
103     if (decoder.messageReceiverName() == Messages::NetworkResourceLoader::messageReceiverName()) {
104         auto loaderIterator = m_networkResourceLoaders.find(decoder.destinationID());
105         if (loaderIterator != m_networkResourceLoaders.end())
106             loaderIterator->value->didReceiveNetworkResourceLoaderMessage(connection, decoder);
107         return;
108     }
109
110     if (decoder.messageReceiverName() == Messages::NetworkSocketStream::messageReceiverName()) {
111         auto socketIterator = m_networkSocketStreams.find(decoder.destinationID());
112         if (socketIterator != m_networkSocketStreams.end()) {
113             socketIterator->value->didReceiveMessage(connection, decoder);
114             if (decoder.messageName() == Messages::NetworkSocketStream::Close::name())
115                 m_networkSocketStreams.remove(socketIterator);
116         }
117         return;
118     }
119
120 #if USE(LIBWEBRTC)
121     if (decoder.messageReceiverName() == Messages::NetworkRTCSocket::messageReceiverName()) {
122         rtcProvider().didReceiveNetworkRTCSocketMessage(connection, decoder);
123         return;
124     }
125     if (decoder.messageReceiverName() == Messages::NetworkRTCMonitor::messageReceiverName()) {
126         rtcProvider().didReceiveNetworkRTCMonitorMessage(connection, decoder);
127         return;
128     }
129     if (decoder.messageReceiverName() == Messages::NetworkRTCProvider::messageReceiverName()) {
130         rtcProvider().didReceiveMessage(connection, decoder);
131         return;
132     }
133 #endif
134 #if ENABLE(WEB_RTC)
135     if (decoder.messageReceiverName() == Messages::NetworkMDNSRegister::messageReceiverName()) {
136         mdnsRegister().didReceiveMessage(connection, decoder);
137         return;
138     }
139 #endif
140
141     if (decoder.messageReceiverName() == Messages::CacheStorageEngineConnection::messageReceiverName()) {
142         cacheStorageConnection().didReceiveMessage(connection, decoder);
143         return;
144     }
145
146     ASSERT_NOT_REACHED();
147 }
148
149 #if USE(LIBWEBRTC)
150 NetworkRTCProvider& NetworkConnectionToWebProcess::rtcProvider()
151 {
152     if (!m_rtcProvider)
153         m_rtcProvider = NetworkRTCProvider::create(*this);
154     return *m_rtcProvider;
155 }
156 #endif
157
158 CacheStorageEngineConnection& NetworkConnectionToWebProcess::cacheStorageConnection()
159 {
160     if (!m_cacheStorageConnection)
161         m_cacheStorageConnection = CacheStorageEngineConnection::create(*this);
162     return *m_cacheStorageConnection;
163 }
164
165 void NetworkConnectionToWebProcess::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& reply)
166 {
167     if (decoder.messageReceiverName() == Messages::NetworkConnectionToWebProcess::messageReceiverName()) {
168         didReceiveSyncNetworkConnectionToWebProcessMessage(connection, decoder, reply);
169         return;
170     }
171     ASSERT_NOT_REACHED();
172 }
173
174 void NetworkConnectionToWebProcess::didClose(IPC::Connection&)
175 {
176     // Protect ourself as we might be otherwise be deleted during this function.
177     Ref<NetworkConnectionToWebProcess> protector(*this);
178
179     for (auto& loader : copyToVector(m_networkResourceLoaders.values()))
180         loader->abort();
181     ASSERT(m_networkResourceLoaders.isEmpty());
182
183     NetworkBlobRegistry::singleton().connectionToWebProcessDidClose(this);
184     NetworkProcess::singleton().removeNetworkConnectionToWebProcess(this);
185
186 #if USE(LIBWEBRTC)
187     if (m_rtcProvider) {
188         m_rtcProvider->close();
189         m_rtcProvider = nullptr;
190     }
191 #endif
192 }
193
194 void NetworkConnectionToWebProcess::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference)
195 {
196 }
197
198 void NetworkConnectionToWebProcess::createSocketStream(URL&& url, PAL::SessionID sessionID, String cachePartition, uint64_t identifier)
199 {
200     ASSERT(!m_networkSocketStreams.contains(identifier));
201     WebCore::SourceApplicationAuditToken token = { };
202 #if PLATFORM(COCOA)
203     token = { NetworkProcess::singleton().sourceApplicationAuditData() };
204 #endif
205     m_networkSocketStreams.set(identifier, NetworkSocketStream::create(WTFMove(url), sessionID, cachePartition, identifier, m_connection, WTFMove(token)));
206 }
207
208 void NetworkConnectionToWebProcess::destroySocketStream(uint64_t identifier)
209 {
210     ASSERT(m_networkSocketStreams.get(identifier));
211     m_networkSocketStreams.remove(identifier);
212 }
213
214 void NetworkConnectionToWebProcess::cleanupForSuspension(Function<void()>&& completionHandler)
215 {
216 #if USE(LIBWEBRTC)
217     if (m_rtcProvider) {
218         m_rtcProvider->closeListeningSockets(WTFMove(completionHandler));
219         return;
220     }
221 #endif
222     completionHandler();
223 }
224
225 void NetworkConnectionToWebProcess::endSuspension()
226 {
227 #if USE(LIBWEBRTC)
228     if (m_rtcProvider)
229         m_rtcProvider->authorizeListeningSockets();
230 #endif
231 }
232
233 void NetworkConnectionToWebProcess::scheduleResourceLoad(NetworkResourceLoadParameters&& loadParameters)
234 {
235     auto identifier = loadParameters.identifier;
236     ASSERT(!m_networkResourceLoaders.contains(identifier));
237
238     auto loader = NetworkResourceLoader::create(WTFMove(loadParameters), *this);
239     m_networkResourceLoaders.add(identifier, loader.ptr());
240     loader->start();
241 }
242
243 void NetworkConnectionToWebProcess::performSynchronousLoad(NetworkResourceLoadParameters&& loadParameters, Ref<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&& reply)
244 {
245     auto identifier = loadParameters.identifier;
246     ASSERT(!m_networkResourceLoaders.contains(identifier));
247
248     auto loader = NetworkResourceLoader::create(WTFMove(loadParameters), *this, WTFMove(reply));
249     m_networkResourceLoaders.add(identifier, loader.ptr());
250     loader->start();
251 }
252
253 void NetworkConnectionToWebProcess::loadPing(NetworkResourceLoadParameters&& loadParameters)
254 {
255     auto completionHandler = [this, protectedThis = makeRef(*this), identifier = loadParameters.identifier] (const ResourceError& error, const ResourceResponse& response) {
256         didFinishPingLoad(identifier, error, response);
257     };
258
259     // PingLoad manages its own lifetime, deleting itself when its purpose has been fulfilled.
260     new PingLoad(WTFMove(loadParameters), WTFMove(completionHandler));
261 }
262
263 void NetworkConnectionToWebProcess::didFinishPingLoad(uint64_t pingLoadIdentifier, const ResourceError& error, const ResourceResponse& response)
264 {
265     if (!m_connection->isValid())
266         return;
267
268     m_connection->send(Messages::NetworkProcessConnection::DidFinishPingLoad(pingLoadIdentifier, error, response), 0);
269 }
270
271 void NetworkConnectionToWebProcess::setOnLineState(bool isOnLine)
272 {
273     m_connection->send(Messages::NetworkProcessConnection::SetOnLineState(isOnLine), 0);
274 }
275
276 void NetworkConnectionToWebProcess::removeLoadIdentifier(ResourceLoadIdentifier identifier)
277 {
278     RefPtr<NetworkResourceLoader> loader = m_networkResourceLoaders.get(identifier);
279
280     // It's possible we have no loader for this identifier if the NetworkProcess crashed and this was a respawned NetworkProcess.
281     if (!loader)
282         return;
283
284     // Abort the load now, as the WebProcess won't be able to respond to messages any more which might lead
285     // to leaked loader resources (connections, threads, etc).
286     loader->abort();
287     ASSERT(!m_networkResourceLoaders.contains(identifier));
288 }
289
290 void NetworkConnectionToWebProcess::setDefersLoading(ResourceLoadIdentifier identifier, bool defers)
291 {
292     RefPtr<NetworkResourceLoader> loader = m_networkResourceLoaders.get(identifier);
293     if (!loader)
294         return;
295
296     loader->setDefersLoading(defers);
297 }
298
299 void NetworkConnectionToWebProcess::prefetchDNS(const String& hostname)
300 {
301     NetworkProcess::singleton().prefetchDNS(hostname);
302 }
303
304 void NetworkConnectionToWebProcess::preconnectTo(uint64_t preconnectionIdentifier, NetworkResourceLoadParameters&& parameters)
305 {
306 #if ENABLE(SERVER_PRECONNECT)
307     new PreconnectTask(WTFMove(parameters), [this, protectedThis = makeRef(*this), identifier = preconnectionIdentifier] (const ResourceError& error) {
308         didFinishPreconnection(identifier, error);
309     });
310 #else
311     UNUSED_PARAM(parameters);
312     didFinishPreconnection(preconnectionIdentifier, internalError(parameters.request.url()));
313 #endif
314 }
315
316 void NetworkConnectionToWebProcess::didFinishPreconnection(uint64_t preconnectionIdentifier, const ResourceError& error)
317 {
318     if (!m_connection->isValid())
319         return;
320
321     m_connection->send(Messages::NetworkProcessConnection::DidFinishPreconnection(preconnectionIdentifier, error), 0);
322 }
323
324 static NetworkStorageSession& storageSession(PAL::SessionID sessionID)
325 {
326     ASSERT(sessionID.isValid());
327     if (sessionID != PAL::SessionID::defaultSessionID()) {
328         if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
329             return *storageSession;
330
331         // Some requests with private browsing mode requested may still be coming shortly after NetworkProcess was told to destroy its session.
332         // FIXME: Find a way to track private browsing sessions more rigorously.
333         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.");
334     }
335     return NetworkStorageSession::defaultStorageSession();
336 }
337
338 void NetworkConnectionToWebProcess::startDownload(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedName)
339 {
340     NetworkProcess::singleton().downloadManager().startDownload(this, sessionID, downloadID, request, suggestedName);
341 }
342
343 void NetworkConnectionToWebProcess::convertMainResourceLoadToDownload(PAL::SessionID sessionID, uint64_t mainResourceLoadIdentifier, DownloadID downloadID, const ResourceRequest& request, const ResourceResponse& response)
344 {
345     auto& networkProcess = NetworkProcess::singleton();
346     // In case a response is served from service worker, we do not have yet the ability to convert the load.
347     if (!mainResourceLoadIdentifier || response.source() == ResourceResponse::Source::ServiceWorker) {
348         networkProcess.downloadManager().startDownload(this, sessionID, downloadID, request);
349         return;
350     }
351
352     NetworkResourceLoader* loader = m_networkResourceLoaders.get(mainResourceLoadIdentifier);
353     if (!loader) {
354         // If we're trying to download a blob here loader can be null.
355         return;
356     }
357
358     loader->convertToDownload(downloadID, request, response);
359 }
360
361 void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
362 {
363     auto& networkStorageSession = storageSession(sessionID);
364     std::tie(cookieString, secureCookiesAccessed) = WebCore::cookiesForDOM(networkStorageSession, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
365 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
366     if (NetworkProcess::singleton().shouldLogCookieInformation())
367         NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::cookiesForDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, std::nullopt);
368 #endif
369 }
370
371 void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
372 {
373     auto& networkStorageSession = storageSession(sessionID);
374     WebCore::setCookiesFromDOM(networkStorageSession, firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
375 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
376     if (NetworkProcess::singleton().shouldLogCookieInformation())
377         NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, std::nullopt);
378 #endif
379 }
380
381 void NetworkConnectionToWebProcess::cookiesEnabled(PAL::SessionID sessionID, bool& result)
382 {
383     result = WebCore::cookiesEnabled(storageSession(sessionID));
384 }
385
386 void NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
387 {
388     std::tie(cookieString, secureCookiesAccessed) = WebCore::cookieRequestHeaderFieldValue(storageSession(sessionID), firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
389 }
390
391 void NetworkConnectionToWebProcess::getRawCookies(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& result)
392 {
393     WebCore::getRawCookies(storageSession(sessionID), firstParty, sameSiteInfo, url, frameID, pageID, result);
394 }
395
396 void NetworkConnectionToWebProcess::deleteCookie(PAL::SessionID sessionID, const URL& url, const String& cookieName)
397 {
398     WebCore::deleteCookie(storageSession(sessionID), url, cookieName);
399 }
400
401 void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, SandboxExtension::Handle&& extensionHandle, const String& contentType)
402 {
403     RefPtr<SandboxExtension> extension = SandboxExtension::create(WTFMove(extensionHandle));
404
405     NetworkBlobRegistry::singleton().registerFileBlobURL(this, url, path, WTFMove(extension), contentType);
406 }
407
408 void NetworkConnectionToWebProcess::registerBlobURL(const URL& url, Vector<BlobPart>&& blobParts, const String& contentType)
409 {
410     NetworkBlobRegistry::singleton().registerBlobURL(this, url, WTFMove(blobParts), contentType);
411 }
412
413 void NetworkConnectionToWebProcess::registerBlobURLFromURL(const URL& url, const URL& srcURL, bool shouldBypassConnectionCheck)
414 {
415     NetworkBlobRegistry::singleton().registerBlobURL(this, url, srcURL, shouldBypassConnectionCheck);
416 }
417
418 void NetworkConnectionToWebProcess::preregisterSandboxExtensionsForOptionallyFileBackedBlob(const Vector<String>& filePaths, SandboxExtension::HandleArray&& handles)
419 {
420 #if ENABLE(SANDBOX_EXTENSIONS)
421     ASSERT(filePaths.size() == handles.size());
422
423     for (size_t i = 0; i < filePaths.size(); ++i)
424         m_blobDataFileReferences.add(filePaths[i], BlobDataFileReferenceWithSandboxExtension::create(filePaths[i], SandboxExtension::create(WTFMove(handles[i]))));
425 #else
426     for (size_t i = 0; i < filePaths.size(); ++i)
427         m_blobDataFileReferences.add(filePaths[i], BlobDataFileReferenceWithSandboxExtension::create(filePaths[i], nullptr));
428 #endif
429 }
430
431 RefPtr<WebCore::BlobDataFileReference> NetworkConnectionToWebProcess::getBlobDataFileReferenceForPath(const String& path)
432 {
433     ASSERT(m_blobDataFileReferences.contains(path));
434     return m_blobDataFileReferences.get(path);
435 }
436
437 void NetworkConnectionToWebProcess::registerBlobURLOptionallyFileBacked(const URL& url, const URL& srcURL, const String& fileBackedPath, const String& contentType)
438 {
439     NetworkBlobRegistry::singleton().registerBlobURLOptionallyFileBacked(this, url, srcURL, fileBackedPath, contentType);
440 }
441
442 void NetworkConnectionToWebProcess::registerBlobURLForSlice(const URL& url, const URL& srcURL, int64_t start, int64_t end)
443 {
444     NetworkBlobRegistry::singleton().registerBlobURLForSlice(this, url, srcURL, start, end);
445 }
446
447 void NetworkConnectionToWebProcess::unregisterBlobURL(const URL& url)
448 {
449     NetworkBlobRegistry::singleton().unregisterBlobURL(this, url);
450 }
451
452 void NetworkConnectionToWebProcess::blobSize(const URL& url, uint64_t& resultSize)
453 {
454     resultSize = NetworkBlobRegistry::singleton().blobSize(this, url);
455 }
456
457 void NetworkConnectionToWebProcess::writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier)
458 {
459     Vector<RefPtr<BlobDataFileReference>> fileReferences;
460     for (auto& url : blobURLs)
461         fileReferences.appendVector(NetworkBlobRegistry::singleton().filesInBlob(*this, { ParsedURLString, url }));
462
463     for (auto& file : fileReferences)
464         file->prepareForFileAccess();
465
466     NetworkBlobRegistry::singleton().writeBlobsToTemporaryFiles(blobURLs, [this, protectedThis = makeRef(*this), requestIdentifier, fileReferences = WTFMove(fileReferences)](auto& fileNames) mutable {
467         for (auto& file : fileReferences)
468             file->revokeFileAccess();
469
470         NetworkProcess::singleton().grantSandboxExtensionsToStorageProcessForBlobs(fileNames, [this, protectedThis = WTFMove(protectedThis), requestIdentifier, fileNames]() {
471             if (!m_connection->isValid())
472                 return;
473
474             m_connection->send(Messages::NetworkProcessConnection::DidWriteBlobsToTemporaryFiles(requestIdentifier, fileNames), 0);
475         });
476     });
477 }
478
479 void NetworkConnectionToWebProcess::storeDerivedDataToCache(const WebKit::NetworkCache::DataKey& dataKey, const IPC::DataReference& data)
480 {
481     if (auto* cache = NetworkProcess::singleton().cache())
482         cache->storeData(dataKey, data.data(), data.size());
483 }
484
485 void NetworkConnectionToWebProcess::setCaptureExtraNetworkLoadMetricsEnabled(bool enabled)
486 {
487     m_captureExtraNetworkLoadMetricsEnabled = enabled;
488     if (!m_captureExtraNetworkLoadMetricsEnabled)
489         m_networkLoadInformationByID.clear();
490 }
491
492 void NetworkConnectionToWebProcess::ensureLegacyPrivateBrowsingSession()
493 {
494     NetworkProcess::singleton().addWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters());
495 }
496
497 void NetworkConnectionToWebProcess::removeStorageAccessForFrame(PAL::SessionID sessionID, uint64_t frameID, uint64_t pageID)
498 {
499 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
500     if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
501         storageSession->removeStorageAccessForFrame(frameID, pageID);
502 #else
503     UNUSED_PARAM(sessionID);
504     UNUSED_PARAM(frameID);
505     UNUSED_PARAM(pageID);
506 #endif
507 }
508
509 void NetworkConnectionToWebProcess::removeStorageAccessForAllFramesOnPage(PAL::SessionID sessionID, uint64_t pageID)
510 {
511 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
512     if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
513         storageSession->removeStorageAccessForAllFramesOnPage(pageID);
514 #else
515     UNUSED_PARAM(sessionID);
516     UNUSED_PARAM(pageID);
517 #endif
518 }
519
520 void NetworkConnectionToWebProcess::addOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
521 {
522     SecurityPolicy::addOriginAccessWhitelistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains);
523 }
524
525 void NetworkConnectionToWebProcess::removeOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains)
526 {
527     SecurityPolicy::removeOriginAccessWhitelistEntry(SecurityOrigin::createFromString(sourceOrigin).get(), destinationProtocol, destinationHost, allowDestinationSubdomains);
528 }
529
530 void NetworkConnectionToWebProcess::resetOriginAccessWhitelists()
531 {
532     SecurityPolicy::resetOriginAccessWhitelists();
533 }
534
535 } // namespace WebKit