blob: 76d7f62dbd2ba6515e6aca5849eb5dda31040646 [file] [log] [blame]
beidson@apple.com12ab9642012-11-14 19:43:42 +00001/*
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.comaec2e292012-11-14 23:59:01 +000031#include "DataReference.h"
32#include "Logging.h"
beidson@apple.comaec2e292012-11-14 23:59:01 +000033#include "NetworkProcessConnection.h"
ap@apple.com61423822012-12-20 00:58:25 +000034#include "PlatformCertificateInfo.h"
beidson@apple.comaec2e292012-11-14 23:59:01 +000035#include "WebCoreArgumentCoders.h"
beidson@apple.com1bc450a2012-12-21 18:46:04 +000036#include "WebErrors.h"
beidson@apple.comaec2e292012-11-14 23:59:01 +000037#include "WebProcess.h"
ap@apple.com18ae25f2013-01-27 01:01:08 +000038#include <WebCore/ResourceError.h>
beidson@apple.com12ab9642012-11-14 19:43:42 +000039#include <WebCore/ResourceLoader.h>
40
41using namespace WebCore;
42
43namespace WebKit {
44
beidson@apple.comaec2e292012-11-14 23:59:01 +000045PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader)
beidson@apple.com12ab9642012-11-14 19:43:42 +000046{
beidson@apple.comaec2e292012-11-14 23:59:01 +000047 return adoptRef(new WebResourceLoader(coreLoader));
beidson@apple.com12ab9642012-11-14 19:43:42 +000048}
49
beidson@apple.comaec2e292012-11-14 23:59:01 +000050WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader)
51 : m_coreLoader(coreLoader)
beidson@apple.com12ab9642012-11-14 19:43:42 +000052{
53}
54
55WebResourceLoader::~WebResourceLoader()
56{
57}
58
beidson@apple.com7fb049d2012-11-17 00:40:15 +000059CoreIPC::Connection* WebResourceLoader::connection() const
60{
61 return WebProcess::shared().networkConnection()->connection();
62}
63
64uint64_t WebResourceLoader::destinationID() const
65{
66 return m_coreLoader->identifier();
67}
68
beidson@apple.com44925772013-01-23 20:21:19 +000069void WebResourceLoader::cancelResourceLoader()
70{
71 m_coreLoader->cancel();
72}
73
ap@apple.com76813412013-01-12 00:08:30 +000074void WebResourceLoader::willSendRequest(const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse, ResourceRequest& newRequest)
beidson@apple.comaec2e292012-11-14 23:59:01 +000075{
76 LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data());
77
ap@apple.com76813412013-01-12 00:08:30 +000078 newRequest = proposedRequest;
beidson@apple.comaec2e292012-11-14 23:59:01 +000079 m_coreLoader->willSendRequest(newRequest, redirectResponse);
beidson@apple.comaec2e292012-11-14 23:59:01 +000080}
81
ap@apple.com61423822012-12-20 00:58:25 +000082void WebResourceLoader::didReceiveResponseWithCertificateInfo(const ResourceResponse& response, const PlatformCertificateInfo& certificateInfo)
beidson@apple.comaec2e292012-11-14 23:59:01 +000083{
ap@apple.com61423822012-12-20 00:58:25 +000084 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.comaec2e292012-11-14 23:59:01 +000088}
89
90void 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
96void 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
102void 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
109void 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.com76813412013-01-12 00:08:30 +0000126void WebResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace, bool& result)
beidson@apple.com29824ff2012-11-19 19:22:48 +0000127{
ap@apple.com76813412013-01-12 00:08:30 +0000128 result = m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace);
beidson@apple.com29824ff2012-11-19 19:22:48 +0000129}
130
beidson@apple.com1bc450a2012-12-21 18:46:04 +0000131void WebResourceLoader::networkProcessCrashed()
132{
133 ASSERT(m_coreLoader);
134 m_coreLoader->didFail(internalError(m_coreLoader->url()));
135}
136
beidson@apple.com12ab9642012-11-14 19:43:42 +0000137} // namespace WebKit
138
139#endif // ENABLE(NETWORK_PROCESS)