Changeset 221999 in webkit


Ignore:
Timestamp:
Sep 13, 2017 4:33:56 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[Curl] Bug fix for synchronous transfer
https://bugs.webkit.org/show_bug.cgi?id=176552

Patch by Basuke Suzuki <Basuke Suzuki> on 2017-09-13
Reviewed by Alex Christensen.

ResourceHandleInternal::m_delegate is null when transfer is synchronous. It should be set ResourceHandleCurlDelegate.
Also the callback functions called when transfer is completed is wrong.

  • platform/network/curl/ResourceHandleCurl.cpp:

(WebCore::ResourceHandle::platformLoadResourceSynchronously):

  • platform/network/curl/ResourceHandleCurlDelegate.cpp:

(WebCore::ResourceHandleCurlDelegate::dispatchSynchronousJob):
(WebCore::ResourceHandleCurlDelegate::notifyFinish):
(WebCore::ResourceHandleCurlDelegate::notifyFail):
(WebCore::ResourceHandleCurlDelegate::didReceiveHeader):
(WebCore::ResourceHandleCurlDelegate::didReceiveData):
(WebCore::ResourceHandleCurlDelegate::willSendData):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r221997 r221999  
     12017-09-13  Basuke Suzuki  <Basuke.Suzuki@sony.com>
     2
     3        [Curl] Bug fix for synchronous transfer
     4        https://bugs.webkit.org/show_bug.cgi?id=176552
     5
     6        Reviewed by Alex Christensen.
     7
     8        ResourceHandleInternal::m_delegate is null when transfer is synchronous. It should be set ResourceHandleCurlDelegate.
     9        Also the callback functions called when transfer is completed is wrong.
     10
     11        * platform/network/curl/ResourceHandleCurl.cpp:
     12        (WebCore::ResourceHandle::platformLoadResourceSynchronously):
     13        * platform/network/curl/ResourceHandleCurlDelegate.cpp:
     14        (WebCore::ResourceHandleCurlDelegate::dispatchSynchronousJob):
     15        (WebCore::ResourceHandleCurlDelegate::notifyFinish):
     16        (WebCore::ResourceHandleCurlDelegate::notifyFail):
     17        (WebCore::ResourceHandleCurlDelegate::didReceiveHeader):
     18        (WebCore::ResourceHandleCurlDelegate::didReceiveData):
     19        (WebCore::ResourceHandleCurlDelegate::willSendData):
     20
    1212017-09-13  Matt Lewis  <jlewis3@apple.com>
    222
  • trunk/Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp

    r220939 r221999  
    231231}
    232232
    233 // sync loader
    234 
    235233void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data)
    236234{
     
    240238    RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(context, request, &client, false, false));
    241239
     240    handle->d->m_delegate = adoptRef(new ResourceHandleCurlDelegate(handle.get()));
    242241    handle->d->m_delegate->dispatchSynchronousJob();
    243242
  • trunk/Source/WebCore/platform/network/curl/ResourceHandleCurlDelegate.cpp

    r221864 r221999  
    172172    setWebTimings(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
    173173
    174     if (m_handle->client()) {
    175         if (ret != CURLE_OK) {
    176             String domain = CurlContext::errorDomain;
    177             int errorCode = m_curlHandle.errorCode();
    178             URL failingURL = m_curlHandle.getEffectiveURL();
    179             String errorDescription = m_curlHandle.errorDescription();
    180             unsigned sslErrors = m_curlHandle.getSslErrors();
    181 
    182             m_handle->client()->didFail(m_handle, ResourceError(domain, errorCode, failingURL, errorDescription, sslErrors));
    183         } else
    184             m_handle->client()->didReceiveResponse(m_handle, ResourceResponse(response()));
    185     }
     174    if (ret != CURLE_OK)
     175        notifyFail();
     176    else
     177        notifyFinish();
    186178}
    187179
     
    292284    m_curlHandle.getTimes(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
    293285
    294     callOnMainThread([protectedThis = makeRef(*this), pretransferTime, dnsLookupTime, connectTime, appConnectTime] {
    295         if (!protectedThis->m_handle)
    296             return;
    297         protectedThis->didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
    298     });
     286    if (isMainThread())
     287        didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
     288    else {
     289        callOnMainThread([protectedThis = makeRef(*this), pretransferTime, dnsLookupTime, connectTime, appConnectTime] {
     290            if (!protectedThis->m_handle)
     291                return;
     292            protectedThis->didFinish(pretransferTime, dnsLookupTime, connectTime, appConnectTime);
     293        });
     294    }
    299295}
    300296
     
    307303    unsigned sslErrors = m_curlHandle.getSslErrors();
    308304
    309     callOnMainThread([protectedThis = makeRef(*this), domain = domain.isolatedCopy(), errorCode, failingURL = failingURL.isolatedCopy(), errorDescription = errorDescription.isolatedCopy(), sslErrors] {
    310         if (!protectedThis->m_handle)
    311             return;
    312         protectedThis->didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
    313     });
     305    if (isMainThread())
     306        didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
     307    else {
     308        callOnMainThread([protectedThis = makeRef(*this), domain = domain.isolatedCopy(), errorCode, failingURL = failingURL.isolatedCopy(), errorDescription = errorDescription.isolatedCopy(), sslErrors] {
     309            if (!protectedThis->m_handle)
     310                return;
     311            protectedThis->didFail(domain, errorCode, failingURL, errorDescription, sslErrors);
     312        });
     313    }
    314314}
    315315
     
    869869        m_curlHandle.getContentLenghtDownload(contentLength);
    870870
    871         callOnMainThread([protectedThis = makeRef(*this), httpCode, contentLength] {
    872             if (!protectedThis->m_handle)
    873                 return;
    874             protectedThis->didReceiveAllHeaders(httpCode, contentLength);
    875         });
     871        if (isMainThread())
     872            didReceiveAllHeaders(httpCode, contentLength);
     873        else {
     874            callOnMainThread([protectedThis = makeRef(*this), httpCode, contentLength] {
     875                if (!protectedThis->m_handle)
     876                    return;
     877                protectedThis->didReceiveAllHeaders(httpCode, contentLength);
     878            });
     879        }
    876880    } else {
    877         callOnMainThread([protectedThis = makeRef(*this), header = header.isolatedCopy() ] {
    878             if (!protectedThis->m_handle)
    879                 return;
    880             protectedThis->didReceiveHeaderLine(header);
    881         });
     881        if (isMainThread())
     882            didReceiveHeaderLine(header);
     883        else {
     884            callOnMainThread([protectedThis = makeRef(*this), header = header.isolatedCopy() ] {
     885                if (!protectedThis->m_handle)
     886                    return;
     887                protectedThis->didReceiveHeaderLine(header);
     888            });
     889        }
    882890    }
    883891
     
    905913        return 0;
    906914
    907     callOnMainThread([protectedThis = makeRef(*this), data] {
    908         if (!protectedThis->m_handle)
    909             return;
    910         protectedThis->didReceiveContentData(data);
    911     });
     915    if (isMainThread())
     916        didReceiveContentData(data);
     917    else {
     918        callOnMainThread([protectedThis = makeRef(*this), data] {
     919            if (!protectedThis->m_handle)
     920                return;
     921            protectedThis->didReceiveContentData(data);
     922        });
     923    }
    912924
    913925    return data.size();
     
    936948        m_sendBytes = 0;
    937949
    938         callOnMainThread([protectedThis = makeRef(*this), buffer, blockSize, numberOfBlocks] {
    939             if (!protectedThis->m_handle)
    940                 return;
    941             protectedThis->prepareSendData(buffer, blockSize, numberOfBlocks);
    942         });
    943 
    944         m_workerThreadConditionVariable.wait(lock, [this] {
    945             return m_sendBytes;
    946         });
     950        if (isMainThread())
     951            prepareSendData(buffer, blockSize, numberOfBlocks);
     952        else {
     953            callOnMainThread([protectedThis = makeRef(*this), buffer, blockSize, numberOfBlocks] {
     954                if (!protectedThis->m_handle)
     955                    return;
     956                protectedThis->prepareSendData(buffer, blockSize, numberOfBlocks);
     957            });
     958
     959            m_workerThreadConditionVariable.wait(lock, [this] {
     960                return m_sendBytes;
     961            });
     962        }
    947963    }
    948964
Note: See TracChangeset for help on using the changeset viewer.