Remove unused WebProcessPool::setCanHandleHTTPSServerTrustEvaluation
[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     void processWillSuspendImminently();
182     void processWillSuspendImminentlyForTestingSync(CompletionHandler<void()>&&);
183     void prepareToSuspend();
184     void cancelPrepareToSuspend();
185     void processDidResume();
186     void resume();
187
188     // Diagnostic messages logging.
189     void logDiagnosticMessage(WebPageProxyIdentifier, const String& message, const String& description, WebCore::ShouldSample);
190     void logDiagnosticMessageWithResult(WebPageProxyIdentifier, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
191     void logDiagnosticMessageWithValue(WebPageProxyIdentifier, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
192
193 #if PLATFORM(COCOA)
194     RetainPtr<CFDataRef> sourceApplicationAuditData() const;
195     bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
196 #endif
197 #if PLATFORM(COCOA) || USE(SOUP)
198     void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
199     void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
200     void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
201 #endif
202
203     void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceResponse&);
204
205     void prefetchDNS(const String&);
206
207     void addWebsiteDataStore(WebsiteDataStoreParameters&&);
208
209 #if ENABLE(RESOURCE_LOAD_STATISTICS)
210     void clearPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
211     void clearUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
212     void deleteWebsiteDataForRegistrableDomains(PAL::SessionID, OptionSet<WebsiteDataType>, Vector<std::pair<RegistrableDomain, WebsiteDataToRemove>>&&, bool shouldNotifyPage, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&&);
213     void deleteCookiesForTesting(PAL::SessionID, RegistrableDomain, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
214     void dumpResourceLoadStatistics(PAL::SessionID, CompletionHandler<void(String)>&&);
215     void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<RegistrableDomain>& domainsToBlock, CompletionHandler<void()>&&);
216     void isGrandfathered(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
217     void isPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
218     void isVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
219     void setAgeCapForClientSideCookies(PAL::SessionID, Optional<Seconds>, CompletionHandler<void()>&&);
220     void isRegisteredAsRedirectingTo(PAL::SessionID, const RedirectedFromDomain&, const RedirectedToDomain&, CompletionHandler<void(bool)>&&);
221     void isRegisteredAsSubFrameUnder(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
222     void isRegisteredAsSubresourceUnder(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
223     void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&);
224     void setUseITPDatabase(PAL::SessionID, bool value);
225     void setMaxStatisticsEntries(PAL::SessionID, uint64_t maximumEntryCount, CompletionHandler<void()>&&);
226     void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
227     void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
228     void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
229     void setPruneEntriesDownTo(PAL::SessionID, uint64_t pruneTargetCount, CompletionHandler<void()>&&);
230     void hadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
231     void hasLocalStorage(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
232     void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&);
233     void logFrameNavigation(PAL::SessionID, const NavigatedToDomain&, const TopFrameDomain&, const NavigatedFromDomain&, bool isRedirect, bool isMainFrame);
234     void logUserInteraction(PAL::SessionID, const TopFrameDomain&, CompletionHandler<void()>&&);
235     void removePrevalentDomains(PAL::SessionID, const Vector<RegistrableDomain>&);
236     void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&);
237     void resetParametersToDefaultValues(PAL::SessionID, CompletionHandler<void()>&&);
238     void scheduleClearInMemoryAndPersistent(PAL::SessionID, Optional<WallTime> modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&);
239     void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&);
240     void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&);
241     void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&);
242     void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
243     void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
244     void setLastSeen(PAL::SessionID, const RegistrableDomain&, Seconds, CompletionHandler<void()>&&);
245     void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
246     void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool value, CompletionHandler<void()>&&);
247     void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool value, CompletionHandler<void()>&&);
248     void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
249     void setResourceLoadStatisticsEnabled(bool);
250     void setResourceLoadStatisticsLogTestingEvent(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>, WebPageProxyIdentifier, WebCore::PageIdentifier);
262     void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
263     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
264     void hasIsolatedSession(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
265     bool isITPDatabaseEnabled() const { return m_isITPDatabaseEnabled; }
266     void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
267 #endif
268
269     using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
270     void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
271
272     void setSessionIsControlledByAutomation(PAL::SessionID, bool);
273     bool sessionIsControlledByAutomation(PAL::SessionID) const;
274
275     void connectionToWebProcessClosed(IPC::Connection&);
276     void getLocalStorageOriginDetails(PAL::SessionID, CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&&);
277
278 #if ENABLE(CONTENT_EXTENSIONS)
279     NetworkContentRuleListManager& networkContentRuleListManager() { return m_networkContentRuleListManager; }
280 #endif
281
282 #if ENABLE(INDEXED_DATABASE)
283     WebCore::IDBServer::IDBServer& idbServer(PAL::SessionID);
284     // WebCore::IDBServer::IDBBackingStoreFileHandler.
285     void accessToTemporaryFileComplete(const String& path) final;
286 #endif
287
288     void syncLocalStorage(CompletionHandler<void()>&&);
289     void clearLegacyPrivateBrowsingLocalStorage();
290
291     void updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID, const WebCore::ClientOrigin&);
292
293 #if ENABLE(SANDBOX_EXTENSIONS)
294     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
295 #endif
296
297     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::Decoder&);
298
299 #if ENABLE(SERVICE_WORKER)
300     WebCore::SWServer* swServerForSessionIfExists(PAL::SessionID sessionID) { return m_swServers.get(sessionID); }
301     WebCore::SWServer& swServerForSession(PAL::SessionID);
302     void registerSWServerConnection(WebSWServerConnection&);
303     void unregisterSWServerConnection(WebSWServerConnection&);
304     
305     void forEachSWServer(const Function<void(WebCore::SWServer&)>&);
306 #endif
307
308 #if PLATFORM(IOS_FAMILY)
309     bool parentProcessHasServiceWorkerEntitlement() const;
310 #else
311     bool parentProcessHasServiceWorkerEntitlement() const { return true; }
312 #endif
313
314 #if PLATFORM(COCOA)
315     NetworkHTTPSUpgradeChecker& networkHTTPSUpgradeChecker();
316 #endif
317
318     const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
319
320     void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
321     void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }
322
323     CacheStorage::Engine* findCacheEngine(const PAL::SessionID&);
324     CacheStorage::Engine& ensureCacheEngine(const PAL::SessionID&, Function<Ref<CacheStorage::Engine>()>&&);
325     void removeCacheEngine(const PAL::SessionID&);
326     void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
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     void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
338     void removeKeptAliveLoad(NetworkResourceLoader&);
339
340     const OptionSet<NetworkCache::CacheOption>& cacheOptions() const { return m_cacheOptions; }
341
342     NetworkConnectionToWebProcess* webProcessConnection(WebCore::ProcessIdentifier) const;
343     WebCore::MessagePortChannelRegistry& messagePortChannelRegistry() { return m_messagePortChannelRegistry; }
344
345 private:
346     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
347     std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
348
349     void terminate() override;
350     void platformTerminate();
351
352     void lowMemoryHandler(Critical);
353     
354     void processDidTransitionToForeground();
355     void processDidTransitionToBackground();
356     void platformProcessDidTransitionToForeground();
357     void platformProcessDidTransitionToBackground();
358
359     enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
360     void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
361     void platformPrepareToSuspend(CompletionHandler<void()>&&);
362     void platformProcessDidResume();
363
364     // AuxiliaryProcess
365     void initializeProcess(const AuxiliaryProcessInitializationParameters&) override;
366     void initializeProcessName(const AuxiliaryProcessInitializationParameters&) override;
367     void initializeSandbox(const AuxiliaryProcessInitializationParameters&, SandboxInitializationParameters&) override;
368     void initializeConnection(IPC::Connection*) override;
369     bool shouldTerminate() override;
370
371     // IPC::Connection::Client
372     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
373     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
374     void didClose(IPC::Connection&) override;
375
376     // DownloadManager::Client
377     void didCreateDownload() override;
378     void didDestroyDownload() override;
379     IPC::Connection* downloadProxyConnection() override;
380     IPC::Connection* parentProcessConnectionForDownloads() override { return parentProcessConnection(); }
381     AuthenticationManager& downloadsAuthenticationManager() override;
382     void pendingDownloadCanceled(DownloadID) override;
383     uint32_t downloadMonitorSpeedMultiplier() const override { return m_downloadMonitorSpeedMultiplier; }
384
385     // Message Handlers
386     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
387     void initializeNetworkProcess(NetworkProcessCreationParameters&&);
388     void createNetworkConnectionToWebProcess(WebCore::ProcessIdentifier, PAL::SessionID, CompletionHandler<void(Optional<IPC::Attachment>&&)>&&);
389
390     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
391     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, uint64_t callbackID);
392     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostnames, uint64_t callbackID);
393
394     void clearCachedCredentials();
395
396     void setCacheStorageParameters(PAL::SessionID, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
397     void initializeQuotaUsers(WebCore::StorageQuotaManager&, PAL::SessionID, const WebCore::ClientOrigin&);
398
399     // FIXME: This should take a session ID so we can identify which disk cache to delete.
400     void clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&&);
401
402     void downloadRequest(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
403     void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
404     void cancelDownload(DownloadID);
405 #if PLATFORM(COCOA)
406     void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
407 #endif
408     void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
409     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
410     void applicationDidEnterBackground();
411     void applicationWillEnterForeground();
412
413     void setCacheModel(CacheModel, String overrideCacheStorageDirectory);
414     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
415     void getNetworkProcessStatistics(uint64_t callbackID);
416     void clearCacheForAllOrigins(uint32_t cachesToClear);
417     void setAllowsAnySSLCertificateForWebSocket(bool, CompletionHandler<void()>&&);
418     
419     void syncAllCookies();
420     void didSyncAllCookies();
421
422 #if USE(SOUP)
423     void setIgnoreTLSErrors(bool);
424     void userPreferredLanguagesChanged(const Vector<String>&);
425     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
426 #endif
427
428 #if USE(CURL)
429     void setNetworkProxySettings(PAL::SessionID, WebCore::CurlProxySettings&&);
430 #endif
431
432 #if PLATFORM(MAC)
433     static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
434 #endif
435
436     void platformSyncAllCookies(CompletionHandler<void()>&&);
437     
438     void registerURLSchemeAsSecure(const String&) const;
439     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
440     void registerURLSchemeAsLocal(const String&) const;
441     void registerURLSchemeAsNoAccess(const String&) const;
442     void registerURLSchemeAsDisplayIsolated(const String&) const;
443     void registerURLSchemeAsCORSEnabled(const String&) const;
444     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
445
446 #if ENABLE(INDEXED_DATABASE)
447     void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
448     void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
449     HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
450     Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
451 #endif
452
453 #if ENABLE(SERVICE_WORKER)
454     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
455
456     void postMessageToServiceWorker(PAL::SessionID, WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
457     
458     void disableServiceWorkerProcessTerminationDelay();
459     
460     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) 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     HashMap<WebCore::ProcessIdentifier, Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
475
476     bool m_hasSetCacheModel { false };
477     CacheModel m_cacheModel { CacheModel::DocumentViewer };
478     bool m_suppressMemoryPressureHandler { false };
479     bool m_diskCacheIsDisabledForTesting { false };
480     String m_uiProcessBundleIdentifier;
481     DownloadManager m_downloadManager;
482
483     HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
484
485     typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
486     NetworkProcessSupplementMap m_supplements;
487
488     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
489     HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
490
491     HashMap<PAL::SessionID, std::unique_ptr<NetworkSession>> m_networkSessions;
492     HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
493     mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
494     bool m_shouldUseTestingNetworkStorageSession { false };
495
496     RefPtr<StorageManagerSet> m_storageManagerSet;
497
498 #if PLATFORM(COCOA)
499     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
500     void setStorageAccessAPIEnabled(bool);
501
502     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
503     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
504     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
505     dispatch_group_t m_clearCacheDispatchGroup { nullptr };
506
507     bool m_suppressesConnectionTerminationOnSystemChange { false };
508 #endif
509
510 #if ENABLE(CONTENT_EXTENSIONS)
511     NetworkContentRuleListManager m_networkContentRuleListManager;
512 #endif
513
514 #if PLATFORM(IOS_FAMILY)
515     WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
516 #endif
517
518     Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
519
520 #if ENABLE(INDEXED_DATABASE)
521     HashMap<PAL::SessionID, String> m_idbDatabasePaths;
522     HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
523 #endif
524
525     Deque<CrossThreadTask> m_storageTasks;
526     Lock m_storageTaskMutex;
527     
528 #if ENABLE(SERVICE_WORKER)
529     bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
530     HashMap<PAL::SessionID, String> m_swDatabasePaths;
531     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
532 #endif
533
534 #if PLATFORM(COCOA)
535     std::unique_ptr<NetworkHTTPSUpgradeChecker> m_networkHTTPSUpgradeChecker;
536 #endif
537
538 #if ENABLE(RESOURCE_LOAD_STATISTICS)
539     bool m_isITPDatabaseEnabled { false };
540 #endif
541     
542     class StorageQuotaManagers {
543     public:
544         uint64_t defaultQuota(const WebCore::ClientOrigin& origin) const { return origin.topOrigin == origin.clientOrigin ? m_defaultQuota : m_defaultThirdPartyQuota; }
545         void setDefaultQuotas(uint64_t defaultQuota, uint64_t defaultThirdPartyQuota)
546         {
547             m_defaultQuota = defaultQuota;
548             m_defaultThirdPartyQuota = defaultThirdPartyQuota;
549         }
550
551         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>>& managersPerOrigin() { return m_managersPerOrigin; }
552
553     private:
554         uint64_t m_defaultQuota { WebCore::StorageQuotaManager::defaultQuota() };
555         uint64_t m_defaultThirdPartyQuota { WebCore::StorageQuotaManager::defaultThirdPartyQuota() };
556         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> m_managersPerOrigin;
557     };
558     HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
559     uint32_t m_downloadMonitorSpeedMultiplier { 1 };
560
561     OptionSet<NetworkCache::CacheOption> m_cacheOptions;
562     WebCore::MessagePortChannelRegistry m_messagePortChannelRegistry;
563 };
564
565 } // namespace WebKit