Skip to content
Permalink
Browse files
2008-03-17 Julien Chaffraix <julien.chaffraix@gmail.com>
        Reviewed by Holger.

        <http://bugs.webkit.org/show_bug.cgi?id=17754>

        - Implement ResourceHandle::loadResourceSynchronously to dispatch synchronous
          requests.

        - Implement WebCoreSynchronousLoader, the ResourceHandleClient which holds
          the network data, response and error for us during the transfert.

        * platform/network/ResourceHandleInternal.h: Remove trailing white space.
        * platform/network/curl/ResourceHandleCurl.cpp: Add WebCoreSynchronousLoader
        (WebCore::WebCoreSynchronousLoader::resourceResponse):
        (WebCore::WebCoreSynchronousLoader::resourceError):
        (WebCore::WebCoreSynchronousLoader::data):
        (WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
        (WebCore::WebCoreSynchronousLoader::didReceiveResponse):
        (WebCore::WebCoreSynchronousLoader::didReceiveData):
        (WebCore::WebCoreSynchronousLoader::didFinishLoading):
        (WebCore::WebCoreSynchronousLoader::didFail):
        (WebCore::ResourceHandle::loadResourceSynchronously): Implement method
        using WebCoreSynchronousLoader.

        * platform/network/curl/ResourceHandleManager.cpp:
        (WebCore::ResourceHandleManager::dispatchSynchronousJob):
        (WebCore::ResourceHandleManager::startJob):
        (WebCore::ResourceHandleManager::initializeHandle): Handle initialization
        method used both for synchronous and asynchronous job.

        * platform/network/curl/ResourceHandleManager.h:


Canonical link: https://commits.webkit.org/24789@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@31109 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
zecke committed Mar 17, 2008
1 parent 8bc0969 commit 2c646bbc807492e43d6d4a03844788cb8ff8c8f5
@@ -1,3 +1,36 @@
2008-03-17 Julien Chaffraix <julien.chaffraix@gmail.com>

Reviewed by Holger.

<http://bugs.webkit.org/show_bug.cgi?id=17754>

- Implement ResourceHandle::loadResourceSynchronously to dispatch synchronous
requests.

- Implement WebCoreSynchronousLoader, the ResourceHandleClient which holds
the network data, response and error for us during the transfert.

* platform/network/ResourceHandleInternal.h: Remove trailing white space.
* platform/network/curl/ResourceHandleCurl.cpp: Add WebCoreSynchronousLoader
(WebCore::WebCoreSynchronousLoader::resourceResponse):
(WebCore::WebCoreSynchronousLoader::resourceError):
(WebCore::WebCoreSynchronousLoader::data):
(WebCore::WebCoreSynchronousLoader::WebCoreSynchronousLoader):
(WebCore::WebCoreSynchronousLoader::didReceiveResponse):
(WebCore::WebCoreSynchronousLoader::didReceiveData):
(WebCore::WebCoreSynchronousLoader::didFinishLoading):
(WebCore::WebCoreSynchronousLoader::didFail):
(WebCore::ResourceHandle::loadResourceSynchronously): Implement method
using WebCoreSynchronousLoader.

* platform/network/curl/ResourceHandleManager.cpp:
(WebCore::ResourceHandleManager::dispatchSynchronousJob):
(WebCore::ResourceHandleManager::startJob):
(WebCore::ResourceHandleManager::initializeHandle): Handle initialization
method used both for synchronous and asynchronous job.

* platform/network/curl/ResourceHandleManager.h:

2008-03-17 Darin Adler <darin@apple.com>

- try to fix GTK build
@@ -160,7 +160,7 @@ namespace WebCore {
#if USE(CURL)
CURL* m_handle;
char* m_url;
struct curl_slist* m_customHeaders;
struct curl_slist* m_customHeaders;
ResourceResponse m_response;
bool m_cancelled;

@@ -35,6 +35,49 @@

namespace WebCore {

class WebCoreSynchronousLoader : public ResourceHandleClient {
public:
WebCoreSynchronousLoader();

virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
virtual void didReceiveData(ResourceHandle*, const char*, int, int lengthReceived);
virtual void didFinishLoading(ResourceHandle*);
virtual void didFail(ResourceHandle*, const ResourceError&);

ResourceResponse resourceResponse() const { return m_response; }
ResourceError resourceError() const { return m_error; }
Vector<char> data() const { return m_data; }

private:
ResourceResponse m_response;
ResourceError m_error;
Vector<char> m_data;
};

WebCoreSynchronousLoader::WebCoreSynchronousLoader()
{
}

void WebCoreSynchronousLoader::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
{
m_response = response;
}

void WebCoreSynchronousLoader::didReceiveData(ResourceHandle*, const char* data, int length, int)
{
m_data.append(data, length);
}

void WebCoreSynchronousLoader::didFinishLoading(ResourceHandle*)
{
}

void WebCoreSynchronousLoader::didFail(ResourceHandle*, const ResourceError& error)
{
m_error = error;
}


ResourceHandleInternal::~ResourceHandleInternal()
{
free(m_url);
@@ -90,9 +133,18 @@ bool ResourceHandle::loadsBlocked()
return false;
}

void ResourceHandle::loadResourceSynchronously(const ResourceRequest&, ResourceError&, ResourceResponse&, Vector<char>&, Frame*)
void ResourceHandle::loadResourceSynchronously(const ResourceRequest& request, ResourceError& error, ResourceResponse& response, Vector<char>& data, Frame*)
{
notImplemented();
WebCoreSynchronousLoader syncLoader;
ResourceHandle handle(request, &syncLoader, true, false, true);

ResourceHandleManager* manager = ResourceHandleManager::sharedInstance();

manager->dispatchSynchronousJob(&handle);

error = syncLoader.resourceError();
data = syncLoader.data();
response = syncLoader.resourceResponse();
}

} // namespace WebCore
@@ -34,6 +34,7 @@
#include "FileSystem.h"
#include "MIMETypeRegistry.h"
#include "NotImplemented.h"
#include "ResourceError.h"
#include "ResourceHandle.h"
#include "ResourceHandleInternal.h"
#include "HTTPParsers.h"
@@ -538,6 +539,30 @@ static void parseDataUrl(ResourceHandle* handle)
client->didFinishLoading(handle);
}

void ResourceHandleManager::dispatchSynchronousJob(ResourceHandle* job)
{
KURL kurl = job->request().url();

if (kurl.protocolIs("data")) {
parseDataUrl(job);
return;
}

initializeHandle(job);

ResourceHandleInternal* handle = job->getInternal();

// curl_easy_perform blocks until the transfert is finished.
CURLcode ret = curl_easy_perform(handle->m_handle);

if (ret != 0) {
ResourceError error(String(handle->m_url), ret, String(handle->m_url), String(curl_easy_strerror(ret)));
handle->client()->didFail(job, error);
}

curl_easy_cleanup(handle->m_handle);
}

void ResourceHandleManager::startJob(ResourceHandle* job)
{
KURL kurl = job->request().url();
@@ -547,6 +572,25 @@ void ResourceHandleManager::startJob(ResourceHandle* job)
return;
}

initializeHandle(job);

m_runningJobs++;
CURLMcode ret = curl_multi_add_handle(m_curlMultiHandle, job->getInternal()->m_handle);
// don't call perform, because events must be async
// timeout will occur and do curl_multi_perform
if (ret && ret != CURLM_CALL_MULTI_PERFORM) {
#ifndef NDEBUG
printf("Error %d starting job %s\n", ret, encodeWithURLEscapeSequences(job->request().url().string()).latin1().data());
#endif
job->cancel();
return;
}
}

