2
* Copyright (C) 2012 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
27
#include "WebResourceLoader.h"
29
#if ENABLE(NETWORK_PROCESS)
31
#include "DataReference.h"
33
#include "NetworkConnectionToWebProcessMessages.h"
34
#include "NetworkProcessConnection.h"
35
#include "NetworkResourceLoaderMessages.h"
36
#include "WebCoreArgumentCoders.h"
37
#include "WebProcess.h"
38
#include <WebCore/ResourceLoader.h>
40
using namespace WebCore;
44
PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader)
46
return adoptRef(new WebResourceLoader(coreLoader));
49
WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader)
50
: m_coreLoader(coreLoader)
54
WebResourceLoader::~WebResourceLoader()
58
CoreIPC::Connection* WebResourceLoader::connection() const
60
return WebProcess::shared().networkConnection()->connection();
63
uint64_t WebResourceLoader::destinationID() const
65
return m_coreLoader->identifier();
68
void WebResourceLoader::willSendRequest(uint64_t requestID, const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse)
70
LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data());
72
ResourceRequest newRequest = proposedRequest;
73
m_coreLoader->willSendRequest(newRequest, redirectResponse);
75
send(Messages::NetworkResourceLoader::WillSendRequestHandled(requestID, newRequest));
78
void WebResourceLoader::didReceiveResponse(const WebCore::ResourceResponse& response)
80
LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponse for '%s'", m_coreLoader->url().string().utf8().data());
81
m_coreLoader->didReceiveResponse(response);
84
void WebResourceLoader::didReceiveData(const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce)
86
LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data());
87
m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, allAtOnce);
90
void WebResourceLoader::didFinishResourceLoad(double finishTime)
92
LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
93
m_coreLoader->didFinishLoading(finishTime);
96
void WebResourceLoader::didFailResourceLoad(const ResourceError& error)
98
LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
100
m_coreLoader->didFail(error);
103
void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime)
105
LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data());
107
RefPtr<ShareableResource> resource = ShareableResource::create(handle);
109
// Only send data to the didReceiveData callback if it exists.
110
if (!resource->size()) {
111
// FIXME (NetworkProcess): Give ResourceLoader the ability to take ResourceBuffer arguments.
112
// That will allow us to pass it along to CachedResources and allow them to hang on to the shared memory behind the scenes.
113
// FIXME (NetworkProcess): Pass along the correct value for encodedDataLength.
114
m_coreLoader->didReceiveData(reinterpret_cast<const char*>(resource->data()), resource->size(), -1 /* encodedDataLength */ , true);
117
m_coreLoader->didFinishLoading(finishTime);
120
void WebResourceLoader::canAuthenticateAgainstProtectionSpace(uint64_t requestID, const ProtectionSpace& protectionSpace)
122
send(Messages::NetworkResourceLoader::CanAuthenticateAgainstProtectionSpaceHandled(requestID, m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace)));
125
void WebResourceLoader::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
127
LOG(Network, "(WebProcess) WebResourceLoader::didReceiveAuthenticationChallenge for '%s'", m_coreLoader->url().string().utf8().data());
129
m_currentAuthenticationChallenge = adoptPtr(new AuthenticationChallenge(challenge));
130
m_currentAuthenticationChallenge->setAuthenticationClient(this);
132
m_coreLoader->didReceiveAuthenticationChallenge(*m_currentAuthenticationChallenge);
135
void WebResourceLoader::didCancelAuthenticationChallenge(const AuthenticationChallenge& challenge)
137
if (m_currentAuthenticationChallenge->identifier() != challenge.identifier())
140
LOG(Network, "(WebProcess) WebResourceLoader::didCancelAuthenticationChallenge for '%s'", m_coreLoader->url().string().utf8().data());
142
m_coreLoader->didCancelAuthenticationChallenge(*m_currentAuthenticationChallenge);
143
m_currentAuthenticationChallenge.clear();
146
// WebCore::AuthenticationClient
147
void WebResourceLoader::receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential)
149
ASSERT(m_currentAuthenticationChallenge && challenge == *m_currentAuthenticationChallenge);
150
send(Messages::NetworkResourceLoader::ReceivedAuthenticationCredential(challenge, credential));
152
m_currentAuthenticationChallenge.clear();
155
void WebResourceLoader::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge)
157
ASSERT(m_currentAuthenticationChallenge && challenge == *m_currentAuthenticationChallenge);
158
send(Messages::NetworkResourceLoader::ReceivedRequestToContinueWithoutAuthenticationCredential(challenge));
160
m_currentAuthenticationChallenge.clear();
163
void WebResourceLoader::receivedCancellation(const AuthenticationChallenge& challenge)
165
ASSERT(m_currentAuthenticationChallenge && challenge == *m_currentAuthenticationChallenge);
166
send(Messages::NetworkResourceLoader::ReceivedAuthenticationCancellation(challenge));
168
m_currentAuthenticationChallenge.clear();
171
} // namespace WebKit
173
#endif // ENABLE(NETWORK_PROCESS)