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