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