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