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" |
ap@apple.com | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 35 | #include "PlatformCertificateInfo.h" |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 36 | #include "WebCoreArgumentCoders.h" |
beidson@apple.com | 1bc450a | 2012-12-21 18:46:04 +0000 | [diff] [blame] | 37 | #include "WebErrors.h" |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 38 | #include "WebProcess.h" |
andersca@apple.com | 0ab76de | 2013-04-22 22:56:19 +0000 | [diff] [blame] | 39 | #include <WebCore/DocumentLoader.h> |
beidson@apple.com | 472f6d2 | 2013-03-18 18:05:26 +0000 | [diff] [blame] | 40 | #include <WebCore/ResourceBuffer.h> |
ap@apple.com | 18ae25f | 2013-01-27 01:01:08 +0000 | [diff] [blame] | 41 | #include <WebCore/ResourceError.h> |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 42 | #include <WebCore/ResourceLoader.h> |
| 43 | |
| 44 | using namespace WebCore; |
| 45 | |
| 46 | namespace WebKit { |
| 47 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 48 | PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader) |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 49 | { |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 50 | return adoptRef(new WebResourceLoader(coreLoader)); |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 51 | } |
| 52 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 53 | WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader) |
| 54 | : m_coreLoader(coreLoader) |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 55 | { |
| 56 | } |
| 57 | |
| 58 | WebResourceLoader::~WebResourceLoader() |
| 59 | { |
| 60 | } |
| 61 | |
beidson@apple.com | 7fb049d | 2012-11-17 00:40:15 +0000 | [diff] [blame] | 62 | CoreIPC::Connection* WebResourceLoader::connection() const |
| 63 | { |
| 64 | return WebProcess::shared().networkConnection()->connection(); |
| 65 | } |
| 66 | |
| 67 | uint64_t WebResourceLoader::destinationID() const |
| 68 | { |
| 69 | return m_coreLoader->identifier(); |
| 70 | } |
| 71 | |
beidson@apple.com | 4492577 | 2013-01-23 20:21:19 +0000 | [diff] [blame] | 72 | void WebResourceLoader::cancelResourceLoader() |
| 73 | { |
| 74 | m_coreLoader->cancel(); |
| 75 | } |
| 76 | |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 77 | void WebResourceLoader::detachFromCoreLoader() |
| 78 | { |
| 79 | m_coreLoader = 0; |
| 80 | } |
| 81 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 82 | void WebResourceLoader::willSendRequest(const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 83 | { |
| 84 | 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] | 85 | |
| 86 | RefPtr<WebResourceLoader> protector(this); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 87 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 88 | ResourceRequest newRequest = proposedRequest; |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 89 | m_coreLoader->willSendRequest(newRequest, redirectResponse); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 90 | |
| 91 | if (!m_coreLoader) |
| 92 | return; |
| 93 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 94 | send(Messages::NetworkResourceLoader::ContinueWillSendRequest(newRequest)); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 95 | } |
| 96 | |
ap@apple.com | 0c05506 | 2013-04-03 18:23:34 +0000 | [diff] [blame] | 97 | void WebResourceLoader::didSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent) |
| 98 | { |
| 99 | m_coreLoader->didSendData(bytesSent, totalBytesToBeSent); |
| 100 | } |
| 101 | |
ap@apple.com | e251501 | 2013-04-28 03:22:55 +0000 | [diff] [blame] | 102 | void WebResourceLoader::didReceiveResponseWithCertificateInfo(const ResourceResponse& response, const PlatformCertificateInfo& certificateInfo, bool needsContinueDidReceiveResponseMessage) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 103 | { |
ap@apple.com | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 104 | 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] | 105 | |
| 106 | RefPtr<WebResourceLoader> protector(this); |
| 107 | |
ap@apple.com | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 108 | ResourceResponse responseCopy(response); |
| 109 | responseCopy.setCertificateChain(certificateInfo.certificateChain()); |
| 110 | m_coreLoader->didReceiveResponse(responseCopy); |
andersca@apple.com | 0ab76de | 2013-04-22 22:56:19 +0000 | [diff] [blame] | 111 | |
ap@apple.com | 63cec80 | 2013-04-29 18:08:57 +0000 | [diff] [blame^] | 112 | if (!m_coreLoader) |
| 113 | return; |
| 114 | |
ap@apple.com | e251501 | 2013-04-28 03:22:55 +0000 | [diff] [blame] | 115 | if (needsContinueDidReceiveResponseMessage) |
andersca@apple.com | 0ab76de | 2013-04-22 22:56:19 +0000 | [diff] [blame] | 116 | send(Messages::NetworkResourceLoader::ContinueDidReceiveResponse()); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 117 | } |
| 118 | |
beidson@apple.com | c289a14 | 2013-03-13 21:36:29 +0000 | [diff] [blame] | 119 | void WebResourceLoader::didReceiveData(const CoreIPC::DataReference& data, int64_t encodedDataLength) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 120 | { |
| 121 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data()); |
beidson@apple.com | c289a14 | 2013-03-13 21:36:29 +0000 | [diff] [blame] | 122 | 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] | 123 | } |
| 124 | |
| 125 | void WebResourceLoader::didFinishResourceLoad(double finishTime) |
| 126 | { |
| 127 | LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); |
| 128 | m_coreLoader->didFinishLoading(finishTime); |
| 129 | } |
| 130 | |
| 131 | void WebResourceLoader::didFailResourceLoad(const ResourceError& error) |
| 132 | { |
| 133 | LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); |
| 134 | |
| 135 | m_coreLoader->didFail(error); |
| 136 | } |
| 137 | |
| 138 | void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime) |
| 139 | { |
| 140 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data()); |
| 141 | |
beidson@apple.com | 2130248 | 2013-03-22 00:14:03 +0000 | [diff] [blame] | 142 | RefPtr<SharedBuffer> buffer = handle.tryWrapInSharedBuffer(); |
| 143 | if (!buffer) { |
| 144 | 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] | 145 | m_coreLoader->didFail(internalError(m_coreLoader->request().url())); |
| 146 | return; |
| 147 | } |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 148 | |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 149 | RefPtr<WebResourceLoader> protector(this); |
| 150 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 151 | // Only send data to the didReceiveData callback if it exists. |
beidson@apple.com | 2130248 | 2013-03-22 00:14:03 +0000 | [diff] [blame] | 152 | if (buffer->size()) |
beidson@apple.com | 472f6d2 | 2013-03-18 18:05:26 +0000 | [diff] [blame] | 153 | m_coreLoader->didReceiveBuffer(buffer.get(), buffer->size(), DataPayloadWholeResource); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 154 | |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 155 | if (!m_coreLoader) |
| 156 | return; |
| 157 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 158 | m_coreLoader->didFinishLoading(finishTime); |
| 159 | } |
| 160 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 161 | void WebResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace) |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 162 | { |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 163 | RefPtr<WebResourceLoader> protector(this); |
| 164 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 165 | bool result = m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace); |
beidson@apple.com | f8d6474 | 2013-03-29 23:02:28 +0000 | [diff] [blame] | 166 | |
| 167 | if (!m_coreLoader) |
| 168 | return; |
| 169 | |
ap@apple.com | cd1fa45 | 2013-03-26 21:27:45 +0000 | [diff] [blame] | 170 | send(Messages::NetworkResourceLoader::ContinueCanAuthenticateAgainstProtectionSpace(result)); |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 171 | } |
| 172 | |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 173 | } // namespace WebKit |
| 174 | |
| 175 | #endif // ENABLE(NETWORK_PROCESS) |