Skip to content
Permalink
Browse files
[WinCairo] Support file downloads
https://bugs.webkit.org/show_bug.cgi?id=240293

Reviewed by Fujii Hironori.

.:

* Source/cmake/OptionsWin.cmake: enable DOWNLOAD_ATTRIBUTE by default in WinCairo.

Source/WebCore:

Properly convert suggested file name to utf8.

Coverred by LayoutTests/http/tests/download/literal-utf-8.html.

* platform/network/curl/ResourceResponseCurl.cpp:
(WebCore::ResourceResponse::platformSuggestedFilename const):

Source/WebKit:

Hooked up Curl calls to Download callbacks. Added basic support for
file downloads in Curl.

* NetworkProcess/curl/NetworkDataTaskCurl.cpp:
(WebKit::NetworkDataTaskCurl::cancel):
(WebKit::NetworkDataTaskCurl::curlDidReceiveData):
(WebKit::NetworkDataTaskCurl::curlDidComplete):
(WebKit::NetworkDataTaskCurl::deleteDownloadFile):
(WebKit::NetworkDataTaskCurl::curlDidFailWithError):
(WebKit::NetworkDataTaskCurl::invokeDidReceiveResponse):
* NetworkProcess/curl/NetworkDataTaskCurl.h:

LayoutTests:

* platform/wincairo/TestExpectations: enable downloads tests.

Canonical link: https://commits.webkit.org/250472@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
yury-s committed May 11, 2022
1 parent 52b96a4 commit 8a920504da6012da394b05d830991a1de3c731d4
Showing 9 changed files with 141 additions and 19 deletions.
@@ -1,3 +1,12 @@
2022-05-11 Yury Semikhatsky <yurys@chromium.org>

[WinCairo] Support file downloads
https://bugs.webkit.org/show_bug.cgi?id=240293

Reviewed by Fujii Hironori.

* Source/cmake/OptionsWin.cmake: enable DOWNLOAD_ATTRIBUTE by default in WinCairo.

2022-05-11 Jonathan Bedard <jbedard@apple.com>

Remove Subversion references from ReadMe
@@ -1,3 +1,12 @@
2022-05-11 Yury Semikhatsky <yurys@chromium.org>

[WinCairo] Support file downloads
https://bugs.webkit.org/show_bug.cgi?id=240293

Reviewed by Fujii Hironori.

* platform/wincairo/TestExpectations: enable downloads tests.

2022-05-11 Antti Koivisto <antti@apple.com>

REGRESSION (r291788): MotionMark Suits subtest is 9% regressed
@@ -54,23 +54,15 @@ fast/dom/DeviceOrientation [ Skip ]
fast/dom/DeviceMotion [ Skip ]
fast/dom/Window/window-properties-device-orientation.html [ Skip ]

# DOWNLOAD_ATTRIBUTE is disabled
fast/dom/HTMLAnchorElement/anchor-download.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-blank-base-target-popup-not-allowed.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-blank-target-popup-not-allowed.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-blank-target.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-backslash.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-doublequote.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-slashes.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-unicode.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-then-revoke.html [ Skip ]
fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Skip ]
# Unexpected suggested file name.
fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-download.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-backslash.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-doublequote.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-slashes.html [ Failure ]
fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Failure ]

# ENABLE_INPUT_TYPE_* are disabled.
# See: webkit.org/b/29359
@@ -765,6 +757,9 @@ http/tests/cache/partitioned-cache-iframe.html [ Failure ]
http/tests/cache/partitioned-cache.html [ Failure ]
http/tests/cache/willsendrequest-returns-null-for-memory-cache-load.html [ Failure ]

# Second link click interrupts current download
http/tests/download/anchor-load-after-download.html [ Skip ]

http/tests/cache-storage [ Skip ]
http/tests/canvas [ Skip ]
http/tests/contentdispositionattachmentsandbox [ Skip ]
@@ -788,7 +783,6 @@ http/tests/cookies/sync-xhr-set-cookie-invalidates-cache.html [ Pass Failure ]
http/tests/css/cross-fade-reload.html [ Timeout Pass ]

