Skip to content

Commit f3f10ae

Browse files
authored
browser(webkit): support downloads on windows (#1642)
1 parent 692f4db commit f3f10ae

File tree

2 files changed

+128
-16
lines changed

2 files changed

+128
-16
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1185
1+
1186

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 127 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5397,6 +5397,92 @@ index 82e6ffd18a3bcd8a14e4a1890fb549269c8b4252..17254c036846b7f80df6bc22e2e01fbc
53975397
const String& host = challenge.protectionSpace().host();
53985398
NSArray *certificates = [NSURLRequest allowsSpecificHTTPSCertificateForHost:host];
53995399
if (!certificates)
5400+
diff --git a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
5401+
index 977a403be8dc962a9ccfa6428bc1d3e7c4682f86..5fb2c30136bffda04d4d5ffacea4511ef86ca427 100644
5402+
--- a/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
5403+
+++ b/Source/WebKit/NetworkProcess/curl/NetworkDataTaskCurl.cpp
5404+
@@ -26,9 +26,13 @@
5405+
#include "config.h"
5406+
#include "NetworkDataTaskCurl.h"
5407+
5408+
+#include "APIError.h"
5409+
#include "AuthenticationChallengeDisposition.h"
5410+
#include "AuthenticationManager.h"
5411+
+#include "DataReference.h"
5412+
+#include "Download.h"
5413+
#include "NetworkSessionCurl.h"
5414+
+#include "NetworkProcess.h"
5415+
#include <WebCore/AuthenticationChallenge.h>
5416+
#include <WebCore/CookieJar.h>
5417+
#include <WebCore/CurlRequest.h>
5418+
@@ -38,6 +42,7 @@
5419+
#include <WebCore/ResourceError.h>
5420+
#include <WebCore/SameSiteInfo.h>
5421+
#include <WebCore/SynchronousLoaderClient.h>
5422+
+#include <wtf/FileSystem.h>
5423+
5424+
namespace WebKit {
5425+
5426+
@@ -177,7 +182,12 @@ void NetworkDataTaskCurl::curlDidReceiveBuffer(CurlRequest&, Ref<SharedBuffer>&&
5427+
auto protectedThis = makeRef(*this);
5428+
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
5429+
return;
5430+
-
5431+
+ if (isDownload()) {
5432+
+ FileSystem::PlatformFileHandle file = FileSystem::openFile(m_pendingDownloadLocation, FileSystem::FileOpenMode::Write);
5433+
+ FileSystem::writeToFile(file, buffer->data(), buffer->size());
5434+
+ FileSystem::closeFile(file);
5435+
+ return;
5436+
+ }
5437+
m_client->didReceiveData(WTFMove(buffer));
5438+
}
5439+
5440+
@@ -186,6 +196,12 @@ void NetworkDataTaskCurl::curlDidComplete(CurlRequest&, NetworkLoadMetrics&& net
5441+
if (state() == State::Canceling || state() == State::Completed || (!m_client && !isDownload()))
5442+
return;
5443+
5444+
+ if (isDownload()) {
5445+
+ auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
5446+
+ ASSERT(download);
5447+
+ download->didFinish();
5448+
+ return;
5449+
+ }
5450+
m_client->didCompleteWithError({ }, WTFMove(networkLoadMetrics));
5451+
}
5452+
5453+
@@ -199,6 +215,13 @@ void NetworkDataTaskCurl::curlDidFailWithError(CurlRequest& request, ResourceErr
5454+
return;
5455+
}
5456+
5457+
+ if (isDownload()) {
5458+
+ auto* download = m_session->networkProcess().downloadManager().download(m_pendingDownloadID);
5459+
+ ASSERT(download);
5460+
+ download->didFail(resourceError, IPC::DataReference());
5461+
+ return;
5462+
+ }
5463+
+
5464+
m_client->didCompleteWithError(resourceError);
5465+
}
5466+
5467+
@@ -235,6 +258,18 @@ void NetworkDataTaskCurl::invokeDidReceiveResponse()
5468+
break;
5469+
case PolicyAction::Ignore:
5470+
break;
5471+
+ case PolicyAction::Download: {
5472+
+ FileSystem::deleteFile(m_pendingDownloadLocation);
5473+
+ auto& downloadManager = m_session->networkProcess().downloadManager();
5474+
+ auto download = makeUnique<Download>(downloadManager, m_pendingDownloadID, *this, *m_session, suggestedFilename());
5475+
+ auto* downloadPtr = download.get();
5476+
+ downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
5477+
+ downloadPtr->didCreateDestination(m_pendingDownloadLocation);
5478+
+
5479+
+ if (m_curlRequest)
5480+
+ m_curlRequest->completeDidReceiveResponse();
5481+
+ break;
5482+
+ }
5483+
default:
5484+
notImplemented();
5485+
break;
54005486
diff --git a/Source/WebKit/NetworkProcess/curl/NetworkProcessCurl.cpp b/Source/WebKit/NetworkProcess/curl/NetworkProcessCurl.cpp
54015487
index 20b659f5cf4895e75a2762a9260611cd5f2fff80..ef094ae0d772f9884fd3021ba0eb4f491264ddbf 100644
54025488
--- a/Source/WebKit/NetworkProcess/curl/NetworkProcessCurl.cpp
@@ -13381,10 +13467,18 @@ index d79c6fdc4fa05e1e4b9acdcc6932e571163320eb..99718b19797788634f4233a8892729b5
1338113467
int m_toolbarItemsWidth { };
1338213468
};
1338313469
diff --git a/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp b/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp
13384-
index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800fd2fc9fe 100644
13470+
index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..30eaa65b5600fce08e6153bbd47fdbca900bbd7b 100644
1338513471
--- a/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp
1338613472
+++ b/Tools/MiniBrowser/win/WebKitBrowserWindow.cpp
13387-
@@ -106,7 +106,7 @@ WKRetainPtr<WKURLRef> createWKURL(const std::wstring& str)
13473+
@@ -32,6 +32,7 @@
13474+
#include <WebKit/WKAuthenticationDecisionListener.h>
13475+
#include <WebKit/WKCertificateInfoCurl.h>
13476+
#include <WebKit/WKCredential.h>
13477+
+#include <WebKit/WKFramePolicyListener.h>
13478+
#include <WebKit/WKInspector.h>
13479+
#include <WebKit/WKProtectionSpace.h>
13480+
#include <WebKit/WKProtectionSpaceCurl.h>
13481+
@@ -106,7 +107,7 @@ WKRetainPtr<WKURLRef> createWKURL(const std::wstring& str)
1338813482
return adoptWK(WKURLCreateWithUTF8CString(utf8.data()));
1338913483
}
1339013484

