Crash child processes if they receive an invalid message
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / NetworkProcess.cpp
1 /*
2  * Copyright (C) 2012-2015 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 "NetworkProcess.h"
28
29 #include "ArgumentCoders.h"
30 #include "Attachment.h"
31 #include "AuthenticationManager.h"
32 #include "ChildProcessMessages.h"
33 #include "CustomProtocolManager.h"
34 #include "DataReference.h"
35 #include "DownloadProxyMessages.h"
36 #include "Logging.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 "WebsiteDataType.h"
53 #include <WebCore/DNS.h>
54 #include <WebCore/DiagnosticLoggingClient.h>
55 #include <WebCore/LogInitialization.h>
56 #include <WebCore/NetworkStorageSession.h>
57 #include <WebCore/PlatformCookieJar.h>
58 #include <WebCore/ResourceRequest.h>
59 #include <WebCore/RuntimeApplicationChecks.h>
60 #include <WebCore/SecurityOriginData.h>
61 #include <WebCore/SecurityOriginHash.h>
62 #include <WebCore/SessionID.h>
63 #include <WebCore/URLParser.h>
64 #include <wtf/OptionSet.h>
65 #include <wtf/RunLoop.h>
66 #include <wtf/text/CString.h>
67
68 #if ENABLE(SEC_ITEM_SHIM)
69 #include "SecItemShim.h"
70 #endif
71
72 #if ENABLE(NETWORK_CACHE)
73 #include "NetworkCache.h"
74 #include "NetworkCacheCoders.h"
75 #endif
76
77 #if ENABLE(NETWORK_CAPTURE)
78 #include "NetworkCaptureManager.h"
79 #endif
80
81 #if PLATFORM(COCOA)
82 #include "NetworkSessionCocoa.h"
83 #endif
84
85 using namespace WebCore;
86
87 namespace WebKit {
88
89 NetworkProcess& NetworkProcess::singleton()
90 {
91     static NeverDestroyed<NetworkProcess> networkProcess;
92     return networkProcess;
93 }
94
95 NetworkProcess::NetworkProcess()
96     : m_hasSetCacheModel(false)
97     , m_cacheModel(CacheModelDocumentViewer)
98     , m_diskCacheIsDisabledForTesting(false)
99     , m_canHandleHTTPSServerTrustEvaluation(true)
100 #if PLATFORM(COCOA)
101     , m_clearCacheDispatchGroup(0)
102 #endif
103 #if PLATFORM(IOS)
104     , m_webSQLiteDatabaseTracker(*this)
105 #endif
106 {
107     NetworkProcessPlatformStrategies::initialize();
108
109     addSupplement<AuthenticationManager>();
110     addSupplement<WebCookieManager>();
111     addSupplement<CustomProtocolManager>();
112 #if USE(NETWORK_SESSION) && PLATFORM(COCOA)
113     NetworkSessionCocoa::setCustomProtocolManager(supplement<CustomProtocolManager>());
114 #endif
115 }
116
117 NetworkProcess::~NetworkProcess()
118 {
119 }
120
121 AuthenticationManager& NetworkProcess::authenticationManager()
122 {
123     return *supplement<AuthenticationManager>();
124 }
125
126 DownloadManager& NetworkProcess::downloadManager()
127 {
128     static NeverDestroyed<DownloadManager> downloadManager(*this);
129     return downloadManager;
130 }
131
132 void NetworkProcess::removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess* connection)
133 {
134     size_t vectorIndex = m_webProcessConnections.find(connection);
135     ASSERT(vectorIndex != notFound);
136
137     m_webProcessConnections.remove(vectorIndex);
138 }
139
140 bool NetworkProcess::shouldTerminate()
141 {
142     // Network process keeps session cookies and credentials, so it should never terminate (as long as UI process connection is alive).
143     return false;
144 }
145
146 void NetworkProcess::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder)
147 {
148     if (messageReceiverMap().dispatchMessage(connection, decoder))
149         return;
150
151     if (decoder.messageReceiverName() == Messages::ChildProcess::messageReceiverName()) {
152         ChildProcess::didReceiveMessage(connection, decoder);
153         return;
154     }
155
156     didReceiveNetworkProcessMessage(connection, decoder);
157 }
158
159 void NetworkProcess::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)
160 {
161     if (messageReceiverMap().dispatchSyncMessage(connection, decoder, replyEncoder))
162         return;
163
164     didReceiveSyncNetworkProcessMessage(connection, decoder, replyEncoder);
165 }
166
167 void NetworkProcess::didClose(IPC::Connection&)
168 {
169     // The UIProcess just exited.
170     stopRunLoop();
171 }
172
173 void NetworkProcess::didCreateDownload()
174 {
175     disableTermination();
176 }
177
178 void NetworkProcess::didDestroyDownload()
179 {
180     enableTermination();
181 }
182
183 IPC::Connection* NetworkProcess::downloadProxyConnection()
184 {
185     return parentProcessConnection();
186 }
187
188 AuthenticationManager& NetworkProcess::downloadsAuthenticationManager()
189 {
190     return authenticationManager();
191 }
192
193 void NetworkProcess::lowMemoryHandler(Critical critical)
194 {
195     if (m_suppressMemoryPressureHandler)
196         return;
197
198     platformLowMemoryHandler(critical);
199     WTF::releaseFastMallocFreeMemory();
200 }
201
202 void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&& parameters)
203 {
204     URLParser::setEnabled(parameters.urlParserEnabled);
205
206     platformInitializeNetworkProcess(parameters);
207
208     WTF::setCurrentThreadIsUserInitiated();
209
210     m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
211     m_loadThrottleLatency = parameters.loadThrottleLatency;
212     if (!m_suppressMemoryPressureHandler) {
213         auto& memoryPressureHandler = MemoryPressureHandler::singleton();
214 #if OS(LINUX)
215         if (parameters.memoryPressureMonitorHandle.fileDescriptor() != -1)
216             memoryPressureHandler.setMemoryPressureMonitorHandle(parameters.memoryPressureMonitorHandle.releaseFileDescriptor());
217 #endif
218         memoryPressureHandler.setLowMemoryHandler([this] (Critical critical, Synchronous) {
219             lowMemoryHandler(critical);
220         });
221         memoryPressureHandler.install();
222     }
223
224 #if ENABLE(NETWORK_CAPTURE)
225     NetworkCapture::Manager::singleton().initialize(
226         parameters.recordReplayMode,
227         parameters.recordReplayCacheLocation);
228 #endif
229
230     m_diskCacheIsDisabledForTesting = parameters.shouldUseTestingNetworkSession;
231
232     m_diskCacheSizeOverride = parameters.diskCacheSizeOverride;
233     setCacheModel(static_cast<uint32_t>(parameters.cacheModel));
234
235     setCanHandleHTTPSServerTrustEvaluation(parameters.canHandleHTTPSServerTrustEvaluation);
236
237     // FIXME: instead of handling this here, a message should be sent later (scales to multiple sessions)
238     if (parameters.privateBrowsingEnabled)
239         RemoteNetworkingContext::ensurePrivateBrowsingSession(SessionID::legacyPrivateSessionID());
240
241     if (parameters.shouldUseTestingNetworkSession)
242         NetworkStorageSession::switchToNewTestingSession();
243
244     for (auto& supplement : m_supplements.values())
245         supplement->initialize(parameters);
246 }
247
248 void NetworkProcess::initializeConnection(IPC::Connection* connection)
249 {
250     ChildProcess::initializeConnection(connection);
251
252     for (auto& supplement : m_supplements.values())
253         supplement->initializeConnection(connection);
254 }
255
256 void NetworkProcess::createNetworkConnectionToWebProcess()
257 {
258 #if USE(UNIX_DOMAIN_SOCKETS)
259     IPC::Connection::SocketPair socketPair = IPC::Connection::createPlatformConnection();
260
261     auto connection = NetworkConnectionToWebProcess::create(socketPair.server);
262     m_webProcessConnections.append(WTFMove(connection));
263
264     IPC::Attachment clientSocket(socketPair.client);
265     parentProcessConnection()->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientSocket), 0);
266 #elif OS(DARWIN)
267     // Create the listening port.
268     mach_port_t listeningPort;
269     mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
270
271     // Create a listening connection.
272     auto connection = NetworkConnectionToWebProcess::create(IPC::Connection::Identifier(listeningPort));
273     m_webProcessConnections.append(WTFMove(connection));
274
275     IPC::Attachment clientPort(listeningPort, MACH_MSG_TYPE_MAKE_SEND);
276     parentProcessConnection()->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientPort), 0);
277 #else
278     notImplemented();
279 #endif
280 }
281
282 void NetworkProcess::clearCachedCredentials()
283 {
284     NetworkStorageSession::defaultStorageSession().credentialStorage().clearCredentials();
285 #if USE(NETWORK_SESSION)
286     NetworkSession::defaultSession().clearCredentials();
287 #endif
288 }
289
290 void NetworkProcess::ensurePrivateBrowsingSession(SessionID sessionID)
291 {
292     RemoteNetworkingContext::ensurePrivateBrowsingSession(sessionID);
293 }
294
295 void NetworkProcess::destroyPrivateBrowsingSession(SessionID sessionID)
296 {
297     SessionTracker::destroySession(sessionID);
298 }
299
300 void NetworkProcess::grantSandboxExtensionsToDatabaseProcessForBlobs(const Vector<String>& filenames, Function<void ()>&& completionHandler)
301 {
302     static uint64_t lastRequestID;
303
304     uint64_t requestID = ++lastRequestID;
305     m_sandboxExtensionForBlobsCompletionHandlers.set(requestID, WTFMove(completionHandler));
306     parentProcessConnection()->send(Messages::NetworkProcessProxy::GrantSandboxExtensionsToDatabaseProcessForBlobs(requestID, filenames), 0);
307 }
308
309 void NetworkProcess::didGrantSandboxExtensionsToDatabaseProcessForBlobs(uint64_t requestID)
310 {
311     if (auto handler = m_sandboxExtensionForBlobsCompletionHandlers.take(requestID))
312         handler();
313 }
314
315 static void fetchDiskCacheEntries(SessionID sessionID, OptionSet<WebsiteDataFetchOption> fetchOptions, Function<void (Vector<WebsiteData::Entry>)>&& completionHandler)
316 {
317 #if ENABLE(NETWORK_CACHE)
318     if (NetworkCache::singleton().isEnabled()) {
319         HashMap<SecurityOriginData, uint64_t> originsAndSizes;
320         NetworkCache::singleton().traverse([fetchOptions, completionHandler = WTFMove(completionHandler), originsAndSizes = WTFMove(originsAndSizes)](auto* traversalEntry) mutable {
321             if (!traversalEntry) {
322                 Vector<WebsiteData::Entry> entries;
323
324                 for (auto& originAndSize : originsAndSizes)
325                     entries.append(WebsiteData::Entry { originAndSize.key, WebsiteDataType::DiskCache, originAndSize.value });
326
327                 RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), entries = WTFMove(entries)] {
328                     completionHandler(entries);
329                 });
330
331                 return;
332             }
333
334             auto url = traversalEntry->entry.response().url();
335             auto result = originsAndSizes.add({url.protocol().toString(), url.host(), url.port()}, 0);
336
337             if (fetchOptions.contains(WebsiteDataFetchOption::ComputeSizes))
338                 result.iterator->value += traversalEntry->entry.sourceStorageRecord().header.size() + traversalEntry->recordInfo.bodySize;
339         });
340
341         return;
342     }
343 #endif
344
345     RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler)] {
346         completionHandler({ });
347     });
348 }
349
350 void NetworkProcess::fetchWebsiteData(SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, OptionSet<WebsiteDataFetchOption> fetchOptions, uint64_t callbackID)
351 {
352     struct CallbackAggregator final : public RefCounted<CallbackAggregator> {
353         explicit CallbackAggregator(Function<void (WebsiteData)>&& completionHandler)
354             : m_completionHandler(WTFMove(completionHandler))
355         {
356         }
357
358         ~CallbackAggregator()
359         {
360             ASSERT(RunLoop::isMain());
361
362             RunLoop::main().dispatch([completionHandler = WTFMove(m_completionHandler), websiteData = WTFMove(m_websiteData)] {
363                 completionHandler(websiteData);
364             });
365         }
366
367         Function<void (WebsiteData)> m_completionHandler;
368         WebsiteData m_websiteData;
369     };
370
371     auto callbackAggregator = adoptRef(*new CallbackAggregator([this, callbackID] (WebsiteData websiteData) {
372         parentProcessConnection()->send(Messages::NetworkProcessProxy::DidFetchWebsiteData(callbackID, websiteData), 0);
373     }));
374
375     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
376         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
377             getHostnamesWithCookies(*networkStorageSession, callbackAggregator->m_websiteData.hostNamesWithCookies);
378     }
379
380     if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
381         fetchDiskCacheEntries(sessionID, fetchOptions, [callbackAggregator = WTFMove(callbackAggregator)](auto entries) mutable {
382             callbackAggregator->m_websiteData.entries.appendVector(entries);
383         });
384     }
385 }
386
387 void NetworkProcess::deleteWebsiteData(SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
388 {
389 #if PLATFORM(COCOA)
390     if (websiteDataTypes.contains(WebsiteDataType::HSTSCache)) {
391         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
392             clearHSTSCache(*networkStorageSession, modifiedSince);
393     }
394 #endif
395
396     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
397         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
398             deleteAllCookiesModifiedSince(*networkStorageSession, modifiedSince);
399     }
400
401     auto completionHandler = [this, callbackID] {
402         parentProcessConnection()->send(Messages::NetworkProcessProxy::DidDeleteWebsiteData(callbackID), 0);
403     };
404
405     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
406         clearDiskCache(modifiedSince, WTFMove(completionHandler));
407         return;
408     }
409
410     completionHandler();
411 }
412
413 static void clearDiskCacheEntries(const Vector<SecurityOriginData>& origins, Function<void ()>&& completionHandler)
414 {
415 #if ENABLE(NETWORK_CACHE)
416     if (NetworkCache::singleton().isEnabled()) {
417         HashSet<RefPtr<SecurityOrigin>> originsToDelete;
418         for (auto& origin : origins)
419             originsToDelete.add(origin.securityOrigin());
420
421         Vector<NetworkCache::Key> cacheKeysToDelete;
422         NetworkCache::singleton().traverse([completionHandler = WTFMove(completionHandler), originsToDelete = WTFMove(originsToDelete), cacheKeysToDelete = WTFMove(cacheKeysToDelete)](auto* traversalEntry) mutable {
423             if (traversalEntry) {
424                 if (originsToDelete.contains(SecurityOrigin::create(traversalEntry->entry.response().url())))
425                     cacheKeysToDelete.append(traversalEntry->entry.key());
426                 return;
427             }
428
429             for (auto& key : cacheKeysToDelete)
430                 NetworkCache::singleton().remove(key);
431
432             RunLoop::main().dispatch(WTFMove(completionHandler));
433             return;
434         });
435
436         return;
437     }
438 #endif
439
440     RunLoop::main().dispatch(WTFMove(completionHandler));
441 }
442
443 void NetworkProcess::deleteWebsiteDataForOrigins(SessionID sessionID, OptionSet<WebsiteDataType> websiteDataTypes, const Vector<SecurityOriginData>& origins, const Vector<String>& cookieHostNames, uint64_t callbackID)
444 {
445     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
446         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
447             deleteCookiesForHostnames(*networkStorageSession, cookieHostNames);
448     }
449
450     auto completionHandler = [this, callbackID] {
451         parentProcessConnection()->send(Messages::NetworkProcessProxy::DidDeleteWebsiteDataForOrigins(callbackID), 0);
452     };
453
454     if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
455         clearDiskCacheEntries(origins, WTFMove(completionHandler));
456         return;
457     }
458
459     completionHandler();
460 }
461
462 void NetworkProcess::downloadRequest(SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedFilename)
463 {
464     downloadManager().startDownload(nullptr, sessionID, downloadID, request, suggestedFilename);
465 }
466
467 void NetworkProcess::resumeDownload(SessionID sessionID, DownloadID downloadID, const IPC::DataReference& resumeData, const String& path, const WebKit::SandboxExtension::Handle& sandboxExtensionHandle)
468 {
469     downloadManager().resumeDownload(sessionID, downloadID, resumeData, path, sandboxExtensionHandle);
470 }
471
472 void NetworkProcess::cancelDownload(DownloadID downloadID)
473 {
474     downloadManager().cancelDownload(downloadID);
475 }
476     
477 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
478 void NetworkProcess::canAuthenticateAgainstProtectionSpace(NetworkResourceLoader& loader, const WebCore::ProtectionSpace& protectionSpace)
479 {
480     static uint64_t lastLoaderID = 0;
481     uint64_t loaderID = ++lastLoaderID;
482     m_waitingNetworkResourceLoaders.set(lastLoaderID, loader);
483     parentProcessConnection()->send(Messages::NetworkProcessProxy::CanAuthenticateAgainstProtectionSpace(loaderID, loader.pageID(), loader.frameID(), protectionSpace), 0);
484 }
485
486 void NetworkProcess::continueCanAuthenticateAgainstProtectionSpace(uint64_t loaderID, bool canAuthenticate)
487 {
488     m_waitingNetworkResourceLoaders.take(loaderID).value()->continueCanAuthenticateAgainstProtectionSpace(canAuthenticate);
489 }
490 #endif
491
492 #if USE(NETWORK_SESSION)
493 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
494 void NetworkProcess::continueCanAuthenticateAgainstProtectionSpaceDownload(DownloadID downloadID, bool canAuthenticate)
495 {
496     downloadManager().continueCanAuthenticateAgainstProtectionSpace(downloadID, canAuthenticate);
497 }
498 #endif
499
500 void NetworkProcess::continueWillSendRequest(DownloadID downloadID, WebCore::ResourceRequest&& request)
501 {
502     downloadManager().continueWillSendRequest(downloadID, WTFMove(request));
503 }
504
505 void NetworkProcess::pendingDownloadCanceled(DownloadID downloadID)
506 {
507     downloadProxyConnection()->send(Messages::DownloadProxy::DidCancel({ }), downloadID.downloadID());
508 }
509
510 void NetworkProcess::findPendingDownloadLocation(NetworkDataTask& networkDataTask, ResponseCompletionHandler&& completionHandler, const ResourceResponse& response)
511 {
512     uint64_t destinationID = networkDataTask.pendingDownloadID().downloadID();
513     downloadProxyConnection()->send(Messages::DownloadProxy::DidReceiveResponse(response), destinationID);
514
515     downloadManager().willDecidePendingDownloadDestination(networkDataTask, WTFMove(completionHandler));
516     downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), networkDataTask.suggestedFilename()), destinationID);
517 }
518 #endif
519
520 void NetworkProcess::continueDecidePendingDownloadDestination(DownloadID downloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite)
521 {
522     if (destination.isEmpty())
523         downloadManager().cancelDownload(downloadID);
524     else
525         downloadManager().continueDecidePendingDownloadDestination(downloadID, destination, sandboxExtensionHandle, allowOverwrite);
526 }
527
528 void NetworkProcess::setCacheModel(uint32_t cm)
529 {
530     CacheModel cacheModel = static_cast<CacheModel>(cm);
531
532     if (m_hasSetCacheModel && (cacheModel == m_cacheModel))
533         return;
534
535     m_hasSetCacheModel = true;
536     m_cacheModel = cacheModel;
537
538     unsigned urlCacheMemoryCapacity = 0;
539     uint64_t urlCacheDiskCapacity = 0;
540     uint64_t diskFreeSize = 0;
541     if (WebCore::getVolumeFreeSpace(m_diskCacheDirectory, diskFreeSize)) {
542         // As a fudge factor, use 1000 instead of 1024, in case the reported byte
543         // count doesn't align exactly to a megabyte boundary.
544         diskFreeSize /= KB * 1000;
545         calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
546     }
547
548     if (m_diskCacheSizeOverride >= 0)
549         urlCacheDiskCapacity = m_diskCacheSizeOverride;
550
551 #if ENABLE(NETWORK_CACHE)
552     auto& networkCache = NetworkCache::singleton();
553     if (networkCache.isEnabled()) {
554         networkCache.setCapacity(urlCacheDiskCapacity);
555         return;
556     }
557 #endif
558
559     platformSetURLCacheSize(urlCacheMemoryCapacity, urlCacheDiskCapacity);
560 }
561
562 void NetworkProcess::setCanHandleHTTPSServerTrustEvaluation(bool value)
563 {
564     m_canHandleHTTPSServerTrustEvaluation = value;
565 }
566
567 void NetworkProcess::getNetworkProcessStatistics(uint64_t callbackID)
568 {
569     StatisticsData data;
570
571     auto& networkProcess = NetworkProcess::singleton();
572     data.statisticsNumbers.set("DownloadsActiveCount", networkProcess.downloadManager().activeDownloadCount());
573     data.statisticsNumbers.set("OutstandingAuthenticationChallengesCount", networkProcess.authenticationManager().outstandingAuthenticationChallengeCount());
574
575     parentProcessConnection()->send(Messages::WebProcessPool::DidGetStatistics(data, callbackID), 0);
576 }
577
578 void NetworkProcess::logDiagnosticMessage(uint64_t webPageID, const String& message, const String& description, ShouldSample shouldSample)
579 {
580     if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample))
581         return;
582
583     parentProcessConnection()->send(Messages::NetworkProcessProxy::LogDiagnosticMessage(webPageID, message, description, ShouldSample::No), 0);
584 }
585
586 void NetworkProcess::logDiagnosticMessageWithResult(uint64_t webPageID, const String& message, const String& description, DiagnosticLoggingResultType result, ShouldSample shouldSample)
587 {
588     if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample))
589         return;
590
591     parentProcessConnection()->send(Messages::NetworkProcessProxy::LogDiagnosticMessageWithResult(webPageID, message, description, result, ShouldSample::No), 0);
592 }
593
594 void NetworkProcess::logDiagnosticMessageWithValue(uint64_t webPageID, const String& message, const String& description, double value, unsigned significantFigures, ShouldSample shouldSample)
595 {
596     if (!DiagnosticLoggingClient::shouldLogAfterSampling(shouldSample))
597         return;
598
599     parentProcessConnection()->send(Messages::NetworkProcessProxy::LogDiagnosticMessageWithValue(webPageID, message, description, value, significantFigures, ShouldSample::No), 0);
600 }
601
602 void NetworkProcess::terminate()
603 {
604 #if ENABLE(NETWORK_CAPTURE)
605     NetworkCapture::Manager::singleton().terminate();
606 #endif
607
608     platformTerminate();
609     ChildProcess::terminate();
610 }
611
612 void NetworkProcess::processWillSuspendImminently(bool& handled)
613 {
614     lowMemoryHandler(Critical::Yes);
615     handled = true;
616 }
617
618 void NetworkProcess::prepareToSuspend()
619 {
620     RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::prepareToSuspend()", this);
621     lowMemoryHandler(Critical::Yes);
622
623     RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::prepareToSuspend() Sending ProcessReadyToSuspend IPC message", this);
624     parentProcessConnection()->send(Messages::NetworkProcessProxy::ProcessReadyToSuspend(), 0);
625 }
626
627 void NetworkProcess::cancelPrepareToSuspend()
628 {
629     // Although it is tempting to send a NetworkProcessProxy::DidCancelProcessSuspension message from here
630     // we do not because prepareToSuspend() already replied with a NetworkProcessProxy::ProcessReadyToSuspend
631     // message. And NetworkProcessProxy expects to receive either a NetworkProcessProxy::ProcessReadyToSuspend-
632     // or NetworkProcessProxy::DidCancelProcessSuspension- message, but not both.
633     RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::cancelPrepareToSuspend()", this);
634 }
635
636 void NetworkProcess::processDidResume()
637 {
638     RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::processDidResume()", this);
639 }
640
641 void NetworkProcess::prefetchDNS(const String& hostname)
642 {
643     WebCore::prefetchDNS(hostname);
644 }
645
646 #if !PLATFORM(COCOA)
647 void NetworkProcess::initializeProcess(const ChildProcessInitializationParameters&)
648 {
649 }
650
651 void NetworkProcess::initializeProcessName(const ChildProcessInitializationParameters&)
652 {
653 }
654
655 void NetworkProcess::initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&)
656 {
657 }
658
659 void NetworkProcess::platformLowMemoryHandler(Critical)
660 {
661 }
662 #endif
663
664 } // namespace WebKit