beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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'' |
| 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 | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 34 | #include "PlatformCertificateInfo.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 | 18ae25f | 2013-01-27 01:01:08 +0000 | [diff] [blame^] | 38 | #include <WebCore/ResourceError.h> |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 39 | #include <WebCore/ResourceLoader.h> |
| 40 | |
| 41 | using namespace WebCore; |
| 42 | |
| 43 | namespace WebKit { |
| 44 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 45 | PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader) |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 46 | { |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 47 | return adoptRef(new WebResourceLoader(coreLoader)); |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 48 | } |
| 49 | |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 50 | WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader) |
| 51 | : m_coreLoader(coreLoader) |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 52 | { |
| 53 | } |
| 54 | |
| 55 | WebResourceLoader::~WebResourceLoader() |
| 56 | { |
| 57 | } |
| 58 | |
beidson@apple.com | 7fb049d | 2012-11-17 00:40:15 +0000 | [diff] [blame] | 59 | CoreIPC::Connection* WebResourceLoader::connection() const |
| 60 | { |
| 61 | return WebProcess::shared().networkConnection()->connection(); |
| 62 | } |
| 63 | |
| 64 | uint64_t WebResourceLoader::destinationID() const |
| 65 | { |
| 66 | return m_coreLoader->identifier(); |
| 67 | } |
| 68 | |
beidson@apple.com | 4492577 | 2013-01-23 20:21:19 +0000 | [diff] [blame] | 69 | void WebResourceLoader::cancelResourceLoader() |
| 70 | { |
| 71 | m_coreLoader->cancel(); |
| 72 | } |
| 73 | |
ap@apple.com | 7681341 | 2013-01-12 00:08:30 +0000 | [diff] [blame] | 74 | void WebResourceLoader::willSendRequest(const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse, ResourceRequest& newRequest) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 75 | { |
| 76 | LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data()); |
| 77 | |
ap@apple.com | 7681341 | 2013-01-12 00:08:30 +0000 | [diff] [blame] | 78 | newRequest = proposedRequest; |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 79 | m_coreLoader->willSendRequest(newRequest, redirectResponse); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 80 | } |
| 81 | |
ap@apple.com | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 82 | void WebResourceLoader::didReceiveResponseWithCertificateInfo(const ResourceResponse& response, const PlatformCertificateInfo& certificateInfo) |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 83 | { |
ap@apple.com | 6142382 | 2012-12-20 00:58:25 +0000 | [diff] [blame] | 84 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponseWithCertificateInfo for '%s'. Status %d.", m_coreLoader->url().string().utf8().data(), response.httpStatusCode()); |
| 85 | ResourceResponse responseCopy(response); |
| 86 | responseCopy.setCertificateChain(certificateInfo.certificateChain()); |
| 87 | m_coreLoader->didReceiveResponse(responseCopy); |
beidson@apple.com | aec2e29 | 2012-11-14 23:59:01 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void WebResourceLoader::didReceiveData(const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce) |
| 91 | { |
| 92 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data()); |
| 93 | m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, allAtOnce); |
| 94 | } |
| 95 | |
| 96 | void WebResourceLoader::didFinishResourceLoad(double finishTime) |
| 97 | { |
| 98 | LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); |
| 99 | m_coreLoader->didFinishLoading(finishTime); |
| 100 | } |
| 101 | |
| 102 | void WebResourceLoader::didFailResourceLoad(const ResourceError& error) |
| 103 | { |
| 104 | LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data()); |
| 105 | |
| 106 | m_coreLoader->didFail(error); |
| 107 | } |
| 108 | |
| 109 | void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime) |
| 110 | { |
| 111 | LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data()); |
| 112 | |
| 113 | RefPtr<ShareableResource> resource = ShareableResource::create(handle); |
| 114 | |
| 115 | // Only send data to the didReceiveData callback if it exists. |
| 116 | if (!resource->size()) { |
| 117 | // FIXME (NetworkProcess): Give ResourceLoader the ability to take ResourceBuffer arguments. |
| 118 | // That will allow us to pass it along to CachedResources and allow them to hang on to the shared memory behind the scenes. |
| 119 | // FIXME (NetworkProcess): Pass along the correct value for encodedDataLength. |
| 120 | m_coreLoader->didReceiveData(reinterpret_cast<const char*>(resource->data()), resource->size(), -1 /* encodedDataLength */ , true); |
| 121 | } |
| 122 | |
| 123 | m_coreLoader->didFinishLoading(finishTime); |
| 124 | } |
| 125 | |
ap@apple.com | 7681341 | 2013-01-12 00:08:30 +0000 | [diff] [blame] | 126 | void WebResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace, bool& result) |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 127 | { |
ap@apple.com | 7681341 | 2013-01-12 00:08:30 +0000 | [diff] [blame] | 128 | result = m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace); |
beidson@apple.com | 29824ff | 2012-11-19 19:22:48 +0000 | [diff] [blame] | 129 | } |
| 130 | |
beidson@apple.com | 1bc450a | 2012-12-21 18:46:04 +0000 | [diff] [blame] | 131 | void WebResourceLoader::networkProcessCrashed() |
| 132 | { |
| 133 | ASSERT(m_coreLoader); |
| 134 | m_coreLoader->didFail(internalError(m_coreLoader->url())); |
| 135 | } |
| 136 | |
beidson@apple.com | 12ab964 | 2012-11-14 19:43:42 +0000 | [diff] [blame] | 137 | } // namespace WebKit |
| 138 | |
| 139 | #endif // ENABLE(NETWORK_PROCESS) |