Source/WebCore:
[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 "NetworkContentRuleListManager.h"
33 #include "NetworkHTTPSUpgradeChecker.h"
34 #include "SandboxExtension.h"
35 #include "WebPageProxyIdentifier.h"
36 #include "WebResourceLoadStatisticsStore.h"
37 #include "WebsiteData.h"
38 #include <WebCore/AdClickAttribution.h>
39 #include <WebCore/ClientOrigin.h>
40 #include <WebCore/CrossSiteNavigationDataTransfer.h>
41 #include <WebCore/DiagnosticLoggingClient.h>
42 #include <WebCore/FetchIdentifier.h>
43 #include <WebCore/IDBKeyData.h>
44 #include <WebCore/IDBServer.h>
45 #include <WebCore/MessagePortChannelRegistry.h>
46 #include <WebCore/PageIdentifier.h>
47 #include <WebCore/RegistrableDomain.h>
48 #include <WebCore/ServiceWorkerIdentifier.h>
49 #include <WebCore/ServiceWorkerTypes.h>
50 #include <memory>
51 #include <wtf/CrossThreadTask.h>
52 #include <wtf/Function.h>
53 #include <wtf/HashSet.h>
54 #include <wtf/MemoryPressureHandler.h>
55 #include <wtf/NeverDestroyed.h>
56 #include <wtf/RetainPtr.h>
57 #include <wtf/WeakPtr.h>
58
59 #if PLATFORM(IOS_FAMILY)
60 #include "WebSQLiteDatabaseTracker.h"
61 #endif
62
63 #if PLATFORM(COCOA)
64 typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
65 #endif
66
67 namespace IPC {
68 class FormDataReference;
69 }
70
71 namespace PAL {
72 class SessionID;
73 }
74
75 namespace WebCore {
76 class CertificateInfo;
77 class CurlProxySettings;
78 class DownloadID;
79 class ProtectionSpace;
80 class StorageQuotaManager;
81 class NetworkStorageSession;
82 class ResourceError;
83 class SWServer;
84 enum class IncludeHttpOnlyCookies : bool;
85 enum class StoredCredentialsPolicy : uint8_t;
86 enum class StorageAccessPromptWasShown : bool;
87 enum class StorageAccessWasGranted : bool;
88 struct ClientOrigin;
89 struct MessageWithMessagePorts;
90 struct SecurityOriginData;
91 struct SoupNetworkProxySettings;
92 struct ServiceWorkerClientIdentifier;
93 }
94
95 namespace WebKit {
96
97 class AuthenticationManager;
98 class NetworkConnectionToWebProcess;
99 class NetworkProcessSupplement;
100 class NetworkProximityManager;
101 class NetworkResourceLoader;
102 class StorageManagerSet;
103 class WebSWServerConnection;
104 class WebSWServerToContextConnection;
105 enum class ShouldGrandfatherStatistics : bool;
106 enum class StorageAccessStatus : uint8_t;
107 enum class WebsiteDataFetchOption;
108 enum class WebsiteDataType;
109 struct NetworkProcessCreationParameters;
110 struct WebsiteDataStoreParameters;
111
112 #if ENABLE(SERVICE_WORKER)
113 class WebSWOriginStore;
114 #endif
115
116 namespace NetworkCache {
117 enum class CacheOption : uint8_t;
118 }
119
120 namespace CacheStorage {
121 class Engine;
122 }
123
124 class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client, public ThreadSafeRefCounted<NetworkProcess>
125 #if ENABLE(INDEXED_DATABASE)
126     , public WebCore::IDBServer::IDBBackingStoreTemporaryFileHandler
127 #endif
128     , public CanMakeWeakPtr<NetworkProcess>
129 {
130     WTF_MAKE_NONCOPYABLE(NetworkProcess);
131 public:
132     using RegistrableDomain = WebCore::RegistrableDomain;
133     using TopFrameDomain = WebCore::RegistrableDomain;
134     using SubFrameDomain = WebCore::RegistrableDomain;
135     using SubResourceDomain = WebCore::RegistrableDomain;
136     using RedirectDomain = WebCore::RegistrableDomain;
137     using RedirectedFromDomain = WebCore::RegistrableDomain;
138     using RedirectedToDomain = WebCore::RegistrableDomain;
139     using NavigatedFromDomain = WebCore::RegistrableDomain;
140     using NavigatedToDomain = WebCore::RegistrableDomain;
141     using DomainInNeedOfStorageAccess = WebCore::RegistrableDomain;
142     using OpenerDomain = WebCore::RegistrableDomain;
143
144     NetworkProcess(AuxiliaryProcessInitializationParameters&&);
145     ~NetworkProcess();
146     static constexpr ProcessType processType = ProcessType::Network;
147
148     template <typename T>
149     T* supplement()
150     {
151         return static_cast<T*>(m_supplements.get(T::supplementName()));
152     }
153
154     template <typename T>
155     void addSupplement()
156     {
157         m_supplements.add(T::supplementName(), makeUnique<T>(*this));
158     }
159
160     void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess&);
161
162     AuthenticationManager& authenticationManager();
163     DownloadManager& downloadManager();
164
165     void setSession(PAL::SessionID, std::unique_ptr<NetworkSession>&&);
166     NetworkSession* networkSession(PAL::SessionID) const final;
167     void destroySession(PAL::SessionID);
168
169     void forEachNetworkSession(const Function<void(NetworkSession&)>&);
170
171     void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
172     WebCore::NetworkStorageSession* storageSession(const PAL::SessionID&) const;
173     WebCore::NetworkStorageSession& defaultStorageSession() const;
174     std::unique_ptr<WebCore::NetworkStorageSession> newTestingSession(const PAL::SessionID&);
175 #if PLATFORM(COCOA)
176     void ensureSession(const PAL::SessionID&, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
177 #else
178     void ensureSession(const PAL::SessionID&, const String& identifier);
179 #endif
180
181     bool canHandleHTTPSServerTrustEvaluation() const { return m_canHandleHTTPSServerTrustEvaluation; }
182
183     void processWillSuspendImminently();
184     void processWillSuspendImminentlyForTestingSync(CompletionHandler<void()>&&);
185     void prepareToSuspend();
186     void cancelPrepareToSuspend();
187     void processDidResume();
188     void resume();
189
190     // Diagnostic messages logging.
191     void logDiagnosticMessage(WebPageProxyIdentifier, const String& message, const String& description, WebCore::ShouldSample);
192     void logDiagnosticMessageWithResult(WebPageProxyIdentifier, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
193     void logDiagnosticMessageWithValue(WebPageProxyIdentifier, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
194
195 #if PLATFORM(COCOA)
196     RetainPtr<CFDataRef> sourceApplicationAuditData() const;
197     bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
198 #endif
199 #if PLATFORM(COCOA) || USE(SOUP)
200     void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
201     void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
202     void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
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>, Vector<std::pair<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 setUseITPDatabase(PAL::SessionID, bool value);
227     void setMaxStatisticsEntries(PAL::SessionID, uint64_t maximumEntryCount, CompletionHandler<void()>&&);
228     void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
229     void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
230     void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
231     void setPruneEntriesDownTo(PAL::SessionID, uint64_t pruneTargetCount, CompletionHandler<void()>&&);
232     void hadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
233     void hasLocalStorage(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
234     void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&);
235     void logFrameNavigation(PAL::SessionID, const NavigatedToDomain&, const TopFrameDomain&, const NavigatedFromDomain&, bool isRedirect, bool isMainFrame);
236     void logUserInteraction(PAL::SessionID, const TopFrameDomain&, CompletionHandler<void()>&&);
237     void removePrevalentDomains(PAL::SessionID, const Vector<RegistrableDomain>&);
238     void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&);
239     void resetParametersToDefaultValues(PAL::SessionID, CompletionHandler<void()>&&);
240     void scheduleClearInMemoryAndPersistent(PAL::SessionID, Optional<WallTime> modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&);
241     void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&);
242     void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&);
243     void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&);
244     void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
245     void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
246     void setLastSeen(PAL::SessionID, const RegistrableDomain&, Seconds, CompletionHandler<void()>&&);
247     void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
248     void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool value, CompletionHandler<void()>&&);
249     void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool value, CompletionHandler<void()>&&);
250     void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
251     void setResourceLoadStatisticsEnabled(bool);
252     void setResourceLoadStatisticsLogTestingEvent(bool);
253     void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&d);
254     void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool value, CompletionHandler<void()>&&);
255     void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
256     void setSubresourceUnderTopFrameDomain(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
257     void setSubresourceUniqueRedirectTo(PAL::SessionID, const SubResourceDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
258     void setSubresourceUniqueRedirectFrom(PAL::SessionID, const SubResourceDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
259     void setTimeToLiveUserInteraction(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
260     void setTopFrameUniqueRedirectTo(PAL::SessionID, const TopFrameDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
261     void setTopFrameUniqueRedirectFrom(PAL::SessionID, const TopFrameDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
262     void registrableDomainsWithWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, bool shouldNotifyPage, CompletionHandler<void(HashSet<RegistrableDomain>&&)>&&);
263     void didCommitCrossSiteLoadWithDataTransfer(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, OptionSet<WebCore::CrossSiteNavigationDataTransfer::Flag>, WebPageProxyIdentifier, WebCore::PageIdentifier);
264     void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
265     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
266     void hasIsolatedSession(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
267     bool isITPDatabaseEnabled() const { return m_isITPDatabaseEnabled; }
268 #endif
269
270     using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
271     void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
272
273     void setSessionIsControlledByAutomation(PAL::SessionID, bool);
274     bool sessionIsControlledByAutomation(PAL::SessionID) const;
275
276     void connectionToWebProcessClosed(IPC::Connection&);
277     void getLocalStorageOriginDetails(PAL::SessionID, CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&&);
278
279 #if ENABLE(CONTENT_EXTENSIONS)
280     NetworkContentRuleListManager& networkContentRuleListManager() { return m_networkContentRuleListManager; }
281 #endif
282
283 #if ENABLE(INDEXED_DATABASE)
284     WebCore::IDBServer::IDBServer& idbServer(PAL::SessionID);
285     // WebCore::IDBServer::IDBBackingStoreFileHandler.
286     void accessToTemporaryFileComplete(const String& path) final;
287 #endif
288
289     void syncLocalStorage(CompletionHandler<void()>&&);
290     void clearLegacyPrivateBrowsingLocalStorage();
291
292     void updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID, const WebCore::ClientOrigin&);
293
294 #if ENABLE(SANDBOX_EXTENSIONS)
295     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
296 #endif
297
298     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::Decoder&);
299
300 #if ENABLE(SERVICE_WORKER)
301     WebCore::SWServer* swServerForSessionIfExists(PAL::SessionID sessionID) { return m_swServers.get(sessionID); }
302     WebCore::SWServer& swServerForSession(PAL::SessionID);
303     void registerSWServerConnection(WebSWServerConnection&);
304     void unregisterSWServerConnection(WebSWServerConnection&);
305     
306     void forEachSWServer(const Function<void(WebCore::SWServer&)>&);
307 #endif
308
309 #if PLATFORM(IOS_FAMILY)
310     bool parentProcessHasServiceWorkerEntitlement() const;
311 #else
312     bool parentProcessHasServiceWorkerEntitlement() const { return true; }
313 #endif
314
315 #if PLATFORM(COCOA)
316     NetworkHTTPSUpgradeChecker& networkHTTPSUpgradeChecker();
317 #endif
318
319     const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
320
321     void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
322     void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }
323
324     CacheStorage::Engine* findCacheEngine(const PAL::SessionID&);
325     CacheStorage::Engine& ensureCacheEngine(const PAL::SessionID&, Function<Ref<CacheStorage::Engine>()>&&);
326     void removeCacheEngine(const PAL::SessionID&);
327     void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
328
329     void storeAdClickAttribution(PAL::SessionID, WebCore::AdClickAttribution&&);
330     void dumpAdClickAttribution(PAL::SessionID, CompletionHandler<void(String)>&&);
331     void clearAdClickAttribution(PAL::SessionID, CompletionHandler<void()>&&);
332     void setAdClickAttributionOverrideTimerForTesting(PAL::SessionID, bool value, CompletionHandler<void()>&&);
333     void setAdClickAttributionConversionURLForTesting(PAL::SessionID, URL&&, CompletionHandler<void()>&&);
334     void markAdClickAttributionsAsExpiredForTesting(PAL::SessionID, CompletionHandler<void()>&&);
335
336     WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
337
338     void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
339     void removeKeptAliveLoad(NetworkResourceLoader&);
340
341     const OptionSet<NetworkCache::CacheOption>& cacheOptions() const { return m_cacheOptions; }
342
343     NetworkConnectionToWebProcess* webProcessConnection(WebCore::ProcessIdentifier) const;
344     WebCore::MessagePortChannelRegistry& messagePortChannelRegistry() { return m_messagePortChannelRegistry; }
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(WebCore::ProcessIdentifier, PAL::SessionID, CompletionHandler<void(Optional<IPC::Attachment>&&)>&&);
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
397     void setCacheStorageParameters(PAL::SessionID, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
398     void initializeQuotaUsers(WebCore::StorageQuotaManager&, PAL::SessionID, const WebCore::ClientOrigin&);
399
400     // FIXME: This should take a session ID so we can identify which disk cache to delete.
401     void clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&&);
402
403     void downloadRequest(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
404     void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
405     void cancelDownload(DownloadID);
406 #if PLATFORM(COCOA)
407     void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
408 #endif
409     void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
410     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
411     void applicationDidEnterBackground();
412     void applicationWillEnterForeground();
413
414     void setCacheModel(CacheModel, String overrideCacheStorageDirectory);
415     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
416     void setCanHandleHTTPSServerTrustEvaluation(bool);
417     void getNetworkProcessStatistics(uint64_t callbackID);
418     void clearCacheForAllOrigins(uint32_t cachesToClear);
419     void setAllowsAnySSLCertificateForWebSocket(bool, CompletionHandler<void()>&&);
420     
421     void syncAllCookies();
422     void didSyncAllCookies();
423
424 #if USE(SOUP)
425     void setIgnoreTLSErrors(bool);
426     void userPreferredLanguagesChanged(const Vector<String>&);
427     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
428 #endif
429
430 #if USE(CURL)
431     void setNetworkProxySettings(PAL::SessionID, WebCore::CurlProxySettings&&);
432 #endif
433
434 #if PLATFORM(MAC)
435     static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
436 #endif
437
438     void platformSyncAllCookies(CompletionHandler<void()>&&);
439     
440     void registerURLSchemeAsSecure(const String&) const;
441     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
442     void registerURLSchemeAsLocal(const String&) const;
443     void registerURLSchemeAsNoAccess(const String&) const;
444     void registerURLSchemeAsDisplayIsolated(const String&) const;
445     void registerURLSchemeAsCORSEnabled(const String&) const;
446     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
447
448 #if ENABLE(INDEXED_DATABASE)
449     void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
450     void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
451     HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
452     Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
453 #endif
454
455 #if ENABLE(SERVICE_WORKER)
456     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
457
458     void postMessageToServiceWorker(PAL::SessionID, WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
459     
460     void disableServiceWorkerProcessTerminationDelay();
461     
462     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
463
464     void addServiceWorkerSession(PAL::SessionID, String& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
465 #endif
466
467     void postStorageTask(CrossThreadTask&&);
468     // For execution on work queue thread only.
469     void performNextStorageTask();
470     void ensurePathExists(const String& path);
471
472     void clearStorageQuota(PAL::SessionID);
473     void initializeStorageQuota(const WebsiteDataStoreParameters&);
474
475     // Connections to WebProcesses.
476     HashMap<WebCore::ProcessIdentifier, Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
477
478     bool m_hasSetCacheModel { false };
479     CacheModel m_cacheModel { CacheModel::DocumentViewer };
480     bool m_suppressMemoryPressureHandler { false };
481     bool m_diskCacheIsDisabledForTesting { false };
482     bool m_canHandleHTTPSServerTrustEvaluation { true };
483     String m_uiProcessBundleIdentifier;
484     DownloadManager m_downloadManager;
485
486     HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
487
488     typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
489     NetworkProcessSupplementMap m_supplements;
490
491     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
492     HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
493
494     HashMap<PAL::SessionID, std::unique_ptr<NetworkSession>> m_networkSessions;
495     HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
496     mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
497     bool m_shouldUseTestingNetworkStorageSession { false };
498
499     RefPtr<StorageManagerSet> m_storageManagerSet;
500
501 #if PLATFORM(COCOA)
502     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
503     void setStorageAccessAPIEnabled(bool);
504
505     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
506     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
507     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
508     dispatch_group_t m_clearCacheDispatchGroup { nullptr };
509
510     bool m_suppressesConnectionTerminationOnSystemChange { false };
511 #endif
512
513 #if ENABLE(CONTENT_EXTENSIONS)
514     NetworkContentRuleListManager m_networkContentRuleListManager;
515 #endif
516
517 #if PLATFORM(IOS_FAMILY)
518     WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
519 #endif
520
521     Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
522
523 #if ENABLE(INDEXED_DATABASE)
524     HashMap<PAL::SessionID, String> m_idbDatabasePaths;
525     HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
526 #endif
527
528     Deque<CrossThreadTask> m_storageTasks;
529     Lock m_storageTaskMutex;
530     
531 #if ENABLE(SERVICE_WORKER)
532     bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
533     HashMap<PAL::SessionID, String> m_swDatabasePaths;
534     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
535 #endif
536
537 #if PLATFORM(COCOA)
538     std::unique_ptr<NetworkHTTPSUpgradeChecker> m_networkHTTPSUpgradeChecker;
539 #endif
540
541 #if ENABLE(RESOURCE_LOAD_STATISTICS)
542     bool m_isITPDatabaseEnabled { false };
543 #endif
544     
545     class StorageQuotaManagers {
546     public:
547         uint64_t defaultQuota(const WebCore::ClientOrigin& origin) const { return origin.topOrigin == origin.clientOrigin ? m_defaultQuota : m_defaultThirdPartyQuota; }
548         void setDefaultQuotas(uint64_t defaultQuota, uint64_t defaultThirdPartyQuota)
549         {
550             m_defaultQuota = defaultQuota;
551             m_defaultThirdPartyQuota = defaultThirdPartyQuota;
552         }
553
554         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>>& managersPerOrigin() { return m_managersPerOrigin; }
555
556     private:
557         uint64_t m_defaultQuota { WebCore::StorageQuotaManager::defaultQuota() };
558         uint64_t m_defaultThirdPartyQuota { WebCore::StorageQuotaManager::defaultThirdPartyQuota() };
559         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> m_managersPerOrigin;
560     };
561     HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
562     uint32_t m_downloadMonitorSpeedMultiplier { 1 };
563
564     OptionSet<NetworkCache::CacheOption> m_cacheOptions;
565     WebCore::MessagePortChannelRegistry m_messagePortChannelRegistry;
566 };
567
568 } // namespace WebKit