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 "WebCoreArgumentCoders.h"
36 #include "WebProcess.h"
37 #include <WebCore/ResourceLoader.h>
39 using namespace WebCore;
43 PassRefPtr<WebResourceLoader> WebResourceLoader::create(PassRefPtr<ResourceLoader> coreLoader)
45 return adoptRef(new WebResourceLoader(coreLoader));
48 WebResourceLoader::WebResourceLoader(PassRefPtr<WebCore::ResourceLoader> coreLoader)
49 : m_coreLoader(coreLoader)
53 WebResourceLoader::~WebResourceLoader()
57 void WebResourceLoader::willSendRequest(uint64_t requestID, const ResourceRequest& proposedRequest, const ResourceResponse& redirectResponse)
59 LOG(Network, "(WebProcess) WebResourceLoader::willSendRequest to '%s'", proposedRequest.url().string().utf8().data());
61 ResourceRequest newRequest = proposedRequest;
62 m_coreLoader->willSendRequest(newRequest, redirectResponse);
64 WebProcess::shared().networkConnection()->connection()->send(Messages::NetworkConnectionToWebProcess::WillSendRequestHandled(requestID, newRequest), 0);
67 void WebResourceLoader::didReceiveResponse(const WebCore::ResourceResponse& response)
69 LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResponse for '%s'", m_coreLoader->url().string().utf8().data());
70 m_coreLoader->didReceiveResponse(response);
73 void WebResourceLoader::didReceiveData(const CoreIPC::DataReference& data, int64_t encodedDataLength, bool allAtOnce)
75 LOG(Network, "(WebProcess) WebResourceLoader::didReceiveData of size %i for '%s'", (int)data.size(), m_coreLoader->url().string().utf8().data());
76 m_coreLoader->didReceiveData(reinterpret_cast<const char*>(data.data()), data.size(), encodedDataLength, allAtOnce);
79 void WebResourceLoader::didFinishResourceLoad(double finishTime)
81 LOG(Network, "(WebProcess) WebResourceLoader::didFinishResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
82 m_coreLoader->didFinishLoading(finishTime);
85 void WebResourceLoader::didFailResourceLoad(const ResourceError& error)
87 LOG(Network, "(WebProcess) WebResourceLoader::didFailResourceLoad for '%s'", m_coreLoader->url().string().utf8().data());
89 m_coreLoader->didFail(error);
92 void WebResourceLoader::didReceiveResource(const ShareableResource::Handle& handle, double finishTime)
94 LOG(Network, "(WebProcess) WebResourceLoader::didReceiveResource for '%s'", m_coreLoader->url().string().utf8().data());
96 RefPtr<ShareableResource> resource = ShareableResource::create(handle);
98 // Only send data to the didReceiveData callback if it exists.
99 if (!resource->size()) {
100 // FIXME (NetworkProcess): Give ResourceLoader the ability to take ResourceBuffer arguments.
101 // That will allow us to pass it along to CachedResources and allow them to hang on to the shared memory behind the scenes.
102 // FIXME (NetworkProcess): Pass along the correct value for encodedDataLength.
103 m_coreLoader->didReceiveData(reinterpret_cast<const char*>(resource->data()), resource->size(), -1 /* encodedDataLength */ , true);
106 m_coreLoader->didFinishLoading(finishTime);
109 } // namespace WebKit
111 #endif // ENABLE(NETWORK_PROCESS)