http/tests/dom [ Skip ]
http/tests/download [ Skip ]
http/tests/eventsource [ Skip ]
http/tests/events/touch/ios [ Skip ]
http/tests/fileapi [ Skip ]
@@ -1,3 +1,17 @@
2022-05-11 Yury Semikhatsky <yurys@chromium.org>

[WinCairo] Support file downloads
https://bugs.webkit.org/show_bug.cgi?id=240293

Reviewed by Fujii Hironori.

Properly convert suggested file name to utf8.

Coverred by LayoutTests/http/tests/download/literal-utf-8.html.

* platform/network/curl/ResourceResponseCurl.cpp:
(WebCore::ResourceResponse::platformSuggestedFilename const):

2022-05-11 Antti Koivisto <antti@apple.com>

REGRESSION (r291788): MotionMark Suits subtest is 9% regressed
@@ -151,7 +151,10 @@ void ResourceResponse::setCertificateInfo(CertificateInfo&& certificateInfo)

String ResourceResponse::platformSuggestedFilename() const
{
return filenameFromHTTPContentDisposition(httpHeaderField(HTTPHeaderName::ContentDisposition)).toString();
StringView contentDisposition = filenameFromHTTPContentDisposition(httpHeaderField(HTTPHeaderName::ContentDisposition));
if (contentDisposition.is8Bit())
return String::fromUTF8WithLatin1Fallback(contentDisposition.characters8(), contentDisposition.length());
return contentDisposition.toString();
}

bool ResourceResponse::shouldRedirect()
@@ -1,3 +1,22 @@
2022-05-11 Yury Semikhatsky <yurys@chromium.org>

[WinCairo] Support file downloads
https://bugs.webkit.org/show_bug.cgi?id=240293

Reviewed by Fujii Hironori.

Hooked up Curl calls to Download callbacks. Added basic support for
file downloads in Curl.

* NetworkProcess/curl/NetworkDataTaskCurl.cpp:
(WebKit::NetworkDataTaskCurl::cancel):
(WebKit::NetworkDataTaskCurl::curlDidReceiveData):
(WebKit::NetworkDataTaskCurl::curlDidComplete):
(WebKit::NetworkDataTaskCurl::deleteDownloadFile):
(WebKit::NetworkDataTaskCurl::curlDidFailWithError):
(WebKit::NetworkDataTaskCurl::invokeDidReceiveResponse):
* NetworkProcess/curl/NetworkDataTaskCurl.h:

2022-05-11 Michael Saboff <msaboff@apple.com>

Need to add DYLD_LIBRARY_PATH for XPC services
@@ -26,8 +26,12 @@
#include "config.h"
#include "NetworkDataTaskCurl.h"

#include "APIError.h"
#include "AuthenticationChallengeDisposition.h"
#include "AuthenticationManager.h"
#include "DataReference.h"
#include "Download.h"
#include "NetworkProcess.h"
#include "NetworkSessionCurl.h"
#include "PrivateRelayed.h"
#include <WebCore/AuthenticationChallenge.h>
@@ -42,6 +46,7 @@
#include <WebCore/ShouldRelaxThirdPartyCookieBlocking.h>
#include <WebCore/SynchronousLoaderClient.h>
#include <pal/text/TextEncoding.h>
#include <wtf/FileSystem.h>

namespace WebKit {

@@ -108,6 +113,9 @@ void NetworkDataTaskCurl::cancel()

if (m_curlRequest)
m_curlRequest->cancel();

if (isDownload())
deleteDownloadFile();
}

void NetworkDataTaskCurl::invalidateAndCancel()
@@ -180,6 +188,23 @@ void NetworkDataTaskCurl::curlDidReceiveData(CurlRequest&, const SharedBuffer& b
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
return;

if (isDownload()) {
auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
RELEASE_ASSERT(download);
uint64_t bytesWritten = 0;
for (auto& segment : buffer) {
if (-1 == FileSystem::writeToFile(m_downloadDestinationFile, segment.segment->data(), segment.segment->size())) {
download->didFail(ResourceError::httpError(CURLE_WRITE_ERROR, m_response.url()), IPC::DataReference());
invalidateAndCancel();
return;
}

bytesWritten += segment.segment->size();
}
download->didReceiveData(bytesWritten, 0, 0);
return;
}

m_client->didReceiveData(buffer);
}

