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