Skip to content

Commit

Permalink
WebDownloadPrivate: adjust to curl.
Browse files Browse the repository at this point in the history
Should fix WebKit#18103.

Untested, HaikuLauncher does not implemet downloads
  • Loading branch information
pulkomandy committed Dec 1, 2022
1 parent 7767cd1 commit 3f103ec
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
34 changes: 33 additions & 1 deletion Source/WebKitLegacy/haiku/API/WebDownloadPrivate.cpp
Expand Up @@ -56,7 +56,7 @@ static const int kMaxMimeTypeGuessTries = 5;
WebDownloadPrivate::WebDownloadPrivate(const ResourceRequest& request,
WebCore::NetworkingContext* context)
: m_webDownload(0)
, m_resourceHandle(ResourceHandle::create(context, request, this, false, false,
, m_resourceHandle(ResourceHandle::create(context, request, nullptr, false, false,
WebCore::ContentEncodingSniffingPolicy::Disable, WebCore::SecurityOrigin::createOpaque(), false))
, m_currentSize(0)
, m_expectedSize(0)
Expand All @@ -68,9 +68,17 @@ WebDownloadPrivate::WebDownloadPrivate(const ResourceRequest& request,
, m_file()
, m_lastProgressReportTime(0)
{
#if USE(CURL)
m_download = adoptRef(new WebCore::CurlDownload());
m_download->init(*this, m_resourceHandle.get(), request, m_response);
#endif
}

#if USE(CURL)
void WebDownloadPrivate::didReceiveResponse(const ResourceResponse& response)
#else
void WebDownloadPrivate::didReceiveResponseAsync(ResourceHandle*, ResourceResponse&& response, WTF::CompletionHandler<void()>&& handler)
#endif
{
if (!response.isNull()) {
if (!response.suggestedFilename().isEmpty())
Expand Down Expand Up @@ -100,6 +108,29 @@ void WebDownloadPrivate::didReceiveResponseAsync(ResourceHandle*, ResourceRespon
m_url = response.url().string();
}

#if USE(CURL)
void WebDownloadPrivate::didReceiveDataOfLength(int encodedDataLength)
{
m_currentSize += encodedDataLength;

// FIXME: Report total size update, if m_currentSize greater than previous total size
BMessage message(B_DOWNLOAD_PROGRESS);
message.AddFloat("progress", m_currentSize * 100.0 / m_expectedSize);
message.AddInt64("current size", m_currentSize);
message.AddInt64("expected size", m_expectedSize);
m_progressListener.SendMessage(&message);
}

void WebDownloadPrivate::didFinish()
{
handleFinished(m_resourceHandle.get(), B_DOWNLOAD_FINISHED);
}

void WebDownloadPrivate::didFail()
{
handleFinished(m_resourceHandle.get(), B_DOWNLOAD_FAILED);
}
#else
void WebDownloadPrivate::didReceiveData(ResourceHandle*, const WebCore::SharedBuffer& buffer, int /*encodedDataLength*/)
{
if (m_file.InitCheck() != B_OK)
Expand Down Expand Up @@ -159,6 +190,7 @@ void WebDownloadPrivate::cannotShowURL(ResourceHandle* handle)
// and error handling.
handleFinished(handle, B_DOWNLOAD_CANNOT_SHOW_URL);
}
#endif

void WebDownloadPrivate::setDownload(BWebDownload* download)
{
Expand Down
23 changes: 21 additions & 2 deletions Source/WebKitLegacy/haiku/API/WebDownloadPrivate.h
Expand Up @@ -28,6 +28,7 @@
#ifndef WebDownload_h
#define WebDownload_h

#include "WebCore/CurlDownload.h"
#include "WebCore/ResourceHandle.h"
#include "WebCore/ResourceHandleClient.h"
#include <File.h>
Expand All @@ -54,19 +55,33 @@ class BWebPage;

namespace BPrivate {

class WebDownloadPrivate : public WebCore::ResourceHandleClient {
WTF_MAKE_NONCOPYABLE(WebDownloadPrivate);
class WebDownloadPrivate
#if USE(CURL)
: public WebCore::CurlDownloadListener
#else
: public WebCore::ResourceHandleClient
#endif
{
WTF_MAKE_NONCOPYABLE(WebDownloadPrivate);
public:
WebDownloadPrivate(const ResourceRequest&, WebCore::NetworkingContext*);

#if USE(CURL)
virtual void didReceiveResponse(const ResourceResponse&) override;
virtual void didReceiveDataOfLength(int) override;
virtual void didFinish() override;
virtual void didFail() override;
#else
// ResourceHandleClient implementation
virtual void didReceiveResponseAsync(ResourceHandle*, ResourceResponse&&, WTF::CompletionHandler<void()>&&) override;
void didReceiveData(ResourceHandle*, const WebCore::SharedBuffer&, int /*encodedDataLength*/) override;
virtual void didFinishLoading(ResourceHandle*, const WebCore::NetworkLoadMetrics&) override;
virtual void didFail(ResourceHandle*, const ResourceError&) override;
virtual void wasBlocked(ResourceHandle*) override;
virtual void cannotShowURL(ResourceHandle*) override;

void willSendRequestAsync(ResourceHandle*, ResourceRequest&&, ResourceResponse&&, CompletionHandler<void(ResourceRequest&&)>&&) override {}
#endif

void setDownload(BWebDownload*);
void start(const BPath& path);
Expand All @@ -88,6 +103,10 @@ class WebDownloadPrivate : public WebCore::ResourceHandleClient {
private:
BWebDownload* m_webDownload;

#if USE(CURL)
RefPtr<WebCore::CurlDownload> m_download;
ResourceResponse m_response;
#endif
RefPtr<ResourceHandle> m_resourceHandle;
off_t m_currentSize;
off_t m_expectedSize;
Expand Down

0 comments on commit 3f103ec

Please sign in to comment.