~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
31
#include "DataReference.h"
 
32
#include "Logging.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>
 
39
 
 
40
using namespace WebCore;
 
41
 
 
42
namespace WebKit {
 
43
 
 
44
PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader)
 
45
{
 
46
    return adoptRef(new WebResourceLoader(coreLoader));
 
47
}
 
48
 
 
49
WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader)
 
50
    : m_coreLoader(coreLoader)
 
51
{
 
52
}
 
53
 
 
54
WebResourceLoader::~WebResourceLoader()
 
55
{
 
56
}
 
57
 
 
58
CoreIPC::Connection* WebResourceLoader::connection() const
 
59
{
 
60
    return WebProcess::shared().networkConnection()->connection();
 
61
}
 
62
 
 
63
uint64_t WebResourceLoader::destinationID() const
 
64
{
 
65
    return m_coreLoader->identifier();
 
66
}
 
67
 
 
68
void WebResourceLoader::willSendRequest(uint64_t requestID, const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse)
 
69
{
 
70
    LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data());
 
71
    
 
72
    ResourceRequest newRequest = proposedRequest;
 
73
    m_coreLoader->willSendRequest(newRequest, redirectResponse);
 
74
 
 
75
    send(Messages::NetworkResourceLoader::WillSendRequestHandled(requestID, newRequest));
 
76
}
 
77
 
 
78
void WebResourceLoader::didReceiveResponse(const WebCore::ResourceResponse& response)
 
79
{
 
80
    LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponse for '%s'", m_coreLoader->url().string().utf8().data());
 
81
    m_coreLoader->didReceiveResponse(response);
 
82
}
 
83
 
 
84
void WebResourceLoader::didReceiveData(const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce)
 
85
{
 
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);
 
88
}
 
89
 
 
90
void WebResourceLoader::didFinishResourceLoad(double finishTime)
 
91
{
 
92
    LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
 
93
    m_coreLoader->didFinishLoading(finishTime);
 
94
}
 
95
 
 
96
void WebResourceLoader::didFailResourceLoad(const ResourceError& error)
 
97
{
 
98
    LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
 
99
    
 
100
    m_coreLoader->didFail(error);
 
101
}
 
102
 
 
103
void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime)
 
104
{
 
105
    LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data());
 
106
 
 
107
    RefPtr<ShareableResource> resource = ShareableResource::create(handle);
 
108
 
 
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);
 
115
    }
 
116
 
 
117
    m_coreLoader->didFinishLoading(finishTime);
 
118
}
 
119
 
 
120
void WebResourceLoader::canAuthenticateAgainstProtectionSpace(uint64_t requestID, const ProtectionSpace& protectionSpace)
 
121
{
 
122
    send(Messages::NetworkResourceLoader::CanAuthenticateAgainstProtectionSpaceHandled(requestID, m_coreLoader->canAuthenticateAgainstProtectionSpace(protectionSpace)));
 
123
}
 
124
 
 
125
void WebResourceLoader::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
 
126
{
 
127
    LOG(Network, "(WebProcess) WebResourceLoader::didReceiveAuthenticationChallenge for '%s'", m_coreLoader->url().string().utf8().data());
 
128
 
 
129
    m_currentAuthenticationChallenge = adoptPtr(new AuthenticationChallenge(challenge));
 
130
    m_currentAuthenticationChallenge->setAuthenticationClient(this);
 
131
 
 
132
    m_coreLoader->didReceiveAuthenticationChallenge(*m_currentAuthenticationChallenge);
 
133
}
 
134
 
 
135
void WebResourceLoader::didCancelAuthenticationChallenge(const AuthenticationChallenge& challenge)
 
136
{
 
137
    if (m_currentAuthenticationChallenge->identifier() != challenge.identifier())
 
138
        return;
 
139
 
 
140
    LOG(Network, "(WebProcess) WebResourceLoader::didCancelAuthenticationChallenge for '%s'", m_coreLoader->url().string().utf8().data());
 
141
 
 
142
    m_coreLoader->didCancelAuthenticationChallenge(*m_currentAuthenticationChallenge);
 
143
    m_currentAuthenticationChallenge.clear();
 
144
}
 
145
 
 
146
// WebCore::AuthenticationClient
 
147
void WebResourceLoader::receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential)
 
148
{
 
149
    ASSERT(m_currentAuthenticationChallenge && challenge == *m_currentAuthenticationChallenge);
 
150
    send(Messages::NetworkResourceLoader::ReceivedAuthenticationCredential(challenge, credential));
 
151
 
 
152
    m_currentAuthenticationChallenge.clear();
 
153
}
 
154
 
 
155
void WebResourceLoader::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge)
 
156
{
 
157
    ASSERT(m_currentAuthenticationChallenge && challenge == *m_currentAuthenticationChallenge);
 
158
    send(Messages::NetworkResourceLoader::ReceivedRequestToContinueWithoutAuthenticationCredential(challenge));
 
159
 
 
160
    m_currentAuthenticationChallenge.clear();
 
161
}
 
162
 
 
163
void WebResourceLoader::receivedCancellation(const AuthenticationChallenge& challenge)
 
164
{
 
165
    ASSERT(m_currentAuthenticationChallenge && challenge == *m_currentAuthenticationChallenge);
 
166
    send(Messages::NetworkResourceLoader::ReceivedAuthenticationCancellation(challenge));
 
167
 
 
168
    m_currentAuthenticationChallenge.clear();
 
169
}
 
170
 
 
171
} // namespace WebKit
 
172
 
 
173
#endif // ENABLE(NETWORK_PROCESS)