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