2f704308edfe953a4c8e7b0d07380c1e451ffb6d
[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&, bool shouldUseTestingNetworkSession, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
177 #else
178     void ensureSession(const PAL::SessionID&, bool shouldUseTestingNetworkSession, 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 mergeStatisticForTesting(PAL::SessionID, const RegistrableDomain&, const TopFrameDomain&, Seconds lastSeen, bool hadUserInteraction, Seconds mostRecentUserInteraction, bool isGrandfathered, bool isPrevalent, bool isVeryPrevalent, unsigned dataRecordsRemoved, 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(PAL::SessionID, bool);
251     void setResourceLoadStatisticsLogTestingEvent(bool);
252     void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&d);
253     void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool value, CompletionHandler<void()>&&);
254     void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
255     void setSubresourceUnderTopFrameDomain(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
256     void setSubresourceUniqueRedirectTo(PAL::SessionID, const SubResourceDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
257     void setSubresourceUniqueRedirectFrom(PAL::SessionID, const SubResourceDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
258     void setTimeToLiveUserInteraction(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
259     void setTopFrameUniqueRedirectTo(PAL::SessionID, const TopFrameDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
260     void setTopFrameUniqueRedirectFrom(PAL::SessionID, const TopFrameDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
261     void registrableDomainsWithWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, bool shouldNotifyPage, CompletionHandler<void(HashSet<RegistrableDomain>&&)>&&);
262     void didCommitCrossSiteLoadWithDataTransfer(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, OptionSet<WebCore::CrossSiteNavigationDataTransfer::Flag>, WebPageProxyIdentifier, WebCore::PageIdentifier);
263     void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
264     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
265     void hasIsolatedSession(PAL::SessionID, const WebCore::RegistrableDomain&, CompletionHandler<void(bool)>&&) const;
266     bool isITPDatabaseEnabled() const { return m_isITPDatabaseEnabled; }
267     void setShouldDowngradeReferrerForTesting(bool, CompletionHandler<void()>&&);
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
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 registerURLSchemeAsCORSEnabled(const String&) const;
443     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
444
445 #if ENABLE(INDEXED_DATABASE)
446     void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
447     void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
448     HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
449     Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
450 #endif
451
452 #if ENABLE(SERVICE_WORKER)
453     void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
454
455     void postMessageToServiceWorker(PAL::SessionID, WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
456     
457     void disableServiceWorkerProcessTerminationDelay();
458     
459     WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
460
461     void addServiceWorkerSession(PAL::SessionID, bool processTerminationDelayEnabled, HashSet<String>&& registeredSchemes, String&& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
462 #endif
463
464     void postStorageTask(CrossThreadTask&&);
465     // For execution on work queue thread only.
466     void performNextStorageTask();
467     void ensurePathExists(const String& path);
468
469     void clearStorageQuota(PAL::SessionID);
470     void initializeStorageQuota(const WebsiteDataStoreParameters&);
471
472     // Connections to WebProcesses.
473     HashMap<WebCore::ProcessIdentifier, Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
474
475     bool m_hasSetCacheModel { false };
476     CacheModel m_cacheModel { CacheModel::DocumentViewer };
477     bool m_suppressMemoryPressureHandler { false };
478     String m_uiProcessBundleIdentifier;
479     DownloadManager m_downloadManager;
480
481     HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
482
483     typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
484     NetworkProcessSupplementMap m_supplements;
485
486     HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
487     HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
488
489     HashMap<PAL::SessionID, std::unique_ptr<NetworkSession>> m_networkSessions;
490     HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
491     mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
492
493     RefPtr<StorageManagerSet> m_storageManagerSet;
494
495 #if PLATFORM(COCOA)
496     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
497     void setStorageAccessAPIEnabled(bool);
498
499     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
500     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
501     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
502     dispatch_group_t m_clearCacheDispatchGroup { nullptr };
503
504     bool m_suppressesConnectionTerminationOnSystemChange { false };
505 #endif
506
507 #if ENABLE(CONTENT_EXTENSIONS)
508     NetworkContentRuleListManager m_networkContentRuleListManager;
509 #endif
510
511 #if PLATFORM(IOS_FAMILY)
512     WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
513 #endif
514
515     Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
516
517 #if ENABLE(INDEXED_DATABASE)
518     HashMap<PAL::SessionID, String> m_idbDatabasePaths;
519     HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
520 #endif
521
522     Deque<CrossThreadTask> m_storageTasks;
523     Lock m_storageTaskMutex;
524     
525 #if ENABLE(SERVICE_WORKER)
526     struct ServiceWorkerInfo {
527         String databasePath;
528         bool processTerminationDelayEnabled { true };
529         HashSet<String> registeredSchemes;
530     };
531     HashMap<PAL::SessionID, ServiceWorkerInfo> m_serviceWorkerInfo;
532     HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
533 #endif
534
535 #if PLATFORM(COCOA)
536     std::unique_ptr<NetworkHTTPSUpgradeChecker> m_networkHTTPSUpgradeChecker;
537 #endif
538
539 #if ENABLE(RESOURCE_LOAD_STATISTICS)
540     bool m_isITPDatabaseEnabled { false };
541 #endif
542     
543     class StorageQuotaManagers {
544     public:
545         uint64_t defaultQuota(const WebCore::ClientOrigin& origin) const { return origin.topOrigin == origin.clientOrigin ? m_defaultQuota : m_defaultThirdPartyQuota; }
546         void setDefaultQuotas(uint64_t defaultQuota, uint64_t defaultThirdPartyQuota)
547         {
548             m_defaultQuota = defaultQuota;
549             m_defaultThirdPartyQuota = defaultThirdPartyQuota;
550         }
551
552         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>>& managersPerOrigin() { return m_managersPerOrigin; }
553
554     private:
555         uint64_t m_defaultQuota { WebCore::StorageQuotaManager::defaultQuota() };
556         uint64_t m_defaultThirdPartyQuota { WebCore::StorageQuotaManager::defaultThirdPartyQuota() };
557         HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> m_managersPerOrigin;
558     };
559     HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
560
561     OptionSet<NetworkCache::CacheOption> m_cacheOptions;
562     WebCore::MessagePortChannelRegistry m_messagePortChannelRegistry;
563 };
564
565 } // namespace WebKit