| 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 | #if ENABLE(RESOURCE_LOAD_STATISTICS) || ENABLE(SERVICE_WORKER) |
| 52 | #include <WebCore/RegistrableDomain.h> |
| 53 | #endif |
| 54 | #include <pal/SessionID.h> |
| 55 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 56 | #include <wtf/HashSet.h> |
| 57 | #endif |
| 58 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 59 | #include <wtf/OptionSet.h> |
| 60 | #endif |
| 61 | #include <wtf/Optional.h> |
| 62 | #if ENABLE(RESOURCE_LOAD_STATISTICS) || ENABLE(SANDBOX_EXTENSIONS) |
| 63 | #include <wtf/Vector.h> |
| 64 | #endif |
| 65 | #include <wtf/text/WTFString.h> |
| 66 | |
| 67 | namespace Messages { |
| 68 | |
| 69 | namespace NetworkProcessProxy { |
| 70 | |
| 71 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 72 | |
| 73 | void RequestStorageAccessConfirm::callReply(IPC::Decoder& decoder, CompletionHandler<void(bool&&)>&& completionHandler) |
| 74 | { |
| 75 | Optional<bool> userDidGrantAccess; |
| 76 | decoder >> userDidGrantAccess; |
| 77 | if (!userDidGrantAccess) { |
| 78 | ASSERT_NOT_REACHED(); |
| 79 | return; |
| 80 | } |
| 81 | completionHandler(WTFMove(*userDidGrantAccess)); |
| 82 | } |
| 83 | |
| 84 | void RequestStorageAccessConfirm::cancelReply(CompletionHandler<void(bool&&)>&& completionHandler) |
| 85 | { |
| 86 | completionHandler({ }); |
| 87 | } |
| 88 | |
| 89 | void RequestStorageAccessConfirm::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, bool userDidGrantAccess) |
| 90 | { |
| 91 | *encoder << userDidGrantAccess; |
| 92 | connection.sendSyncReply(WTFMove(encoder)); |
| 93 | } |
| 94 | |
| 95 | #endif |
| 96 | |
| 97 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 98 | |
| 99 | void DeleteWebsiteDataInUIProcessForRegistrableDomains::callReply(IPC::Decoder& decoder, CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&& completionHandler) |
| 100 | { |
| 101 | Optional<HashSet<WebCore::RegistrableDomain>> domainsWithMatchingDataRecords; |
| 102 | decoder >> domainsWithMatchingDataRecords; |
| 103 | if (!domainsWithMatchingDataRecords) { |
| 104 | ASSERT_NOT_REACHED(); |
| 105 | return; |
| 106 | } |
| 107 | completionHandler(WTFMove(*domainsWithMatchingDataRecords)); |
| 108 | } |
| 109 | |
| 110 | void DeleteWebsiteDataInUIProcessForRegistrableDomains::cancelReply(CompletionHandler<void(HashSet<WebCore::RegistrableDomain>&&)>&& completionHandler) |
| 111 | { |
| 112 | completionHandler({ }); |
| 113 | } |
| 114 | |
| 115 | void DeleteWebsiteDataInUIProcessForRegistrableDomains::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const HashSet<WebCore::RegistrableDomain>& domainsWithMatchingDataRecords) |
| 116 | { |
| 117 | *encoder << domainsWithMatchingDataRecords; |
| 118 | connection.sendSyncReply(WTFMove(encoder)); |
| 119 | } |
| 120 | |
| 121 | #endif |
| 122 | |
| 123 | #if ENABLE(SANDBOX_EXTENSIONS) |
| 124 | |
| 125 | void GetSandboxExtensionsForBlobFiles::callReply(IPC::Decoder& decoder, CompletionHandler<void(WebKit::SandboxExtension::HandleArray&&)>&& completionHandler) |
| 126 | { |
| 127 | Optional<WebKit::SandboxExtension::HandleArray> extensions; |
| 128 | decoder >> extensions; |
| 129 | if (!extensions) { |
| 130 | ASSERT_NOT_REACHED(); |
| 131 | return; |
| 132 | } |
| 133 | completionHandler(WTFMove(*extensions)); |
| 134 | } |
| 135 | |
| 136 | void GetSandboxExtensionsForBlobFiles::cancelReply(CompletionHandler<void(WebKit::SandboxExtension::HandleArray&&)>&& completionHandler) |
| 137 | { |
| 138 | completionHandler({ }); |
| 139 | } |
| 140 | |
| 141 | void GetSandboxExtensionsForBlobFiles::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const WebKit::SandboxExtension::HandleArray& extensions) |
| 142 | { |
| 143 | *encoder << extensions; |
| 144 | connection.sendSyncReply(WTFMove(encoder)); |
| 145 | } |
| 146 | |
| 147 | #endif |
| 148 | |
| 149 | void RequestStorageSpace::callReply(IPC::Decoder& decoder, CompletionHandler<void(Optional<uint64_t>&&)>&& completionHandler) |
| 150 | { |
| 151 | Optional<Optional<uint64_t>> newQuota; |
| 152 | decoder >> newQuota; |
| 153 | if (!newQuota) { |
| 154 | ASSERT_NOT_REACHED(); |
| 155 | return; |
| 156 | } |
| 157 | completionHandler(WTFMove(*newQuota)); |
| 158 | } |
| 159 | |
| 160 | void RequestStorageSpace::cancelReply(CompletionHandler<void(Optional<uint64_t>&&)>&& completionHandler) |
| 161 | { |
| 162 | completionHandler({ }); |
| 163 | } |
| 164 | |
| 165 | void RequestStorageSpace::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection, const Optional<uint64_t>& newQuota) |
| 166 | { |
| 167 | *encoder << newQuota; |
| 168 | connection.sendSyncReply(WTFMove(encoder)); |
| 169 | } |
| 170 | |
| 171 | } // namespace NetworkProcessProxy |
| 172 | |
| 173 | } // namespace Messages |
| 174 | |
| 175 | namespace WebKit { |
| 176 | |
| 177 | void NetworkProcessProxy::didReceiveNetworkProcessProxyMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
| 178 | { |
| 179 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess::name()) { |
| 180 | IPC::handleMessage<Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess>(decoder, this, &NetworkProcessProxy::didCreateNetworkConnectionToWebProcess); |
| 181 | return; |
| 182 | } |
| 183 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge::name()) { |
| 184 | IPC::handleMessage<Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge>(decoder, this, &NetworkProcessProxy::didReceiveAuthenticationChallenge); |
| 185 | return; |
| 186 | } |
| 187 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidFetchWebsiteData::name()) { |
| 188 | IPC::handleMessage<Messages::NetworkProcessProxy::DidFetchWebsiteData>(decoder, this, &NetworkProcessProxy::didFetchWebsiteData); |
| 189 | return; |
| 190 | } |
| 191 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidDeleteWebsiteData::name()) { |
| 192 | IPC::handleMessage<Messages::NetworkProcessProxy::DidDeleteWebsiteData>(decoder, this, &NetworkProcessProxy::didDeleteWebsiteData); |
| 193 | return; |
| 194 | } |
| 195 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidDeleteWebsiteDataForOrigins::name()) { |
| 196 | IPC::handleMessage<Messages::NetworkProcessProxy::DidDeleteWebsiteDataForOrigins>(decoder, this, &NetworkProcessProxy::didDeleteWebsiteDataForOrigins); |
| 197 | return; |
| 198 | } |
| 199 | if (decoder.messageName() == Messages::NetworkProcessProxy::DidSyncAllCookies::name()) { |
| 200 | IPC::handleMessage<Messages::NetworkProcessProxy::DidSyncAllCookies>(decoder, this, &NetworkProcessProxy::didSyncAllCookies); |
| 201 | return; |
| 202 | } |
| 203 | if (decoder.messageName() == Messages::NetworkProcessProxy::ProcessReadyToSuspend::name()) { |
| 204 | IPC::handleMessage<Messages::NetworkProcessProxy::ProcessReadyToSuspend>(decoder, this, &NetworkProcessProxy::processReadyToSuspend); |
| 205 | return; |
| 206 | } |
| 207 | if (decoder.messageName() == Messages::NetworkProcessProxy::SetIsHoldingLockedFiles::name()) { |
| 208 | IPC::handleMessage<Messages::NetworkProcessProxy::SetIsHoldingLockedFiles>(decoder, this, &NetworkProcessProxy::setIsHoldingLockedFiles); |
| 209 | return; |
| 210 | } |
| 211 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogDiagnosticMessage::name()) { |
| 212 | IPC::handleMessage<Messages::NetworkProcessProxy::LogDiagnosticMessage>(decoder, this, &NetworkProcessProxy::logDiagnosticMessage); |
| 213 | return; |
| 214 | } |
| 215 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogDiagnosticMessageWithResult::name()) { |
| 216 | IPC::handleMessage<Messages::NetworkProcessProxy::LogDiagnosticMessageWithResult>(decoder, this, &NetworkProcessProxy::logDiagnosticMessageWithResult); |
| 217 | return; |
| 218 | } |
| 219 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogDiagnosticMessageWithValue::name()) { |
| 220 | IPC::handleMessage<Messages::NetworkProcessProxy::LogDiagnosticMessageWithValue>(decoder, this, &NetworkProcessProxy::logDiagnosticMessageWithValue); |
| 221 | return; |
| 222 | } |
| 223 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogGlobalDiagnosticMessageWithValue::name()) { |
| 224 | IPC::handleMessage<Messages::NetworkProcessProxy::LogGlobalDiagnosticMessageWithValue>(decoder, this, &NetworkProcessProxy::logGlobalDiagnosticMessageWithValue); |
| 225 | return; |
| 226 | } |
| 227 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 228 | if (decoder.messageName() == Messages::NetworkProcessProxy::LogTestingEvent::name()) { |
| 229 | IPC::handleMessage<Messages::NetworkProcessProxy::LogTestingEvent>(decoder, this, &NetworkProcessProxy::logTestingEvent); |
| 230 | return; |
| 231 | } |
| 232 | #endif |
| 233 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 234 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed::name()) { |
| 235 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsProcessed>(decoder, this, &NetworkProcessProxy::notifyResourceLoadStatisticsProcessed); |
| 236 | return; |
| 237 | } |
| 238 | #endif |
| 239 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 240 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyWebsiteDataDeletionForRegistrableDomainsFinished::name()) { |
| 241 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyWebsiteDataDeletionForRegistrableDomainsFinished>(decoder, this, &NetworkProcessProxy::notifyWebsiteDataDeletionForRegistrableDomainsFinished); |
| 242 | return; |
| 243 | } |
| 244 | #endif |
| 245 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 246 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyWebsiteDataScanForRegistrableDomainsFinished::name()) { |
| 247 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyWebsiteDataScanForRegistrableDomainsFinished>(decoder, this, &NetworkProcessProxy::notifyWebsiteDataScanForRegistrableDomainsFinished); |
| 248 | return; |
| 249 | } |
| 250 | #endif |
| 251 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 252 | if (decoder.messageName() == Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsTelemetryFinished::name()) { |
| 253 | IPC::handleMessage<Messages::NetworkProcessProxy::NotifyResourceLoadStatisticsTelemetryFinished>(decoder, this, &NetworkProcessProxy::notifyResourceLoadStatisticsTelemetryFinished); |
| 254 | return; |
| 255 | } |
| 256 | #endif |
| 257 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 258 | if (decoder.messageName() == Messages::NetworkProcessProxy::RequestStorageAccessConfirm::name()) { |
| 259 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::RequestStorageAccessConfirm>(connection, decoder, this, &NetworkProcessProxy::requestStorageAccessConfirm); |
| 260 | return; |
| 261 | } |
| 262 | #endif |
| 263 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 264 | if (decoder.messageName() == Messages::NetworkProcessProxy::DeleteWebsiteDataInUIProcessForRegistrableDomains::name()) { |
| 265 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::DeleteWebsiteDataInUIProcessForRegistrableDomains>(connection, decoder, this, &NetworkProcessProxy::deleteWebsiteDataInUIProcessForRegistrableDomains); |
| 266 | return; |
| 267 | } |
| 268 | #endif |
| 269 | #if ENABLE(CONTENT_EXTENSIONS) |
| 270 | if (decoder.messageName() == Messages::NetworkProcessProxy::ContentExtensionRules::name()) { |
| 271 | IPC::handleMessage<Messages::NetworkProcessProxy::ContentExtensionRules>(decoder, this, &NetworkProcessProxy::contentExtensionRules); |
| 272 | return; |
| 273 | } |
| 274 | #endif |
| 275 | if (decoder.messageName() == Messages::NetworkProcessProxy::RetrieveCacheStorageParameters::name()) { |
| 276 | IPC::handleMessage<Messages::NetworkProcessProxy::RetrieveCacheStorageParameters>(decoder, this, &NetworkProcessProxy::retrieveCacheStorageParameters); |
| 277 | return; |
| 278 | } |
| 279 | #if ENABLE(SANDBOX_EXTENSIONS) |
| 280 | if (decoder.messageName() == Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles::name()) { |
| 281 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::GetSandboxExtensionsForBlobFiles>(connection, decoder, this, &NetworkProcessProxy::getSandboxExtensionsForBlobFiles); |
| 282 | return; |
| 283 | } |
| 284 | #endif |
| 285 | #if ENABLE(SERVICE_WORKER) |
| 286 | if (decoder.messageName() == Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess::name()) { |
| 287 | IPC::handleMessage<Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcess>(decoder, this, &NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcess); |
| 288 | return; |
| 289 | } |
| 290 | #endif |
| 291 | #if ENABLE(SERVICE_WORKER) |
| 292 | if (decoder.messageName() == Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcessForExplicitSession::name()) { |
| 293 | IPC::handleMessage<Messages::NetworkProcessProxy::EstablishWorkerContextConnectionToNetworkProcessForExplicitSession>(decoder, this, &NetworkProcessProxy::establishWorkerContextConnectionToNetworkProcessForExplicitSession); |
| 294 | return; |
| 295 | } |
| 296 | #endif |
| 297 | if (decoder.messageName() == Messages::NetworkProcessProxy::RequestStorageSpace::name()) { |
| 298 | IPC::handleMessageAsync<Messages::NetworkProcessProxy::RequestStorageSpace>(connection, decoder, this, &NetworkProcessProxy::requestStorageSpace); |
| 299 | return; |
| 300 | } |
| 301 | UNUSED_PARAM(connection); |
| 302 | UNUSED_PARAM(decoder); |
| 303 | ASSERT_NOT_REACHED(); |
| 304 | } |
| 305 | |
| 306 | } // namespace WebKit |
| 307 | |
| 308 | |