2 * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "NetworkProcess.h"
29 #include "ArgumentCoders.h"
30 #include "Attachment.h"
31 #include "AuthenticationManager.h"
32 #include "ChildProcessMessages.h"
33 #include "DataReference.h"
34 #include "DownloadProxyMessages.h"
35 #include "LegacyCustomProtocolManager.h"
37 #include "NetworkConnectionToWebProcess.h"
38 #include "NetworkProcessCreationParameters.h"
39 #include "NetworkProcessPlatformStrategies.h"
40 #include "NetworkProcessProxyMessages.h"
41 #include "NetworkResourceLoader.h"
42 #include "NetworkSession.h"
43 #include "RemoteNetworkingContext.h"
44 #include "SessionTracker.h"
45 #include "StatisticsData.h"
46 #include "WebCookieManager.h"
47 #include "WebCoreArgumentCoders.h"
48 #include "WebPageProxyMessages.h"
49 #include "WebProcessPoolMessages.h"
50 #include "WebsiteData.h"
51 #include "WebsiteDataFetchOption.h"
52 #include "WebsiteDataStoreParameters.h"
53 #include "WebsiteDataType.h"
54 #include <WebCore/DNS.h>
55 #include <WebCore/DiagnosticLoggingClient.h>
56 #include <WebCore/LogInitialization.h>
57 #include <WebCore/MIMETypeRegistry.h>
58 #include <WebCore/NetworkStorageSession.h>
59 #include <WebCore/PlatformCookieJar.h>
60 #include <WebCore/ResourceRequest.h>
61 #include <WebCore/RuntimeApplicationChecks.h>
62 #include <WebCore/SecurityOriginData.h>
63 #include <WebCore/SecurityOriginHash.h>
64 #include <WebCore/Settings.h>
65 #include <WebCore/URLParser.h>
66 #include <pal/SessionID.h>
67 #include <wtf/OptionSet.h>
68 #include <wtf/RunLoop.h>
69 #include <wtf/text/CString.h>
71 #if ENABLE(SEC_ITEM_SHIM)
72 #include "SecItemShim.h"
75 #if ENABLE(NETWORK_CACHE)
76 #include "NetworkCache.h"
77 #include "NetworkCacheCoders.h"
80 #if ENABLE(NETWORK_CAPTURE)
81 #include "NetworkCaptureManager.h"
85 #include "NetworkSessionCocoa.h"
88 using namespace WebCore;
92 NetworkProcess& NetworkProcess::singleton()
94 static NeverDestroyed<NetworkProcess> networkProcess;
95 return networkProcess;
98 NetworkProcess::NetworkProcess()
99 : m_hasSetCacheModel(false)
100 , m_cacheModel(CacheModelDocumentViewer)
101 , m_diskCacheIsDisabledForTesting(false)
102 , m_canHandleHTTPSServerTrustEvaluation(true)
104 , m_clearCacheDispatchGroup(0)
107 , m_webSQLiteDatabaseTracker(*this)
110 NetworkProcessPlatformStrategies::initialize();
112 addSupplement<AuthenticationManager>();
113 addSupplement<WebCookieManager>();
114 addSupplement<LegacyCustomProtocolManager>();
115 #if USE(NETWORK_SESSION) && PLATFORM(COCOA)
116 NetworkSessionCocoa::setLegacyCustomProtocolManager(supplement<LegacyCustomProtocolManager>());
120 NetworkProcess::~NetworkProcess()
124 AuthenticationManager& NetworkProcess::authenticationManager()
126 return *supplement<AuthenticationManager>();
129 DownloadManager& NetworkProcess::downloadManager()
131 static NeverDestroyed<DownloadManager> downloadManager(*this);
132 return downloadManager;
135 void NetworkProcess::removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess* connection)
137 size_t vectorIndex = m_webProcessConnections.find(connection);
138 ASSERT(vectorIndex != notFound);
140 m_webProcessConnections.remove(vectorIndex);
143 bool NetworkProcess::shouldTerminate()
145 // Network process keeps session cookies and credentials, so it should never terminate (as long as UI process connection is alive).
149 void NetworkProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
151 if (messageReceiverMap().dispatchMessage(connection, decoder))
154 if (decoder.messageReceiverName() == Messages::ChildProcess::messageReceiverName()) {
155 ChildProcess::didReceiveMessage(connection, decoder);
159 didReceiveNetworkProcessMessage(connection, decoder);
162 void NetworkProcess::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)
164 if (messageReceiverMap().dispatchSyncMessage(connection, decoder, replyEncoder))
167 didReceiveSyncNetworkProcessMessage(connection, decoder, replyEncoder);
170 void NetworkProcess::didClose(IPC::Connection&)
172 // The UIProcess just exited.
176 void NetworkProcess::didCreateDownload()
178 disableTermination();
181 void NetworkProcess::didDestroyDownload()
186 IPC::Connection* NetworkProcess::downloadProxyConnection()
188 return parentProcessConnection();
191 AuthenticationManager& NetworkProcess::downloadsAuthenticationManager()
193 return authenticationManager();
196 void NetworkProcess::lowMemoryHandler(Critical critical)
198 if (m_suppressMemoryPressureHandler)
201 WTF::releaseFastMallocFreeMemory();
204 void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&& parameters)
206 WebCore::setPresentingApplicationPID(parameters.presentingApplicationPID);
207 platformInitializeNetworkProcess(parameters);
209 WTF::Thread::setCurrentThreadIsUserInitiated();
211 m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
212 m_loadThrottleLatency = parameters.loadThrottleLatency;
213 if (!m_suppressMemoryPressureHandler) {
214 auto& memoryPressureHandler = MemoryPressureHandler::singleton();
216 if (parameters.memoryPressureMonitorHandle.fileDescriptor() != -1)
217 memoryPressureHandler.setMemoryPressureMonitorHandle(parameters.memoryPressureMonitorHandle.releaseFileDescriptor());
219 memoryPressureHandler.setLowMemoryHandler([this] (Critical critical, Synchronous) {
220 lowMemoryHandler(critical);
222 memoryPressureHandler.install();
225 #if ENABLE(NETWORK_CAPTURE)
226 NetworkCapture::Manager::singleton().initialize(
227 parameters.recordReplayMode,
228 parameters.recordReplayCacheLocation);
231 m_diskCacheIsDisabledForTesting = parameters.shouldUseTestingNetworkSession;
233 m_diskCacheSizeOverride = parameters.diskCacheSizeOverride;
234 setCacheModel(static_cast<uint32_t>(parameters.cacheModel));
236 setCanHandleHTTPSServerTrustEvaluation(parameters.canHandleHTTPSServerTrustEvaluation);
238 // FIXME: instead of handling this here, a message should be sent later (scales to multiple sessions)
239 if (parameters.privateBrowsingEnabled)
240 RemoteNetworkingContext::ensurePrivateBrowsingSession({PAL::SessionID::legacyPrivateSessionID(), { }, { }, { }, { }, { }});
242 if (parameters.shouldUseTestingNetworkSession)
243 NetworkStorageSession::switchToNewTestingSession();
245 for (auto& supplement : m_supplements.values())
246 supplement->initialize(parameters);
249 void NetworkProcess::initializeConnection(IPC::Connection* connection)
251 ChildProcess::initializeConnection(connection);
253 for (auto& supplement : m_supplements.values())
254 supplement->initializeConnection(connection);
257 void NetworkProcess::createNetworkConnectionToWebProcess()
259 #if USE(UNIX_DOMAIN_SOCKETS)
260 IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
262 auto connection = NetworkConnectionToWebProcess::create(socketPair.server);
263 m_webProcessConnections.append(WTFMove(connection));
265 IPC::Attachment clientSocket(socketPair.client);
266 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientSocket), 0);
268 // Create the listening port.
269 mach_port_t listeningPort;
270 mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
272 // Create a listening connection.
273 auto connection = NetworkConnectionToWebProcess::create(IPC::Connection::Identifier(listeningPort));
274 m_webProcessConnections.append(WTFMove(connection));
276 IPC::Attachment clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
277 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientPort), 0);
283 void NetworkProcess::clearCachedCredentials()
285 NetworkStorageSession::defaultStorageSession().credentialStorage().clearCredentials();
286 #if USE(NETWORK_SESSION)
287 NetworkSession::defaultSession().clearCredentials();
291 void NetworkProcess::ensurePrivateBrowsingSession(WebsiteDataStoreParameters&& parameters)
293 RemoteNetworkingContext::ensurePrivateBrowsingSession(WTFMove(parameters));
296 void NetworkProcess::addWebsiteDataStore(WebsiteDataStoreParameters&& parameters)
298 RemoteNetworkingContext::ensureWebsiteDataStoreSession(WTFMove(parameters));
301 void NetworkProcess::destroySession(PAL::SessionID sessionID)
303 SessionTracker::destroySession(sessionID);
306 void NetworkProcess::grantSandboxExtensionsToStorageProcessForBlobs(const Vector<String>& filenames, Function<void ()>&& completionHandler)
308 static uint64_t lastRequestID;
310 uint64_t requestID = ++lastRequestID;
311 m_sandboxExtensionForBlobsCompletionHandlers.set(requestID, WTFMove(completionHandler));
312 parentProcessConnection()->send(Messages::NetworkProcessProxy::GrantSandboxExtensionsToStorageProcessForBlobs(requestID, filenames), 0);
315 void NetworkProcess::didGrantSandboxExtensionsToStorageProcessForBlobs(uint64_t requestID)
317 if (auto handler = m_sandboxExtensionForBlobsCompletionHandlers.take(requestID))
321 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
322 void NetworkProcess::updateCookiePartitioningForTopPrivatelyOwnedDomains(PAL::SessionID sessionID, const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool shouldClearFirst)
324 if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
325 networkStorageSession->setShouldPartitionCookiesForHosts(domainsToRemove, domainsToAdd, shouldClearFirst);
329 static void fetchDiskCacheEntries(PAL::SessionID sessionID, OptionSet<WebsiteDataFetchOption> fetchOptions, Function<void (Vector<WebsiteData::Entry>)>&& completionHandler)
331 #if ENABLE(NETWORK_CACHE)
332 if (auto* cache = NetworkProcess::singleton().cache()) {
333 HashMap<SecurityOriginData, uint64_t> originsAndSizes;
334 cache->traverse([fetchOptions, completionHandler = WTFMove(completionHandler), originsAndSizes = WTFMove(originsAndSizes)](auto* traversalEntry) mutable {
335 if (!traversalEntry) {
336 Vector<WebsiteData::Entry> entries;
338 for (auto& originAndSize : originsAndSizes)
339 entries.append(WebsiteData::Entry { originAndSize.key, WebsiteDataType::DiskCache, originAndSize.value });
341 RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), entries = WTFMove(entries)] {
342 completionHandler(entries);
348 auto url = traversalEntry->entry.response().url();
349 auto result = originsAndSizes.add({url.protocol().toString(), url.host(), url.port()}, 0);
351 if (fetchOptions.contains(WebsiteDataFetchOption::ComputeSizes))
352 result.iterator->value += traversalEntry->entry.sourceStorageRecord().header.size() + traversalEntry->recordInfo.bodySize;
359 RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)] {
360 completionHandler({ });
364 void NetworkProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, OptionSet<WebsiteDataFetchOption> fetchOptions, uint64_t callbackID)
366 struct CallbackAggregator final : public RefCounted<CallbackAggregator> {
367 explicit CallbackAggregator(Function<void (WebsiteData)>&& completionHandler)
368 : m_completionHandler(WTFMove(completionHandler))
372 ~CallbackAggregator()
374 ASSERT(RunLoop::isMain());
376 RunLoop::main().dispatch([completionHandler = WTFMove(m_completionHandler), websiteData = WTFMove(m_websiteData)] {
377 completionHandler(websiteData);
381 Function<void (WebsiteData)> m_completionHandler;
382 WebsiteData m_websiteData;
385 auto callbackAggregator = adoptRef(*new CallbackAggregator([this, callbackID] (WebsiteData websiteData) {
386 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidFetchWebsiteData(callbackID, websiteData), 0);
389 if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
390 if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
391 getHostnamesWithCookies(*networkStorageSession, callbackAggregator->m_websiteData.hostNamesWithCookies);
394 if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
395 if (NetworkStorageSession::storageSession(sessionID))
396 callbackAggregator->m_websiteData.originsWithCredentials = NetworkStorageSession::storageSession(sessionID)->credentialStorage().originsWithCredentials();
399 if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
400 fetchDiskCacheEntries(sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
401 callbackAggregator->m_websiteData.entries.appendVector(entries);
406 void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
409 if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
410 if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
411 clearHSTSCache(*networkStorageSession, modifiedSince);
415 if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
416 if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
417 deleteAllCookiesModifiedSince(*networkStorageSession, modifiedSince);
420 if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
421 if (NetworkStorageSession::storageSession(sessionID))
422 NetworkStorageSession::storageSession(sessionID)->credentialStorage().clearCredentials();
425 auto completionHandler = [this, callbackID] {
426 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidDeleteWebsiteData(callbackID), 0);
429 if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
430 clearDiskCache(modifiedSince, WTFMove(completionHandler));
437 static void clearDiskCacheEntries(const Vector<SecurityOriginData>& origins, Function<void ()>&& completionHandler)
439 #if ENABLE(NETWORK_CACHE)
440 if (auto* cache = NetworkProcess::singleton().cache()) {
441 HashSet<RefPtr<SecurityOrigin>> originsToDelete;
442 for (auto& origin : origins)
443 originsToDelete.add(origin.securityOrigin());
445 Vector<NetworkCache::Key> cacheKeysToDelete;
446 cache->traverse([cache, completionHandler = WTFMove(completionHandler), originsToDelete = WTFMove(originsToDelete), cacheKeysToDelete = WTFMove(cacheKeysToDelete)](auto* traversalEntry) mutable {
447 if (traversalEntry) {
448 if (originsToDelete.contains(SecurityOrigin::create(traversalEntry->entry.response().url())))
449 cacheKeysToDelete.append(traversalEntry->entry.key());
453 cache->remove(cacheKeysToDelete, WTFMove(completionHandler));
461 RunLoop::main().dispatch(WTFMove(completionHandler));
464 void NetworkProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, const Vector<SecurityOriginData>& origins, const Vector<String>& cookieHostNames, uint64_t callbackID)
466 if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
467 if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
468 deleteCookiesForHostnames(*networkStorageSession, cookieHostNames);
471 auto completionHandler = [this, callbackID] {
472 parentProcessConnection()->send(Messages::NetworkProcessProxy::DidDeleteWebsiteDataForOrigins(callbackID), 0);
475 if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
476 clearDiskCacheEntries(origins, WTFMove(completionHandler));
483 void NetworkProcess::downloadRequest(PAL::SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedFilename)
485 downloadManager().startDownload(nullptr, sessionID, downloadID, request, suggestedFilename);
488 void NetworkProcess::resumeDownload(PAL::SessionID sessionID, DownloadID downloadID, const IPC::DataReference& resumeData, const String& path, const WebKit::SandboxExtension::Handle& sandboxExtensionHandle)
490 downloadManager().resumeDownload(sessionID, downloadID, resumeData, path, sandboxExtensionHandle);
493 void NetworkProcess::cancelDownload(DownloadID downloadID)
495 downloadManager().cancelDownload(downloadID);
498 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
499 void NetworkProcess::canAuthenticateAgainstProtectionSpace(NetworkResourceLoader& loader, const WebCore::ProtectionSpace& protectionSpace)
501 static uint64_t lastLoaderID = 0;
502 uint64_t loaderID = ++lastLoaderID;
503 m_waitingNetworkResourceLoaders.set(lastLoaderID, loader);
504 parentProcessConnection()->send(Messages::NetworkProcessProxy::CanAuthenticateAgainstProtectionSpace(loaderID, loader.pageID(), loader.frameID(), protectionSpace), 0);
507 void NetworkProcess::continueCanAuthenticateAgainstProtectionSpace(uint64_t loaderID, bool canAuthenticate)
509 m_waitingNetworkResourceLoaders.take(loaderID).value()->continueCanAuthenticateAgainstProtectionSpace(canAuthenticate);
513 #if USE(NETWORK_SESSION)
514 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
515 void NetworkProcess::continueCanAuthenticateAgainstProtectionSpaceDownload(DownloadID downloadID, bool canAuthenticate)
517 downloadManager().continueCanAuthenticateAgainstProtectionSpace(downloadID, canAuthenticate);
521 void NetworkProcess::continueWillSendRequest(DownloadID downloadID, WebCore::ResourceRequest&& request)
523 downloadManager().continueWillSendRequest(downloadID, WTFMove(request));
526 void NetworkProcess::pendingDownloadCanceled(DownloadID downloadID)
528 downloadProxyConnection()->send(Messages::DownloadProxy::DidCancel({ }), downloadID.downloadID());
531 void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTask, ResponseCompletionHandler&& completionHandler, const ResourceResponse& response)
533 uint64_t destinationID = networkDataTask.pendingDownloadID().downloadID();
534 downloadProxyConnection()->send(Messages::DownloadProxy::DidReceiveResponse(response), destinationID);
536 downloadManager().willDecidePendingDownloadDestination(networkDataTask, WTFMove(completionHandler));
538 // As per https://html.spec.whatwg.org/#as-a-download (step 2), the filename from the Content-Disposition header
539 // should override the suggested filename from the download attribute.
540 String suggestedFilename = response.isAttachmentWithFilename() ? response.suggestedFilename() : networkDataTask.suggestedFilename();
541 suggestedFilename = MIMETypeRegistry::appendFileExtensionIfNecessary(suggestedFilename, response.mimeType());
543 downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), suggestedFilename), destinationID);
547 void NetworkProcess::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite)
549 if (destination.isEmpty())
550 downloadManager().cancelDownload(downloadID);
552 downloadManager().continueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle, allowOverwrite);
555 void NetworkProcess::setCacheModel(uint32_t cm)
557 CacheModel cacheModel = static_cast<CacheModel>(cm);
559 if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
562 m_hasSetCacheModel = true;
563 m_cacheModel = cacheModel;
565 unsigned urlCacheMemoryCapacity = 0;
566 uint64_t urlCacheDiskCapacity = 0;
567 uint64_t diskFreeSize = 0;
568 if (WebCore::getVolumeFreeSpace(m_diskCacheDirectory, diskFreeSize)) {
569 // As a fudge factor, use 1000 instead of 1024, in case the reported byte
570 // count doesn't align exactly to a megabyte boundary.
571 diskFreeSize /= KB * 1000;
572 calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
575 if (m_diskCacheSizeOverride >= 0)
576 urlCacheDiskCapacity = m_diskCacheSizeOverride;
578 #if ENABLE(NETWORK_CACHE)
580 m_cache->setCapacity(urlCacheDiskCapacity);
585 platformSetURLCacheSize(urlCacheMemoryCapacity, urlCacheDiskCapacity);
588 void NetworkProcess::setCanHandleHTTPSServerTrustEvaluation(bool value)
590 m_canHandleHTTPSServerTrustEvaluation = value;
593 void NetworkProcess::getNetworkProcessStatistics(uint64_t callbackID)
597 auto& networkProcess = NetworkProcess::singleton();
598 data.statisticsNumbers.set("DownloadsActiveCount", networkProcess.downloadManager().activeDownloadCount());
599 data.statisticsNumbers.set("OutstandingAuthenticationChallengesCount", networkProcess.authenticationManager().outstandingAuthenticationChallengeCount());
601 parentProcessConnection()->send(Messages::WebProcessPool::DidGetStatistics(data, callbackID), 0);
604 void NetworkProcess::setAllowsAnySSLCertificateForWebSocket(bool allows)
606 Settings::setAllowsAnySSLCertificate(allows);
609 void NetworkProcess::logDiagnosticMessage(uint64_t webPageID, const String& message, const String& description, ShouldSample shouldSample)
611 if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample))
614 parentProcessConnection()->send(Messages::NetworkProcessProxy::LogDiagnosticMessage(webPageID, message, description, ShouldSample::No), 0);
617 void NetworkProcess::logDiagnosticMessageWithResult(uint64_t webPageID, const String& message, const String& description, DiagnosticLoggingResultType result, ShouldSample shouldSample)
619 if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample))
622 parentProcessConnection()->send(Messages::NetworkProcessProxy::LogDiagnosticMessageWithResult(webPageID, message, description, result, ShouldSample::No), 0);
625 void NetworkProcess::logDiagnosticMessageWithValue(uint64_t webPageID, const String& message, const String& description, double value, unsigned significantFigures, ShouldSample shouldSample)
627 if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample))
630 parentProcessConnection()->send(Messages::NetworkProcessProxy::LogDiagnosticMessageWithValue(webPageID, message, description, value, significantFigures, ShouldSample::No), 0);
633 void NetworkProcess::terminate()
635 #if ENABLE(NETWORK_CAPTURE)
636 NetworkCapture::Manager::singleton().terminate();
640 ChildProcess::terminate();
643 // FIXME: We can remove this one by adapting RefCounter.
644 class TaskCounter : public RefCounted<TaskCounter> {
646 explicit TaskCounter(Function<void()>&& callback) : m_callback(WTFMove(callback)) { }
647 ~TaskCounter() { m_callback(); };
650 Function<void()> m_callback;
653 void NetworkProcess::actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend shouldAcknowledgeWhenReadyToSuspend)
655 lowMemoryHandler(Critical::Yes);
657 RefPtr<TaskCounter> delayedTaskCounter;
658 if (shouldAcknowledgeWhenReadyToSuspend == ShouldAcknowledgeWhenReadyToSuspend::Yes) {
659 delayedTaskCounter = adoptRef(new TaskCounter([this] {
660 RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::notifyProcessReadyToSuspend() Sending ProcessReadyToSuspend IPC message", this);
661 if (parentProcessConnection())
662 parentProcessConnection()->send(Messages::NetworkProcessProxy::ProcessReadyToSuspend(), 0);
666 for (auto& connection : m_webProcessConnections)
667 connection->cleanupForSuspension([delayedTaskCounter] { });
670 void NetworkProcess::processWillSuspendImminently(bool& handled)
672 actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend::No);
676 void NetworkProcess::prepareToSuspend()
678 RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::prepareToSuspend()", this);
679 actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend::Yes);
682 void NetworkProcess::cancelPrepareToSuspend()
684 // Although it is tempting to send a NetworkProcessProxy::DidCancelProcessSuspension message from here
685 // we do not because prepareToSuspend() already replied with a NetworkProcessProxy::ProcessReadyToSuspend
686 // message. And NetworkProcessProxy expects to receive either a NetworkProcessProxy::ProcessReadyToSuspend-
687 // or NetworkProcessProxy::DidCancelProcessSuspension- message, but not both.
688 RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::cancelPrepareToSuspend()", this);
689 for (auto& connection : m_webProcessConnections)
690 connection->endSuspension();
693 void NetworkProcess::processDidResume()
695 RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::processDidResume()", this);
696 for (auto& connection : m_webProcessConnections)
697 connection->endSuspension();
700 void NetworkProcess::prefetchDNS(const String& hostname)
702 WebCore::prefetchDNS(hostname);
705 String NetworkProcess::cacheStorageDirectory(PAL::SessionID sessionID) const
707 if (sessionID.isEphemeral())
710 if (sessionID == PAL::SessionID::defaultSessionID())
711 return m_cacheStorageDirectory;
713 auto* session = NetworkStorageSession::storageSession(sessionID);
717 return session->cacheStorageDirectory();
721 void NetworkProcess::initializeProcess(const ChildProcessInitializationParameters&)
725 void NetworkProcess::initializeProcessName(const ChildProcessInitializationParameters&)
729 void NetworkProcess::initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&)
733 void NetworkProcess::syncAllCookies()
739 } // namespace WebKit