beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | f7a5acc | 2016-11-05 03:02:39 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012-2016 Apple Inc. All rights reserved. |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 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 | #include "config.h" |
| 27 | #include "NetworkProcessProxy.h" |
| 28 | |
beidson@apple.com | daf9106 | 2013-01-26 00:03:48 +0000 | [diff] [blame] | 29 | #include "AuthenticationChallengeProxy.h" |
beidson@apple.com | 4630340 | 2016-04-08 16:57:29 +0000 | [diff] [blame] | 30 | #include "DatabaseProcessMessages.h" |
andersca@apple.com | 93b4c36 | 2012-12-16 01:26:05 +0000 | [diff] [blame] | 31 | #include "DownloadProxyMessages.h" |
beidson@apple.com | 11c7bf0 | 2017-03-06 02:53:31 +0000 | [diff] [blame] | 32 | #include "LegacyCustomProtocolManagerProxyMessages.h" |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 33 | #include "Logging.h" |
beidson@apple.com | c9a08bc | 2012-10-12 23:37:30 +0000 | [diff] [blame] | 34 | #include "NetworkProcessCreationParameters.h" |
| 35 | #include "NetworkProcessMessages.h" |
beidson@apple.com | 4630340 | 2016-04-08 16:57:29 +0000 | [diff] [blame] | 36 | #include "SandboxExtension.h" |
timothy_horton@apple.com | 284c216 | 2017-05-07 18:03:05 +0000 | [diff] [blame] | 37 | #include "WebPageProxy.h" |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 38 | #include "WebProcessMessages.h" |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 39 | #include "WebProcessPool.h" |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 40 | #include "WebsiteData.h" |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 41 | |
commit-queue@webkit.org | b48afca | 2013-12-08 18:26:15 +0000 | [diff] [blame] | 42 | #if ENABLE(SEC_ITEM_SHIM) |
| 43 | #include "SecItemShimProxy.h" |
| 44 | #endif |
| 45 | |
bdakin@apple.com | 1539c6c | 2015-01-28 22:22:16 +0000 | [diff] [blame] | 46 | #if PLATFORM(IOS) |
dbates@webkit.org | dcec383 | 2014-11-21 16:40:55 +0000 | [diff] [blame] | 47 | #include <wtf/spi/darwin/XPCSPI.h> |
| 48 | #endif |
| 49 | |
beidson@apple.com | daf9106 | 2013-01-26 00:03:48 +0000 | [diff] [blame] | 50 | #define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, connection()) |
| 51 | |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 52 | using namespace WebCore; |
| 53 | |
| 54 | namespace WebKit { |
| 55 | |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 56 | static uint64_t generateCallbackID() |
| 57 | { |
| 58 | static uint64_t callbackID; |
| 59 | |
| 60 | return ++callbackID; |
| 61 | } |
| 62 | |
gyuyoung.kim@webkit.org | 5f7960e | 2015-06-17 03:33:26 +0000 | [diff] [blame] | 63 | Ref<NetworkProcessProxy> NetworkProcessProxy::create(WebProcessPool& processPool) |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 64 | { |
gyuyoung.kim@webkit.org | 5f7960e | 2015-06-17 03:33:26 +0000 | [diff] [blame] | 65 | return adoptRef(*new NetworkProcessProxy(processPool)); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 66 | } |
| 67 | |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 68 | NetworkProcessProxy::NetworkProcessProxy(WebProcessPool& processPool) |
akling@apple.com | 8a932a4 | 2017-02-01 14:55:00 +0000 | [diff] [blame] | 69 | : ChildProcessProxy(processPool.alwaysRunsAtBackgroundPriority()) |
| 70 | , m_processPool(processPool) |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 71 | , m_numPendingConnectionRequests(0) |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 72 | , m_customProtocolManagerProxy(this, processPool) |
cdumez@apple.com | f98c3bf | 2017-04-28 22:41:56 +0000 | [diff] [blame] | 73 | , m_throttler(*this, processPool.shouldTakeUIBackgroundAssertion()) |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 74 | { |
ap@apple.com | 10a670e | 2012-12-05 23:28:31 +0000 | [diff] [blame] | 75 | connect(); |
| 76 | } |
| 77 | |
weinig@apple.com | 444fbd69 | 2013-01-27 05:32:53 +0000 | [diff] [blame] | 78 | NetworkProcessProxy::~NetworkProcessProxy() |
| 79 | { |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 80 | ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty()); |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 81 | ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty()); |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 82 | ASSERT(m_pendingDeleteWebsiteDataForOriginsCallbacks.isEmpty()); |
weinig@apple.com | 444fbd69 | 2013-01-27 05:32:53 +0000 | [diff] [blame] | 83 | } |
| 84 | |
ap@apple.com | 10a670e | 2012-12-05 23:28:31 +0000 | [diff] [blame] | 85 | void NetworkProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions) |
| 86 | { |
andersca@apple.com | b0b614f | 2016-02-12 21:11:28 +0000 | [diff] [blame] | 87 | launchOptions.processType = ProcessLauncher::ProcessType::Network; |
ap@apple.com | 9640e6f | 2015-09-25 22:36:09 +0000 | [diff] [blame] | 88 | ChildProcessProxy::getLaunchOptions(launchOptions); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 89 | } |
| 90 | |
andersca@apple.com | 15bc086 | 2015-01-16 21:37:42 +0000 | [diff] [blame] | 91 | void NetworkProcessProxy::connectionWillOpen(IPC::Connection& connection) |
andersca@apple.com | 296139a | 2013-02-12 20:56:57 +0000 | [diff] [blame] | 92 | { |
mitz@apple.com | da402b7 | 2013-12-04 21:04:31 +0000 | [diff] [blame] | 93 | #if ENABLE(SEC_ITEM_SHIM) |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 94 | SecItemShimProxy::singleton().initializeConnection(connection); |
mrobinson@webkit.org | ab8540d | 2014-03-20 17:20:58 +0000 | [diff] [blame] | 95 | #else |
| 96 | UNUSED_PARAM(connection); |
andersca@apple.com | 296139a | 2013-02-12 20:56:57 +0000 | [diff] [blame] | 97 | #endif |
| 98 | } |
| 99 | |
beidson@apple.com | e1fcf79 | 2015-05-15 04:39:51 +0000 | [diff] [blame] | 100 | void NetworkProcessProxy::processWillShutDown(IPC::Connection& connection) |
| 101 | { |
| 102 | ASSERT_UNUSED(connection, this->connection() == &connection); |
| 103 | } |
| 104 | |
achristensen@apple.com | 0d7548e | 2017-01-18 22:43:22 +0000 | [diff] [blame] | 105 | void NetworkProcessProxy::getNetworkProcessConnection(Ref<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>&& reply) |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 106 | { |
achristensen@apple.com | 0d7548e | 2017-01-18 22:43:22 +0000 | [diff] [blame] | 107 | m_pendingConnectionReplies.append(WTFMove(reply)); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 108 | |
andersca@apple.com | 90ab0cb | 2014-02-27 23:16:41 +0000 | [diff] [blame] | 109 | if (state() == State::Launching) { |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 110 | m_numPendingConnectionRequests++; |
| 111 | return; |
| 112 | } |
| 113 | |
andersca@apple.com | bcd68d4 | 2016-08-25 23:09:28 +0000 | [diff] [blame] | 114 | connection()->send(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess(), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply); |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 115 | } |
| 116 | |
jeffm@apple.com | 76858a1 | 2014-10-02 21:01:08 +0000 | [diff] [blame] | 117 | DownloadProxy* NetworkProcessProxy::createDownloadProxy(const ResourceRequest& resourceRequest) |
andersca@apple.com | 12e7492 | 2012-12-15 23:11:52 +0000 | [diff] [blame] | 118 | { |
| 119 | if (!m_downloadProxyMap) |
zandobersek@gmail.com | da3be5e3 | 2014-04-27 13:40:14 +0000 | [diff] [blame] | 120 | m_downloadProxyMap = std::make_unique<DownloadProxyMap>(this); |
andersca@apple.com | 12e7492 | 2012-12-15 23:11:52 +0000 | [diff] [blame] | 121 | |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 122 | return m_downloadProxyMap->createDownloadProxy(m_processPool, resourceRequest); |
andersca@apple.com | 12e7492 | 2012-12-15 23:11:52 +0000 | [diff] [blame] | 123 | } |
| 124 | |
andersca@apple.com | 8da0d68 | 2016-02-26 22:26:03 +0000 | [diff] [blame] | 125 | void NetworkProcessProxy::fetchWebsiteData(SessionID sessionID, OptionSet<WebsiteDataType> dataTypes, OptionSet<WebsiteDataFetchOption> fetchOptions, std::function<void (WebsiteData)> completionHandler) |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 126 | { |
| 127 | ASSERT(canSendMessage()); |
| 128 | |
| 129 | uint64_t callbackID = generateCallbackID(); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 130 | auto token = throttler().backgroundActivityToken(); |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 131 | RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is fetching Website data", this); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 132 | |
cdumez@apple.com | bc419b6 | 2016-06-28 18:08:39 +0000 | [diff] [blame] | 133 | m_pendingFetchWebsiteDataCallbacks.add(callbackID, [this, token, completionHandler, sessionID](WebsiteData websiteData) { |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 134 | completionHandler(WTFMove(websiteData)); |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 135 | RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is releasing a background assertion because the Network process is done fetching Website data", this); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 136 | }); |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 137 | |
andersca@apple.com | 8da0d68 | 2016-02-26 22:26:03 +0000 | [diff] [blame] | 138 | send(Messages::NetworkProcess::FetchWebsiteData(sessionID, dataTypes, fetchOptions, callbackID), 0); |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 139 | } |
| 140 | |
andersca@apple.com | 908a96d | 2016-02-26 19:49:36 +0000 | [diff] [blame] | 141 | void NetworkProcessProxy::deleteWebsiteData(WebCore::SessionID sessionID, OptionSet<WebsiteDataType> dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler) |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 142 | { |
| 143 | auto callbackID = generateCallbackID(); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 144 | auto token = throttler().backgroundActivityToken(); |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 145 | RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is deleting Website data", this); |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 146 | |
cdumez@apple.com | bc419b6 | 2016-06-28 18:08:39 +0000 | [diff] [blame] | 147 | m_pendingDeleteWebsiteDataCallbacks.add(callbackID, [this, token, completionHandler, sessionID] { |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 148 | completionHandler(); |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 149 | RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is releasing a background assertion because the Network process is done deleting Website data", this); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 150 | }); |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 151 | send(Messages::NetworkProcess::DeleteWebsiteData(sessionID, dataTypes, modifiedSince, callbackID), 0); |
| 152 | } |
| 153 | |
commit-queue@webkit.org | 778879b | 2016-11-12 01:18:22 +0000 | [diff] [blame] | 154 | void NetworkProcessProxy::deleteWebsiteDataForOrigins(SessionID sessionID, OptionSet<WebsiteDataType> dataTypes, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, std::function<void()> completionHandler) |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 155 | { |
| 156 | ASSERT(canSendMessage()); |
| 157 | |
| 158 | uint64_t callbackID = generateCallbackID(); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 159 | auto token = throttler().backgroundActivityToken(); |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 160 | RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is deleting Website data for several origins", this); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 161 | |
cdumez@apple.com | bc419b6 | 2016-06-28 18:08:39 +0000 | [diff] [blame] | 162 | m_pendingDeleteWebsiteDataForOriginsCallbacks.add(callbackID, [this, token, completionHandler, sessionID] { |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 163 | completionHandler(); |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 164 | RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NetworkProcessProxy is releasing a background assertion because the Network process is done deleting Website data for several origins", this); |
andersca@apple.com | 7360512 | 2015-07-20 17:08:10 +0000 | [diff] [blame] | 165 | }); |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 166 | |
commit-queue@webkit.org | 778879b | 2016-11-12 01:18:22 +0000 | [diff] [blame] | 167 | send(Messages::NetworkProcess::DeleteWebsiteDataForOrigins(sessionID, dataTypes, origins, cookieHostNames, callbackID), 0); |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 168 | } |
| 169 | |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 170 | void NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch() |
| 171 | { |
| 172 | // The network process must have crashed or exited, send any pending sync replies we might have. |
| 173 | while (!m_pendingConnectionReplies.isEmpty()) { |
achristensen@apple.com | 0d7548e | 2017-01-18 22:43:22 +0000 | [diff] [blame] | 174 | Ref<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 175 | |
commit-queue@webkit.org | a91a0be | 2015-11-01 14:23:21 +0000 | [diff] [blame] | 176 | #if USE(UNIX_DOMAIN_SOCKETS) |
andersca@apple.com | 69388f0 | 2013-12-30 20:20:02 +0000 | [diff] [blame] | 177 | reply->send(IPC::Attachment()); |
commit-queue@webkit.org | a91a0be | 2015-11-01 14:23:21 +0000 | [diff] [blame] | 178 | #elif OS(DARWIN) |
| 179 | reply->send(IPC::Attachment(0, MACH_MSG_TYPE_MOVE_SEND)); |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 180 | #else |
| 181 | notImplemented(); |
| 182 | #endif |
| 183 | } |
| 184 | |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 185 | for (const auto& callback : m_pendingFetchWebsiteDataCallbacks.values()) |
| 186 | callback(WebsiteData()); |
| 187 | m_pendingFetchWebsiteDataCallbacks.clear(); |
| 188 | |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 189 | for (const auto& callback : m_pendingDeleteWebsiteDataCallbacks.values()) |
| 190 | callback(); |
| 191 | m_pendingDeleteWebsiteDataCallbacks.clear(); |
| 192 | |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 193 | for (const auto& callback : m_pendingDeleteWebsiteDataForOriginsCallbacks.values()) |
| 194 | callback(); |
| 195 | m_pendingDeleteWebsiteDataForOriginsCallbacks.clear(); |
| 196 | |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 197 | // Tell the network process manager to forget about this network process proxy. This may cause us to be deleted. |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 198 | m_processPool.networkProcessCrashed(this); |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 199 | } |
| 200 | |
andersca@apple.com | 5ecb531 | 2016-08-20 00:11:17 +0000 | [diff] [blame] | 201 | void NetworkProcessProxy::didReceiveMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 202 | { |
weinig@apple.com | aa38204 | 2013-02-07 04:40:29 +0000 | [diff] [blame] | 203 | if (dispatchMessage(connection, decoder)) |
andersca@apple.com | 93b4c36 | 2012-12-16 01:26:05 +0000 | [diff] [blame] | 204 | return; |
| 205 | |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 206 | if (m_processPool.dispatchMessage(connection, decoder)) |
ap@apple.com | a6354cb | 2012-12-24 01:29:47 +0000 | [diff] [blame] | 207 | return; |
| 208 | |
andersca@apple.com | 93914d8 | 2013-01-30 22:48:09 +0000 | [diff] [blame] | 209 | didReceiveNetworkProcessProxyMessage(connection, decoder); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 210 | } |
| 211 | |
andersca@apple.com | 5ecb531 | 2016-08-20 00:11:17 +0000 | [diff] [blame] | 212 | void NetworkProcessProxy::didReceiveSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder) |
andersca@apple.com | 93b4c36 | 2012-12-16 01:26:05 +0000 | [diff] [blame] | 213 | { |
weinig@apple.com | aa38204 | 2013-02-07 04:40:29 +0000 | [diff] [blame] | 214 | if (dispatchSyncMessage(connection, decoder, replyEncoder)) |
andersca@apple.com | 93b4c36 | 2012-12-16 01:26:05 +0000 | [diff] [blame] | 215 | return; |
| 216 | |
| 217 | ASSERT_NOT_REACHED(); |
| 218 | } |
| 219 | |
andersca@apple.com | 30e768b | 2015-01-04 20:14:45 +0000 | [diff] [blame] | 220 | void NetworkProcessProxy::didClose(IPC::Connection&) |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 221 | { |
andersca@apple.com | 12e7492 | 2012-12-15 23:11:52 +0000 | [diff] [blame] | 222 | if (m_downloadProxyMap) |
| 223 | m_downloadProxyMap->processDidClose(); |
carlosgc@webkit.org | 2cd97a7 | 2016-11-22 07:49:55 +0000 | [diff] [blame] | 224 | m_customProtocolManagerProxy.processDidClose(); |
andersca@apple.com | 12e7492 | 2012-12-15 23:11:52 +0000 | [diff] [blame] | 225 | |
cdumez@apple.com | 9b21ebc | 2015-04-03 17:54:47 +0000 | [diff] [blame] | 226 | m_tokenForHoldingLockedFiles = nullptr; |
| 227 | |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 228 | // This may cause us to be deleted. |
| 229 | networkProcessCrashedOrFailedToLaunch(); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 230 | } |
| 231 | |
andersca@apple.com | 30e768b | 2015-01-04 20:14:45 +0000 | [diff] [blame] | 232 | void NetworkProcessProxy::didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference, IPC::StringReference) |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 233 | { |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 234 | } |
| 235 | |
andersca@apple.com | 69388f0 | 2013-12-30 20:20:02 +0000 | [diff] [blame] | 236 | void NetworkProcessProxy::didCreateNetworkConnectionToWebProcess(const IPC::Attachment& connectionIdentifier) |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 237 | { |
| 238 | ASSERT(!m_pendingConnectionReplies.isEmpty()); |
| 239 | |
| 240 | // Grab the first pending connection reply. |
| 241 | RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply> reply = m_pendingConnectionReplies.takeFirst(); |
| 242 | |
commit-queue@webkit.org | a91a0be | 2015-11-01 14:23:21 +0000 | [diff] [blame] | 243 | #if USE(UNIX_DOMAIN_SOCKETS) |
svillar@igalia.com | e78749f | 2013-12-09 12:28:44 +0000 | [diff] [blame] | 244 | reply->send(connectionIdentifier); |
commit-queue@webkit.org | a91a0be | 2015-11-01 14:23:21 +0000 | [diff] [blame] | 245 | #elif OS(DARWIN) |
| 246 | reply->send(IPC::Attachment(connectionIdentifier.port(), MACH_MSG_TYPE_MOVE_SEND)); |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 247 | #else |
| 248 | notImplemented(); |
| 249 | #endif |
| 250 | } |
| 251 | |
beidson@apple.com | daf9106 | 2013-01-26 00:03:48 +0000 | [diff] [blame] | 252 | void NetworkProcessProxy::didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const WebCore::AuthenticationChallenge& coreChallenge, uint64_t challengeID) |
| 253 | { |
| 254 | WebPageProxy* page = WebProcessProxy::webPage(pageID); |
| 255 | MESSAGE_CHECK(page); |
| 256 | |
krollin@apple.com | 77db180 | 2016-06-20 20:52:45 +0000 | [diff] [blame] | 257 | auto authenticationChallenge = AuthenticationChallengeProxy::create(coreChallenge, challengeID, connection()); |
| 258 | page->didReceiveAuthenticationChallengeProxy(frameID, WTFMove(authenticationChallenge)); |
beidson@apple.com | daf9106 | 2013-01-26 00:03:48 +0000 | [diff] [blame] | 259 | } |
| 260 | |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 261 | void NetworkProcessProxy::didFetchWebsiteData(uint64_t callbackID, const WebsiteData& websiteData) |
| 262 | { |
| 263 | auto callback = m_pendingFetchWebsiteDataCallbacks.take(callbackID); |
| 264 | callback(websiteData); |
| 265 | } |
| 266 | |
andersca@apple.com | 5ebf458 | 2014-12-09 20:29:59 +0000 | [diff] [blame] | 267 | void NetworkProcessProxy::didDeleteWebsiteData(uint64_t callbackID) |
| 268 | { |
| 269 | auto callback = m_pendingDeleteWebsiteDataCallbacks.take(callbackID); |
| 270 | callback(); |
| 271 | } |
| 272 | |
andersca@apple.com | ce92768 | 2015-02-27 20:14:22 +0000 | [diff] [blame] | 273 | void NetworkProcessProxy::didDeleteWebsiteDataForOrigins(uint64_t callbackID) |
| 274 | { |
| 275 | auto callback = m_pendingDeleteWebsiteDataForOriginsCallbacks.take(callbackID); |
| 276 | callback(); |
| 277 | } |
| 278 | |
beidson@apple.com | 4630340 | 2016-04-08 16:57:29 +0000 | [diff] [blame] | 279 | void NetworkProcessProxy::grantSandboxExtensionsToDatabaseProcessForBlobs(uint64_t requestID, const Vector<String>& paths) |
| 280 | { |
annulen@yandex.ru | 6a85450 | 2016-05-01 21:08:52 +0000 | [diff] [blame] | 281 | #if ENABLE(DATABASE_PROCESS) |
carlosgc@webkit.org | b48eddf | 2016-07-29 05:16:01 +0000 | [diff] [blame] | 282 | #if ENABLE(SANDBOX_EXTENSIONS) |
beidson@apple.com | 4630340 | 2016-04-08 16:57:29 +0000 | [diff] [blame] | 283 | SandboxExtension::HandleArray extensions; |
| 284 | extensions.allocate(paths.size()); |
| 285 | for (size_t i = 0; i < paths.size(); ++i) { |
| 286 | // ReadWrite is required for creating hard links as well as deleting the temporary file, which the DatabaseProcess will do. |
| 287 | SandboxExtension::createHandle(paths[i], SandboxExtension::ReadWrite, extensions[i]); |
| 288 | } |
| 289 | |
| 290 | m_processPool.sendToDatabaseProcessRelaunchingIfNecessary(Messages::DatabaseProcess::GrantSandboxExtensionsForBlobs(paths, extensions)); |
carlosgc@webkit.org | b48eddf | 2016-07-29 05:16:01 +0000 | [diff] [blame] | 291 | #endif |
beidson@apple.com | 4630340 | 2016-04-08 16:57:29 +0000 | [diff] [blame] | 292 | connection()->send(Messages::NetworkProcess::DidGrantSandboxExtensionsToDatabaseProcessForBlobs(requestID), 0); |
annulen@yandex.ru | 6a85450 | 2016-05-01 21:08:52 +0000 | [diff] [blame] | 293 | #endif |
beidson@apple.com | 4630340 | 2016-04-08 16:57:29 +0000 | [diff] [blame] | 294 | } |
| 295 | |
wilander@apple.com | 1bccb96 | 2017-03-09 04:02:14 +0000 | [diff] [blame] | 296 | #if HAVE(CFNETWORK_STORAGE_PARTITIONING) |
wilander@apple.com | fc67cb8 | 2017-04-25 17:05:04 +0000 | [diff] [blame] | 297 | void NetworkProcessProxy::shouldPartitionCookiesForTopPrivatelyOwnedDomains(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst) |
wilander@apple.com | 1bccb96 | 2017-03-09 04:02:14 +0000 | [diff] [blame] | 298 | { |
wilander@apple.com | fc67cb8 | 2017-04-25 17:05:04 +0000 | [diff] [blame] | 299 | connection()->send(Messages::NetworkProcess::ShouldPartitionCookiesForTopPrivatelyOwnedDomains(domainsToRemove, domainsToAdd, clearFirst), 0); |
wilander@apple.com | 1bccb96 | 2017-03-09 04:02:14 +0000 | [diff] [blame] | 300 | } |
| 301 | #endif |
| 302 | |
andersca@apple.com | 69388f0 | 2013-12-30 20:20:02 +0000 | [diff] [blame] | 303 | void NetworkProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier) |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 304 | { |
ap@apple.com | 10a670e | 2012-12-05 23:28:31 +0000 | [diff] [blame] | 305 | ChildProcessProxy::didFinishLaunching(launcher, connectionIdentifier); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 306 | |
andersca@apple.com | 69388f0 | 2013-12-30 20:20:02 +0000 | [diff] [blame] | 307 | if (IPC::Connection::identifierIsNull(connectionIdentifier)) { |
andersca@apple.com | 7f6925c | 2016-08-12 18:50:02 +0000 | [diff] [blame] | 308 | networkProcessCrashedOrFailedToLaunch(); |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 309 | return; |
| 310 | } |
| 311 | |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 312 | for (unsigned i = 0; i < m_numPendingConnectionRequests; ++i) |
ap@apple.com | 10a670e | 2012-12-05 23:28:31 +0000 | [diff] [blame] | 313 | connection()->send(Messages::NetworkProcess::CreateNetworkConnectionToWebProcess(), 0); |
beidson@apple.com | dfbdf94 | 2012-10-19 23:26:16 +0000 | [diff] [blame] | 314 | |
| 315 | m_numPendingConnectionRequests = 0; |
commit-queue@webkit.org | 948d584 | 2012-11-07 01:17:53 +0000 | [diff] [blame] | 316 | |
mitz@apple.com | 1b97088 | 2014-02-15 17:06:17 +0000 | [diff] [blame] | 317 | #if PLATFORM(COCOA) |
weinig@apple.com | 9c5a3ea | 2014-12-23 20:29:26 +0000 | [diff] [blame] | 318 | if (m_processPool.processSuppressionEnabled()) |
commit-queue@webkit.org | b1ebaef | 2013-01-29 22:52:19 +0000 | [diff] [blame] | 319 | setProcessSuppressionEnabled(true); |
commit-queue@webkit.org | 948d584 | 2012-11-07 01:17:53 +0000 | [diff] [blame] | 320 | #endif |
barraclough@apple.com | d915134 | 2014-04-17 01:40:04 +0000 | [diff] [blame] | 321 | |
bdakin@apple.com | 1539c6c | 2015-01-28 22:22:16 +0000 | [diff] [blame] | 322 | #if PLATFORM(IOS) |
simon.fraser@apple.com | dd0dee1 | 2014-04-22 00:23:04 +0000 | [diff] [blame] | 323 | if (xpc_connection_t connection = this->connection()->xpcConnection()) |
dbates@webkit.org | 3c7f071 | 2015-05-12 22:06:44 +0000 | [diff] [blame] | 324 | m_throttler.didConnectToProcess(xpc_connection_get_pid(connection)); |
barraclough@apple.com | d915134 | 2014-04-17 01:40:04 +0000 | [diff] [blame] | 325 | #endif |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 326 | } |
| 327 | |
cdumez@apple.com | 172b890 | 2017-01-30 18:45:21 +0000 | [diff] [blame] | 328 | void NetworkProcessProxy::logDiagnosticMessage(uint64_t pageID, const String& message, const String& description, WebCore::ShouldSample shouldSample) |
cdumez@apple.com | 35cab1d | 2015-02-11 23:57:31 +0000 | [diff] [blame] | 329 | { |
| 330 | WebPageProxy* page = WebProcessProxy::webPage(pageID); |
| 331 | // FIXME: We do this null-check because by the time the decision to log is made, the page may be gone. We should refactor to avoid this, |
| 332 | // but for now we simply drop the message in the rare case this happens. |
| 333 | if (!page) |
| 334 | return; |
| 335 | |
cdumez@apple.com | 172b890 | 2017-01-30 18:45:21 +0000 | [diff] [blame] | 336 | page->logDiagnosticMessage(message, description, shouldSample); |
cdumez@apple.com | 35cab1d | 2015-02-11 23:57:31 +0000 | [diff] [blame] | 337 | } |
| 338 | |
cdumez@apple.com | 172b890 | 2017-01-30 18:45:21 +0000 | [diff] [blame] | 339 | void NetworkProcessProxy::logDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result, WebCore::ShouldSample shouldSample) |
cdumez@apple.com | 35cab1d | 2015-02-11 23:57:31 +0000 | [diff] [blame] | 340 | { |
| 341 | WebPageProxy* page = WebProcessProxy::webPage(pageID); |
| 342 | // FIXME: We do this null-check because by the time the decision to log is made, the page may be gone. We should refactor to avoid this, |
| 343 | // but for now we simply drop the message in the rare case this happens. |
| 344 | if (!page) |
| 345 | return; |
| 346 | |
cdumez@apple.com | 172b890 | 2017-01-30 18:45:21 +0000 | [diff] [blame] | 347 | page->logDiagnosticMessageWithResult(message, description, result, shouldSample); |
cdumez@apple.com | 35cab1d | 2015-02-11 23:57:31 +0000 | [diff] [blame] | 348 | } |
| 349 | |
cdumez@apple.com | 172b890 | 2017-01-30 18:45:21 +0000 | [diff] [blame] | 350 | void NetworkProcessProxy::logDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample shouldSample) |
cdumez@apple.com | 35cab1d | 2015-02-11 23:57:31 +0000 | [diff] [blame] | 351 | { |
| 352 | WebPageProxy* page = WebProcessProxy::webPage(pageID); |
| 353 | // FIXME: We do this null-check because by the time the decision to log is made, the page may be gone. We should refactor to avoid this, |
| 354 | // but for now we simply drop the message in the rare case this happens. |
| 355 | if (!page) |
| 356 | return; |
| 357 | |
cdumez@apple.com | 172b890 | 2017-01-30 18:45:21 +0000 | [diff] [blame] | 358 | page->logDiagnosticMessageWithValue(message, description, value, significantFigures, shouldSample); |
cdumez@apple.com | 35cab1d | 2015-02-11 23:57:31 +0000 | [diff] [blame] | 359 | } |
| 360 | |
commit-queue@webkit.org | ec8a30a | 2016-06-27 20:59:27 +0000 | [diff] [blame] | 361 | #if USE(PROTECTION_SPACE_AUTH_CALLBACK) |
| 362 | void NetworkProcessProxy::canAuthenticateAgainstProtectionSpace(uint64_t loaderID, uint64_t pageID, uint64_t frameID, const WebCore::ProtectionSpace& protectionSpace) |
| 363 | { |
| 364 | WebPageProxy* page = WebProcessProxy::webPage(pageID); |
| 365 | if (!page) |
| 366 | return; |
| 367 | |
| 368 | page->canAuthenticateAgainstProtectionSpace(loaderID, frameID, protectionSpace); |
| 369 | } |
| 370 | #endif |
| 371 | |
dbates@webkit.org | 4b41cef | 2015-05-11 17:27:13 +0000 | [diff] [blame] | 372 | void NetworkProcessProxy::sendProcessWillSuspendImminently() |
| 373 | { |
| 374 | if (!canSendMessage()) |
| 375 | return; |
| 376 | |
| 377 | bool handled = false; |
simon.fraser@apple.com | cbeb30c3 | 2016-11-27 02:27:55 +0000 | [diff] [blame] | 378 | sendSync(Messages::NetworkProcess::ProcessWillSuspendImminently(), Messages::NetworkProcess::ProcessWillSuspendImminently::Reply(handled), 0, 1_s); |
dbates@webkit.org | 4b41cef | 2015-05-11 17:27:13 +0000 | [diff] [blame] | 379 | } |
| 380 | |
dbates@webkit.org | b89b156 | 2015-05-14 03:07:25 +0000 | [diff] [blame] | 381 | void NetworkProcessProxy::sendPrepareToSuspend() |
cdumez@apple.com | 7554d07 | 2015-03-31 19:03:40 +0000 | [diff] [blame] | 382 | { |
| 383 | if (canSendMessage()) |
dbates@webkit.org | b89b156 | 2015-05-14 03:07:25 +0000 | [diff] [blame] | 384 | send(Messages::NetworkProcess::PrepareToSuspend(), 0); |
cdumez@apple.com | 7554d07 | 2015-03-31 19:03:40 +0000 | [diff] [blame] | 385 | } |
| 386 | |
dbates@webkit.org | b89b156 | 2015-05-14 03:07:25 +0000 | [diff] [blame] | 387 | void NetworkProcessProxy::sendCancelPrepareToSuspend() |
cdumez@apple.com | 7554d07 | 2015-03-31 19:03:40 +0000 | [diff] [blame] | 388 | { |
| 389 | if (canSendMessage()) |
dbates@webkit.org | b89b156 | 2015-05-14 03:07:25 +0000 | [diff] [blame] | 390 | send(Messages::NetworkProcess::CancelPrepareToSuspend(), 0); |
cdumez@apple.com | 7554d07 | 2015-03-31 19:03:40 +0000 | [diff] [blame] | 391 | } |
| 392 | |
cdumez@apple.com | 7554d07 | 2015-03-31 19:03:40 +0000 | [diff] [blame] | 393 | void NetworkProcessProxy::sendProcessDidResume() |
| 394 | { |
| 395 | if (canSendMessage()) |
| 396 | send(Messages::NetworkProcess::ProcessDidResume(), 0); |
| 397 | } |
| 398 | |
| 399 | void NetworkProcessProxy::processReadyToSuspend() |
| 400 | { |
dbates@webkit.org | 3c7f071 | 2015-05-12 22:06:44 +0000 | [diff] [blame] | 401 | m_throttler.processReadyToSuspend(); |
cdumez@apple.com | 7554d07 | 2015-03-31 19:03:40 +0000 | [diff] [blame] | 402 | } |
| 403 | |
barraclough@apple.com | 2b8cba6 | 2015-05-22 17:19:39 +0000 | [diff] [blame] | 404 | void NetworkProcessProxy::didSetAssertionState(AssertionState) |
| 405 | { |
| 406 | } |
| 407 | |
cdumez@apple.com | 9b21ebc | 2015-04-03 17:54:47 +0000 | [diff] [blame] | 408 | void NetworkProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles) |
| 409 | { |
| 410 | if (!isHoldingLockedFiles) { |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 411 | RELEASE_LOG(ProcessSuspension, "UIProcess is releasing a background assertion because the Network process is no longer holding locked files"); |
cdumez@apple.com | 9b21ebc | 2015-04-03 17:54:47 +0000 | [diff] [blame] | 412 | m_tokenForHoldingLockedFiles = nullptr; |
| 413 | return; |
| 414 | } |
cdumez@apple.com | 7706fbe | 2016-06-22 17:00:23 +0000 | [diff] [blame] | 415 | if (!m_tokenForHoldingLockedFiles) { |
krollin@apple.com | 03e63b1 | 2016-09-01 01:33:40 +0000 | [diff] [blame] | 416 | RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the Network process is holding locked files"); |
dbates@webkit.org | 3c7f071 | 2015-05-12 22:06:44 +0000 | [diff] [blame] | 417 | m_tokenForHoldingLockedFiles = m_throttler.backgroundActivityToken(); |
cdumez@apple.com | 7706fbe | 2016-06-22 17:00:23 +0000 | [diff] [blame] | 418 | } |
cdumez@apple.com | 9b21ebc | 2015-04-03 17:54:47 +0000 | [diff] [blame] | 419 | } |
| 420 | |
beidson@apple.com | 21dd3ed | 2012-10-12 17:13:13 +0000 | [diff] [blame] | 421 | } // namespace WebKit |