@@ -188,9 +213,27 @@ void NetworkDataTaskCurl::curlDidComplete(CurlRequest&, NetworkLoadMetrics&& net
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
return;

if (isDownload()) {
auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
RELEASE_ASSERT(download);
FileSystem::closeFile(m_downloadDestinationFile);
m_downloadDestinationFile = FileSystem::invalidPlatformFileHandle;
download->didFinish();
return;
}

m_client->didCompleteWithError({ }, WTFMove(networkLoadMetrics));
}

void NetworkDataTaskCurl::deleteDownloadFile()
{
if (FileSystem::isHandleValid(m_downloadDestinationFile)) {
FileSystem::closeFile(m_downloadDestinationFile);
FileSystem::deleteFile(m_pendingDownloadLocation);
m_downloadDestinationFile = FileSystem::invalidPlatformFileHandle;
}
}

void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceError&& resourceError, CertificateInfo&& certificateInfo)
{
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
@@ -201,6 +244,14 @@ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceErr
return;
}

if (isDownload()) {
deleteDownloadFile();
auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
RELEASE_ASSERT(download);
download->didFail(resourceError, IPC::DataReference());
return;
}

m_client->didCompleteWithError(resourceError);
}

@@ -238,6 +289,24 @@ void NetworkDataTaskCurl::invokeDidReceiveResponse()
case PolicyAction::Ignore:
invalidateAndCancel();
break;
case PolicyAction::Download: {
m_downloadDestinationFile = FileSystem::openFile(m_pendingDownloadLocation, FileSystem::FileOpenMode::Write);
if (!FileSystem::isHandleValid(m_downloadDestinationFile)) {
if (m_client)
m_client->didCompleteWithError(ResourceError::httpError(CURLE_WRITE_ERROR, m_response.url()));
invalidateAndCancel();
return;
}

auto& downloadManager = m_session->networkProcess().downloadManager();
auto download = makeUnique<Download>(downloadManager, m_pendingDownloadID, *this, *m_session, suggestedFilename());
auto* downloadPtr = download.get();
downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
downloadPtr->didCreateDestination(m_pendingDownloadLocation);
if (m_curlRequest)
m_curlRequest->completeDidReceiveResponse();
break;
}
default:
notImplemented();
break;
@@ -32,6 +32,7 @@
#include <WebCore/ProtectionSpace.h>
#include <WebCore/ResourceResponse.h>
#include <WebCore/ShouldRelaxThirdPartyCookieBlocking.h>
#include <wtf/FileSystem.h>
#include <wtf/MonotonicTime.h>

namespace WebCore {
@@ -93,6 +94,7 @@ class NetworkDataTaskCurl final : public NetworkDataTask, public WebCore::CurlRe
void unblockCookies();

String suggestedFilename() const override;
void deleteDownloadFile();

State m_state { State::Suspended };

@@ -104,6 +106,8 @@ class NetworkDataTaskCurl final : public NetworkDataTask, public WebCore::CurlRe
WebCore::FrameIdentifier m_frameID;
WebCore::PageIdentifier m_pageID;

FileSystem::PlatformFileHandle m_downloadDestinationFile { FileSystem::invalidPlatformFileHandle };

bool m_blockingCookies { false };

WebCore::ShouldRelaxThirdPartyCookieBlocking m_shouldRelaxThirdPartyCookieBlocking { WebCore::ShouldRelaxThirdPartyCookieBlocking::No };
@@ -64,6 +64,7 @@ if (${WTF_PLATFORM_WIN_CAIRO})

WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CSS_CONIC_GRADIENTS PRIVATE ON)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DARK_MODE_CSS PRIVATE ON)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DOWNLOAD_ATTRIBUTE PRIVATE ON)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FILTERS_LEVEL_2 PRIVATE ON)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_LEGACY_ENCRYPTED_MEDIA PUBLIC OFF)
WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PUBLIC_SUFFIX_LIST PRIVATE ON)

0 comments on commit 8a92050

Please sign in to comment.