@@ -13393,7 +13487,7 @@ index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800
1339313487
{
1339413488
auto conf = adoptWK(WKPageConfigurationCreate());
1339513489

13396-
@@ -120,8 +120,8 @@ Ref<BrowserWindow> WebKitBrowserWindow::create(BrowserWindowClient& client, HWND
13490+
@@ -120,8 +121,8 @@ Ref<BrowserWindow> WebKitBrowserWindow::create(BrowserWindowClient& client, HWND
1339713491
WKPreferencesSetDeveloperExtrasEnabled(prefs.get(), true);
1339813492
WKPageConfigurationSetPreferences(conf.get(), prefs.get());
1339913493

@@ -13404,7 +13498,7 @@ index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800
1340413498

1340513499
return adoptRef(*new WebKitBrowserWindow(client, conf.get(), mainWnd));
1340613500
}
13407-
@@ -142,11 +142,17 @@ WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, WKPageConf
13501+
@@ -142,11 +143,17 @@ WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, WKPageConf
1340813502
navigationClient.didReceiveAuthenticationChallenge = didReceiveAuthenticationChallenge;
1340913503
WKPageSetPageNavigationClient(page, &navigationClient.base);
1341013504

@@ -13424,15 +13518,20 @@ index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800
1342413518
WKPageSetPageUIClient(page, &uiClient.base);
1342513519

1342613520
WKPageStateClientV0 stateClient = { };
13427-
@@ -158,7 +164,6 @@ WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, WKPageConf
13521+
@@ -158,7 +165,11 @@ WebKitBrowserWindow::WebKitBrowserWindow(BrowserWindowClient& client, WKPageConf
1342813522
stateClient.didChangeActiveURL = didChangeActiveURL;
1342913523
WKPageSetPageStateClient(page, &stateClient.base);
1343013524

1343113525
- updateProxySettings();
13526+
+ WKPagePolicyClientV1 policyClient = { };
13527+
+ policyClient.base.version = 1;
13528+
+ policyClient.base.clientInfo = this;
13529+
+ policyClient.decidePolicyForResponse_deprecatedForUseWithV0 = decidePolicyForResponse;
13530+
+ WKPageSetPagePolicyClient(page, &policyClient.base);
1343213531
resetZoom();
1343313532
}
1343413533

13435-
@@ -182,6 +187,29 @@ void WebKitBrowserWindow::updateProxySettings()
13534+
@@ -182,6 +193,29 @@ void WebKitBrowserWindow::updateProxySettings()
1343613535
WKWebsiteDataStoreEnableCustomNetworkProxySettings(store, url.get(), excludeHosts.get());
1343713536
}
1343813537

@@ -13462,23 +13561,21 @@ index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800
1346213561
HRESULT WebKitBrowserWindow::init()
1346313562
{
1346413563
return S_OK;
13465-
@@ -250,7 +278,6 @@ void WebKitBrowserWindow::openProxySettings()
13564+
@@ -250,7 +284,6 @@ void WebKitBrowserWindow::openProxySettings()
1346613565
{
1346713566
if (askProxySettings(m_hMainWnd, m_proxy))
1346813567
updateProxySettings();
1346913568
-
1347013569
}
1347113570

1347213571
void WebKitBrowserWindow::setUserAgent(_bstr_t& customUAString)
13473-
@@ -388,18 +415,94 @@ bool WebKitBrowserWindow::canTrustServerCertificate(WKProtectionSpaceRef protect
13572+
@@ -388,18 +421,94 @@ bool WebKitBrowserWindow::canTrustServerCertificate(WKProtectionSpaceRef protect
1347413573
return false;
1347513574
}
1347613575

1347713576
-WKPageRef WebKitBrowserWindow::createNewPage(WKPageRef page, WKPageConfigurationRef configuration, WKNavigationActionRef navigationAction, WKWindowFeaturesRef windowFeatures, const void *clientInfo)
1347813577
+void WebKitBrowserWindow::closeWindow(WKPageRef page, const void* clientInfo)
13479-
{
13480-
- auto& newWindow = MainWindow::create().leakRef();
13481-
- auto factory = [configuration](BrowserWindowClient& client, HWND mainWnd, bool) -> auto {
13578+
+{
1348213579
+ auto& thisWindow = toWebKitBrowserWindow(clientInfo);
1348313580
+ PostMessage(thisWindow.m_hMainWnd, WM_CLOSE, 0, 0);
1348413581
+}
@@ -13505,7 +13602,9 @@ index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800
1350513602
+}
1350613603
+
1350713604
+void WebKitBrowserWindow::runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, const void *clientInfo)
13508-
+{
13605+
{
13606+
- auto& newWindow = MainWindow::create().leakRef();
13607+
- auto factory = [configuration](BrowserWindowClient& client, HWND mainWnd, bool) -> auto {
1350913608
+ auto& thisWindow = toWebKitBrowserWindow(clientInfo);
1351013609
+ WKRetain(listener);
1351113610
+ thisWindow.m_beforeUnloadDialog = listener;
@@ -13572,8 +13671,20 @@ index 1e4fb27884034dcca333f77efd24150d4c9dc2ec..ed9046f38f0b517644f8c5208c8b7800
1357213671
return newPage.leakRef();
1357313672
}
1357413673

13674+
@@ -408,3 +517,11 @@ void WebKitBrowserWindow::didNotHandleKeyEvent(WKPageRef, WKNativeEventPtr event
13675+
auto& thisWindow = toWebKitBrowserWindow(clientInfo);
13676+
PostMessage(thisWindow.m_hMainWnd, event->message, event->wParam, event->lParam);
13677+
}
13678+
+
13679+
+void WebKitBrowserWindow::decidePolicyForResponse(WKPageRef page, WKFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKFramePolicyListenerRef listener, WKTypeRef userData, const void* clientInfo)
13680+
+{
13681+
+ if (WKURLResponseIsAttachment(response))
13682+
+ WKFramePolicyListenerDownload(listener);
13683+
+ else
13684+
+ WKFramePolicyListenerUse(listener);
13685+
+}
1357513686
diff --git a/Tools/MiniBrowser/win/WebKitBrowserWindow.h b/Tools/MiniBrowser/win/WebKitBrowserWindow.h
13576-
index 373d0de77e852c673a6615e0acedd5195e3c021b..cfeb4f806f79d1a213fdb13346e2b383b9a64273 100644
13687+
index 373d0de77e852c673a6615e0acedd5195e3c021b..2f25d60c366efa428197dba4a7e0aea6de86af6c 100644
1357713688
--- a/Tools/MiniBrowser/win/WebKitBrowserWindow.h
1357813689
+++ b/Tools/MiniBrowser/win/WebKitBrowserWindow.h
1357913690
@@ -26,6 +26,7 @@
@@ -13599,7 +13710,7 @@ index 373d0de77e852c673a6615e0acedd5195e3c021b..cfeb4f806f79d1a213fdb13346e2b383
1359913710

1360013711
HRESULT init() override;
1360113712
HWND hwnd() override;
13602-
@@ -71,6 +75,12 @@ private:
13713+
@@ -71,11 +75,22 @@ private:
1360313714
static void didChangeActiveURL(const void*);
1360413715
static void didReceiveAuthenticationChallenge(WKPageRef, WKAuthenticationChallengeRef, const void*);
1360513716
static WKPageRef createNewPage(WKPageRef, WKPageConfigurationRef, WKNavigationActionRef, WKWindowFeaturesRef, const void *);
@@ -13610,9 +13721,10 @@ index 373d0de77e852c673a6615e0acedd5195e3c021b..cfeb4f806f79d1a213fdb13346e2b383
1361013721
+ static void runBeforeUnloadConfirmPanel(WKPageRef page, WKStringRef message, WKFrameRef frame, WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, const void *clientInfo);
1361113722
+ static void handleJavaScriptDialog(WKPageRef page, bool accept, WKStringRef value, const void *clientInfo);
1361213723
static void didNotHandleKeyEvent(WKPageRef, WKNativeEventPtr, const void*);
13724+
+ static void decidePolicyForResponse(WKPageRef, WKFrameRef, WKURLResponseRef, WKURLRequestRef, WKFramePolicyListenerRef, WKTypeRef, const void*);
1361313725

1361413726
BrowserWindowClient& m_client;
13615-
@@ -78,4 +88,8 @@ private:
13727+
WKRetainPtr<WKViewRef> m_view;
1361613728
HWND m_hMainWnd { nullptr };
1361713729
ProxySettings m_proxy { };
1361813730
std::unordered_map<std::wstring, std::wstring> m_acceptedServerTrustCerts;

0 commit comments

Comments
 (0)