Skip to content

Commit

Permalink
browser(webkit): support downloads larger than 16Kb on Windows (#6343)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Apr 27, 2021
1 parent 3413574 commit 0039b31
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
4 changes: 2 additions & 2 deletions browser_patches/webkit/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1467
Changed: yurys@chromium.org Mon 26 Apr 2021 04:14:04 PM PDT
1468
Changed: yurys@chromium.org Tue, Apr 27, 2021 10:33:49 PM
71 changes: 56 additions & 15 deletions browser_patches/webkit/patches/bootstrap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -8394,7 +8394,7 @@ index 88abe8c29c43b8c8881d29e25a21e4dd370ab498..c5e3439a0ce52a9d368b984c7849fac7
#if !LOG_DISABLED
LOG(NetworkSession, "%llu didReceiveResponse completionHandler (%d)", taskIdentifier, policyAction);
diff --git a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc2e0712de 100644
index e9fdf357d64f8916b35e5e00469b997580db3abd..7f44429cde3a8d2e44b47d3f65549b76a24ed38a 100644
--- a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
+++ b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
@@ -26,9 +26,13 @@
Expand Down Expand Up @@ -8428,46 +8428,69 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
m_curlRequest->setStartTime(m_startTime);
m_curlRequest->start();
}
@@ -153,6 +160,7 @@ void NetworkDataTaskCurl::curlDidReceiveResponse(CurlRequest& request, CurlRespo
@@ -109,6 +116,9 @@ void NetworkDataTaskCurl::cancel()

if (m_curlRequest)
m_curlRequest->cancel();
+
+ if (isDownload())
+ deleteDownloadFile();
}

void NetworkDataTaskCurl::invalidateAndCancel()
@@ -153,6 +163,7 @@ void NetworkDataTaskCurl::curlDidReceiveResponse(CurlRequest& request, CurlRespo
m_response = ResourceResponse(receivedResponse);
m_response.setCertificateInfo(WTFMove(receivedResponse.certificateInfo));
m_response.setDeprecatedNetworkLoadMetrics(Box<NetworkLoadMetrics>::create(WTFMove(receivedResponse.networkLoadMetrics)));
+ m_response.m_httpRequestHeaderFields = request.resourceRequest().httpHeaderFields();

handleCookieHeaders(request.resourceRequest(), receivedResponse);

@@ -180,7 +188,12 @@ void NetworkDataTaskCurl::curlDidReceiveBuffer(CurlRequest&, Ref<SharedBuffer>&&
@@ -180,7 +191,10 @@ void NetworkDataTaskCurl::curlDidReceiveBuffer(CurlRequest&, Ref<SharedBuffer>&&
auto protectedThis = makeRef(*this);
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
return;
-
+ if (isDownload()) {
+ FileSystem::PlatformFileHandle file = FileSystem::openFile(m_pendingDownloadLocation, FileSystem::FileOpenMode::Write);
+ FileSystem::writeToFile(file, buffer->data(), buffer->size());
+ FileSystem::closeFile(file);
+ FileSystem::writeToFile(m_downloadDestinationFile, buffer->data(), buffer->size());
+ return;
+ }
m_client->didReceiveData(WTFMove(buffer));
}

@@ -189,6 +202,12 @@ void NetworkDataTaskCurl::curlDidComplete(CurlRequest&, NetworkLoadMetrics&& net
@@ -189,9 +203,26 @@ 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);
+ ASSERT(download);
+ FileSystem::closeFile(m_downloadDestinationFile);
+ m_downloadDestinationFile = FileSystem::invalidPlatformFileHandle;
+ download->didFinish();
+ return;
+ }
m_client->didCompleteWithError({ }, WTFMove(networkLoadMetrics));
}

@@ -202,6 +221,13 @@ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceErr
+void NetworkDataTaskCurl::deleteDownloadFile()
+{
+ if (m_downloadDestinationFile != FileSystem::invalidPlatformFileHandle) {
+ 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()))
@@ -202,6 +233,14 @@ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceErr
return;
}

+ if (isDownload()) {
+ deleteDownloadFile();
+ auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
+ ASSERT(download);
+ download->didFail(resourceError, IPC::DataReference());
Expand All @@ -8477,7 +8500,7 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
m_client->didCompleteWithError(resourceError);
}

@@ -239,6 +265,18 @@ void NetworkDataTaskCurl::invokeDidReceiveResponse()
@@ -239,6 +278,19 @@ void NetworkDataTaskCurl::invokeDidReceiveResponse()
case PolicyAction::Ignore:
invalidateAndCancel();
break;
Expand All @@ -8487,6 +8510,7 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
+ auto download = makeUnique<Download>(downloadManager, m_pendingDownloadID, *this, *m_session, suggestedFilename());
+ auto* downloadPtr = download.get();
+ downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
+ m_downloadDestinationFile = FileSystem::openFile(m_pendingDownloadLocation, FileSystem::FileOpenMode::Write);
+ downloadPtr->didCreateDestination(m_pendingDownloadLocation);
+
+ if (m_curlRequest)
Expand All @@ -8496,7 +8520,7 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
default:
notImplemented();
break;
@@ -321,6 +359,8 @@ void NetworkDataTaskCurl::willPerformHTTPRedirection()
@@ -321,6 +373,8 @@ void NetworkDataTaskCurl::willPerformHTTPRedirection()
m_curlRequest->setUserPass(m_initialCredential.user(), m_initialCredential.password());
m_curlRequest->setAuthenticationScheme(ProtectionSpaceAuthenticationSchemeHTTPBasic);
}
Expand All @@ -8506,10 +8530,18 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
m_curlRequest->start();

diff --git a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h
index 46c215a99a9bb31546e8880ce6f0876193c075fe..3509c62ac2c970fdcf78db2503c0cc4259f56dbd 100644
index 46c215a99a9bb31546e8880ce6f0876193c075fe..82c3afd36a91962c540e69d176c086b98e80ddc1 100644
--- a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h
+++ b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h
@@ -85,14 +85,13 @@ private:
@@ -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 {
@@ -85,13 +86,13 @@ private:

void appendCookieHeader(WebCore::ResourceRequest&);
void handleCookieHeaders(const WebCore::ResourceRequest&, const WebCore::CurlResponse&);
Expand All @@ -8519,12 +8551,21 @@ index 46c215a99a9bb31546e8880ce6f0876193c075fe..3509c62ac2c970fdcf78db2503c0cc42
bool shouldBlockCookies(const WebCore::ResourceRequest&);
void blockCookies();
void unblockCookies();

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

State m_state { State::Suspended };

RefPtr<WebCore::CurlRequest> m_curlRequest;
@@ -104,6 +105,8 @@ private:
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 };
diff --git a/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp b/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp
index 0d690beb77a8d299b6e0137ac3f21d40eff2f2d9..25a05f893cb10aaeaaf17c7c27bd2a1e61abe384 100644
--- a/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp
Expand Down

0 comments on commit 0039b31

Please sign in to comment.