beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 1 | /* |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 2 | * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +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 "WebResourceLoader.h" |
| 28 | |
| 29 | #if ENABLE(NETWORK_PROCESS) |
| 30 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 31 | #include "DataReference.h" |
| 32 | #include "Logging.h" |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 33 | #include "NetworkProcessConnection.h" |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 34 | #include "NetworkResourceLoaderMessages.h" |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 35 | #include "WebCoreArgumentCoders.h" |
beidson@apple.com | 1bc450a | 2012-12-21 18:46:04 +0000 | [diff] [blame] | 36 | #include "WebErrors.h" |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 37 | #include "WebProcess.h" |
ap@apple.com | 178e91d | 2014-05-18 05:29:36 +0000 | [diff] [blame] | 38 | #include <WebCore/ApplicationCacheHost.h> |
ossy@webkit.org | 84c850d | 2013-12-12 12:30:58 +0000 | [diff] [blame] | 39 | #include <WebCore/CertificateInfo.h> |
andersca@apple.com | 0ab76de | 2013-04-22 22:56:19 +0000 | [diff] [blame] | 40 | #include <WebCore/DocumentLoader.h> |
beidson@apple.com | 472f6d2 | 2013-03-18 18:05:26 +0000 | [diff] [blame] | 41 | #include <WebCore/ResourceBuffer.h> |
ap@apple.com | 18ae25f | 2013-01-27 01:01:08 +0000 | [diff] [blame] | 42 | #include <WebCore/ResourceError.h> |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 43 | #include <WebCore/ResourceLoader.h> |
| 44 | |
| 45 | using namespace WebCore; |
| 46 | |
| 47 | namespace WebKit { |
| 48 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 49 | PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader) |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 50 | { |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 51 | return adoptRef(new WebResourceLoader(coreLoader)); |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 52 | } |
| 53 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 54 | WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader) |
| 55 | : m_coreLoader(coreLoader) |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | |
| 59 | WebResourceLoader::~WebResourceLoader() |
| 60 | { |
| 61 | } |
| 62 | |
andersca@apple.com | 69388f0 | 2013-12-30 20:20:02 +0000 | [diff] [blame] | 63 | IPC::Connection* WebResourceLoader::messageSenderConnection() |
beidson@apple.com | 7fb049d | 2012-11-17 00:40:15 +0000 | [diff] [blame] | 64 | { |
| 65 | return WebProcess::shared().networkConnection()->connection(); |
| 66 | } |
| 67 | |
andersca@apple.com | d4aa592 | 2013-05-25 00:17:20 +0000 | [diff] [blame] | 68 | uint64_t WebResourceLoader::messageSenderDestinationID() |
beidson@apple.com | 7fb049d | 2012-11-17 00:40:15 +0000 | [diff] [blame] | 69 | { |
| 70 | return m_coreLoader->identifier(); |
| 71 | } |
| 72 | |
beidson@apple.com | 4492577 | 2013-01-23 20:21:19 +0000 | [diff] [blame] | 73 | void WebResourceLoader::cancelResourceLoader() |
| 74 | { |
| 75 | m_coreLoader->cancel(); |
| 76 | } |
| 77 | |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 78 | void WebResourceLoader::detachFromCoreLoader() |
| 79 | { |
| 80 | m_coreLoader = 0; |
| 81 | } |
| 82 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 83 | void WebResourceLoader::willSendRequest(const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 84 | { |
| 85 | LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data()); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 86 | |
akling@apple.com | a34e522 | 2013-09-10 03:44:05 +0000 | [diff] [blame] | 87 | Ref<WebResourceLoader> protect(*this); |
ap@apple.com | 178e91d | 2014-05-18 05:29:36 +0000 | [diff] [blame] | 88 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 89 | ResourceRequest newRequest = proposedRequest; |
ap@apple.com | 178e91d | 2014-05-18 05:29:36 +0000 | [diff] [blame] | 90 | if (m_coreLoader->documentLoader()->applicationCacheHost()->maybeLoadFallbackForRedirect(m_coreLoader.get(), newRequest, redirectResponse)) |
| 91 | return; |
commit-queue@webkit.org | 0edb411 | 2014-09-11 17:20:18 +0000 | [diff] [blame^] | 92 | // FIXME: Do we need to update NetworkResourceLoader clientCredentialPolicy in case loader policy is DoNotAskClientForCrossOriginCredentials? |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 93 | m_coreLoader->willSendRequest(newRequest, redirectResponse); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 94 | |
| 95 | if (!m_coreLoader) |
| 96 | return; |
| 97 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 98 | send(Messages::NetworkResourceLoader::ContinueWillSendRequest(newRequest)); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 99 | } |
| 100 | |
ap@apple.com | 0c05506 | 2013-04-03 18:23:34 +0000 | [diff] [blame] | 101 | void WebResourceLoader::didSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent) |
| 102 | { |
| 103 | m_coreLoader->didSendData(bytesSent, totalBytesToBeSent); |
| 104 | } |
| 105 | |
antti@apple.com | 6d2fe7d | 2014-09-09 08:19:16 +0000 | [diff] [blame] | 106 | void WebResourceLoader::didReceiveResponse(const ResourceResponse& response, bool needsContinueDidReceiveResponseMessage) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 107 | { |
ap@apple.com | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 108 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponseWithCertificateInfo for '%s'. Status %d.", m_coreLoader->url().string().utf8().data(), response.httpStatusCode()); |
andersca@apple.com | 028c073 | 2013-04-23 21:56:59 +0000 | [diff] [blame] | 109 | |
akling@apple.com | a34e522 | 2013-09-10 03:44:05 +0000 | [diff] [blame] | 110 | Ref<WebResourceLoader> protect(*this); |
andersca@apple.com | 028c073 | 2013-04-23 21:56:59 +0000 | [diff] [blame] | 111 | |
antti@apple.com | 6d2fe7d | 2014-09-09 08:19:16 +0000 | [diff] [blame] | 112 | if (m_coreLoader->documentLoader()->applicationCacheHost()->maybeLoadFallbackForResponse(m_coreLoader.get(), response)) |
ap@apple.com | 178e91d | 2014-05-18 05:29:36 +0000 | [diff] [blame] | 113 | return; |
aestes@apple.com | 08cc699 | 2014-08-05 17:49:44 +0000 | [diff] [blame] | 114 | |
| 115 | #if USE(QUICK_LOOK) |
| 116 | // Refrain from calling didReceiveResponse if QuickLook will convert this response, since the MIME type of the |
| 117 | // converted resource isn't yet known. WebResourceLoaderQuickLookDelegate will later call didReceiveResponse upon |
| 118 | // receiving the converted data. |
antti@apple.com | 6d2fe7d | 2014-09-09 08:19:16 +0000 | [diff] [blame] | 119 | m_coreLoader->documentLoader()->setQuickLookHandle(QuickLookHandle::create(resourceLoader(), response.nsURLResponse())); |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 120 | if (!m_coreLoader->documentLoader()->quickLookHandle()) |
aestes@apple.com | 08cc699 | 2014-08-05 17:49:44 +0000 | [diff] [blame] | 121 | #endif |
antti@apple.com | 6d2fe7d | 2014-09-09 08:19:16 +0000 | [diff] [blame] | 122 | m_coreLoader->didReceiveResponse(response); |
andersca@apple.com | 0ab76de | 2013-04-22 22:56:19 +0000 | [diff] [blame] | 123 | |
beidson@apple.com | 6b67733 | 2013-04-30 19:21:07 +0000 | [diff] [blame] | 124 | // If m_coreLoader becomes null as a result of the didReceiveResponse callback, we can't use the send function(). |
ap@apple.com | 63cec80 | 2013-04-29 18:08:57 +0000 | [diff] [blame] | 125 | if (!m_coreLoader) |
| 126 | return; |
| 127 | |
ap@apple.com | e251501 | 2013-04-28 03:22:55 +0000 | [diff] [blame] | 128 | if (needsContinueDidReceiveResponseMessage) |
andersca@apple.com | 0ab76de | 2013-04-22 22:56:19 +0000 | [diff] [blame] | 129 | send(Messages::NetworkResourceLoader::ContinueDidReceiveResponse()); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 130 | } |
| 131 | |
andersca@apple.com | 69388f0 | 2013-12-30 20:20:02 +0000 | [diff] [blame] | 132 | void WebResourceLoader::didReceiveData(const IPC::DataReference& data, int64_t encodedDataLength) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 133 | { |
| 134 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data()); |
commit-queue@webkit.org | 1cabcea | 2014-03-19 19:24:30 +0000 | [diff] [blame] | 135 | |
| 136 | #if USE(QUICK_LOOK) |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 137 | if (QuickLookHandle* quickLookHandle = m_coreLoader->documentLoader()->quickLookHandle()) { |
| 138 | if (quickLookHandle->didReceiveData(adoptCF(CFDataCreate(kCFAllocatorDefault, data.data(), data.size())).get())) |
commit-queue@webkit.org | 1cabcea | 2014-03-19 19:24:30 +0000 | [diff] [blame] | 139 | return; |
| 140 | } |
| 141 | #endif |
beidson@apple.com | c289a14 | 2013-03-13 21:36:29 +0000 | [diff] [blame] | 142 | m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, DataPayloadBytes); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void WebResourceLoader::didFinishResourceLoad(double finishTime) |
| 146 | { |
| 147 | LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); |
commit-queue@webkit.org | 1cabcea | 2014-03-19 19:24:30 +0000 | [diff] [blame] | 148 | |
| 149 | #if USE(QUICK_LOOK) |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 150 | if (QuickLookHandle* quickLookHandle = m_coreLoader->documentLoader()->quickLookHandle()) { |
| 151 | if (quickLookHandle->didFinishLoading()) |
| 152 | return; |
| 153 | } |
commit-queue@webkit.org | 1cabcea | 2014-03-19 19:24:30 +0000 | [diff] [blame] | 154 | #endif |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 155 | m_coreLoader->didFinishLoading(finishTime); |
| 156 | } |
| 157 | |
| 158 | void WebResourceLoader::didFailResourceLoad(const ResourceError& error) |
| 159 | { |
| 160 | LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); |
| 161 | |
commit-queue@webkit.org | 1cabcea | 2014-03-19 19:24:30 +0000 | [diff] [blame] | 162 | #if USE(QUICK_LOOK) |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 163 | if (QuickLookHandle* quickLookHandle = m_coreLoader->documentLoader()->quickLookHandle()) |
| 164 | quickLookHandle->didFail(); |
commit-queue@webkit.org | 1cabcea | 2014-03-19 19:24:30 +0000 | [diff] [blame] | 165 | #endif |
ap@apple.com | 178e91d | 2014-05-18 05:29:36 +0000 | [diff] [blame] | 166 | if (m_coreLoader->documentLoader()->applicationCacheHost()->maybeLoadFallbackForError(m_coreLoader.get(), error)) |
| 167 | return; |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 168 | m_coreLoader->didFail(error); |
| 169 | } |
| 170 | |
ossy@webkit.org | b72e86c0 | 2013-10-10 15:35:02 +0000 | [diff] [blame] | 171 | #if ENABLE(SHAREABLE_RESOURCE) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 172 | void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime) |
| 173 | { |
| 174 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data()); |
| 175 | |
aestes@apple.com | 425d314 | 2014-05-23 00:40:23 +0000 | [diff] [blame] | 176 | #if USE(QUICK_LOOK) |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 177 | if (QuickLookHandle* quickLookHandle = m_coreLoader->documentLoader()->quickLookHandle()) { |
aestes@apple.com | 425d314 | 2014-05-23 00:40:23 +0000 | [diff] [blame] | 178 | RetainPtr<CFDataRef> cfBuffer = handle.tryWrapInCFData(); |
| 179 | if (cfBuffer) { |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 180 | if (quickLookHandle->didReceiveData(cfBuffer.get())) { |
| 181 | quickLookHandle->didFinishLoading(); |
aestes@apple.com | 425d314 | 2014-05-23 00:40:23 +0000 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | } else |
aestes@apple.com | 0661314 | 2014-08-07 00:16:36 +0000 | [diff] [blame] | 185 | quickLookHandle->didFail(); |
aestes@apple.com | 425d314 | 2014-05-23 00:40:23 +0000 | [diff] [blame] | 186 | } |
| 187 | #endif |
| 188 | |
beidson@apple.com | 2130248 | 2013-03-22 00:14:03 +0000 | [diff] [blame] | 189 | RefPtr<SharedBuffer> buffer = handle.tryWrapInSharedBuffer(); |
| 190 | if (!buffer) { |
| 191 | LOG_ERROR("Unable to create buffer from ShareableResource sent from the network process."); |
beidson@apple.com | 472f6d2 | 2013-03-18 18:05:26 +0000 | [diff] [blame] | 192 | m_coreLoader->didFail(internalError(m_coreLoader->request().url())); |
| 193 | return; |
| 194 | } |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 195 | |
akling@apple.com | a34e522 | 2013-09-10 03:44:05 +0000 | [diff] [blame] | 196 | Ref<WebResourceLoader> protect(*this); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 197 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 198 | // Only send data to the didReceiveData callback if it exists. |
beidson@apple.com | 2130248 | 2013-03-22 00:14:03 +0000 | [diff] [blame] | 199 | if (buffer->size()) |
beidson@apple.com | 472f6d2 | 2013-03-18 18:05:26 +0000 | [diff] [blame] | 200 | m_coreLoader->didReceiveBuffer(buffer.get(), buffer->size(), DataPayloadWholeResource); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 201 | |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 202 | if (!m_coreLoader) |
| 203 | return; |
| 204 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 205 | m_coreLoader->didFinishLoading(finishTime); |
| 206 | } |
ossy@webkit.org | b72e86c0 | 2013-10-10 15:35:02 +0000 | [diff] [blame] | 207 | #endif |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 208 | |
ossy@webkit.org | ba31fed | 2013-09-17 08:20:21 +0000 | [diff] [blame] | 209 | #if USE(PROTECTION_SPACE_AUTH_CALLBACK) |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 210 | void WebResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace) |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 211 | { |
akling@apple.com | a34e522 | 2013-09-10 03:44:05 +0000 | [diff] [blame] | 212 | Ref<WebResourceLoader> protect(*this); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 213 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 214 | bool result = m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 215 | |
| 216 | if (!m_coreLoader) |
| 217 | return; |
| 218 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 219 | send(Messages::NetworkResourceLoader::ContinueCanAuthenticateAgainstProtectionSpace(result)); |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 220 | } |
ossy@webkit.org | ba31fed | 2013-09-17 08:20:21 +0000 | [diff] [blame] | 221 | #endif |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 222 | |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 223 | } // namespace WebKit |
| 224 | |
| 225 | #endif // ENABLE(NETWORK_PROCESS) |