6347c18c7ddfdb3d8f2e1f63fced848734178f93
[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
185     // Diagnostic messages logging.
186     void logDiagnosticMessage(uint64_t webPageID, const String& message, const String& description, WebCore::ShouldSample);
187     void logDiagnosticMessageWithResult(uint64_t webPageID, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
188     void logDiagnosticMessageWithValue(uint64_t webPageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
189
190 #if PLATFORM(COCOA)
191     RetainPtr<CFDataRef> sourceApplicationAuditData() const;
192     void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
193     void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
194     void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
195     bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
196 #endif
197
198     void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceResponse&);
199
200     void prefetchDNS(const String&);
201
202     void addWebsiteDataStore(WebsiteDataStoreParameters&&);
203
204 #if ENABLE(RESOURCE_LOAD_STATISTICS)
205     void clearPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
206     void clearUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
207     void deleteWebsiteDataForRegistrableDomains(PAL::SessionID, OptionSet<WebsiteDataType>, HashMap<RegistrableDomain, WebsiteDataToRemove>&&, bool shouldNotifyPage, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&&);
208     void deleteCookiesForTesting(PAL::SessionID, RegistrableDomain, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
209     void dumpResourceLoadStatistics(PAL::SessionID, CompletionHandler<void(String)>&&);
210     void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<RegistrableDomain>& domainsToBlock, CompletionHandler<void()>&&);
211     void isGrandfathered(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
212     void isPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
213     void isVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
214     void setAgeCapForClientSideCookies(PAL::SessionID, Optional<Seconds>, CompletionHandler<void()>&&);
215     void isRegisteredAsRedirectingTo(PAL::SessionID, const RedirectedFromDomain&, const RedirectedToDomain&, CompletionHandler<void(bool)>&&);
216     void isRegisteredAsSubFrameUnder(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
217     void isRegisteredAsSubresourceUnder(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
218     void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&);
219     void setMaxStatisticsEntries(PAL::SessionID, uint64_t maximumEntryCount, CompletionHandler<void()>&&);
220     void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
221     void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
222     void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
223     void setPruneEntriesDownTo(PAL::SessionID, uint64_t pruneTargetCount, CompletionHandler<void()>&&);
224     void hadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
225     void hasStorageAccessForFrame(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, FrameID, PageID, CompletionHandler<void(bool)>&&);
226     void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&);
227     void grantStorageAccess(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, Optional<FrameID>, PageID, bool userWasPrompted, CompletionHandler<void(bool)>&&);
228     void hasStorageAccess(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, Optional<FrameID>, PageID, CompletionHandler<void(bool)>&&);
229     void logFrameNavigation(PAL::SessionID, const NavigatedToDomain&, const TopFrameDomain&, const NavigatedFromDomain&, bool isRedirect, bool isMainFrame);
230     void logUserInteraction(PAL::SessionID, const TopFrameDomain&, CompletionHandler<void()>&&);
231     void removeAllStorageAccess(PAL::SessionID, CompletionHandler<void()>&&);
232     void removePrevalentDomains(PAL::SessionID, const Vector<RegistrableDomain>&);
233     void requestStorageAccess(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, Optional<FrameID>, PageID, CompletionHandler<void(StorageAccessStatus)>&&);
234     void requestStorageAccessGranted(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, FrameID, PageID, CompletionHandler<void(bool)>&&);
235     void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&);
236     void resetParametersToDefaultValues(PAL::SessionID, CompletionHandler<void()>&&);
237     void scheduleClearInMemoryAndPersistent(PAL::SessionID, Optional<WallTime> modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&);
238     void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&);
239     void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&);
240     void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&);
241     void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
242     void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
243     void setLastSeen(PAL::SessionID, const RegistrableDomain&, Seconds, CompletionHandler<void()>&&);
244     void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
245     void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool value, CompletionHandler<void()>&&);
246     void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool value, CompletionHandler<void()>&&);
247     void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool value, CompletionHandler<void()>&&);
248     void setResourceLoadStatisticsEnabled(bool);
249     void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&d);
250     void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool value, CompletionHandler<void()>&&);
251     void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
252     void setSubresourceUnderTopFrameDomain(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&);
253     void setSubresourceUniqueRedirectTo(PAL::SessionID, const SubResourceDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
254     void setSubresourceUniqueRedirectFrom(PAL::SessionID, const SubResourceDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
255     void setTimeToLiveUserInteraction(PAL::SessionID, Seconds, CompletionHandler<void()>&&);
256     void setTopFrameUniqueRedirectTo(PAL::SessionID, const TopFrameDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&);
257     void setTopFrameUniqueRedirectFrom(PAL::SessionID, const TopFrameDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&);
258     void registrableDomainsWithWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, bool shouldNotifyPage, CompletionHandler<void(HashSet<RegistrableDomain>&&)>&&);
259     void committedCrossSiteLoadWithLinkDecoration(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, uint64_t pageID, CompletionHandler<void()>&&);
260     void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
261     void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
262 #endif
263
264     using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
265     void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
266
267     void preconnectTo(const URL&, WebCore::StoredCredentialsPolicy);
268
269     void setSessionIsControlledByAutomation(PAL::SessionID, bool);
270     bool sessionIsControlledByAutomation(PAL::SessionID) const;
271
272 #if ENABLE(CONTENT_EXTENSIONS)
273     NetworkContentRuleListManager& networkContentRuleListManager() { return m_networkContentRuleListManager; }
274 #endif
275
276 #if ENABLE(INDEXED_DATABASE)
277     WebCore::IDBServer::IDBServer& idbServer(PAL::SessionID);
278     // WebCore::IDBServer::IDBBackingStoreFileHandler.
279     void accessToTemporaryFileComplete(const String& path) final;
280     void setIDBPerOriginQuota(uint64_t);
281 #endif
282     void updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID, const WebCore::ClientOrigin&);
283
284 #if ENABLE(SANDBOX_EXTENSIONS)
285     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
286 #endif
287
288     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::Decoder&);
289
290 #if ENABLE(SERVICE_WORKER)
291     WebSWServerToContextConnection* serverToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&);
292     void createServerToContextConnection(const WebCore::RegistrableDomain&, Optional<PAL::SessionID>);
293     
294     WebCore::SWServer& swServerForSession(PAL::SessionID);
295     void registerSWServerConnection(WebSWServerConnection&);
296     void unregisterSWServerConnection(WebSWServerConnection&);
297     
298     void swContextConnectionMayNoLongerBeNeeded(WebSWServerToContextConnection&);
299     
300     WebSWServerToContextConnection* connectionToContextProcessFromIPCConnection(IPC::Connection&);
301     void connectionToContextProcessWasClosed(Ref<WebSWServerToContextConnection>&&);
302 #endif
303
304 #if PLATFORM(IOS_FAMILY)
305     bool parentProcessHasServiceWorkerEntitlement() const;
306 #else
307     bool parentProcessHasServiceWorkerEntitlement() const { return true; }
308 #endif
309
310 #if PLATFORM(COCOA)
311     NetworkHTTPSUpgradeChecker& networkHTTPSUpgradeChecker() { return m_networkHTTPSUpgradeChecker; }
312 #endif
313
314     const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
315
316     void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
317     void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }
318
319     CacheStorage::Engine* findCacheEngine(const PAL::SessionID&);
320     CacheStorage::Engine& ensureCacheEngine(const PAL::SessionID&, Function<Ref<CacheStorage::Engine>()>&&);
321     void removeCacheEngine(const PAL::SessionID&);
322     void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
323
324     NetworkBlobRegistry& networkBlobRegistry() override { return m_networkBlobRegistry; }
325
326     void storeAdClickAttribution(PAL::SessionID, WebCore::AdClickAttribution&&);
327     void dumpAdClickAttribution(PAL::SessionID, CompletionHandler<void(String)>&&);
328     void clearAdClickAttribution(PAL::SessionID, CompletionHandler<void()>&&);
329
330     WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
331
332 private:
333     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
334     std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
335
336     void terminate() override;
337     void platformTerminate();
338
339     void lowMemoryHandler(Critical);
340     
341     void processDidTransitionToForeground();
342     void processDidTransitionToBackground();
343     void platformProcessDidTransitionToForeground();
344     void platformProcessDidTransitionToBackground();
345
346     enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
347     void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
348     void platformPrepareToSuspend(CompletionHandler<void()>&&);
349     void platformProcessDidResume();
350
351     // AuxiliaryProcess
352     void initializeProcess(const AuxiliaryProcessInitializationParameters&) override;
353     void initializeProcessName(const AuxiliaryProcessInitializationParameters&) override;
354     void initializeSandbox(const AuxiliaryProcessInitializationParameters&, SandboxInitializationParameters&) override;
355     void initializeConnection(IPC::Connection*) override;
356     bool shouldTerminate() override;
357
358     // IPC::Connection::Client
359     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
360     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
361     void didClose(IPC::Connection&) override;
362
363     // DownloadManager::Client
364     void didCreateDownload() override;
365     void didDestroyDownload() override;
366     IPC::Connection* downloadProxyConnection() override;
367     IPC::Connection* parentProcessConnectionForDownloads() override { return parentProcessConnection(); }
368     AuthenticationManager& downloadsAuthenticationManager() override;
369     void pendingDownloadCanceled(DownloadID) override;
370     uint32_t downloadMonitorSpeedMultiplier() const override { return m_downloadMonitorSpeedMultiplier; }
371
372     // Message Handlers
373     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
374     void initializeNetworkProcess(NetworkProcessCreationParameters&&);
375     void createNetworkConnectionToWebProcess(bool isServiceWorkerProcess, WebCore::RegistrableDomain&&);
376
377     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
378     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, uint64_t callbackID);
379     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostnames, uint64_t callbackID);
380
381     void clearCachedCredentials();
382
383     void setCacheStorageParameters(PAL::SessionID, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
384     void initializeQuotaUsers(WebCore::StorageQuotaManager&, PAL::SessionID, const WebCore::ClientOrigin&);
385
386     // FIXME: This should take a session ID so we can identify which disk cache to delete.
387     void clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&&);
388
389     void downloadRequest(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
390     void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
391     void cancelDownload(DownloadID);
392 #if PLATFORM(COCOA)
393     void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
394 #endif
395     void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
396     void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
397     void applicationDidEnterBackground();
398     void applicationWillEnterForeground();
399
400     void setCacheModel(CacheModel);
401     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
402     void setCanHandleHTTPSServerTrustEvaluation(bool);
403     void getNetworkProcessStatistics(uint64_t callbackID);
404     void clearCacheForAllOrigins(uint32_t cachesToClear);
405     void setAllowsAnySSLCertificateForWebSocket(bool, CompletionHandler<void()>&&);
406     
407     void syncAllCookies();
408     void didSyncAllCookies();
409
410     void notifyHoldingLockedFiles(bool isIDBDatabaseHoldingLockedFiles);
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