1 | /* |
2 | * Copyright (C) 2010-2018 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'' AND |
14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR |
17 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
20 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
21 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 | */ |
24 | |
25 | #include "config.h" |
26 | |
27 | #include "NetworkProcessProxy.h" |
28 | |
29 | #include "ArgumentCoders.h" |
30 | #include "Attachment.h" |
31 | #include "Decoder.h" |
32 | #include "HandleMessage.h" |
33 | #include "NetworkProcessProxyMessages.h" |
34 | #if ENABLE(SANDBOX_EXTENSIONS) |
35 | #include "SandboxExtension.h" |
36 | #endif |
37 | #if ENABLE(CONTENT_EXTENSIONS) |
38 | #include "UserContentControllerIdentifier.h" |
39 | #endif |
40 | #include "WebCoreArgumentCoders.h" |
41 | #include "WebsiteData.h" |
42 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
43 | #include "WebsiteDataFetchOption.h" |
44 | #endif |
45 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
46 | #include "WebsiteDataType.h" |
47 | #endif |
48 | #include <WebCore/AuthenticationChallenge.h> |
49 | #include <WebCore/ClientOrigin.h> |
50 | #include <WebCore/DiagnosticLoggingClient.h> |
51 | #include <WebCore/PageIdentifier.h> |
52 | #if ENABLE(RESOURCE_LOAD_STATISTICS) || ENABLE(SERVICE_WORKER) |
53 | #include <WebCore/RegistrableDomain.h> |
54 | #endif |
55 | #include <pal/SessionID.h> |
56 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
57 | #include <wtf/HashSet.h> |
58 | #endif |
59 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
60 | #include <wtf/OptionSet.h> |
61 | #endif |
62 | #include <wtf/Optional.h> |
63 | #if ENABLE(RESOURCE_LOAD_STATISTICS) || ENABLE(SANDBOX_EXTENSIONS) |
64 | #include <wtf/Vector.h> |
65 | #endif |
66 | #include <wtf/text/WTFString.h> |
67 | |
68 | namespace Messages { |
69 | |
70 | namespace NetworkProcessProxy { |
71 | |
72 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
73 | |
74 | void RequestStorageAccessConfirm::callReply(IPC::Decoder& decoder, CompletionHandler<void(bool&&)>&& completionHandler) |
75 | { |
76 | Optional<bool> userDidGrantAccess; |
77 | decoder >> userDidGrantAccess; |
78 | if (!userDidGrantAccess) { |
79 | ASSERT_NOT_REACHED(); |
80 | cancelReply(WTFMove(completionHandler)); |
81 | return; |
82 | } |
83 | completionHandler(WTFMove(*userDidGrantAccess)); |
84 | } |
85 | |
86 | void RequestStorageAccessConfirm::cancelReply(CompletionHandler<void(bool&&)>&& completionHandler) |
87 | { |
88 | completionHandler(IPC::AsyncReplyError<bool>::create()); |
89 | } |
90 | |
91 | void RequestStorageAccessConfirm::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, bool userDidGrantAccess) |
92 | { |
93 | *encoder << userDidGrantAccess; |
94 | connection.sendSyncReply(WTFMove(encoder)); |
95 | } |
96 | |
97 | #endif |
98 | |
99 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
100 | |
101 | void DeleteWebsiteDataInUIProcessForRegistrableDomains::callReply(IPC::Decoder& decoder, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&& completionHandler) |
102 | { |
103 | Optional<HashSet<WebCore::RegistrableDomain>> domainsWithMatchingDataRecords; |
104 | decoder >> domainsWithMatchingDataRecords; |
105 | if (!domainsWithMatchingDataRecords) { |
106 | ASSERT_NOT_REACHED(); |
107 | cancelReply(WTFMove(completionHandler)); |
108 | return; |
109 | } |
110 | completionHandler(WTFMove(*domainsWithMatchingDataRecords)); |
111 | } |
112 | |
113 | void DeleteWebsiteDataInUIProcessForRegistrableDomains::cancelReply(CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&& completionHandler) |
114 | { |
115 | completionHandler(IPC::AsyncReplyError<HashSet<WebCore::RegistrableDomain>>::create()); |
116 | } |
117 | |
118 | void DeleteWebsiteDataInUIProcessForRegistrableDomains::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const HashSet<WebCore::RegistrableDomain>& domainsWithMatchingDataRecords) |
119 | { |
120 | *encoder << domainsWithMatchingDataRecords; |
121 | connection.sendSyncReply(WTFMove(encoder)); |
122 | } |
123 | |
124 | #endif |
125 | |
126 | #if ENABLE(SANDBOX_EXTENSIONS) |
127 | |
128 | void GetSandboxExtensionsForBlobFiles::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebKit::SandboxExtension::HandleArray&&)>&& completionHandler) |
129 | { |
130 | Optional<WebKit::SandboxExtension::HandleArray> extensions; |
131 | decoder >> extensions; |
132 | if (!extensions) { |
133 | ASSERT_NOT_REACHED(); |
134 | cancelReply(WTFMove(completionHandler)); |
135 | return; |
136 | } |
137 | completionHandler(WTFMove(*extensions)); |
138 | } |
139 | |
140 | void GetSandboxExtensionsForBlobFiles::cancelReply(CompletionHandler<void(WebKit::SandboxExtension::HandleArray&&)>&& completionHandler) |
141 | { |
142 | completionHandler(IPC::AsyncReplyError<WebKit::SandboxExtension::HandleArray>::create()); |
143 | } |
144 | |
145 | void GetSandboxExtensionsForBlobFiles::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebKit::SandboxExtension::HandleArray& extensions) |
146 | { |
147 | *encoder << extensions; |
148 | connection.sendSyncReply(WTFMove(encoder)); |
149 | } |
150 | |
151 | #endif |
152 | |
153 | void RequestStorageSpace::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<uint64_t>&&)>&& completionHandler) |
154 | { |
155 | Optional<Optional<uint64_t>> newQuota; |
156 | decoder >> newQuota; |
157 | if (!newQuota) { |
158 | ASSERT_NOT_REACHED(); |
159 | cancelReply(WTFMove(completionHandler)); |
160 | return; |
161 | } |
162 | completionHandler(WTFMove(*newQuota)); |
163 | } |
164 | |
165 | void RequestStorageSpace::cancelReply(CompletionHandler<void(Optional<uint64_t>&&)>&& completionHandler) |
166 | { |
167 | completionHandler(IPC::AsyncReplyError<Optional<uint64_t>>::create()); |
168 | } |
169 | |
170 | void RequestStorageSpace::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<uint64_t>& newQuota) |
171 | { |
172 | *encoder << newQuota; |
173 | connection.sendSyncReply(WTFMove(encoder)); |
174 | } |
175 | |
176 | } // namespace NetworkProcessProxy |
177 | |
178 | } // namespace Messages |
179 | |
180 | namespace WebKit { |
181 | |
182 | void NetworkProcessProxy::didReceiveNetworkProcessProxyMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
183 | { |
184 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess::name()) { |
185 | IPC::handleMessage<Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess>(decoder, this, &NetworkProcessProxy::didCreateNetworkConnectionToWebProcess); |
186 | return; |
187 | } |
188 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge::name()) { |
189 | IPC::handleMessage<Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge>(decoder, this, &NetworkProcessProxy::didReceiveAuthenticationChallenge); |
190 | return; |
191 | } |
192 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidFetchWebsiteData::name()) { |
193 | IPC::handleMessage<Messages::NetworkProcessProxy::DidFetchWebsiteData>(decoder, this, &NetworkProcessProxy::didFetchWebsiteData); |
194 | return; |
195 | } |
196 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidDeleteWebsiteData::name()) { |
197 | IPC::handleMessage<Messages::NetworkProcessProxy::DidDeleteWebsiteData>(decoder, this, &NetworkProcessProxy::didDeleteWebsiteData); |
198 | return; |
199 | } |
200 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidDeleteWebsiteDataForOrigins::name()) { |
201 | IPC::handleMessage<Messages::NetworkProcessProxy::DidDeleteWebsiteDataForOrigins>(decoder, this, &NetworkProcessProxy::didDeleteWebsiteDataForOrigins); |
202 | return; |
203 | } |
204 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidSyncAllCookies::name()) { |
205 | IPC::handleMessage<Messages::NetworkProcessProxy::DidSyncAllCookies>(decoder, this, &NetworkProcessProxy::didSyncAllCookies); |
206 | return; |
207 | } |
208 | if (decoder.messageName() == Messages::NetworkProcessProxy::ProcessReadyToSuspend::name()) { |
209 | IPC::handleMessage<Messages::NetworkProcessProxy::ProcessReadyToSuspend>(decoder, this, &NetworkProcessProxy::processReadyToSuspend); |
210 | return; |
211 | } |
212 | if (decoder.messageName() == Messages::NetworkProcessProxy::SetIsHoldingLockedFiles::name()) { |
213 | IPC::handleMessage<Messages::NetworkProcessProxy::SetIsHoldingLockedFiles>(decoder, this, &NetworkProcessProxy::setIsHoldingLockedFiles); |
214 | return; |
215 | } |
216 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogDiagnosticMessage::name()) { |
217 | IPC::handleMessage<Messages::NetworkProcessProxy::LogDiagnosticMessage>(decoder, this, &NetworkProcessProxy::logDiagnosticMessage); |
218 | return; |
219 | } |
220 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogDiagnosticMessageWithResult::name()) { |
221 | IPC::handleMessage<Messages::NetworkProcessProxy::LogDiagnosticMessageWithResult>(decoder, this, &NetworkProcessProxy::logDiagnosticMessageWithResult); |
222 | return; |
223 | } |
224 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogDiagnosticMessageWithValue::name()) { |
225 | IPC::handleMessage<Messages::NetworkProcessProxy::LogDiagnosticMessageWithValue>(decoder, this, &NetworkProcessProxy::logDiagnosticMessageWithValue); |
226 | return; |
227 | } |
228 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogGlobalDiagnosticMessageWithValue::name()) { |
229 | IPC::handleMessage<Messages::NetworkProcessProxy::LogGlobalDiagnosticMessageWithValue>(decoder, this, &NetworkProcessProxy::logGlobalDiagnosticMessageWithValue); |
230 | return; |
231 | } |
232 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
233 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogTestingEvent::name()) { |
234 | IPC::handleMessage<Messages::NetworkProcessProxy::LogTestingEvent>(decoder, this, &NetworkProcessProxy::logTestingEvent); |
235 | return; |
236 | } |
237 | #endif |
238 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
239 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed::name()) { |
240 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed>(decoder, this, &NetworkProcessProxy::notifyResourceLoadStatisticsProcessed); |
241 | return; |
242 | } |
243 | #endif |
244 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
245 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyWebsiteDataDeletionForRegistrableDomainsFinished::name()) { |
246 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyWebsiteDataDeletionForRegistrableDomainsFinished>(decoder, this, &NetworkProcessProxy::notifyWebsiteDataDeletionForRegistrableDomainsFinished); |
247 | return; |
248 | } |
249 | #endif |
250 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
251 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyWebsiteDataScanForRegistrableDomainsFinished::name()) { |
252 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyWebsiteDataScanForRegistrableDomainsFinished>(decoder, this, &NetworkProcessProxy::notifyWebsiteDataScanForRegistrableDomainsFinished); |
253 | return; |
254 | } |
255 | #endif |
256 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
257 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsTelemetryFinished::name()) { |
258 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsTelemetryFinished>(decoder, this, &NetworkProcessProxy::notifyResourceLoadStatisticsTelemetryFinished); |
259 | return; |
260 | } |
261 | #endif |
262 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
263 | if (decoder.messageName() == Messages::NetworkProcessProxy::RequestStorageAccessConfirm::name()) { |
264 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::RequestStorageAccessConfirm>(connection, decoder, this, &NetworkProcessProxy::requestStorageAccessConfirm); |
265 | return; |
266 | } |
267 | #endif |
268 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
269 | if (decoder.messageName() == Messages::NetworkProcessProxy::DeleteWebsiteDataInUIProcessForRegistrableDomains::name()) { |
270 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::DeleteWebsiteDataInUIProcessForRegistrableDomains>(connection, decoder, this, &NetworkProcessProxy::deleteWebsiteDataInUIProcessForRegistrableDomains); |
271 | return; |
272 | } |
273 | #endif |
274 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
275 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidCommitCrossSiteLoadWithDataTransferFromPrevalentResource::name()) { |
276 | IPC::handleMessage<Messages::NetworkProcessProxy::DidCommitCrossSiteLoadWithDataTransferFromPrevalentResource>(decoder, this, &NetworkProcessProxy::didCommitCrossSiteLoadWithDataTransferFromPrevalentResource); |
277 | return; |
278 | } |
279 | #endif |
280 | #if ENABLE(CONTENT_EXTENSIONS) |
281 | if (decoder.messageName() == Messages::NetworkProcessProxy::ContentExtensionRules::name()) { |
282 | IPC::handleMessage<Messages::NetworkProcessProxy::ContentExtensionRules>(decoder, this, &NetworkProcessProxy::contentExtensionRules); |
283 | return; |
284 | } |
285 | #endif |
286 | if (decoder.messageName() == Messages::NetworkProcessProxy::RetrieveCacheStorageParameters::name()) { |
287 | IPC::handleMessage<Messages::NetworkProcessProxy::RetrieveCacheStorageParameters>(decoder, this, &NetworkProcessProxy::retrieveCacheStorageParameters); |
288 | return; |
289 | } |
290 | #if ENABLE(SANDBOX_EXTENSIONS) |
291 | if (decoder.messageName() == Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles::name()) { |
292 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles>(connection, decoder, this, &NetworkProcessProxy::getSandboxExtensionsForBlobFiles); |
293 | return; |
294 | } |
295 | #endif |
296 | #if ENABLE(SERVICE_WORKER) |
297 | if (decoder.messageName() == Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess::name()) { |
298 | IPC::handleMessage<Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess>(decoder, this, &NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcess); |
299 | return; |
300 | } |
301 | #endif |
302 | #if ENABLE(SERVICE_WORKER) |
303 | if (decoder.messageName() == Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcessForExplicitSession::name()) { |
304 | IPC::handleMessage<Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcessForExplicitSession>(decoder, this, &NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcessForExplicitSession); |
305 | return; |
306 | } |
307 | #endif |
308 | if (decoder.messageName() == Messages::NetworkProcessProxy::RequestStorageSpace::name()) { |
309 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::RequestStorageSpace>(connection, decoder, this, &NetworkProcessProxy::requestStorageSpace); |
310 | return; |
311 | } |
312 | UNUSED_PARAM(connection); |
313 | UNUSED_PARAM(decoder); |
314 | ASSERT_NOT_REACHED(); |
315 | } |
316 | |
317 | } // namespace WebKit |
318 | |
319 | |