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