2 * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #include "AuxiliaryProcess.h"
29 #include "CacheModel.h"
30 #include "DownloadManager.h"
31 #include "LocalStorageDatabaseTracker.h"
32 #include "NetworkBlobRegistry.h"
33 #include "NetworkContentRuleListManager.h"
34 #include "NetworkHTTPSUpgradeChecker.h"
35 #include "SandboxExtension.h"
36 #include "WebResourceLoadStatisticsStore.h"
37 #include "WebsiteData.h"
38 #include <WebCore/AdClickAttribution.h>
39 #include <WebCore/ClientOrigin.h>
40 #include <WebCore/CrossSiteNavigationDataTransfer.h>
41 #include <WebCore/DiagnosticLoggingClient.h>
42 #include <WebCore/FetchIdentifier.h>
43 #include <WebCore/IDBKeyData.h>
44 #include <WebCore/IDBServer.h>
45 #include <WebCore/PageIdentifier.h>
46 #include <WebCore/RegistrableDomain.h>
47 #include <WebCore/ServiceWorkerIdentifier.h>
48 #include <WebCore/ServiceWorkerTypes.h>
50 #include <wtf/CrossThreadTask.h>
51 #include <wtf/Function.h>
52 #include <wtf/HashSet.h>
53 #include <wtf/MemoryPressureHandler.h>
54 #include <wtf/NeverDestroyed.h>
55 #include <wtf/RetainPtr.h>
56 #include <wtf/WeakPtr.h>
58 #if PLATFORM(IOS_FAMILY)
59 #include "WebSQLiteDatabaseTracker.h"
63 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
67 class FormDataReference;
75 class CertificateInfo;
76 class CurlProxySettings;
78 class ProtectionSpace;
79 class StorageQuotaManager;
80 class NetworkStorageSession;
83 enum class IncludeHttpOnlyCookies : bool;
84 enum class StoredCredentialsPolicy : uint8_t;
85 enum class StorageAccessPromptWasShown : bool;
86 enum class StorageAccessWasGranted : bool;
88 struct MessageWithMessagePorts;
89 struct SecurityOriginData;
90 struct SoupNetworkProxySettings;
91 struct ServiceWorkerClientIdentifier;
96 class AuthenticationManager;
97 class NetworkConnectionToWebProcess;
98 class NetworkProcessSupplement;
99 class NetworkProximityManager;
100 class NetworkResourceLoader;
101 class WebSWServerConnection;
102 class WebSWServerToContextConnection;
103 enum class ShouldGrandfatherStatistics : bool;
104 enum class StorageAccessStatus : uint8_t;
105 enum class WebsiteDataFetchOption;
106 enum class WebsiteDataType;
107 struct NetworkProcessCreationParameters;
108 struct WebsiteDataStoreParameters;
110 #if ENABLE(SERVICE_WORKER)
111 class WebSWOriginStore;
114 namespace NetworkCache {
115 enum class CacheOption : uint8_t;
118 namespace CacheStorage {
122 class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client, public ThreadSafeRefCounted<NetworkProcess>
123 #if ENABLE(INDEXED_DATABASE)
124 , public WebCore::IDBServer::IDBBackingStoreTemporaryFileHandler
126 , public CanMakeWeakPtr<NetworkProcess>
128 WTF_MAKE_NONCOPYABLE(NetworkProcess);
130 using RegistrableDomain = WebCore::RegistrableDomain;
131 using TopFrameDomain = WebCore::RegistrableDomain;
132 using SubFrameDomain = WebCore::RegistrableDomain;
133 using SubResourceDomain = WebCore::RegistrableDomain;
134 using RedirectDomain = WebCore::RegistrableDomain;
135 using RedirectedFromDomain = WebCore::RegistrableDomain;
136 using RedirectedToDomain = WebCore::RegistrableDomain;
137 using NavigatedFromDomain = WebCore::RegistrableDomain;
138 using NavigatedToDomain = WebCore::RegistrableDomain;
139 using DomainInNeedOfStorageAccess = WebCore::RegistrableDomain;
140 using OpenerDomain = WebCore::RegistrableDomain;
141 using FrameID = uint64_t;
143 NetworkProcess(AuxiliaryProcessInitializationParameters&&);
145 static constexpr ProcessType processType = ProcessType::Network;
147 template <typename T>
150 return static_cast<T*>(m_supplements.get(T::supplementName()));
153 template <typename T>
156 m_supplements.add(T::supplementName(), std::make_unique<T>(*this));
159 void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess&);
161 AuthenticationManager& authenticationManager();
162 DownloadManager& downloadManager();
164 void setSession(const PAL::SessionID&, Ref<NetworkSession>&&);
165 NetworkSession* networkSession(const PAL::SessionID&) const final;
166 NetworkSession* networkSessionByConnection(IPC::Connection&) const;
167 void destroySession(const PAL::SessionID&);
169 // Needed for test infrastructure
170 HashMap<PAL::SessionID, Ref<NetworkSession>>& networkSessions() { return m_networkSessions; }
172 void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
173 WebCore::NetworkStorageSession* storageSession(const PAL::SessionID&) const;
174 WebCore::NetworkStorageSession& defaultStorageSession() const;
175 void switchToNewTestingSession();
177 void ensureSession(const PAL::SessionID&, const String& identifier, RetainPtr<CFHTTPCookieStorageRef>&&);
179 void ensureSession(const PAL::SessionID&, const String& identifier);
182 bool canHandleHTTPSServerTrustEvaluation() const { return m_canHandleHTTPSServerTrustEvaluation; }
184 void processWillSuspendImminently();
185 void prepareToSuspend();
186 void cancelPrepareToSuspend();
187 void processDidResume();
190 // Diagnostic messages logging.
191 void logDiagnosticMessage(WebCore::PageIdentifier, const String& message, const String& description, WebCore::ShouldSample);
192 void logDiagnosticMessageWithResult(WebCore::PageIdentifier, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
193 void logDiagnosticMessageWithValue(WebCore::PageIdentifier, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
196 RetainPtr<CFDataRef> sourceApplicationAuditData() const;
197 void getHostNamesWithHSTSCache(WebCore::NetworkStorageSession&, HashSet<String>&);
198 void deleteHSTSCacheForHostNames(WebCore::NetworkStorageSession&, const Vector<String>&);
199 void clearHSTSCache(WebCore::NetworkStorageSession&, WallTime modifiedSince);
200 bool suppressesConnectionTerminationOnSystemChange() const { return m_suppressesConnectionTerminationOnSystemChange; }
203 void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler&&, const WebCore::ResourceResponse&);
205 void prefetchDNS(const String&);
207 void addWebsiteDataStore(WebsiteDataStoreParameters&&);
209 #if ENABLE(RESOURCE_LOAD_STATISTICS)
210 void clearPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
211 void clearUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
212 void deleteWebsiteDataForRegistrableDomains(PAL::SessionID, OptionSet<WebsiteDataType>, HashMap<RegistrableDomain, WebsiteDataToRemove>&&, bool shouldNotifyPage, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&&);
213 void deleteCookiesForTesting(PAL::SessionID, RegistrableDomain, bool includeHttpOnlyCookies, CompletionHandler<void()>&&);
214 void dumpResourceLoadStatistics(PAL::SessionID, CompletionHandler<void(String)>&&);
215 void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<RegistrableDomain>& domainsToBlock, CompletionHandler<void()>&&);
216 void isGrandfathered(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
217 void isPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
218 void isVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
219 void setAgeCapForClientSideCookies(PAL::SessionID, Optional<Seconds>, CompletionHandler<void()>&&);
220 void isRegisteredAsRedirectingTo(PAL::SessionID, const RedirectedFromDomain&, const RedirectedToDomain&, CompletionHandler<void(bool)>&&);
221 void isRegisteredAsSubFrameUnder(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
222 void isRegisteredAsSubresourceUnder(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&);
223 void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&);
224 void setMaxStatisticsEntries(PAL::SessionID, uint64_t maximumEntryCount, CompletionHandler<void()>&&);
225 void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
226 void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
227 void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&);
228 void setPruneEntriesDownTo(PAL::SessionID, uint64_t pruneTargetCount, CompletionHandler<void()>&&);
229 void hadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
230 void hasLocalStorage(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&);
231 void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&);
232 void logFrameNavigation(PAL::SessionID, const NavigatedToDomain&, const TopFrameDomain&, const NavigatedFromDomain&, bool isRedirect, bool isMainFrame);
233 void logUserInteraction(PAL::SessionID, const TopFrameDomain&, CompletionHandler<void()>&&);
234 void removePrevalentDomains(PAL::SessionID, const Vector<RegistrableDomain>&);
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 didCommitCrossSiteLoadWithDataTransfer(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, OptionSet<WebCore::CrossSiteNavigationDataTransfer::Flag>, WebCore::PageIdentifier);
260 void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, CompletionHandler<void()>&&);
261 void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&);
264 using CacheStorageRootPathCallback = CompletionHandler<void(String&&)>;
265 void cacheStorageRootPath(PAL::SessionID, CacheStorageRootPathCallback&&);
267 void preconnectTo(const URL&, WebCore::StoredCredentialsPolicy);
269 void setSessionIsControlledByAutomation(PAL::SessionID, bool);
270 bool sessionIsControlledByAutomation(PAL::SessionID) const;
272 void webPageWasAdded(IPC::Connection&, PAL::SessionID, WebCore::PageIdentifier, WebCore::PageIdentifier);
273 void webPageWasRemoved(IPC::Connection&, PAL::SessionID, WebCore::PageIdentifier);
274 void webProcessWasDisconnected(IPC::Connection&);
275 void webProcessSessionChanged(IPC::Connection&, PAL::SessionID, const Vector<WebCore::PageIdentifier>&);
276 void getLocalStorageOriginDetails(PAL::SessionID, CompletionHandler<void(Vector<LocalStorageDatabaseTracker::OriginDetails>&&)>&&);
278 #if ENABLE(CONTENT_EXTENSIONS)
279 NetworkContentRuleListManager& networkContentRuleListManager() { return m_networkContentRuleListManager; }
282 #if ENABLE(INDEXED_DATABASE)
283 WebCore::IDBServer::IDBServer& idbServer(PAL::SessionID);
284 // WebCore::IDBServer::IDBBackingStoreFileHandler.
285 void accessToTemporaryFileComplete(const String& path) final;
286 void setIDBPerOriginQuota(uint64_t);
288 void updateQuotaBasedOnSpaceUsageForTesting(PAL::SessionID, const WebCore::ClientOrigin&);
290 #if ENABLE(SANDBOX_EXTENSIONS)
291 void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, CompletionHandler<void(SandboxExtension::HandleArray&&)>&&);
294 void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::Decoder&);
296 #if ENABLE(SERVICE_WORKER)
297 WebSWServerToContextConnection* serverToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&);
298 void createServerToContextConnection(const WebCore::RegistrableDomain&, Optional<PAL::SessionID>);
300 WebCore::SWServer& swServerForSession(PAL::SessionID);
301 void registerSWServerConnection(WebSWServerConnection&);
302 void unregisterSWServerConnection(WebSWServerConnection&);
304 void swContextConnectionMayNoLongerBeNeeded(WebSWServerToContextConnection&);
306 WebSWServerToContextConnection* connectionToContextProcessFromIPCConnection(IPC::Connection&);
307 void connectionToContextProcessWasClosed(Ref<WebSWServerToContextConnection>&&);
310 #if PLATFORM(IOS_FAMILY)
311 bool parentProcessHasServiceWorkerEntitlement() const;
313 bool parentProcessHasServiceWorkerEntitlement() const { return true; }
317 NetworkHTTPSUpgradeChecker& networkHTTPSUpgradeChecker();
320 const String& uiProcessBundleIdentifier() const { return m_uiProcessBundleIdentifier; }
322 void ref() const override { ThreadSafeRefCounted<NetworkProcess>::ref(); }
323 void deref() const override { ThreadSafeRefCounted<NetworkProcess>::deref(); }
325 CacheStorage::Engine* findCacheEngine(const PAL::SessionID&);
326 CacheStorage::Engine& ensureCacheEngine(const PAL::SessionID&, Function<Ref<CacheStorage::Engine>()>&&);
327 void removeCacheEngine(const PAL::SessionID&);
328 void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t>)>&&);
330 NetworkBlobRegistry& networkBlobRegistry() override { return m_networkBlobRegistry; }
332 void storeAdClickAttribution(PAL::SessionID, WebCore::AdClickAttribution&&);
333 void dumpAdClickAttribution(PAL::SessionID, CompletionHandler<void(String)>&&);
334 void clearAdClickAttribution(PAL::SessionID, CompletionHandler<void()>&&);
335 void setAdClickAttributionOverrideTimerForTesting(PAL::SessionID, bool value, CompletionHandler<void()>&&);
336 void setAdClickAttributionConversionURLForTesting(PAL::SessionID, URL&&, CompletionHandler<void()>&&);
337 void markAdClickAttributionsAsExpiredForTesting(PAL::SessionID, CompletionHandler<void()>&&);
339 WebCore::StorageQuotaManager& storageQuotaManager(PAL::SessionID, const WebCore::ClientOrigin&);
341 void addKeptAliveLoad(Ref<NetworkResourceLoader>&&);
342 void removeKeptAliveLoad(NetworkResourceLoader&);
344 const String& diskCacheDirectory() const { return m_diskCacheDirectory; }
345 const OptionSet<NetworkCache::CacheOption>& cacheOptions() const { return m_cacheOptions; }
348 void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
349 std::unique_ptr<WebCore::NetworkStorageSession> platformCreateDefaultStorageSession() const;
351 void terminate() override;
352 void platformTerminate();
354 void lowMemoryHandler(Critical);
356 void processDidTransitionToForeground();
357 void processDidTransitionToBackground();
358 void platformProcessDidTransitionToForeground();
359 void platformProcessDidTransitionToBackground();
361 enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
362 void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
363 void platformPrepareToSuspend(CompletionHandler<void()>&&);
364 void platformProcessDidResume();
367 void initializeProcess(const AuxiliaryProcessInitializationParameters&) override;
368 void initializeProcessName(const AuxiliaryProcessInitializationParameters&) override;
369 void initializeSandbox(const AuxiliaryProcessInitializationParameters&, SandboxInitializationParameters&) override;
370 void initializeConnection(IPC::Connection*) override;
371 bool shouldTerminate() override;
373 // IPC::Connection::Client
374 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
375 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
376 void didClose(IPC::Connection&) override;
378 // DownloadManager::Client
379 void didCreateDownload() override;
380 void didDestroyDownload() override;
381 IPC::Connection* downloadProxyConnection() override;
382 IPC::Connection* parentProcessConnectionForDownloads() override { return parentProcessConnection(); }
383 AuthenticationManager& downloadsAuthenticationManager() override;
384 void pendingDownloadCanceled(DownloadID) override;
385 uint32_t downloadMonitorSpeedMultiplier() const override { return m_downloadMonitorSpeedMultiplier; }
388 void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
389 void initializeNetworkProcess(NetworkProcessCreationParameters&&);
390 void createNetworkConnectionToWebProcess(bool isServiceWorkerProcess, WebCore::RegistrableDomain&&);
392 void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
393 void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, uint64_t callbackID);
394 void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostnames, uint64_t callbackID);
396 void clearCachedCredentials();
397 void clearPermanentCredentialsForProtectionSpace(const WebCore::ProtectionSpace&, CompletionHandler<void()>&&);
399 void setCacheStorageParameters(PAL::SessionID, String&& cacheStorageDirectory, SandboxExtension::Handle&&);
400 void initializeQuotaUsers(WebCore::StorageQuotaManager&, PAL::SessionID, const WebCore::ClientOrigin&);
402 // FIXME: This should take a session ID so we can identify which disk cache to delete.
403 void clearDiskCache(WallTime modifiedSince, CompletionHandler<void()>&&);
405 void downloadRequest(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
406 void resumeDownload(PAL::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, SandboxExtension::Handle&&);
407 void cancelDownload(DownloadID);
409 void publishDownloadProgress(DownloadID, const URL&, SandboxExtension::Handle&&);
411 void continueWillSendRequest(DownloadID, WebCore::ResourceRequest&&);
412 void continueDecidePendingDownloadDestination(DownloadID, String destination, SandboxExtension::Handle&&, bool allowOverwrite);
413 void applicationDidEnterBackground();
414 void applicationWillEnterForeground();
416 void setCacheModel(CacheModel);
417 void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
418 void setCanHandleHTTPSServerTrustEvaluation(bool);
419 void getNetworkProcessStatistics(uint64_t callbackID);
420 void clearCacheForAllOrigins(uint32_t cachesToClear);
421 void setAllowsAnySSLCertificateForWebSocket(bool, CompletionHandler<void()>&&);
423 void syncAllCookies();
424 void didSyncAllCookies();
427 void setIgnoreTLSErrors(bool);
428 void userPreferredLanguagesChanged(const Vector<String>&);
429 void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
433 void setNetworkProxySettings(PAL::SessionID, WebCore::CurlProxySettings&&);
437 static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
440 void platformSyncAllCookies(CompletionHandler<void()>&&);
442 void registerURLSchemeAsSecure(const String&) const;
443 void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
444 void registerURLSchemeAsLocal(const String&) const;
445 void registerURLSchemeAsNoAccess(const String&) const;
446 void registerURLSchemeAsDisplayIsolated(const String&) const;
447 void registerURLSchemeAsCORSEnabled(const String&) const;
448 void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&) const;
450 #if ENABLE(INDEXED_DATABASE)
451 void addIndexedDatabaseSession(PAL::SessionID, String&, SandboxExtension::Handle&);
452 void collectIndexedDatabaseOriginsForVersion(const String&, HashSet<WebCore::SecurityOriginData>&);
453 HashSet<WebCore::SecurityOriginData> indexedDatabaseOrigins(const String& path);
454 Ref<WebCore::IDBServer::IDBServer> createIDBServer(PAL::SessionID);
457 #if ENABLE(SERVICE_WORKER)
458 void didCreateWorkerContextProcessConnection(const IPC::Attachment&);
460 void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
461 void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
463 void disableServiceWorkerProcessTerminationDelay();
465 WebSWOriginStore* existingSWOriginStoreForSession(PAL::SessionID) const;
466 bool needsServerToContextConnectionForRegistrableDomain(const WebCore::RegistrableDomain&) const;
468 void addServiceWorkerSession(PAL::SessionID, String& serviceWorkerRegistrationDirectory, const SandboxExtension::Handle&);
471 void postStorageTask(CrossThreadTask&&);
472 // For execution on work queue thread only.
473 void performNextStorageTask();
474 void ensurePathExists(const String& path);
476 void clearStorageQuota(PAL::SessionID);
477 void initializeStorageQuota(const WebsiteDataStoreParameters&);
479 // Connections to WebProcesses.
480 Vector<Ref<NetworkConnectionToWebProcess>> m_webProcessConnections;
482 String m_diskCacheDirectory;
483 bool m_hasSetCacheModel { false };
484 CacheModel m_cacheModel { CacheModel::DocumentViewer };
485 bool m_suppressMemoryPressureHandler { false };
486 bool m_diskCacheIsDisabledForTesting { false };
487 bool m_canHandleHTTPSServerTrustEvaluation { true };
488 String m_uiProcessBundleIdentifier;
489 DownloadManager m_downloadManager;
491 HashMap<PAL::SessionID, Ref<CacheStorage::Engine>> m_cacheEngines;
493 typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
494 NetworkProcessSupplementMap m_supplements;
496 HashSet<PAL::SessionID> m_sessionsControlledByAutomation;
497 HashMap<PAL::SessionID, Vector<CacheStorageRootPathCallback>> m_cacheStorageParametersCallbacks;
499 HashMap<PAL::SessionID, Ref<NetworkSession>> m_networkSessions;
500 HashMap<PAL::SessionID, std::unique_ptr<WebCore::NetworkStorageSession>> m_networkStorageSessions;
501 mutable std::unique_ptr<WebCore::NetworkStorageSession> m_defaultNetworkStorageSession;
502 NetworkBlobRegistry m_networkBlobRegistry;
505 void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
506 void setStorageAccessAPIEnabled(bool);
508 // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
509 // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
510 // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
511 dispatch_group_t m_clearCacheDispatchGroup { nullptr };
513 bool m_suppressesConnectionTerminationOnSystemChange { false };
516 #if ENABLE(CONTENT_EXTENSIONS)
517 NetworkContentRuleListManager m_networkContentRuleListManager;
520 #if PLATFORM(IOS_FAMILY)
521 WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
524 Ref<WorkQueue> m_storageTaskQueue { WorkQueue::create("com.apple.WebKit.StorageTask") };
526 #if ENABLE(INDEXED_DATABASE)
527 HashMap<PAL::SessionID, String> m_idbDatabasePaths;
528 HashMap<PAL::SessionID, RefPtr<WebCore::IDBServer::IDBServer>> m_idbServers;
529 uint64_t m_idbPerOriginQuota { WebCore::IDBServer::defaultPerOriginQuota };
532 Deque<CrossThreadTask> m_storageTasks;
533 Lock m_storageTaskMutex;
535 #if ENABLE(SERVICE_WORKER)
536 HashMap<WebCore::RegistrableDomain, RefPtr<WebSWServerToContextConnection>> m_serverToContextConnections;
537 bool m_waitingForServerToContextProcessConnection { false };
538 bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
539 HashMap<PAL::SessionID, String> m_swDatabasePaths;
540 HashMap<PAL::SessionID, std::unique_ptr<WebCore::SWServer>> m_swServers;
541 HashMap<WebCore::SWServerConnectionIdentifier, WebSWServerConnection*> m_swServerConnections;
545 std::unique_ptr<NetworkHTTPSUpgradeChecker> m_networkHTTPSUpgradeChecker;
548 class StorageQuotaManagers {
550 uint64_t defaultQuota(const WebCore::ClientOrigin& origin) const { return origin.topOrigin == origin.clientOrigin ? m_defaultQuota : m_defaultThirdPartyQuota; }
551 void setDefaultQuotas(uint64_t defaultQuota, uint64_t defaultThirdPartyQuota)
553 m_defaultQuota = defaultQuota;
554 m_defaultThirdPartyQuota = defaultThirdPartyQuota;
557 HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>>& managersPerOrigin() { return m_managersPerOrigin; }
560 uint64_t m_defaultQuota { WebCore::StorageQuotaManager::defaultQuota() };
561 uint64_t m_defaultThirdPartyQuota { WebCore::StorageQuotaManager::defaultThirdPartyQuota() };
562 HashMap<WebCore::ClientOrigin, std::unique_ptr<WebCore::StorageQuotaManager>> m_managersPerOrigin;
564 HashMap<PAL::SessionID, StorageQuotaManagers> m_storageQuotaManagers;
565 uint32_t m_downloadMonitorSpeedMultiplier { 1 };
567 HashMap<IPC::Connection::UniqueID, PAL::SessionID> m_sessionByConnection;
569 OptionSet<NetworkCache::CacheOption> m_cacheOptions;
572 } // namespace WebKit