Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp (221998 => 221999)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp 2017-09-13 23:20:30 UTC (rev 221998)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp 2017-09-13 23:33:56 UTC (rev 221999)
@@ -230,8 +230,6 @@
ASSERT_NOT_REACHED();
}
-// sync loader
-
void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data)
{
ASSERT(isMainThread());
@@ -239,6 +237,7 @@
SynchronousLoaderClient client;
RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(context, request, &client, false, false));
+ handle->d->m_delegate = adoptRef(new ResourceHandleCurlDelegate(handle.get()));
handle->d->m_delegate->dispatchSynchronousJob();
error = client.error();
Modified: trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp (221998 => 221999)
--- trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-13 23:20:30 UTC (rev 221998)
+++ trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp 2017-09-13 23:33:56 UTC (rev 221999)
@@ -171,18 +171,10 @@
m_curlHandle.getTimes(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
setWebTimings(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
- if (m_handle->client()) {
- if (ret != CURLE_OK) {
- String domain = CurlContext::errorDomain;
- int errorCode = m_curlHandle.errorCode();
- URL failingURL = m_curlHandle.getEffectiveURL();
- String errorDescription = m_curlHandle.errorDescription();
- unsigned sslErrors = m_curlHandle.getSslErrors();
-
- m_handle->client()->didFail(m_handle, ResourceError(domain, errorCode, failingURL, errorDescription, sslErrors));
- } else
- m_handle->client()->didReceiveResponse(m_handle, ResourceResponse(response()));
- }
+ if (ret != CURLE_OK)
+ notifyFail();
+ else
+ notifyFinish();
}
void ResourceHandleCurlDelegate::retain()
@@ -291,11 +283,15 @@
m_curlHandle.getTimes(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
- callOnMainThread([protectedThis = makeRef(*this), pretransferTime, dnsLookupTime, connectTime, appConnectTime] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
- });
+ if (isMainThread())
+ didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), pretransferTime, dnsLookupTime, connectTime, appConnectTime] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
+ });
+ }
}
void ResourceHandleCurlDelegate::notifyFail()
@@ -306,11 +302,15 @@
String errorDescription = m_curlHandle.errorDescription();
unsigned sslErrors = m_curlHandle.getSslErrors();
- callOnMainThread([protectedThis = makeRef(*this), domain = domain.isolatedCopy(), errorCode, failingURL = failingURL.isolatedCopy(), errorDescription = errorDescription.isolatedCopy(), sslErrors] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
- });
+ if (isMainThread())
+ didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), domain = domain.isolatedCopy(), errorCode, failingURL = failingURL.isolatedCopy(), errorDescription = errorDescription.isolatedCopy(), sslErrors] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
+ });
+ }
}
ResourceResponse& ResourceHandleCurlDelegate::response()
@@ -868,17 +868,25 @@
long long contentLength = 0;
m_curlHandle.getContentLenghtDownload(contentLength);
- callOnMainThread([protectedThis = makeRef(*this), httpCode, contentLength] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didReceiveAllHeaders(httpCode, contentLength);
- });
+ if (isMainThread())
+ didReceiveAllHeaders(httpCode, contentLength);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), httpCode, contentLength] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didReceiveAllHeaders(httpCode, contentLength);
+ });
+ }
} else {
- callOnMainThread([protectedThis = makeRef(*this), header = header.isolatedCopy() ] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didReceiveHeaderLine(header);
- });
+ if (isMainThread())
+ didReceiveHeaderLine(header);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), header = header.isolatedCopy() ] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didReceiveHeaderLine(header);
+ });
+ }
}
return header.length();
@@ -904,11 +912,15 @@
if (!data.size())
return 0;
- callOnMainThread([protectedThis = makeRef(*this), data] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->didReceiveContentData(data);
- });
+ if (isMainThread())
+ didReceiveContentData(data);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), data] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->didReceiveContentData(data);
+ });
+ }
return data.size();
}
@@ -935,15 +947,19 @@
m_sendBytes = 0;
- callOnMainThread([protectedThis = makeRef(*this), buffer, blockSize, numberOfBlocks] {
- if (!protectedThis->m_handle)
- return;
- protectedThis->prepareSendData(buffer, blockSize, numberOfBlocks);
- });
+ if (isMainThread())
+ prepareSendData(buffer, blockSize, numberOfBlocks);
+ else {
+ callOnMainThread([protectedThis = makeRef(*this), buffer, blockSize, numberOfBlocks] {
+ if (!protectedThis->m_handle)
+ return;
+ protectedThis->prepareSendData(buffer, blockSize, numberOfBlocks);
+ });
- m_workerThreadConditionVariable.wait(lock, [this] {
- return m_sendBytes;
- });
+ m_workerThreadConditionVariable.wait(lock, [this] {
+ return m_sendBytes;
+ });
+ }
}
return m_sendBytes;