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