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 "APIWebsiteDataStore.h" |
29 | #include "AuxiliaryProcessProxy.h" |
30 | #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) |
31 | #include "LegacyCustomProtocolManagerProxy.h" |
32 | #endif |
33 | #include "NetworkProcessProxyMessages.h" |
34 | #include "ProcessLauncher.h" |
35 | #include "ProcessThrottler.h" |
36 | #include "ProcessThrottlerClient.h" |
37 | #include "UserContentControllerIdentifier.h" |
38 | #include "WebProcessProxyMessages.h" |
39 | #include <WebCore/RegistrableDomain.h> |
40 | #include <memory> |
41 | #include <wtf/Deque.h> |
42 | |
43 | namespace PAL { |
44 | class SessionID; |
45 | } |
46 | |
47 | namespace WebCore { |
48 | class AuthenticationChallenge; |
49 | class ProtectionSpace; |
50 | class ResourceRequest; |
51 | enum class ShouldSample : bool; |
52 | enum class StorageAccessPromptWasShown : bool; |
53 | enum class StorageAccessWasGranted : bool; |
54 | class SecurityOrigin; |
55 | struct SecurityOriginData; |
56 | } |
57 | |
58 | namespace WebKit { |
59 | |
60 | class DownloadProxy; |
61 | class DownloadProxyMap; |
62 | class WebProcessPool; |
63 | enum class ShouldGrandfatherStatistics : bool; |
64 | enum class StorageAccessStatus : uint8_t; |
65 | enum class WebsiteDataFetchOption; |
66 | enum class WebsiteDataType; |
67 | struct NetworkProcessCreationParameters; |
68 | class WebUserContentControllerProxy; |
69 | struct WebsiteData; |
70 | |
71 | class NetworkProcessProxy final : public AuxiliaryProcessProxy, private ProcessThrottlerClient, public CanMakeWeakPtr<NetworkProcessProxy> { |
72 | public: |
73 | using RegistrableDomain = WebCore::RegistrableDomain; |
74 | using TopFrameDomain = WebCore::RegistrableDomain; |
75 | using SubFrameDomain = WebCore::RegistrableDomain; |
76 | using SubResourceDomain = WebCore::RegistrableDomain; |
77 | using RedirectDomain = WebCore::RegistrableDomain; |
78 | using RedirectedFromDomain = WebCore::RegistrableDomain; |
79 | using RedirectedToDomain = WebCore::RegistrableDomain; |
80 | using NavigatedFromDomain = WebCore::RegistrableDomain; |
81 | using NavigatedToDomain = WebCore::RegistrableDomain; |
82 | using DomainInNeedOfStorageAccess = WebCore::RegistrableDomain; |
83 | using OpenerDomain = WebCore::RegistrableDomain; |
84 | using OpenerPageID = uint64_t; |
85 | using PageID = uint64_t; |
86 | using FrameID = uint64_t; |
87 | |
88 | explicit NetworkProcessProxy(WebProcessPool&); |
89 | ~NetworkProcessProxy(); |
90 | |
91 | void getNetworkProcessConnection(WebProcessProxy&, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply&&); |
92 | |
93 | DownloadProxy& createDownloadProxy(const WebCore::ResourceRequest&); |
94 | |
95 | void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, CompletionHandler<void(WebsiteData)>&&); |
96 | void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, CompletionHandler<void()>&& completionHandler); |
97 | void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebKit::WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, const Vector<String>& HSTSCacheHostNames, CompletionHandler<void()>&&); |
98 | |
99 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
100 | void clearPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&); |
101 | void clearUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&); |
102 | void dumpResourceLoadStatistics(PAL::SessionID, CompletionHandler<void(String)>&&); |
103 | void updatePrevalentDomainsToBlockCookiesFor(PAL::SessionID, const Vector<RegistrableDomain>&, CompletionHandler<void()>&&); |
104 | void hasHadUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&); |
105 | void isGrandfathered(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&); |
106 | void isPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&); |
107 | void isRegisteredAsRedirectingTo(PAL::SessionID, const RedirectedFromDomain&, const RedirectedToDomain&, CompletionHandler<void(bool)>&&); |
108 | void isRegisteredAsSubFrameUnder(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&); |
109 | void isRegisteredAsSubresourceUnder(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&); |
110 | void isVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void(bool)>&&); |
111 | void logUserInteraction(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&); |
112 | void scheduleStatisticsAndDataRecordsProcessing(PAL::SessionID, CompletionHandler<void()>&&); |
113 | void setLastSeen(PAL::SessionID, const RegistrableDomain&, Seconds, CompletionHandler<void()>&&); |
114 | void setAgeCapForClientSideCookies(PAL::SessionID, Optional<Seconds>, CompletionHandler<void()>&&); |
115 | void setCacheMaxAgeCap(PAL::SessionID, Seconds, CompletionHandler<void()>&&); |
116 | void setGrandfathered(PAL::SessionID, const RegistrableDomain&, bool isGrandfathered, CompletionHandler<void()>&&); |
117 | void setNotifyPagesWhenDataRecordsWereScanned(PAL::SessionID, bool, CompletionHandler<void()>&&); |
118 | void setIsRunningResourceLoadStatisticsTest(PAL::SessionID, bool, CompletionHandler<void()>&&); |
119 | void setNotifyPagesWhenTelemetryWasCaptured(PAL::SessionID, bool, CompletionHandler<void()>&&); |
120 | void setSubframeUnderTopFrameDomain(PAL::SessionID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void()>&&); |
121 | void setSubresourceUnderTopFrameDomain(PAL::SessionID, const SubResourceDomain&, const TopFrameDomain&, CompletionHandler<void()>&&); |
122 | void setSubresourceUniqueRedirectTo(PAL::SessionID, const SubResourceDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&); |
123 | void setSubresourceUniqueRedirectFrom(PAL::SessionID, const SubResourceDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&); |
124 | void setTimeToLiveUserInteraction(PAL::SessionID, Seconds, CompletionHandler<void()>&&); |
125 | void setTopFrameUniqueRedirectTo(PAL::SessionID, const TopFrameDomain&, const RedirectedToDomain&, CompletionHandler<void()>&&); |
126 | void setTopFrameUniqueRedirectFrom(PAL::SessionID, const TopFrameDomain&, const RedirectedFromDomain&, CompletionHandler<void()>&&); |
127 | void setPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&); |
128 | void setPrevalentResourceForDebugMode(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&); |
129 | void setVeryPrevalentResource(PAL::SessionID, const RegistrableDomain&, CompletionHandler<void()>&&); |
130 | void getAllStorageAccessEntries(PAL::SessionID, CompletionHandler<void(Vector<String> domains)>&&); |
131 | void requestStorageAccessConfirm(PageID, FrameID, const SubFrameDomain&, const TopFrameDomain&, CompletionHandler<void(bool)>&&); |
132 | void resetParametersToDefaultValues(PAL::SessionID, CompletionHandler<void()>&&); |
133 | void scheduleClearInMemoryAndPersistent(PAL::SessionID, ShouldGrandfatherStatistics, CompletionHandler<void()>&&); |
134 | void scheduleClearInMemoryAndPersistent(PAL::SessionID, Optional<WallTime> modifiedSince, ShouldGrandfatherStatistics, CompletionHandler<void()>&&); |
135 | void scheduleCookieBlockingUpdate(PAL::SessionID, CompletionHandler<void()>&&); |
136 | void submitTelemetry(PAL::SessionID, CompletionHandler<void()>&&); |
137 | void setCacheMaxAgeCapForPrevalentResources(PAL::SessionID, Seconds, CompletionHandler<void()>&&); |
138 | void setGrandfatheringTime(PAL::SessionID, Seconds, CompletionHandler<void()>&&); |
139 | void setMaxStatisticsEntries(PAL::SessionID, size_t maximumEntryCount, CompletionHandler<void()>&&); |
140 | void setMinimumTimeBetweenDataRecordsRemoval(PAL::SessionID, Seconds, CompletionHandler<void()>&&); |
141 | void setPruneEntriesDownTo(PAL::SessionID, size_t pruneTargetCount, CompletionHandler<void()>&&); |
142 | void setResourceLoadStatisticsDebugMode(PAL::SessionID, bool debugMode, CompletionHandler<void()>&&); |
143 | void setShouldClassifyResourcesBeforeDataRecordsRemoval(PAL::SessionID, bool, CompletionHandler<void()>&&); |
144 | void resetCacheMaxAgeCapForPrevalentResources(PAL::SessionID, CompletionHandler<void()>&&); |
145 | void committedCrossSiteLoadWithLinkDecoration(PAL::SessionID, const NavigatedFromDomain&, const NavigatedToDomain&, PageID, CompletionHandler<void()>&&); |
146 | void setCrossSiteLoadWithLinkDecorationForTesting(PAL::SessionID, const NavigatedFromDomain&, const NavigatedToDomain&, CompletionHandler<void()>&&); |
147 | void resetCrossSiteLoadsWithLinkDecorationForTesting(PAL::SessionID, CompletionHandler<void()>&&); |
148 | void deleteCookiesForTesting(PAL::SessionID, const RegistrableDomain&, bool includeHttpOnlyCookies, CompletionHandler<void()>&&); |
149 | void deleteWebsiteDataInUIProcessForRegistrableDomains(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, Vector<RegistrableDomain>, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&&); |
150 | #endif |
151 | |
152 | void processReadyToSuspend(); |
153 | |
154 | void sendProcessDidTransitionToForeground(); |
155 | void sendProcessDidTransitionToBackground(); |
156 | void synthesizeAppIsBackground(bool background); |
157 | |
158 | void setIsHoldingLockedFiles(bool); |
159 | |
160 | void syncAllCookies(); |
161 | void didSyncAllCookies(); |
162 | |
163 | ProcessThrottler& throttler() { return m_throttler; } |
164 | WebProcessPool& processPool() { return m_processPool; } |
165 | |
166 | #if ENABLE(CONTENT_EXTENSIONS) |
167 | void didDestroyWebUserContentControllerProxy(WebUserContentControllerProxy&); |
168 | #endif |
169 | |
170 | void addSession(Ref<WebsiteDataStore>&&); |
171 | void removeSession(PAL::SessionID); |
172 | |
173 | void takeUploadAssertion(); |
174 | void clearUploadAssertion(); |
175 | |
176 | #if ENABLE(INDEXED_DATABASE) |
177 | void createSymLinkForFileUpgrade(const String& indexedDatabaseDirectory); |
178 | #endif |
179 | |
180 | // ProcessThrottlerClient |
181 | void sendProcessWillSuspendImminently() final; |
182 | void sendProcessDidResume() final; |
183 | |
184 | private: |
185 | // AuxiliaryProcessProxy |
186 | void getLaunchOptions(ProcessLauncher::LaunchOptions&) override; |
187 | void connectionWillOpen(IPC::Connection&) override; |
188 | void processWillShutDown(IPC::Connection&) override; |
189 | |
190 | void networkProcessCrashed(); |
191 | void clearCallbackStates(); |
192 | |
193 | // ProcessThrottlerClient |
194 | void sendPrepareToSuspend() final; |
195 | void sendCancelPrepareToSuspend() final; |
196 | void didSetAssertionState(AssertionState) final; |
197 | |
198 | // IPC::Connection::Client |
199 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
200 | void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override; |
201 | void didClose(IPC::Connection&) override; |
202 | void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; |
203 | |
204 | // Message handlers |
205 | void didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::Decoder&); |
206 | void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&); |
207 | void didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, WebCore::AuthenticationChallenge&&, uint64_t challengeID); |
208 | void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&); |
209 | void didDeleteWebsiteData(uint64_t callbackID); |
210 | void didDeleteWebsiteDataForOrigins(uint64_t callbackID); |
211 | void logDiagnosticMessage(uint64_t pageID, const String& message, const String& description, WebCore::ShouldSample); |
212 | void logDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result, WebCore::ShouldSample); |
213 | void logDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample); |
214 | void logGlobalDiagnosticMessageWithValue(const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample); |
215 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
216 | void logTestingEvent(PAL::SessionID, const String& event); |
217 | void notifyResourceLoadStatisticsProcessed(); |
218 | void notifyWebsiteDataDeletionForRegistrableDomainsFinished(); |
219 | void notifyWebsiteDataScanForRegistrableDomainsFinished(); |
220 | void notifyResourceLoadStatisticsTelemetryFinished(unsigned totalPrevalentResources, unsigned totalPrevalentResourcesWithUserInteraction, unsigned top3SubframeUnderTopFrameOrigins); |
221 | #endif |
222 | void retrieveCacheStorageParameters(PAL::SessionID); |
223 | |
224 | #if ENABLE(CONTENT_EXTENSIONS) |
225 | void contentExtensionRules(UserContentControllerIdentifier); |
226 | #endif |
227 | |
228 | #if ENABLE(SANDBOX_EXTENSIONS) |
229 | void getSandboxExtensionsForBlobFiles(const Vector<String>& paths, Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles::AsyncReply&&); |
230 | #endif |
231 | |
232 | #if ENABLE(SERVICE_WORKER) |
233 | void establishWorkerContextConnectionToNetworkProcess(WebCore::RegistrableDomain&&); |
234 | void establishWorkerContextConnectionToNetworkProcessForExplicitSession(WebCore::RegistrableDomain&&, PAL::SessionID); |
235 | #endif |
236 | |
237 | void requestStorageSpace(PAL::SessionID, const WebCore::ClientOrigin&, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(Optional<uint64_t> quota)>&&); |
238 | |
239 | WebsiteDataStore* websiteDataStoreFromSessionID(PAL::SessionID); |
240 | |
241 | // ProcessLauncher::Client |
242 | void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; |
243 | |
244 | WebProcessPool& m_processPool; |
245 | |
246 | unsigned m_numPendingConnectionRequests; |
247 | Deque<std::pair<WeakPtr<WebProcessProxy>, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>> m_pendingConnectionReplies; |
248 | |
249 | HashMap<uint64_t, CompletionHandler<void(WebsiteData)>> m_pendingFetchWebsiteDataCallbacks; |
250 | HashMap<uint64_t, CompletionHandler<void()>> m_pendingDeleteWebsiteDataCallbacks; |
251 | HashMap<uint64_t, CompletionHandler<void()>> m_pendingDeleteWebsiteDataForOriginsCallbacks; |
252 | |
253 | std::unique_ptr<DownloadProxyMap> m_downloadProxyMap; |
254 | #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) |
255 | LegacyCustomProtocolManagerProxy m_customProtocolManagerProxy; |
256 | #endif |
257 | ProcessThrottler m_throttler; |
258 | ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles; |
259 | ProcessThrottler::BackgroundActivityToken m_syncAllCookiesToken; |
260 | |
261 | unsigned m_syncAllCookiesCounter { 0 }; |
262 | |
263 | #if ENABLE(CONTENT_EXTENSIONS) |
264 | HashSet<WebUserContentControllerProxy*> m_webUserContentControllerProxies; |
265 | #endif |
266 | |
267 | HashMap<PAL::SessionID, RefPtr<WebsiteDataStore>> m_websiteDataStores; |
268 | |
269 | std::unique_ptr<ProcessAssertion> m_uploadAssertion; |
270 | }; |
271 | |
272 | } // namespace WebKit |
273 | |