7957cae8b8d1c63fba9ab1fc871c363c3bb72cae
[WebKit-https.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 "NetworkBlobRegistry.h"
32 #include "NetworkContentRuleListManager.h"
33 #include "NetworkHTTPSUpgradeChecker.h"
34 #include "SandboxExtension.h"
35 #include <WebCore/AdClickAttribution.h>
36 #include <WebCore/ClientOrigin.h>
37 #include <WebCore/DiagnosticLoggingClient.h>
38 #include <WebCore/FetchIdentifier.h>
39 #include <WebCore/IDBKeyData.h>
40 #include <WebCore/IDBServer.h>
41 #include <WebCore/RegistrableDomain.h>
42 #include <WebCore/ServiceWorkerIdentifier.h>
43 #include <WebCore/ServiceWorkerTypes.h>
44 #include <memory>
45 #include <wtf/CrossThreadTask.h>
46 #include <wtf/Function.h>
47 #include <wtf/HashSet.h>
48 #include <wtf/MemoryPressureHandler.h>
49 #include <wtf/NeverDestroyed.h>
50 #include <wtf/RetainPtr.h>
51 #include <wtf/WeakPtr.h>
52
53 #if PLATFORM(IOS_FAMILY)
54 #include "WebSQLiteDatabaseTracker.h"
55 #endif
56
57 #if PLATFORM(COCOA)
58 typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
59 #endif
60
61 namespace IPC {
62 class FormDataReference;
63 }
64
65 namespace PAL {
66 class SessionID;
67 }
68
69 namespace WebCore {
70 class CertificateInfo;
71 class CurlProxySettings;
72 class DownloadID;
73 class StorageQuotaManager;
74 class NetworkStorageSession;
75 class ResourceError;
76 class SWServer;
77 enum class IncludeHttpOnlyCookies : bool;
78 enum class StoredCredentialsPolicy : bool;
79 struct ClientOrigin;
80 struct MessageWithMessagePorts;
81 struct SecurityOriginData;
82 struct SoupNetworkProxySettings;
83 struct ServiceWorkerClientIdentifier;
84 }
85
86 namespace WebKit {
87
88 class AuthenticationManager;
89 class NetworkConnectionToWebProcess;
90 class NetworkProcessSupplement;
91 class NetworkProximityManager;
92 class WebSWServerConnection;
93 class WebSWServerToContextConnection;
94 enum class ShouldGrandfatherStatistics : bool;
95 enum class StorageAccessStatus : uint8_t;
96 enum class WebsiteDataFetchOption;
97 enum class WebsiteDataType;
98 struct NetworkProcessCreationParameters;
99 struct WebsiteDataStoreParameters;
100
101 #if ENABLE(SERVICE_WORKER)
102 class WebSWOriginStore;
103 #endif
104
105 namespace CacheStorage {
106 class Engine;
107 }
108
109 namespace NetworkCache {
110 class Cache;
111 }
112
113 class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client, public ThreadSafeRefCounted<NetworkProcess>
114 #if ENABLE(INDEXED_DATABASE)
115     , public WebCore::IDBServer::IDBBackingStoreTemporaryFileHandler
116 #endif
117     , public CanMakeWeakPtr<NetworkProcess>
118 {
119     WTF_MAKE_NONCOPYABLE(NetworkProcess);
120 public:
121     using RegistrableDomain = WebCore::RegistrableDomain;
122     using TopFrameDomain = WebCore::RegistrableDomain;
123     using SubFrameDomain = WebCore::RegistrableDomain;
124     using SubResourceDomain = WebCore::RegistrableDomain;
125     using RedirectDomain = WebCore::RegistrableDomain;
126     using RedirectedFromDomain = WebCore::RegistrableDomain;
127     using RedirectedToDomain = WebCore::RegistrableDomain;
128     using NavigatedFromDomain = WebCore::RegistrableDomain;
129     using NavigatedToDomain = WebCore::RegistrableDomain;
130     using DomainInNeedOfStorageAccess = WebCore::RegistrableDomain;
131     using OpenerDomain = WebCore::RegistrableDomain;
132     using OpenerPageID = uint64_t;
133     using PageID = uint64_t;
134     using FrameID = uint64_t;
135
136     NetworkProcess(AuxiliaryProcessInitializationParameters&&);
137     ~NetworkProcess();
138     static constexpr ProcessType processType = ProcessType::Network;
139
140     template <typename T>
141     T* supplement()
142     {
143         return static_cast<T*>(m_supplements.get(T::supplementName()));
144     }
145
146     template <typename T>
147     void addSupplement()
148     {
149         m_supplements.add(T::supplementName(), std::make_unique<T>(*this));
150     }
151
152     void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess&);
153
154     AuthenticationManager& authenticationManager();
155     DownloadManager& downloadManager();
156 #if ENABLE(PROXIMITY_NETWORKING)
157     NetworkProximityManager& proximityManager();
158 #endif
159
160     NetworkCache::Cache* cache() { return m_cache.get(); }
161
162     void setSession(const PAL::SessionID&, Ref<NetworkSession>&&);
163     NetworkSession* networkSession(const PAL::SessionID&) const override;
164     void destroySession(const PAL::SessionID&);
165
166     // Needed for test infrastructure
167     HashMap<PAL::SessionID, Ref<NetworkSession>>& networkSessions() { return m_networkSessions; }
168
169     void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
170     WebCore::NetworkStorageSession* storageSession(const PAL::SessionID&) const;
171     WebCore::NetworkStorageSession& defaultStorageSession() const;
172     void switchToNewTestingSession();
173 #if PLATFORM(COCOA)
174     void ensureSession(const PAL::SessionID&, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
175 #else
176     void ensureSession(const PAL::SessionID&, const String& identifier);
177 #endif
178
179     bool canHandleHTTPSServerTrustEvaluation() const { return m_canHandleHTTPSServerTrustEvaluation; }
180
181     void processWillSuspendImminently(CompletionHandler<void(bool)>&&);
182     void prepareToSuspend();
183     void cancelPrepareToSuspend();
184     void processDidResume();
185
186     // Diagnostic messages logging.
187     void logDiagnosticMessage(uint64_t webPageID, const String& message, const String& description, WebCore::ShouldSample);
188     void logDiagnosticMessageWithResult(uint64_t webPageID, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
189     void logDiagnosticMessageWithValue(uint64_t webPageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
190
191 #if PLATFORM(COCOA)
192     RetainPtr<CFDataRef> sourceApplicationAuditData() const;
193     void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
194     void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
195     void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
196     bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
197 #endif
198
199     void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceResponse&);
200
201     void prefetchDNS(const String&);
202
203     void addWebsiteDataStore(WebsiteDataStoreParameters&&);
204
205 #if ENABLE(RESOURCE_LOAD_STATISTICS)
206     void clearPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
207     void clearUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
208     void deleteWebsiteDataForRegistrableDomainsInAllPersistentDataStores(PAL::SessionID, OptionSet<WebsiteDataType>, Vector<RegistrableDomain>&&, bool shouldNotifyPage, WebCore::IncludeHttpOnlyCookies, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&&);
209     void deleteCookiesForTesting(PAL::SessionID, RegistrableDomain, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
210     void dumpResourceLoadStatistics(PAL::SessionID, CompletionHandler<void(String)>&&);
211     void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<RegistrableDomain>& domainsToBlock, CompletionHandler<void()>&&);
212     void isGrandfathered(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
213     void isPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
214     void isVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
215     void setAgeCapForClientSideCookies(PAL::SessionID, Optional<Seconds>, CompletionHandler<void()>&&);
216     void isRegisteredAsRedirectingTo(PAL::SessionID, const RedirectedFromDomain&, const RedirectedToDomain&, CompletionHandler<void(bool)>&&);
217     void isRegisteredAsSubFrameUnder(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
218     void isRegisteredAsSubresourceUnder(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
219     void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&);
220     void setMaxStatisticsEntries(PAL::SessionID, uint64_t maximumEntryCount, CompletionHandler<void()>&&);
221     void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
222     void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
223     void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
224     void setPruneEntriesDownTo(PAL::SessionID, uint64_t pruneTargetCount, CompletionHandler<void()>&&);
225     void hadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
226     void hasStorageAccessForFrame(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, FrameID, PageID, CompletionHandler<void(bool)>&&);
227     void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&);
228     void grantStorageAccess(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, Optional<FrameID>, PageID, bool userWasPrompted, CompletionHandler<void(bool)>&&);
229     void hasStorageAccess(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, Optional<FrameID>, PageID, CompletionHandler<void(bool)>&&);
230     void logFrameNavigation(PAL::SessionID, const NavigatedToDomain&, const TopFrameDomain&, const NavigatedFromDomain&, bool isRedirect, bool isMainFrame);
231     void logUserInteraction(PAL::SessionID, const TopFrameDomain&, CompletionHandler<void()>&&);
232     void removeAllStorageAccess(PAL::SessionID, CompletionHandler<void()>&&);
233     void removePrevalentDomains(PAL::SessionID, const Vector<RegistrableDomain>&);
234     void requestStorageAccess(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, Optional<FrameID>, PageID, CompletionHandler<void(StorageAccessStatus)>&&);
235     void requestStorageAccessGranted(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, FrameID, PageID, CompletionHandler<void(bool)>&&);
236     void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&);
237     void resetParametersToDefaultValues(PAL::SessionID, CompletionHandler<void()>&&);
238     void scheduleClearInMemoryAndPersistent(PAL::SessionID, Optional<WallTime> modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&);
239     void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&);
240     void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&);
241     void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&);
242     void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
243     void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
244     void setLastSeen(PAL::SessionID, const RegistrableDomain&, Seconds, CompletionHandler<void()>&&);
245     void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
246     void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool value, CompletionHandler<void()>&&);
247     void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool value, CompletionHandler<void()>&&);
248     void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
249     void setResourceLoadStatisticsEnabled(bool);
250     void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&d);
251     void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool value, CompletionHandler<void()>&&);
252     void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
253     void setSubresourceUnderTopFrameDomain(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
254     void setSubresourceUniqueRedirectTo(PAL::SessionID, const SubResourceDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
255     void setSubresourceUniqueRedirectFrom(PAL::SessionID, const SubResourceDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
256     void setTimeToLiveUserInteraction(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
257     void setTopFrameUniqueRedirectTo(PAL::SessionID, const TopFrameDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
258     void setTopFrameUniqueRedirectFrom(PAL::SessionID, const TopFrameDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
259     void registrableDomainsWithWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, bool shouldNotifyPage, CompletionHandler<void(HashSet<RegistrableDomain>&&)>&&);
260     void committedCrossSiteLoadWithLinkDecoration(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, uint64_t pageID, CompletionHandler<void()>&&);
261     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
262 #endif
263
264     using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
265     void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
266
267     void preconnectTo(const URL&, WebCore::StoredCredentialsPolicy);
268
269     void setSessionIsControlledByAutomation(PAL::SessionID, bool);
270     bool sessionIsControlledByAutomation(PAL::SessionID) const;
271
272 #if ENABLE(CONTENT_EXTENSIONS)
273     NetworkContentRuleListManager& networkContentRuleListManager() { return m_networkContentRuleListManager; }
274 #endif
275
276 #if ENABLE(INDEXED_DATABASE)
277     WebCore::IDBServer::IDBServer& idbServer(PAL::SessionID);
278     // WebCore::IDBServer::IDBBackingStoreFileHandler.
279     void accessToTemporaryFileComplete(const String& path) final;
280     void setIDBPerOriginQuota(uint64_t);
281 #endif
282
283 #if ENABLE(SANDBOX_EXTENSIONS)
284     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
285 #endif
286
287     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::Decoder&);
288
289 #if ENABLE(SERVICE_WORKER)
290     WebSWServerToContextConnection* serverToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&);
291     void createServerToContextConnection(const WebCore::RegistrableDomain&, Optional<PAL::SessionID>);
292     
293     WebCore::SWServer& swServerForSession(PAL::SessionID);
294     void registerSWServerConnection(WebSWServerConnection&);
295     void unregisterSWServerConnection(WebSWServerConnection&);
296     
297     void swContextConnectionMayNoLongerBeNeeded(WebSWServerToContextConnection&);
298     
299     WebSWServerToContextConnection* connectionToContextProcessFromIPCConnection(IPC::Connection&);
300     void connectionToContextProcessWasClosed(Ref<WebSWServerToContextConnection>&&);
301 #endif
302
303 #if PLATFORM(IOS_FAMILY)
304     bool parentProcessHasServiceWorkerEntitlement() const;
305 #else
306     bool parentProcessHasServiceWorkerEntitlement() const { return true; }
307 #endif
308
309 #if PLATFORM(COCOA)
310     NetworkHTTPSUpgradeChecker& networkHTTPSUpgradeChecker() { return m_networkHTTPSUpgradeChecker; }
311 #endif
312
313     const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
314
315     void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
316     void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }
317
318     CacheStorage::Engine* findCacheEngine(const PAL::SessionID&);
319     CacheStorage::Engine& ensureCacheEngine(const PAL::SessionID&, Function<Ref<CacheStorage::Engine>()>&&);
320     void removeCacheEngine(const PAL::SessionID&);
321     void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
322
323     NetworkBlobRegistry& networkBlobRegistry() override { return m_networkBlobRegistry; }
324
325     void storeAdClickAttribution(PAL::SessionID, WebCore::AdClickAttribution&&);
326     void dumpAdClickAttribution(PAL::SessionID, CompletionHandler<void(String)>&&);
327     void clearAdClickAttribution(PAL::SessionID, CompletionHandler<void()>&&);
328
329     WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
330
331 private:
332     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
333     std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
334
335     void terminate() override;
336     void platformTerminate();
337
338     void lowMemoryHandler(Critical);
339     
340     void processDidTransitionToForeground();
341     void processDidTransitionToBackground();
342     void platformProcessDidTransitionToForeground();
343     void platformProcessDidTransitionToBackground();
344
345     enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
346     void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
347     void platformPrepareToSuspend(CompletionHandler<void()>&&);
348     void platformProcessDidResume();
349
350     // AuxiliaryProcess
351     void initializeProcess(const AuxiliaryProcessInitializationParameters&) override;
352     void initializeProcessName(const AuxiliaryProcessInitializationParameters&) override;
353     void initializeSandbox(const AuxiliaryProcessInitializationParameters&, SandboxInitializationParameters&) override;
354     void initializeConnection(IPC::Connection*) override;
355     bool shouldTerminate() override;
356
357     // IPC::Connection::Client
358     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
359     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
360     void didClose(IPC::Connection&) override;
361
362     // DownloadManager::Client
363     void didCreateDownload() override;
364     void didDestroyDownload() override;
365     IPC::Connection* downloadProxyConnection() override;
366     IPC::Connection* parentProcessConnectionForDownloads() override { return parentProcessConnection(); }
367     AuthenticationManager& downloadsAuthenticationManager() override;
368     void pendingDownloadCanceled(DownloadID) override;
369
370     // Message Handlers
371     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
372     void initializeNetworkProcess(NetworkProcessCreationParameters&&);
373     void createNetworkConnectionToWebProcess(bool isServiceWorkerProcess, WebCore::RegistrableDomain&&);
374
375     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
376     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, uint64_t callbackID);
377     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostnames, uint64_t callbackID);
378
379     void clearCachedCredentials();
380
381     void setCacheStorageParameters(PAL::SessionID, uint64_t quota, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
382
383     // FIXME: This should take a session ID so we can identify which disk cache to delete.
384     void clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&&);
385
386     void downloadRequest(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
387     void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
388     void cancelDownload(DownloadID);
389 #if PLATFORM(COCOA)
390     void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
391 #endif
392     void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
393     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
394
395     void setCacheModel(CacheModel);
396     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
397     void setCanHandleHTTPSServerTrustEvaluation(bool);
398     void getNetworkProcessStatistics(uint64_t callbackID);
399     void clearCacheForAllOrigins(uint32_t cachesToClear);
400     void setAllowsAnySSLCertificateForWebSocket(bool, CompletionHandler<void()>&&);
401     
402     void syncAllCookies();
403     void didSyncAllCookies();
404
405     void notifyHoldingLockedFiles(bool isIDBDatabaseHoldingLockedFiles);
406 #if USE(SOUP)
407     void setIgnoreTLSErrors(bool);
408     void userPreferredLanguagesChanged(const Vector<String>&);
409     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
410 #endif
411
412 #if USE(CURL)
413     void setNetworkProxySettings(PAL::SessionID, WebCore::CurlProxySettings&&);
414 #endif
415
416 #if PLATFORM(MAC)
417     static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
418 #endif
419
420     void platformSyncAllCookies(CompletionHandler<void()>&&);
421
422     void registerURLSchemeAsSecure(const String&) const;
423     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
424     void registerURLSchemeAsLocal(const String&) const;
425     void registerURLSchemeAsNoAccess(const String&) const;
426     void registerURLSchemeAsDisplayIsolated(const String&) const;
427     void registerURLSchemeAsCORSEnabled(const String&) const;
428     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
429
430 #if ENABLE(INDEXED_DATABASE)
431     void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
432     void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
433     HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
434     Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
435 #endif
436
437 #if ENABLE(SERVICE_WORKER)
438     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
439     
440     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
441     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
442     
443     void disableServiceWorkerProcessTerminationDelay();
444     
445     WebSWOriginStore& swOriginStoreForSession(PAL::SessionID);
446     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
447     bool needsServerToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&) const;
448
449     void addServiceWorkerSession(PAL::SessionID, String& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
450 #endif
451
452     void postStorageTask(CrossThreadTask&&);
453     // For execution on work queue thread only.
454     void performNextStorageTask();
455     void ensurePathExists(const String& path);
456
457     void clearStorageQuota(PAL::SessionID);
458
459     // Connections to WebProcesses.
460     Vector<Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
461
462     String m_diskCacheDirectory;
463     bool m_hasSetCacheModel { false };
464     CacheModel m_cacheModel { CacheModel::DocumentViewer };
465     bool m_suppressMemoryPressureHandler { false };
466     bool m_diskCacheIsDisabledForTesting { false };
467     bool m_canHandleHTTPSServerTrustEvaluation { true };
468     String m_uiProcessBundleIdentifier;
469     DownloadManager m_downloadManager;
470
471     HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
472
473     RefPtr<NetworkCache::Cache> m_cache;
474
475     typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
476     NetworkProcessSupplementMap m_supplements;
477
478     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
479     HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
480
481     HashMap<PAL::SessionID, Ref<NetworkSession>> m_networkSessions;
482     HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
483     mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
484     NetworkBlobRegistry m_networkBlobRegistry;
485
486 #if PLATFORM(COCOA)
487     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
488     void setStorageAccessAPIEnabled(bool);
489
490     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
491     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
492     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
493     dispatch_group_t m_clearCacheDispatchGroup { nullptr };
494
495     bool m_suppressesConnectionTerminationOnSystemChange { false };
496 #endif
497
498 #if ENABLE(CONTENT_EXTENSIONS)
499     NetworkContentRuleListManager m_networkContentRuleListManager;
500 #endif
501
502 #if PLATFORM(IOS_FAMILY)
503     WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
504 #endif
505
506     Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
507
508 #if ENABLE(INDEXED_DATABASE)
509     HashMap<PAL::SessionID, String> m_idbDatabasePaths;
510     HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
511     uint64_t m_idbPerOriginQuota { WebCore::IDBServer::defaultPerOriginQuota };
512 #endif
513
514     Deque<CrossThreadTask> m_storageTasks;
515     Lock m_storageTaskMutex;
516     
517 #if ENABLE(SERVICE_WORKER)
518     HashMap<WebCore::RegistrableDomain, RefPtr<WebSWServerToContextConnection>> m_serverToContextConnections;
519     bool m_waitingForServerToContextProcessConnection { false };
520     bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
521     HashMap<PAL::SessionID, String> m_swDatabasePaths;
522     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
523     HashMap<WebCore::SWServerConnectionIdentifier, WebSWServerConnection*> m_swServerConnections;
524 #endif
525
526 #if PLATFORM(COCOA)
527     NetworkHTTPSUpgradeChecker m_networkHTTPSUpgradeChecker;
528 #endif
529
530     struct StorageQuotaManagers {
531         uint64_t defaultQuota { WebCore::StorageQuotaManager::defaultQuota() };
532         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> managersPerOrigin;
533     };
534     HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
535 };
536
537 } // namespace WebKit