void ResourceHandleManager::initializeHandle(ResourceHandle* job)
{
KURL kurl = job->request().url();

// Remove any fragment part, otherwise curl will send it as part of the request.
kurl.setRef("");

@@ -588,6 +632,8 @@ void ResourceHandleManager::startJob(ResourceHandle* job)

// url must remain valid through the request
ASSERT(!d->m_url);

// url is in ASCII so latin1() will only convert it to char* without character translation.
d->m_url = strdup(url.latin1().data());
curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url);

@@ -624,18 +670,6 @@ void ResourceHandleManager::startJob(ResourceHandle* job)
curl_easy_setopt(d->m_handle, CURLOPT_HTTPHEADER, headers);
d->m_customHeaders = headers;
}

m_runningJobs++;
CURLMcode ret = curl_multi_add_handle(m_curlMultiHandle, d->m_handle);
// don't call perform, because events must be async
// timeout will occur and do curl_multi_perform
if (ret && ret != CURLM_CALL_MULTI_PERFORM) {
#ifndef NDEBUG
printf("Error %d starting job %s\n", ret, job->request().url().string().latin1().data());
#endif
job->cancel();
return;
}
}

void ResourceHandleManager::cancel(ResourceHandle* job)
@@ -44,6 +44,8 @@ class ResourceHandleManager {
void cancel(ResourceHandle*);
void setCookieJarFileName(const char* cookieJarFileName);

void dispatchSynchronousJob(ResourceHandle*);

void setupPOST(ResourceHandle*, struct curl_slist**);
void setupPUT(ResourceHandle*, struct curl_slist**);

@@ -56,6 +58,8 @@ class ResourceHandleManager {
void startJob(ResourceHandle*);
bool startScheduledJobs();

void initializeHandle(ResourceHandle*);

Timer<ResourceHandleManager> m_downloadTimer;
CURLM* m_curlMultiHandle;
CURLSH* m_curlShareHandle;

0 comments on commit 2c646bb

Please sign in to comment.