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