Remove unused WebProcessPool::requestNetworkingStatistics
[WebKit.git] / Source / WebKit / NetworkProcess / NetworkProcess.h
1 /*
2  * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include "AuxiliaryProcess.h"
29 #include "CacheModel.h"
30 #include "DownloadManager.h"
31 #include "LocalStorageDatabaseTracker.h"
32 #include "NetworkContentRuleListManager.h"
33 #include "NetworkHTTPSUpgradeChecker.h"
34 #include "SandboxExtension.h"
35 #include "WebPageProxyIdentifier.h"
36 #include "WebResourceLoadStatisticsStore.h"
37 #include "WebsiteData.h"
38 #include <WebCore/AdClickAttribution.h>
39 #include <WebCore/ClientOrigin.h>
40 #include <WebCore/CrossSiteNavigationDataTransfer.h>
41 #include <WebCore/DiagnosticLoggingClient.h>
42 #include <WebCore/FetchIdentifier.h>
43 #include <WebCore/IDBKeyData.h>
44 #include <WebCore/IDBServer.h>
45 #include <WebCore/MessagePortChannelRegistry.h>
46 #include <WebCore/PageIdentifier.h>
47 #include <WebCore/RegistrableDomain.h>
48 #include <WebCore/ServiceWorkerIdentifier.h>
49 #include <WebCore/ServiceWorkerTypes.h>
50 #include <memory>
51 #include <wtf/CrossThreadTask.h>
52 #include <wtf/Function.h>
53 #include <wtf/HashSet.h>
54 #include <wtf/MemoryPressureHandler.h>
55 #include <wtf/NeverDestroyed.h>
56 #include <wtf/RetainPtr.h>
57 #include <wtf/WeakPtr.h>
58
59 #if PLATFORM(IOS_FAMILY)
60 #include "WebSQLiteDatabaseTracker.h"
61 #endif
62
63 #if PLATFORM(COCOA)
64 typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
65 #endif
66
67 namespace IPC {
68 class FormDataReference;
69 }
70
71 namespace PAL {
72 class SessionID;
73 }
74
75 namespace WebCore {
76 class CertificateInfo;
77 class CurlProxySettings;
78 class DownloadID;
79 class ProtectionSpace;
80 class StorageQuotaManager;
81 class NetworkStorageSession;
82 class ResourceError;
83 class SWServer;
84 enum class IncludeHttpOnlyCookies : bool;
85 enum class StoredCredentialsPolicy : uint8_t;
86 enum class StorageAccessPromptWasShown : bool;
87 enum class StorageAccessWasGranted : bool;
88 struct ClientOrigin;
89 struct MessageWithMessagePorts;
90 struct SecurityOriginData;
91 struct SoupNetworkProxySettings;
92 struct ServiceWorkerClientIdentifier;
93 }
94
95 namespace WebKit {
96
97 class AuthenticationManager;
98 class NetworkConnectionToWebProcess;
99 class NetworkProcessSupplement;
100 class NetworkProximityManager;
101 class NetworkResourceLoader;
102 class StorageManagerSet;
103 class WebSWServerConnection;
104 class WebSWServerToContextConnection;
105 enum class ShouldGrandfatherStatistics : bool;
106 enum class StorageAccessStatus : uint8_t;
107 enum class WebsiteDataFetchOption;
108 enum class WebsiteDataType;
109 struct NetworkProcessCreationParameters;
110 struct WebsiteDataStoreParameters;
111
112 #if ENABLE(SERVICE_WORKER)
113 class WebSWOriginStore;
114 #endif
115
116 namespace NetworkCache {
117 enum class CacheOption : uint8_t;
118 }
119
120 namespace CacheStorage {
121 class Engine;
122 }
123
124 class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client, public ThreadSafeRefCounted<NetworkProcess>
125 #if ENABLE(INDEXED_DATABASE)
126     , public WebCore::IDBServer::IDBBackingStoreTemporaryFileHandler
127 #endif
128     , public CanMakeWeakPtr<NetworkProcess>
129 {
130     WTF_MAKE_NONCOPYABLE(NetworkProcess);
131 public:
132     using RegistrableDomain = WebCore::RegistrableDomain;
133     using TopFrameDomain = WebCore::RegistrableDomain;
134     using SubFrameDomain = WebCore::RegistrableDomain;
135     using SubResourceDomain = WebCore::RegistrableDomain;
136     using RedirectDomain = WebCore::RegistrableDomain;
137     using RedirectedFromDomain = WebCore::RegistrableDomain;
138     using RedirectedToDomain = WebCore::RegistrableDomain;
139     using NavigatedFromDomain = WebCore::RegistrableDomain;
140     using NavigatedToDomain = WebCore::RegistrableDomain;
141     using DomainInNeedOfStorageAccess = WebCore::RegistrableDomain;
142     using OpenerDomain = WebCore::RegistrableDomain;
143
144     NetworkProcess(AuxiliaryProcessInitializationParameters&&);
145     ~NetworkProcess();
146     static constexpr ProcessType processType = ProcessType::Network;
147
148     template <typename T>
149     T* supplement()
150     {
151         return static_cast<T*>(m_supplements.get(T::supplementName()));
152     }
153
154     template <typename T>
155     void addSupplement()
156     {
157         m_supplements.add(T::supplementName(), makeUnique<T>(*this));
158     }
159
160     void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess&);
161
162     AuthenticationManager& authenticationManager();
163     DownloadManager& downloadManager();
164
165     void setSession(PAL::SessionID, std::unique_ptr<NetworkSession>&&);
166     NetworkSession* networkSession(PAL::SessionID) const final;
167     void destroySession(PAL::SessionID);
168
169     void forEachNetworkSession(const Function<void(NetworkSession&)>&);
170
171     void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
172     WebCore::NetworkStorageSession* storageSession(const PAL::SessionID&) const;
173     WebCore::NetworkStorageSession& defaultStorageSession() const;
174     std::unique_ptr<WebCore::NetworkStorageSession> newTestingSession(const PAL::SessionID&);
175 #if PLATFORM(COCOA)
176     void ensureSession(const PAL::SessionID&, bool shouldUseTestingNetworkSession, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
177 #else
178     void ensureSession(const PAL::SessionID&, bool shouldUseTestingNetworkSession, const String& identifier);
179 #endif
180
181     void processWillSuspendImminently();
182     void processWillSuspendImminentlyForTestingSync(CompletionHandler<void()>&&);
183     void prepareToSuspend();
184     void cancelPrepareToSuspend();
185     void processDidResume();
186     void resume();
187
188     // Diagnostic messages logging.
189     void logDiagnosticMessage(WebPageProxyIdentifier, const String& message, const String& description, WebCore::ShouldSample);
190     void logDiagnosticMessageWithResult(WebPageProxyIdentifier, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
191     void logDiagnosticMessageWithValue(WebPageProxyIdentifier, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
192
193 #if PLATFORM(COCOA)
194     RetainPtr<CFDataRef> sourceApplicationAuditData() const;
195     bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
196 #endif
197 #if PLATFORM(COCOA) || USE(SOUP)
198     void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
199     void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
200     void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
201 #endif
202
203     void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceResponse&);
204
205     void prefetchDNS(const String&);
206
207     void addWebsiteDataStore(WebsiteDataStoreParameters&&);
208
209 #if ENABLE(RESOURCE_LOAD_STATISTICS)
210     void clearPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
211     void clearUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
212     void deleteWebsiteDataForRegistrableDomains(PAL::SessionID, OptionSet<WebsiteDataType>, Vector<std::pair<RegistrableDomain, WebsiteDataToRemove>>&&, bool shouldNotifyPage, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&&);
213     void deleteCookiesForTesting(PAL::SessionID, RegistrableDomain, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
214     void dumpResourceLoadStatistics(PAL::SessionID, CompletionHandler<void(String)>&&);
215     void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<RegistrableDomain>& domainsToBlock, CompletionHandler<void()>&&);
216     void isGrandfathered(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
217     void isPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
218     void isVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
219     void setAgeCapForClientSideCookies(PAL::SessionID, Optional<Seconds>, CompletionHandler<void()>&&);
220     void isRegisteredAsRedirectingTo(PAL::SessionID, const RedirectedFromDomain&, const RedirectedToDomain&, CompletionHandler<void(bool)>&&);
221     void isRegisteredAsSubFrameUnder(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
222     void isRegisteredAsSubresourceUnder(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
223     void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&);
224     void setUseITPDatabase(PAL::SessionID, bool value);
225     void setMaxStatisticsEntries(PAL::SessionID, uint64_t maximumEntryCount, CompletionHandler<void()>&&);
226     void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
227     void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
228     void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
229     void setPruneEntriesDownTo(PAL::SessionID, uint64_t pruneTargetCount, CompletionHandler<void()>&&);
230     void hadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
231     void isRelationshipOnlyInDatabaseOnce(PAL::SessionID, const RegistrableDomain& subDomain, const RegistrableDomain& topDomain, CompletionHandler<void(bool)>&&);
232     void hasLocalStorage(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
233     void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&);
234     void logFrameNavigation(PAL::SessionID, const NavigatedToDomain&, const TopFrameDomain&, const NavigatedFromDomain&, bool isRedirect, bool isMainFrame);
235     void logUserInteraction(PAL::SessionID, const TopFrameDomain&, CompletionHandler<void()>&&);
236     void removePrevalentDomains(PAL::SessionID, const Vector<RegistrableDomain>&);
237     void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&);
238     void resetParametersToDefaultValues(PAL::SessionID, CompletionHandler<void()>&&);
239     void scheduleClearInMemoryAndPersistent(PAL::SessionID, Optional<WallTime> modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&);
240     void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&);
241     void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&);
242     void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&);
243     void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
244     void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
245     void setLastSeen(PAL::SessionID, const RegistrableDomain&, Seconds, CompletionHandler<void()>&&);
246     void mergeStatisticForTesting(PAL::SessionID, const RegistrableDomain&, const TopFrameDomain& topFrameDomain1, const TopFrameDomain& topFrameDomain2, Seconds lastSeen, bool hadUserInteraction, Seconds mostRecentUserInteraction, bool isGrandfathered, bool isPrevalent, bool isVeryPrevalent, unsigned dataRecordsRemoved, CompletionHandler<void()>&&);
247     void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
248     void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool value, CompletionHandler<void()>&&);
249     void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool value, CompletionHandler<void()>&&);
250     void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
251     void setResourceLoadStatisticsEnabled(PAL::SessionID, bool);
252     void setResourceLoadStatisticsLogTestingEvent(bool);
253     void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&d);
254     void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool value, CompletionHandler<void()>&&);
255     void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
256     void setSubresourceUnderTopFrameDomain(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
257     void setSubresourceUniqueRedirectTo(PAL::SessionID, const SubResourceDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
258     void setSubresourceUniqueRedirectFrom(PAL::SessionID, const SubResourceDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
259     void setTimeToLiveUserInteraction(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
260     void setTopFrameUniqueRedirectTo(PAL::SessionID, const TopFrameDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
261     void setTopFrameUniqueRedirectFrom(PAL::SessionID, const TopFrameDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
262     void registrableDomainsWithWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, bool shouldNotifyPage, CompletionHandler<void(HashSet<RegistrableDomain>&&)>&&);
263     void didCommitCrossSiteLoadWithDataTransfer(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, OptionSet<WebCore::CrossSiteNavigationDataTransfer::Flag>, WebPageProxyIdentifier, WebCore::PageIdentifier);
264     void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
265     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
266     void hasIsolatedSession(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
267     bool isITPDatabaseEnabled() const { return m_isITPDatabaseEnabled; }
268     void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
269 #endif
270
271     using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
272     void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
273
274     void setSessionIsControlledByAutomation(PAL::SessionID, bool);
275     bool sessionIsControlledByAutomation(PAL::SessionID) const;
276
277     void connectionToWebProcessClosed(IPC::Connection&);
278     void getLocalStorageOriginDetails(PAL::SessionID, CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&&);
279
280 #if ENABLE(CONTENT_EXTENSIONS)
281     NetworkContentRuleListManager& networkContentRuleListManager() { return m_networkContentRuleListManager; }
282 #endif
283
284 #if ENABLE(INDEXED_DATABASE)
285     WebCore::IDBServer::IDBServer& idbServer(PAL::SessionID);
286     // WebCore::IDBServer::IDBBackingStoreFileHandler.
287     void accessToTemporaryFileComplete(const String& path) final;
288 #endif
289
290     void syncLocalStorage(CompletionHandler<void()>&&);
291     void clearLegacyPrivateBrowsingLocalStorage();
292
293     void updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID, const WebCore::ClientOrigin&);
294
295 #if ENABLE(SANDBOX_EXTENSIONS)
296     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
297 #endif
298
299     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::Decoder&);
300
301 #if ENABLE(SERVICE_WORKER)
302     WebCore::SWServer* swServerForSessionIfExists(PAL::SessionID sessionID) { return m_swServers.get(sessionID); }
303     WebCore::SWServer& swServerForSession(PAL::SessionID);
304     void registerSWServerConnection(WebSWServerConnection&);
305     void unregisterSWServerConnection(WebSWServerConnection&);
306     
307     void forEachSWServer(const Function<void(WebCore::SWServer&)>&);
308 #endif
309
310 #if PLATFORM(IOS_FAMILY)
311     bool parentProcessHasServiceWorkerEntitlement() const;
312 #else
313     bool parentProcessHasServiceWorkerEntitlement() const { return true; }
314 #endif
315
316 #if PLATFORM(COCOA)
317     NetworkHTTPSUpgradeChecker& networkHTTPSUpgradeChecker();
318 #endif
319
320     const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
321
322     void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
323     void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }
324
325     CacheStorage::Engine* findCacheEngine(const PAL::SessionID&);
326     CacheStorage::Engine& ensureCacheEngine(const PAL::SessionID&, Function<Ref<CacheStorage::Engine>()>&&);
327     void removeCacheEngine(const PAL::SessionID&);
328     void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
329
330     void storeAdClickAttribution(PAL::SessionID, WebCore::AdClickAttribution&&);
331     void dumpAdClickAttribution(PAL::SessionID, CompletionHandler<void(String)>&&);
332     void clearAdClickAttribution(PAL::SessionID, CompletionHandler<void()>&&);
333     void setAdClickAttributionOverrideTimerForTesting(PAL::SessionID, bool value, CompletionHandler<void()>&&);
334     void setAdClickAttributionConversionURLForTesting(PAL::SessionID, URL&&, CompletionHandler<void()>&&);
335     void markAdClickAttributionsAsExpiredForTesting(PAL::SessionID, CompletionHandler<void()>&&);
336
337     WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
338
339     void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
340     void removeKeptAliveLoad(NetworkResourceLoader&);
341
342     const OptionSet<NetworkCache::CacheOption>& cacheOptions() const { return m_cacheOptions; }
343
344     NetworkConnectionToWebProcess* webProcessConnection(WebCore::ProcessIdentifier) const;
345     WebCore::MessagePortChannelRegistry& messagePortChannelRegistry() { return m_messagePortChannelRegistry; }
346
347     void setServiceWorkerFetchTimeoutForTesting(Seconds, CompletionHandler<void()>&&);
348     void resetServiceWorkerFetchTimeoutForTesting(CompletionHandler<void()>&&);
349     Seconds serviceWorkerFetchTimeout() const { return m_serviceWorkerFetchTimeout; }
350
351 private:
352     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
353     std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
354
355     void terminate() override;
356     void platformTerminate();
357
358     void lowMemoryHandler(Critical);
359     
360     void processDidTransitionToForeground();
361     void processDidTransitionToBackground();
362     void platformProcessDidTransitionToForeground();
363     void platformProcessDidTransitionToBackground();
364
365     enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
366     void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
367     void platformPrepareToSuspend(CompletionHandler<void()>&&);
368     void platformProcessDidResume();
369
370     // AuxiliaryProcess
371     void initializeProcess(const AuxiliaryProcessInitializationParameters&) override;
372     void initializeProcessName(const AuxiliaryProcessInitializationParameters&) override;
373     void initializeSandbox(const AuxiliaryProcessInitializationParameters&, SandboxInitializationParameters&) override;
374     void initializeConnection(IPC::Connection*) override;
375     bool shouldTerminate() override;
376
377     // IPC::Connection::Client
378     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
379     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
380     void didClose(IPC::Connection&) override;
381
382     // DownloadManager::Client
383     void didCreateDownload() override;
384     void didDestroyDownload() override;
385     IPC::Connection* downloadProxyConnection() override;
386     IPC::Connection* parentProcessConnectionForDownloads() override { return parentProcessConnection(); }
387     AuthenticationManager& downloadsAuthenticationManager() override;
388     void pendingDownloadCanceled(DownloadID) override;
389
390     // Message Handlers
391     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
392     void initializeNetworkProcess(NetworkProcessCreationParameters&&);
393     void createNetworkConnectionToWebProcess(WebCore::ProcessIdentifier, PAL::SessionID, CompletionHandler<void(Optional<IPC::Attachment>&&)>&&);
394
395     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
396     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, uint64_t callbackID);
397     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostnames, uint64_t callbackID);
398
399     void clearCachedCredentials();
400
401     void setCacheStorageParameters(PAL::SessionID, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
402     void initializeQuotaUsers(WebCore::StorageQuotaManager&, PAL::SessionID, const WebCore::ClientOrigin&);
403
404     // FIXME: This should take a session ID so we can identify which disk cache to delete.
405     void clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&&);
406
407     void downloadRequest(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
408     void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
409     void cancelDownload(DownloadID);
410 #if PLATFORM(COCOA)
411     void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
412 #endif
413     void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
414     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
415     void applicationDidEnterBackground();
416     void applicationWillEnterForeground();
417
418     void setCacheModel(CacheModel, String overrideCacheStorageDirectory);
419     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
420     void clearCacheForAllOrigins(uint32_t cachesToClear);
421     void setAllowsAnySSLCertificateForWebSocket(bool, CompletionHandler<void()>&&);
422     
423     void syncAllCookies();
424     void didSyncAllCookies();
425
426 #if USE(SOUP)
427     void setIgnoreTLSErrors(bool);
428     void userPreferredLanguagesChanged(const Vector<String>&);
429     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
430 #endif
431
432 #if USE(CURL)
433     void setNetworkProxySettings(PAL::SessionID, WebCore::CurlProxySettings&&);
434 #endif
435
436 #if PLATFORM(MAC)
437     static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
438 #endif
439
440     void platformSyncAllCookies(CompletionHandler<void()>&&);
441     
442     void registerURLSchemeAsSecure(const String&) const;
443     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
444     void registerURLSchemeAsLocal(const String&) const;
445     void registerURLSchemeAsNoAccess(const String&) const;
446     void registerURLSchemeAsCORSEnabled(const String&) const;
447     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
448
449 #if ENABLE(INDEXED_DATABASE)
450     void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
451     void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
452     HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
453     Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
454 #endif
455
456 #if ENABLE(SERVICE_WORKER)
457     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
458
459     void postMessageToServiceWorker(PAL::SessionID, WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
460     
461     void disableServiceWorkerProcessTerminationDelay();
462     
463     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
464
465     void addServiceWorkerSession(PAL::SessionID, bool processTerminationDelayEnabled, HashSet<String>&& registeredSchemes, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
466 #endif
467
468     void postStorageTask(CrossThreadTask&&);
469     // For execution on work queue thread only.
470     void performNextStorageTask();
471     void ensurePathExists(const String& path);
472
473     void clearStorageQuota(PAL::SessionID);
474     void initializeStorageQuota(const WebsiteDataStoreParameters&);
475
476     // Connections to WebProcesses.
477     HashMap<WebCore::ProcessIdentifier, Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
478
479     bool m_hasSetCacheModel { false };
480     CacheModel m_cacheModel { CacheModel::DocumentViewer };
481     bool m_suppressMemoryPressureHandler { false };
482     String m_uiProcessBundleIdentifier;
483     DownloadManager m_downloadManager;
484
485     HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
486
487     typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
488     NetworkProcessSupplementMap m_supplements;
489
490     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
491     HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
492
493     HashMap<PAL::SessionID, std::unique_ptr<NetworkSession>> m_networkSessions;
494     HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
495     mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
496
497     RefPtr<StorageManagerSet> m_storageManagerSet;
498
499 #if PLATFORM(COCOA)
500     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
501     void setStorageAccessAPIEnabled(bool);
502
503     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
504     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
505     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
506     dispatch_group_t m_clearCacheDispatchGroup { nullptr };
507
508     bool m_suppressesConnectionTerminationOnSystemChange { false };
509 #endif
510
511 #if ENABLE(CONTENT_EXTENSIONS)
512     NetworkContentRuleListManager m_networkContentRuleListManager;
513 #endif
514
515 #if PLATFORM(IOS_FAMILY)
516     WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
517 #endif
518
519     Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
520
521 #if ENABLE(INDEXED_DATABASE)
522     HashMap<PAL::SessionID, String> m_idbDatabasePaths;
523     HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
524 #endif
525
526     Deque<CrossThreadTask> m_storageTasks;
527     Lock m_storageTaskMutex;
528     
529 #if ENABLE(SERVICE_WORKER)
530     struct ServiceWorkerInfo {
531         String databasePath;
532         bool processTerminationDelayEnabled { true };
533         HashSet<String> registeredSchemes;
534     };
535     HashMap<PAL::SessionID, ServiceWorkerInfo> m_serviceWorkerInfo;
536     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
537 #endif
538
539 #if PLATFORM(COCOA)
540     std::unique_ptr<NetworkHTTPSUpgradeChecker> m_networkHTTPSUpgradeChecker;
541 #endif
542
543 #if ENABLE(RESOURCE_LOAD_STATISTICS)
544     bool m_isITPDatabaseEnabled { false };
545 #endif
546     
547     class StorageQuotaManagers {
548     public:
549         uint64_t defaultQuota(const WebCore::ClientOrigin& origin) const { return origin.topOrigin == origin.clientOrigin ? m_defaultQuota : m_defaultThirdPartyQuota; }
550         void setDefaultQuotas(uint64_t defaultQuota, uint64_t defaultThirdPartyQuota)
551         {
552             m_defaultQuota = defaultQuota;
553             m_defaultThirdPartyQuota = defaultThirdPartyQuota;
554         }
555
556         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>>& managersPerOrigin() { return m_managersPerOrigin; }
557
558     private:
559         uint64_t m_defaultQuota { WebCore::StorageQuotaManager::defaultQuota() };
560         uint64_t m_defaultThirdPartyQuota { WebCore::StorageQuotaManager::defaultThirdPartyQuota() };
561         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> m_managersPerOrigin;
562     };
563     HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
564
565     OptionSet<NetworkCache::CacheOption> m_cacheOptions;
566     WebCore::MessagePortChannelRegistry m_messagePortChannelRegistry;
567
568     static const Seconds defaultServiceWorkerFetchTimeout;
569     Seconds m_serviceWorkerFetchTimeout { defaultServiceWorkerFetchTimeout };
570 };
571
572 } // namespace WebKit