Diff
Modified: trunk/LayoutTests/ChangeLog (221748 => 221749)
--- trunk/LayoutTests/ChangeLog 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/LayoutTests/ChangeLog 2017-09-07 19:51:58 UTC (rev 221749)
@@ -1,3 +1,18 @@
+2017-09-07 Chris Dumez <[email protected]>
+
+ [WK2] Notify client when downloads are redirected
+ https://bugs.webkit.org/show_bug.cgi?id=176481
+ <rdar://problem/34309065>
+
+ Reviewed by Geoffrey Garen.
+
+ Add layout test coverage.
+
+ * http/tests/download/anchor-download-redirect-expected.txt: Added.
+ * http/tests/download/anchor-download-redirect.html: Added.
+ * platform/ios-wk2/TestExpectations:
+ * platform/mac-wk1/TestExpectations:
+
2017-09-07 Per Arne Vollan <[email protected]>
Marked imported/w3c/web-platform-tests/html/semantics/embedded-content/the-iframe-element/cross_origin_parentage.html as slow.
Added: trunk/LayoutTests/http/tests/download/anchor-download-redirect-expected.txt (0 => 221749)
--- trunk/LayoutTests/http/tests/download/anchor-download-redirect-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-redirect-expected.txt 2017-09-07 19:51:58 UTC (rev 221749)
@@ -0,0 +1,7 @@
+Download started.
+Download was redirected to "http://127.0.0.1:8000/media/resources/test.pdf".
+Downloading URL with suggested filename "foo.pdf"
+Download completed.
+Tests that download redirects are reported to the client. the link.
+
+The suggested filename at the top should be foo.pdf and you should see a redirect to /media/resources/test.pdf.
Added: trunk/LayoutTests/http/tests/download/anchor-download-redirect.html (0 => 221749)
--- trunk/LayoutTests/http/tests/download/anchor-download-redirect.html (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-redirect.html 2017-09-07 19:51:58 UTC (rev 221749)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+ if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.setShouldLogDownloadCallbacks(true);
+ testRunner.waitUntilDownloadFinished();
+ }
+</script>
+</head>
+<body>
+<p>
+Tests that download redirects are reported to the client.
+<a id="dl" href="" download="foo.pdf">the link</a>.
+<p>
+The suggested filename at the top should be foo.pdf and you should see a redirect to /media/resources/test.pdf.
+<script>
+ function click(elmt)
+ {
+ if (!window.eventSender)
+ return;
+
+ eventSender.mouseMoveTo(elmt.offsetLeft + 5, elmt.offsetTop + 5);
+ eventSender.mouseDown();
+ eventSender.mouseUp();
+ }
+
+ function runTest()
+ {
+ var link = document.getElementById("dl");
+ click(link);
+ }
+ runTest();
+</script>
+</body>
+</html>
Modified: trunk/LayoutTests/platform/ios-wk2/TestExpectations (221748 => 221749)
--- trunk/LayoutTests/platform/ios-wk2/TestExpectations 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/LayoutTests/platform/ios-wk2/TestExpectations 2017-09-07 19:51:58 UTC (rev 221749)
@@ -1806,6 +1806,7 @@
webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
webkit.org/b/156067 http/tests/download/anchor-download-attribute-content-disposition.html [ Skip ]
webkit.org/b/156067 http/tests/download/anchor-download-no-extension.html [ Skip ]
+webkit.org/b/156067 http/tests/download/anchor-download-redirect.html [ Skip ]
webkit.org/b/156067 http/tests/download/area-download.html [ Skip ]
webkit.org/b/156067 http/tests/security/anchor-download-allow-blob.html [ Skip ]
webkit.org/b/156067 http/tests/security/anchor-download-allow-data.html [ Skip ]
Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (221748 => 221749)
--- trunk/LayoutTests/platform/mac-wk1/TestExpectations 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations 2017-09-07 19:51:58 UTC (rev 221749)
@@ -241,6 +241,7 @@
webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html [ Skip ]
webkit.org/b/156069 http/tests/download/anchor-download-attribute-content-disposition.html [ Skip ]
webkit.org/b/156069 http/tests/download/anchor-download-no-extension.html [ Skip ]
+webkit.org/b/156069 http/tests/download/anchor-download-redirect.html [ Skip ]
webkit.org/b/156069 http/tests/download/area-download.html [ Skip ]
webkit.org/b/156069 http/tests/security/anchor-download-allow-blob.html [ Skip ]
webkit.org/b/156069 http/tests/security/anchor-download-allow-data.html [ Skip ]
Modified: trunk/Source/WebKit/ChangeLog (221748 => 221749)
--- trunk/Source/WebKit/ChangeLog 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/ChangeLog 2017-09-07 19:51:58 UTC (rev 221749)
@@ -1,3 +1,40 @@
+2017-09-07 Chris Dumez <[email protected]>
+
+ [WK2] Notify client when downloads are redirected
+ https://bugs.webkit.org/show_bug.cgi?id=176481
+ <rdar://problem/34309065>
+
+ Reviewed by Geoffrey Garen.
+
+ Notify client when downloads are redirected via both ObjC and C
+ API.
+
+ * NetworkProcess/Downloads/Download.cpp:
+ (WebKit::Download::willSendRedirectedRequest):
+ * NetworkProcess/Downloads/Download.h:
+ * NetworkProcess/Downloads/mac/DownloadMac.mm:
+ (-[WKDownloadAsDelegate download:willSendRequest:redirectResponse:]):
+ * UIProcess/API/APIDownloadClient.h:
+ (API::DownloadClient::willSendRequest):
+ * UIProcess/API/C/WKContext.cpp:
+ (WKContextSetDownloadClient):
+ * UIProcess/API/C/WKContextDownloadClient.h:
+ * UIProcess/API/Cocoa/_WKDownloadDelegate.h:
+ * UIProcess/Cocoa/DownloadClient.h:
+ * UIProcess/Cocoa/DownloadClient.mm:
+ (WebKit::DownloadClient::DownloadClient):
+ (WebKit::DownloadClient::willSendRequest):
+ * UIProcess/Downloads/DownloadProxy.cpp:
+ (WebKit::DownloadProxy::willSendRequest):
+ * UIProcess/Downloads/DownloadProxy.h:
+ * UIProcess/Downloads/DownloadProxy.messages.in:
+
+ * UIProcess/mac/WebContextMenuProxyMac.mm:
+ (WebKit::WebContextMenuProxyMac::showContextMenuWithItems):
+ Set menu proxy before calling menuFromProposedMenu() client delegate.
+ This allows me to perform one of the menu item's action from the
+ menuFromProposedMenu() client delegate in my API test.
+
2017-09-07 Alex Christensen <[email protected]>
Modernize Geolocation code
Modified: trunk/Source/WebKit/NetworkProcess/Downloads/Download.cpp (221748 => 221749)
--- trunk/Source/WebKit/NetworkProcess/Downloads/Download.cpp 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/Download.cpp 2017-09-07 19:51:58 UTC (rev 221749)
@@ -152,6 +152,11 @@
send(Messages::DownloadProxy::DidStart(m_request, m_suggestedName));
}
+void Download::willSendRedirectedRequest(WebCore::ResourceRequest&& redirectRequest, WebCore::ResourceResponse&& redirectResponse)
+{
+ send(Messages::DownloadProxy::WillSendRequest(WTFMove(redirectRequest), WTFMove(redirectResponse)));
+}
+
void Download::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge)
{
m_downloadManager.downloadsAuthenticationManager().didReceiveAuthenticationChallenge(*this, authenticationChallenge);
Modified: trunk/Source/WebKit/NetworkProcess/Downloads/Download.h (221748 => 221749)
--- trunk/Source/WebKit/NetworkProcess/Downloads/Download.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/Download.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -62,6 +62,7 @@
class Credential;
class ResourceError;
class ResourceHandle;
+class ResourceRequest;
class ResourceResponse;
}
@@ -104,6 +105,7 @@
const WebCore::ResourceRequest& request() const { return m_request; }
void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&);
void didStart();
+ void willSendRedirectedRequest(WebCore::ResourceRequest&&, WebCore::ResourceResponse&&);
void didReceiveResponse(const WebCore::ResourceResponse&);
bool shouldDecodeSourceDataOfMIMEType(const String& mimeType);
String decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite);
Modified: trunk/Source/WebKit/NetworkProcess/Downloads/mac/DownloadMac.mm (221748 => 221749)
--- trunk/Source/WebKit/NetworkProcess/Downloads/mac/DownloadMac.mm 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/NetworkProcess/Downloads/mac/DownloadMac.mm 2017-09-07 19:51:58 UTC (rev 221749)
@@ -208,6 +208,10 @@
- (NSURLRequest *)download:(NSURLDownload *)download willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
+ dispatchOnMainThread(^ {
+ if (_download && redirectResponse)
+ _download->willSendRedirectedRequest(request, redirectResponse);
+ });
return request;
}
Modified: trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/API/APIDownloadClient.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -60,7 +60,7 @@
virtual void didCancel(WebKit::WebProcessPool*, WebKit::DownloadProxy*) { }
virtual void processDidCrash(WebKit::WebProcessPool*, WebKit::DownloadProxy*) { }
virtual bool canAuthenticateAgainstProtectionSpace(WebKit::WebProtectionSpace*) { return true; }
- virtual void willSendRequest(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse&, WTF::Function<void(const WebCore::ResourceRequest&)>&& callback) { callback(request); }
+ virtual void willSendRequest(WebKit::WebProcessPool*, WebKit::DownloadProxy*, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse&, WTF::Function<void(const WebCore::ResourceRequest&)>&& callback) { callback(request); }
};
} // namespace API
Modified: trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContext.cpp 2017-09-07 19:51:58 UTC (rev 221749)
@@ -51,7 +51,7 @@
namespace API {
template<> struct ClientTraits<WKContextDownloadClientBase> {
- typedef std::tuple<WKContextDownloadClientV0> Versions;
+ typedef std::tuple<WKContextDownloadClientV0, WKContextDownloadClientV1> Versions;
};
template<> struct ClientTraits<WKContextHistoryClientBase> {
typedef std::tuple<WKContextHistoryClientV0> Versions;
@@ -261,6 +261,15 @@
m_client.processDidCrash(toAPI(processPool), toAPI(downloadProxy), m_client.base.clientInfo);
}
+ void willSendRequest(WebProcessPool* processPool, DownloadProxy* downloadProxy, const ResourceRequest& request, const ResourceResponse&, WTF::Function<void(const ResourceRequest&)>&& callback) override
+ {
+ if (m_client.didReceiveServerRedirect)
+ m_client.didReceiveServerRedirect(toAPI(processPool), toAPI(downloadProxy), toURLRef(request.url().string().impl()), m_client.base.clientInfo);
+
+ callback(request);
+ }
+
+
};
toImpl(contextRef)->setDownloadClient(std::make_unique<DownloadClient>(wkClient));
Modified: trunk/Source/WebKit/UIProcess/API/C/WKContextDownloadClient.h (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/API/C/WKContextDownloadClient.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/API/C/WKContextDownloadClient.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -39,6 +39,7 @@
typedef void (*WKContextDownloadDidFailCallback)(WKContextRef context, WKDownloadRef download, WKErrorRef error, const void *clientInfo);
typedef void (*WKContextDownloadDidCancel)(WKContextRef context, WKDownloadRef download, const void *clientInfo);
typedef void (*WKContextDownloadProcessDidCrashCallback)(WKContextRef context, WKDownloadRef download, const void *clientInfo);
+typedef void (*WKContextDownloadDidReceiveServerRedirect)(WKContextRef context, WKDownloadRef download, WKURLRef url, const void *clientInfo);
typedef struct WKContextDownloadClientBase {
int version;
@@ -62,4 +63,24 @@
WKContextDownloadProcessDidCrashCallback processDidCrash;
} WKContextDownloadClientV0;
+typedef struct WKContextDownloadClientV1 {
+ WKContextDownloadClientBase base;
+
+ // Version 0.
+ WKContextDownloadDidStartCallback didStart;
+ WKContextDownloadDidReceiveAuthenticationChallengeCallback didReceiveAuthenticationChallenge;
+ WKContextDownloadDidReceiveResponseCallback didReceiveResponse;
+ WKContextDownloadDidReceiveDataCallback didReceiveData;
+ WKContextDownloadShouldDecodeSourceDataOfMIMETypeCallback shouldDecodeSourceDataOfMIMEType;
+ WKContextDownloadDecideDestinationWithSuggestedFilenameCallback decideDestinationWithSuggestedFilename;
+ WKContextDownloadDidCreateDestinationCallback didCreateDestination;
+ WKContextDownloadDidFinishCallback didFinish;
+ WKContextDownloadDidFailCallback didFail;
+ WKContextDownloadDidCancel didCancel;
+ WKContextDownloadProcessDidCrashCallback processDidCrash;
+
+ // Version 1.
+ WKContextDownloadDidReceiveServerRedirect didReceiveServerRedirect;
+} WKContextDownloadClientV1;
+
#endif // WKContextDownloadClient_h
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate.h (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKDownloadDelegate.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -34,6 +34,7 @@
@protocol _WKDownloadDelegate <NSObject>
@optional
- (void)_downloadDidStart:(_WKDownload *)download;
+- (void)_download:(_WKDownload *)download didReceiveServerRedirectToURL:(NSURL *)url WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
- (void)_download:(_WKDownload *)download didReceiveResponse:(NSURLResponse *)response;
- (void)_download:(_WKDownload *)download didReceiveData:(uint64_t)length;
- (NSString *)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename allowOverwrite:(BOOL *)allowOverwrite;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.h (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -48,13 +48,14 @@
private:
// From API::DownloadClient
- virtual void didStart(WebProcessPool*, DownloadProxy*);
- virtual void didReceiveResponse(WebProcessPool*, DownloadProxy*, const WebCore::ResourceResponse&);
- virtual void didReceiveData(WebProcessPool*, DownloadProxy*, uint64_t length);
- virtual String decideDestinationWithSuggestedFilename(WebProcessPool*, DownloadProxy*, const String& filename, bool& allowOverwriteParam);
- virtual void didFinish(WebProcessPool*, DownloadProxy*);
- virtual void didFail(WebProcessPool*, DownloadProxy*, const WebCore::ResourceError&);
- virtual void didCancel(WebProcessPool*, DownloadProxy*);
+ void didStart(WebProcessPool*, DownloadProxy*) final;
+ void didReceiveResponse(WebProcessPool*, DownloadProxy*, const WebCore::ResourceResponse&) final;
+ void didReceiveData(WebProcessPool*, DownloadProxy*, uint64_t length) final;
+ String decideDestinationWithSuggestedFilename(WebProcessPool*, DownloadProxy*, const String& filename, bool& allowOverwriteParam) final;
+ void didFinish(WebProcessPool*, DownloadProxy*) final;
+ void didFail(WebProcessPool*, DownloadProxy*, const WebCore::ResourceError&) final;
+ void didCancel(WebProcessPool*, DownloadProxy*) final;
+ void willSendRequest(WebProcessPool*, DownloadProxy*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, WTF::Function<void(const WebCore::ResourceRequest&)>&&) final;
WeakObjCPtr<id <_WKDownloadDelegate>> m_delegate;
@@ -66,6 +67,7 @@
bool downloadDidFinish : 1;
bool downloadDidFail : 1;
bool downloadDidCancel : 1;
+ bool downloadDidReceiveServerRedirectToURL : 1;
} m_delegateMethods;
};
Modified: trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm 2017-09-07 19:51:58 UTC (rev 221749)
@@ -31,6 +31,7 @@
#import "_WKDownloadDelegate.h"
#import "_WKDownloadInternal.h"
#import "DownloadProxy.h"
+#import "WKNSURLExtras.h"
#import <WebCore/ResourceError.h>
#import <WebCore/ResourceResponse.h>
@@ -52,6 +53,7 @@
m_delegateMethods.downloadDidFinish = [delegate respondsToSelector:@selector(_downloadDidFinish:)];
m_delegateMethods.downloadDidFail = [delegate respondsToSelector:@selector(_download:didFailWithError:)];
m_delegateMethods.downloadDidCancel = [delegate respondsToSelector:@selector(_downloadDidCancel:)];
+ m_delegateMethods.downloadDidReceiveServerRedirectToURL = [delegate respondsToSelector:@selector(_download:didReceiveServerRedirectToURL:)];
}
void DownloadClient::didStart(WebProcessPool*, DownloadProxy* downloadProxy)
@@ -101,6 +103,14 @@
[m_delegate.get() _downloadDidCancel:wrapper(*downloadProxy)];
}
+void DownloadClient::willSendRequest(WebProcessPool*, DownloadProxy* downloadProxy, const WebCore::ResourceRequest& request, const WebCore::ResourceResponse&, WTF::Function<void(const WebCore::ResourceRequest&)>&& callback)
+{
+ if (m_delegateMethods.downloadDidReceiveServerRedirectToURL)
+ [m_delegate.get() _download:wrapper(*downloadProxy) didReceiveServerRedirectToURL:[NSURL _web_URLWithWTFString:request.url().string()]];
+
+ callback(request);
+}
+
} // namespace WebKit
#endif // WK_API_ENABLED
Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.cpp 2017-09-07 19:51:58 UTC (rev 221749)
@@ -113,8 +113,7 @@
m_processPool->downloadClient().didReceiveAuthenticationChallenge(m_processPool.get(), this, authenticationChallengeProxy.get());
}
-#if USE(NETWORK_SESSION)
-#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
+#if USE(NETWORK_SESSION) && USE(PROTECTION_SPACE_AUTH_CALLBACK)
void DownloadProxy::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace)
{
if (!m_processPool)
@@ -136,18 +135,21 @@
return;
RefPtr<DownloadProxy> protectedThis(this);
- m_processPool->downloadClient().willSendRequest(proposedRequest, redirectResponse, [protectedThis](const ResourceRequest& newRequest) {
+ m_processPool->downloadClient().willSendRequest(m_processPool.get(), this, proposedRequest, redirectResponse, [protectedThis](const ResourceRequest& newRequest) {
+#if USE(NETWORK_SESSION)
if (!protectedThis->m_processPool)
return;
-
+
auto* networkProcessProxy = protectedThis->m_processPool->networkProcess();
if (!networkProcessProxy)
return;
-
+
networkProcessProxy->send(Messages::NetworkProcess::ContinueWillSendRequest(protectedThis->m_downloadID, newRequest), 0);
+#else
+ UNUSED_PARAM(newRequest);
+#endif
});
}
-#endif
void DownloadProxy::didReceiveResponse(const ResourceResponse& response)
{
Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -86,11 +86,11 @@
void didFinish();
void didFail(const WebCore::ResourceError&, const IPC::DataReference& resumeData);
void didCancel(const IPC::DataReference& resumeData);
+ void willSendRequest(const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse& redirectResponse);
#if USE(NETWORK_SESSION)
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
void canAuthenticateAgainstProtectionSpace(const WebCore::ProtectionSpace&);
#endif
- void willSendRequest(const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse& redirectResponse);
#else
void decideDestinationWithSuggestedFilename(const String& filename, const String& mimeType, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle);
#endif
Modified: trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.messages.in 2017-09-07 19:51:58 UTC (rev 221749)
@@ -23,8 +23,8 @@
messages -> DownloadProxy {
DidStart(WebCore::ResourceRequest request, AtomicString suggestedFilename)
DidReceiveAuthenticationChallenge(WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
+ WillSendRequest(WebCore::ResourceRequest redirectRequest, WebCore::ResourceResponse redirectResponse))
#if USE(NETWORK_SESSION)
- WillSendRequest(WebCore::ResourceRequest redirectRequest, WebCore::ResourceResponse redirectResponse))
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
CanAuthenticateAgainstProtectionSpace(WebCore::ProtectionSpace protectionSpace)
#endif
Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (221748 => 221749)
--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm 2017-09-07 19:51:58 UTC (rev 221749)
@@ -455,10 +455,9 @@
void WebContextMenuProxyMac::showContextMenuWithItems(const Vector<WebContextMenuItemData>& items)
{
auto menu = createContextMenuFromItems(items);
+ [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
m_menu = m_page.contextMenuClient().menuFromProposedMenu(m_page, menu.get(), m_context.webHitTestResultData(), m_userData.object());
- [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
-
NSPoint menuLocation = [m_webView convertPoint:m_context.menuLocation() toView:nil];
NSEvent *event = [NSEvent mouseEventWithType:NSEventTypeRightMouseUp location:menuLocation modifierFlags:0 timestamp:0 windowNumber:m_webView.window.windowNumber context:nil eventNumber:0 clickCount:0 pressure:0];
[NSMenu popUpContextMenu:m_menu.get() withEvent:event forView:m_webView];
Modified: trunk/Tools/ChangeLog (221748 => 221749)
--- trunk/Tools/ChangeLog 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Tools/ChangeLog 2017-09-07 19:51:58 UTC (rev 221749)
@@ -1,3 +1,25 @@
+2017-09-07 Chris Dumez <[email protected]>
+
+ [WK2] Notify client when downloads are redirected
+ https://bugs.webkit.org/show_bug.cgi?id=176481
+ <rdar://problem/34309065>
+
+ Reviewed by Geoffrey Garen.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/Download.mm:
+ (-[UIDownloadAsFileTestDelegate _webView:contextMenu:forElement:]):
+ (-[RedirectedDownloadDelegate _download:decideDestinationWithSuggestedFilename:allowOverwrite:]):
+ (-[RedirectedDownloadDelegate _download:didReceiveServerRedirectToURL:]):
+ (-[RedirectedDownloadDelegate _downloadDidFinish:]):
+ (TEST):
+ Add API test coverage.
+
+ * WebKitTestRunner/TestController.cpp:
+ (WTR::TestController::createWebViewWithOptions):
+ (WTR::TestController::downloadDidReceiveServerRedirectToURL):
+ * WebKitTestRunner/TestController.h:
+ Add layout test infrastructure.
+
2017-09-07 Per Arne Vollan <[email protected]>
[Win] fast/canvas/2d.getPath.modification.html is failing.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm (221748 => 221749)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Download.mm 2017-09-07 19:51:58 UTC (rev 221749)
@@ -31,17 +31,22 @@
#import "PlatformUtilities.h"
#import "Test.h"
+#import "TestProtocol.h"
+#import "TestWKWebView.h"
#import <WebCore/FileSystem.h>
#import <WebKit/_WKDownload.h>
#import <WebKit/_WKDownloadDelegate.h>
#import <WebKit/WKNavigationDelegatePrivate.h>
#import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WKUIDelegatePrivate.h>
#import <WebKit/WKWebView.h>
#import <WebKit/WKWebViewConfiguration.h>
#import <wtf/RetainPtr.h>
+#import <wtf/mac/AppKitCompatibilityDeclarations.h>
#import <wtf/text/WTFString.h>
static bool isDone;
+static bool hasReceivedRedirect;
static bool hasReceivedResponse;
static NSURL *sourceURL = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
@@ -422,5 +427,81 @@
runTest(adoptNS([[DownloadBlobURLNavigationDelegate alloc] init]).get(), adoptNS([[BlobDownloadDelegate alloc] init]).get(), originalURL);
}
+@interface UIDownloadAsFileTestDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation UIDownloadAsFileTestDelegate
+
+- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element
+{
+ static const long downloadLinkedFileTag = 2;
+ auto index = [menu indexOfItemWithTag:downloadLinkedFileTag];
+ [menu performActionForItemAtIndex:index];
+ return nil;
+}
+
+@end
+
+@interface RedirectedDownloadDelegate : NSObject <_WKDownloadDelegate>
+@end
+
+@implementation RedirectedDownloadDelegate {
+ String _destinationPath;
+}
+
+- (NSString *)_download:(_WKDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename allowOverwrite:(BOOL *)allowOverwrite
+{
+ WebCore::PlatformFileHandle fileHandle;
+ _destinationPath = WebCore::openTemporaryFile("TestWebKitAPI", fileHandle);
+ EXPECT_TRUE(fileHandle != WebCore::invalidPlatformFileHandle);
+ WebCore::closeFile(fileHandle);
+ *allowOverwrite = YES;
+ return _destinationPath;
+}
+
+- (void)_download:(_WKDownload *)download didReceiveServerRedirectToURL:(NSURL *)url
+{
+ EXPECT_STREQ("http://pass/", [url.absoluteString UTF8String]);
+ hasReceivedRedirect = true;
+}
+
+- (void)_downloadDidFinish:(_WKDownload *)download
+{
+ WebCore::deleteFile(_destinationPath);
+ isDone = true;
+}
+
+@end
+
+TEST(_WKDownload, RedirectedDownload)
+{
+ [TestProtocol registerWithScheme:@"http"];
+
+ hasReceivedRedirect = false;
+ isDone = false;
+
+ auto delegate = adoptNS([[UIDownloadAsFileTestDelegate alloc] init]);
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
+ [webView setUIDelegate:delegate.get()];
+ auto downloadDelegate = adoptNS([[RedirectedDownloadDelegate alloc] init]);
+ [[[webView configuration] processPool] _setDownloadDelegate:downloadDelegate.get()];
+
+ auto window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]);
+ [[window contentView] addSubview:webView.get()];
+
+ [webView synchronouslyLoadHTMLString:@"<a style='display: block; height: 100%; width: 100%' href=''>test</a>"];
+
+ NSPoint clickPoint = NSMakePoint(100, 100);
+ [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSEventTypeRightMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+ [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSEventTypeRightMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+
+ isDone = false;
+ TestWebKitAPI::Util::run(&isDone);
+ EXPECT_TRUE(hasReceivedRedirect);
+
+ [TestProtocol unregister];
+}
+
#endif
#endif
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (221748 => 221749)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2017-09-07 19:51:58 UTC (rev 221749)
@@ -596,8 +596,8 @@
};
WKPageSetPageNavigationClient(m_mainWebView->page(), &pageNavigationClient.base);
- WKContextDownloadClientV0 downloadClient = {
- { 0, this },
+ WKContextDownloadClientV1 downloadClient = {
+ { 1, this },
downloadDidStart,
0, // didReceiveAuthenticationChallenge
0, // didReceiveResponse
@@ -608,7 +608,8 @@
downloadDidFinish,
downloadDidFail,
downloadDidCancel,
- 0 // processDidCrash;
+ 0, // processDidCrash;
+ downloadDidReceiveServerRedirectToURL
};
WKContextSetDownloadClient(context(), &downloadClient.base);
@@ -1730,6 +1731,11 @@
static_cast<TestController*>(const_cast<void*>(clientInfo))->downloadDidCancel(context, download);
}
+void TestController::downloadDidReceiveServerRedirectToURL(WKContextRef context, WKDownloadRef download, WKURLRef url, const void* clientInfo)
+{
+ static_cast<TestController*>(const_cast<void*>(clientInfo))->downloadDidReceiveServerRedirectToURL(context, download, url);
+}
+
void TestController::downloadDidStart(WKContextRef context, WKDownloadRef download)
{
if (m_shouldLogDownloadCallbacks)
@@ -1767,6 +1773,18 @@
m_currentInvocation->notifyDownloadDone();
}
+void TestController::downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef url)
+{
+ if (m_shouldLogDownloadCallbacks) {
+ StringBuilder builder;
+ builder.appendLiteral("Download was redirected to \"");
+ WKRetainPtr<WKStringRef> urlStringWK = adoptWK(WKURLCopyString(url));
+ builder.append(toSTD(urlStringWK).c_str());
+ builder.appendLiteral("\".\n");
+ m_currentInvocation->outputText(builder.toString());
+ }
+}
+
void TestController::downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef error)
{
if (m_shouldLogDownloadCallbacks) {
Modified: trunk/Tools/WebKitTestRunner/TestController.h (221748 => 221749)
--- trunk/Tools/WebKitTestRunner/TestController.h 2017-09-07 19:39:40 UTC (rev 221748)
+++ trunk/Tools/WebKitTestRunner/TestController.h 2017-09-07 19:51:58 UTC (rev 221749)
@@ -266,6 +266,8 @@
void downloadDidFail(WKContextRef, WKDownloadRef, WKErrorRef);
static void downloadDidCancel(WKContextRef, WKDownloadRef, const void*);
void downloadDidCancel(WKContextRef, WKDownloadRef);
+ static void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef, const void*);
+ void downloadDidReceiveServerRedirectToURL(WKContextRef, WKDownloadRef, WKURLRef);
static void processDidCrash(WKPageRef, const void* clientInfo);
void processDidCrash();