@@ -8394,7 +8394,7 @@ index 88abe8c29c43b8c8881d29e25a21e4dd370ab498..c5e3439a0ce52a9d368b984c7849fac7
8394
8394
#if !LOG_DISABLED
8395
8395
LOG(NetworkSession, "%llu didReceiveResponse completionHandler (%d)", taskIdentifier, policyAction);
8396
8396
diff --git a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
8397
- index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc2e0712de 100644
8397
+ index e9fdf357d64f8916b35e5e00469b997580db3abd..7f44429cde3a8d2e44b47d3f65549b76a24ed38a 100644
8398
8398
--- a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
8399
8399
+++ b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
8400
8400
@@ -26,9 +26,13 @@
@@ -8428,46 +8428,69 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
8428
8428
m_curlRequest->setStartTime(m_startTime);
8429
8429
m_curlRequest->start();
8430
8430
}
8431
- @@ -153,6 +160,7 @@ void NetworkDataTaskCurl::curlDidReceiveResponse(CurlRequest& request, CurlRespo
8431
+ @@ -109,6 +116,9 @@ void NetworkDataTaskCurl::cancel()
8432
+
8433
+ if (m_curlRequest)
8434
+ m_curlRequest->cancel();
8435
+ +
8436
+ + if (isDownload())
8437
+ + deleteDownloadFile();
8438
+ }
8439
+
8440
+ void NetworkDataTaskCurl::invalidateAndCancel()
8441
+ @@ -153,6 +163,7 @@ void NetworkDataTaskCurl::curlDidReceiveResponse(CurlRequest& request, CurlRespo
8432
8442
m_response = ResourceResponse(receivedResponse);
8433
8443
m_response.setCertificateInfo(WTFMove(receivedResponse.certificateInfo));
8434
8444
m_response.setDeprecatedNetworkLoadMetrics(Box<NetworkLoadMetrics>::create(WTFMove(receivedResponse.networkLoadMetrics)));
8435
8445
+ m_response.m_httpRequestHeaderFields = request.resourceRequest().httpHeaderFields();
8436
8446
8437
8447
handleCookieHeaders(request.resourceRequest(), receivedResponse);
8438
8448
8439
- @@ -180,7 +188,12 @@ void NetworkDataTaskCurl::curlDidReceiveBuffer(CurlRequest&, Ref<SharedBuffer>&&
8449
+ @@ -180,7 +191,10 @@ void NetworkDataTaskCurl::curlDidReceiveBuffer(CurlRequest&, Ref<SharedBuffer>&&
8440
8450
auto protectedThis = makeRef(*this);
8441
8451
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
8442
8452
return;
8443
8453
-
8444
8454
+ if (isDownload()) {
8445
- + FileSystem::PlatformFileHandle file = FileSystem::openFile(m_pendingDownloadLocation, FileSystem::FileOpenMode::Write);
8446
- + FileSystem::writeToFile(file, buffer->data(), buffer->size());
8447
- + FileSystem::closeFile(file);
8455
+ + FileSystem::writeToFile(m_downloadDestinationFile, buffer->data(), buffer->size());
8448
8456
+ return;
8449
8457
+ }
8450
8458
m_client->didReceiveData(WTFMove(buffer));
8451
8459
}
8452
8460
8453
- @@ -189,6 +202,12 @@ void NetworkDataTaskCurl::curlDidComplete(CurlRequest&, NetworkLoadMetrics&& net
8461
+ @@ -189,9 +203,26 @@ void NetworkDataTaskCurl::curlDidComplete(CurlRequest&, NetworkLoadMetrics&& net
8454
8462
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
8455
8463
return;
8456
8464
8457
8465
+ if (isDownload()) {
8458
8466
+ auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
8459
8467
+ ASSERT(download);
8468
+ + FileSystem::closeFile(m_downloadDestinationFile);
8469
+ + m_downloadDestinationFile = FileSystem::invalidPlatformFileHandle;
8460
8470
+ download->didFinish();
8461
8471
+ return;
8462
8472
+ }
8463
8473
m_client->didCompleteWithError({ }, WTFMove(networkLoadMetrics));
8464
8474
}
8465
8475
8466
- @@ -202,6 +221,13 @@ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceErr
8476
+ +void NetworkDataTaskCurl::deleteDownloadFile()
8477
+ +{
8478
+ + if (m_downloadDestinationFile != FileSystem::invalidPlatformFileHandle) {
8479
+ + FileSystem::closeFile(m_downloadDestinationFile);
8480
+ + FileSystem::deleteFile(m_pendingDownloadLocation);
8481
+ + m_downloadDestinationFile = FileSystem::invalidPlatformFileHandle;
8482
+ + }
8483
+ +}
8484
+ +
8485
+ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceError&& resourceError, CertificateInfo&& certificateInfo)
8486
+ {
8487
+ if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
8488
+ @@ -202,6 +233,14 @@ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceErr
8467
8489
return;
8468
8490
}
8469
8491
8470
8492
+ if (isDownload()) {
8493
+ + deleteDownloadFile();
8471
8494
+ auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
8472
8495
+ ASSERT(download);
8473
8496
+ download->didFail(resourceError, IPC::DataReference());
@@ -8477,7 +8500,7 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
8477
8500
m_client->didCompleteWithError(resourceError);
8478
8501
}
8479
8502
8480
- @@ -239,6 +265,18 @@ void NetworkDataTaskCurl::invokeDidReceiveResponse()
8503
+ @@ -239,6 +278,19 @@ void NetworkDataTaskCurl::invokeDidReceiveResponse()
8481
8504
case PolicyAction::Ignore:
8482
8505
invalidateAndCancel();
8483
8506
break;
@@ -8487,6 +8510,7 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
8487
8510
+ auto download = makeUnique<Download>(downloadManager, m_pendingDownloadID, *this, *m_session, suggestedFilename());
8488
8511
+ auto* downloadPtr = download.get();
8489
8512
+ downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
8513
+ + m_downloadDestinationFile = FileSystem::openFile(m_pendingDownloadLocation, FileSystem::FileOpenMode::Write);
8490
8514
+ downloadPtr->didCreateDestination(m_pendingDownloadLocation);
8491
8515
+
8492
8516
+ if (m_curlRequest)
@@ -8496,7 +8520,7 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
8496
8520
default:
8497
8521
notImplemented();
8498
8522
break;
8499
- @@ -321,6 +359 ,8 @@ void NetworkDataTaskCurl::willPerformHTTPRedirection()
8523
+ @@ -321,6 +373 ,8 @@ void NetworkDataTaskCurl::willPerformHTTPRedirection()
8500
8524
m_curlRequest->setUserPass(m_initialCredential.user(), m_initialCredential.password());
8501
8525
m_curlRequest->setAuthenticationScheme(ProtectionSpaceAuthenticationSchemeHTTPBasic);
8502
8526
}
@@ -8506,10 +8530,18 @@ index e9fdf357d64f8916b35e5e00469b997580db3abd..32135740fb58e7ca124a4fdc8514ebfc
8506
8530
m_curlRequest->start();
8507
8531
8508
8532
diff --git a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h
8509
- index 46c215a99a9bb31546e8880ce6f0876193c075fe..3509c62ac2c970fdcf78db2503c0cc4259f56dbd 100644
8533
+ index 46c215a99a9bb31546e8880ce6f0876193c075fe..82c3afd36a91962c540e69d176c086b98e80ddc1 100644
8510
8534
--- a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h
8511
8535
+++ b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.h
8512
- @@ -85,14 +85,13 @@ private:
8536
+ @@ -32,6 +32,7 @@
8537
+ #include <WebCore/ProtectionSpace.h>
8538
+ #include <WebCore/ResourceResponse.h>
8539
+ #include <WebCore/ShouldRelaxThirdPartyCookieBlocking.h>
8540
+ +#include <wtf/FileSystem.h>
8541
+ #include <wtf/MonotonicTime.h>
8542
+
8543
+ namespace WebCore {
8544
+ @@ -85,13 +86,13 @@ private:
8513
8545
8514
8546
void appendCookieHeader(WebCore::ResourceRequest&);
8515
8547
void handleCookieHeaders(const WebCore::ResourceRequest&, const WebCore::CurlResponse&);
@@ -8519,12 +8551,21 @@ index 46c215a99a9bb31546e8880ce6f0876193c075fe..3509c62ac2c970fdcf78db2503c0cc42
8519
8551
bool shouldBlockCookies(const WebCore::ResourceRequest&);
8520
8552
void blockCookies();
8521
8553
void unblockCookies();
8522
-
8523
- - String suggestedFilename() const override;
8524
8554
-
8555
+ - String suggestedFilename() const override;
8556
+ + void deleteDownloadFile();
8557
+
8525
8558
State m_state { State::Suspended };
8526
8559
8527
- RefPtr<WebCore::CurlRequest> m_curlRequest;
8560
+ @@ -104,6 +105,8 @@ private:
8561
+ WebCore::FrameIdentifier m_frameID;
8562
+ WebCore::PageIdentifier m_pageID;
8563
+
8564
+ + FileSystem::PlatformFileHandle m_downloadDestinationFile { FileSystem::invalidPlatformFileHandle };
8565
+ +
8566
+ bool m_blockingCookies { false };
8567
+
8568
+ WebCore::ShouldRelaxThirdPartyCookieBlocking m_shouldRelaxThirdPartyCookieBlocking { WebCore::ShouldRelaxThirdPartyCookieBlocking::No };
8528
8569
diff --git a/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp b/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp
8529
8570
index 0d690beb77a8d299b6e0137ac3f21d40eff2f2d9..25a05f893cb10aaeaaf17c7c27bd2a1e61abe384 100644
8530
8571
--- a/Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp
0 commit comments