Diff
Modified: trunk/Source/WebKit/ChangeLog (221215 => 221216)
--- trunk/Source/WebKit/ChangeLog 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/ChangeLog 2017-08-26 00:13:47 UTC (rev 221216)
@@ -1,3 +1,36 @@
+2017-08-25 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate equivalent of WKPageUIClient's saveDataToFileInDownloadsFolder
+ https://bugs.webkit.org/show_bug.cgi?id=176000
+ <rdar://problem/29270035>
+
+ Reviewed by Andy Estes.
+
+ Covered by a new API test.
+
+ * Shared/Cocoa/WKNSData.h:
+ (wrapper): Deleted.
+ * UIProcess/API/APIUIClient.h:
+ (API::UIClient::saveDataToFileInDownloadsFolder):
+ * UIProcess/API/C/WKPage.cpp:
+ (WKPageSetPageUIClient):
+ * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+ * UIProcess/Cocoa/UIDelegate.h:
+ * UIProcess/Cocoa/UIDelegate.mm:
+ (WebKit::UIDelegate::setDelegate):
+ (WebKit::UIDelegate::UIClient::saveDataToFileInDownloadsFolder):
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::saveDataToFileInDownloadsFolder):
+ (WebKit::WebPageProxy::savePDFToFileInDownloadsFolder):
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/WebPageProxy.messages.in:
+ * WebProcess/WebPage/WebFrame.cpp:
+ (WebKit::WebFrame::url const):
+ * WebProcess/WebPage/WebFrame.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::savePDFToFileInDownloadsFolder):
+ * WebProcess/WebPage/WebPage.h:
+
2017-08-25 David Kilzer <[email protected]>
Fix -Wunused-lambda-capture warnings in WebKit with new clang compiler
Modified: trunk/Source/WebKit/Shared/Cocoa/WKNSData.h (221215 => 221216)
--- trunk/Source/WebKit/Shared/Cocoa/WKNSData.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/Shared/Cocoa/WKNSData.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -30,6 +30,8 @@
#import "APIData.h"
#import "WKObject.h"
+namespace API {
+
inline NSData *wrapper(API::Data& data)
{
ASSERT([data.wrapper() isKindOfClass:[NSData self]]);
@@ -36,6 +38,8 @@
return (NSData *)data.wrapper();
}
+}
+
@interface WKNSData : NSData <WKObject>
@end
Modified: trunk/Source/WebKit/UIProcess/API/APIUIClient.h (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/API/APIUIClient.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/API/APIUIClient.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -142,7 +142,7 @@
virtual bool canRunModal() const { return false; }
virtual void runModal(WebKit::WebPageProxy*) { }
- virtual void saveDataToFileInDownloadsFolder(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, const WTF::String&, Data*) { }
+ virtual void saveDataToFileInDownloadsFolder(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, Data&) { }
virtual void pinnedStateDidChange(WebKit::WebPageProxy&) { }
Modified: trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp 2017-08-26 00:13:47 UTC (rev 221216)
@@ -2043,12 +2043,12 @@
m_client.runModal(toAPI(page), m_client.base.clientInfo);
}
- void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data) final
+ void saveDataToFileInDownloadsFolder(WebPageProxy* page, const String& suggestedFilename, const String& mimeType, const WebCore::URL& originatingURL, API::Data& data) final
{
if (!m_client.saveDataToFileInDownloadsFolder)
return;
- m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURLString.impl()), toAPI(data), m_client.base.clientInfo);
+ m_client.saveDataToFileInDownloadsFolder(toAPI(page), toAPI(suggestedFilename.impl()), toAPI(mimeType.impl()), toURLRef(originatingURL.string().impl()), toAPI(&data), m_client.base.clientInfo);
}
void pinnedStateDidChange(WebPageProxy& page) final
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -32,6 +32,7 @@
#import <WebKit/WKWebViewPrivate.h>
#import <WebKit/_WKActivatedElementInfo.h>
+@class NSData;
@class UIScrollView;
@class UIViewController;
@class WKFrameInfo;
@@ -143,6 +144,7 @@
- (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url WK_API_AVAILABLE(macosx(WK_MAC_TBA));
- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
- (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
#endif
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -100,9 +100,10 @@
void takeFocus(WebPageProxy*, WKFocusDirection) final;
void focus(WebPageProxy*) final;
void unfocus(WebPageProxy*) final;
- void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) final;
- void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
+ void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
+ void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
+ void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, API::Data&) final;
#endif
bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
bool checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final;
@@ -148,6 +149,7 @@
bool webViewTakeFocus : 1;
bool webViewDidNotHandleWheelEvent : 1;
bool webViewHandleAutoplayEventWithFlags : 1;
+ bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
#endif
bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm 2017-08-26 00:13:47 UTC (rev 221216)
@@ -35,6 +35,7 @@
#import "UserMediaPermissionCheckProxy.h"
#import "UserMediaPermissionRequestProxy.h"
#import "WKFrameInfoInternal.h"
+#import "WKNSData.h"
#import "WKNavigationActionInternal.h"
#import "WKOpenPanelParametersInternal.h"
#import "WKSecurityOriginInternal.h"
@@ -107,9 +108,9 @@
m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
+ m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL = [delegate respondsToSelector:@selector(_webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:)];
m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
#endif
-
m_delegateMethods.webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler = [delegate respondsToSelector:@selector(_webView:decideDatabaseQuotaForSecurityOrigin:currentQuota:currentOriginUsage:currentDatabaseUsage:expectedUsage:decisionHandler:)];
m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded = [delegate respondsToSelector:@selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:)];
m_delegateMethods.webViewPrintFrame = [delegate respondsToSelector:@selector(_webView:printFrame:)];
@@ -486,7 +487,19 @@
[(id <WKUIDelegatePrivate>)delegate _showWebView:m_uiDelegate.m_webView];
}
+
+void UIDelegate::UIClient::saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String& suggestedFilename, const WTF::String& mimeType, const WebCore::URL& originatingURL, API::Data& data)
+{
+ if (!m_uiDelegate.m_delegateMethods.webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL)
+ return;
+
+ auto delegate = m_uiDelegate.m_delegate.get();
+ if (!delegate)
+ return;
+ [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView saveDataToFile:wrapper(data) suggestedFilename:suggestedFilename mimeType:mimeType originatingURL:originatingURL];
+}
+
bool UIDelegate::UIClient::runOpenPanel(WebPageProxy*, WebFrameProxy* webFrameProxy, const WebCore::SecurityOriginData& securityOriginData, API::OpenPanelParameters* openPanelParameters, WebOpenPanelResultListenerProxy* listener)
{
if (!m_uiDelegate.m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler)
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2017-08-26 00:13:47 UTC (rev 221216)
@@ -6113,18 +6113,18 @@
m_drawingArea->setBackingStoreIsDiscardable(isDiscardable);
}
-void WebPageProxy::saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data* data)
+void WebPageProxy::saveDataToFileInDownloadsFolder(String&& suggestedFilename, String&& mimeType, URL&& originatingURLString, API::Data& data)
{
m_uiClient->saveDataToFileInDownloadsFolder(this, suggestedFilename, mimeType, originatingURLString, data);
}
-void WebPageProxy::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference& dataReference)
+void WebPageProxy::savePDFToFileInDownloadsFolder(String&& suggestedFilename, URL&& originatingURL, const IPC::DataReference& dataReference)
{
if (!suggestedFilename.endsWith(".pdf", false))
return;
- saveDataToFileInDownloadsFolder(suggestedFilename, "application/pdf", originatingURLString,
- API::Data::create(dataReference.data(), dataReference.size()).ptr());
+ saveDataToFileInDownloadsFolder(WTFMove(suggestedFilename), ASCIILiteral("application/pdf"), WTFMove(originatingURL),
+ API::Data::create(dataReference.data(), dataReference.size()).get());
}
void WebPageProxy::setMinimumLayoutSize(const IntSize& minimumLayoutSize)
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -950,8 +950,8 @@
void handleAlternativeTextUIResult(const String& result);
#endif
- void saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, API::Data*);
- void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference&);
+ void saveDataToFileInDownloadsFolder(String&& suggestedFilename, String&& mimeType, WebCore::URL&& originatingURL, API::Data&);
+ void savePDFToFileInDownloadsFolder(String&& suggestedFilename, WebCore::URL&& originatingURL, const IPC::DataReference&);
#if PLATFORM(COCOA)
void savePDFToTemporaryFolderAndOpenWithNativeApplicationRaw(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size, const String& pdfUUID);
void savePDFToTemporaryFolderAndOpenWithNativeApplication(const String& suggestedFilename, const String& originatingURLString, const IPC::DataReference&, const String& pdfUUID);
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (221215 => 221216)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in 2017-08-26 00:13:47 UTC (rev 221216)
@@ -404,7 +404,7 @@
SaveRecentSearches(String name, Vector<WebCore::RecentSearch> searchItems)
LoadRecentSearches(String name) -> (Vector<WebCore::RecentSearch> result)
- SavePDFToFileInDownloadsFolder(String suggestedFilename, String originatingURLString, IPC::DataReference data)
+ SavePDFToFileInDownloadsFolder(String suggestedFilename, WebCore::URL originatingURL, IPC::DataReference data)
#if PLATFORM(COCOA)
SavePDFToTemporaryFolderAndOpenWithNativeApplication(String suggestedFilename, String originatingURLString, IPC::DataReference data, String pdfUUID)
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp (221215 => 221216)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp 2017-08-26 00:13:47 UTC (rev 221216)
@@ -85,7 +85,7 @@
g_return_val_if_fail(WEBKIT_IS_FRAME(frame), 0);
if (frame->priv->uri.isNull())
- frame->priv->uri = frame->priv->webFrame->url().utf8();
+ frame->priv->uri = frame->priv->webFrame->url().string().utf8();
return frame->priv->uri.data();
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp (221215 => 221216)
--- trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebFrame.cpp 2017-08-26 00:13:47 UTC (rev 221216)
@@ -392,16 +392,16 @@
return m_coreFrame->tree().uniqueName();
}
-String WebFrame::url() const
+URL WebFrame::url() const
{
if (!m_coreFrame)
- return String();
+ return { };
- DocumentLoader* documentLoader = m_coreFrame->loader().documentLoader();
+ auto* documentLoader = m_coreFrame->loader().documentLoader();
if (!documentLoader)
- return String();
+ return { };
- return documentLoader->url().string();
+ return documentLoader->url();
}
CertificateInfo WebFrame::certificateInfo() const
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h (221215 => 221216)
--- trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebFrame.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -98,7 +98,7 @@
// WKBundleFrame API and SPI functions
bool isMainFrame() const;
String name() const;
- String url() const;
+ WebCore::URL url() const;
WebCore::CertificateInfo certificateInfo() const;
String innerText() const;
bool isFrameSet() const;
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (221215 => 221216)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2017-08-26 00:13:47 UTC (rev 221216)
@@ -4562,9 +4562,9 @@
}
#endif
-void WebPage::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size)
+void WebPage::savePDFToFileInDownloadsFolder(const String& suggestedFilename, const URL& originatingURL, const uint8_t* data, unsigned long size)
{
- send(Messages::WebPageProxy::SavePDFToFileInDownloadsFolder(suggestedFilename, originatingURLString, IPC::DataReference(data, size)));
+ send(Messages::WebPageProxy::SavePDFToFileInDownloadsFolder(suggestedFilename, originatingURL, IPC::DataReference(data, size)));
}
#if PLATFORM(COCOA)
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (221215 => 221216)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2017-08-26 00:13:47 UTC (rev 221216)
@@ -871,7 +871,7 @@
NSDictionary *dataDetectionContext() const { return m_dataDetectionContext.get(); }
#endif
- void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size);
+ void savePDFToFileInDownloadsFolder(const String& suggestedFilename, const WebCore::URL& originatingURL, const uint8_t* data, unsigned long size);
#if PLATFORM(COCOA)
void savePDFToTemporaryFolderAndOpenWithNativeApplication(const String& suggestedFilename, const String& originatingURLString, const uint8_t* data, unsigned long size, const String& pdfUUID);
#endif
Modified: trunk/Tools/ChangeLog (221215 => 221216)
--- trunk/Tools/ChangeLog 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Tools/ChangeLog 2017-08-26 00:13:47 UTC (rev 221216)
@@ -1,3 +1,17 @@
+2017-08-25 Alex Christensen <[email protected]>
+
+ Add WKUIDelegatePrivate equivalent of WKPageUIClient's saveDataToFileInDownloadsFolder
+ https://bugs.webkit.org/show_bug.cgi?id=176000
+ <rdar://problem/29270035>
+
+ Reviewed by Andy Estes.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
+ (-[FocusDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+ (TEST):
+ (-[SaveDataToFileDelegate _webView:saveDataToFile:suggestedFilename:mimeType:originatingURL:]):
+ (-[SaveDataToFileDelegate webView:didFinishNavigation:]):
+
2017-08-25 Youenn Fablet <[email protected]>
WPT server should not need to copy test harness files
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm (221215 => 221216)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm 2017-08-25 23:59:35 UTC (rev 221215)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm 2017-08-26 00:13:47 UTC (rev 221216)
@@ -100,7 +100,6 @@
[view keyUp:tabEvent(window, NSEventTypeKeyUp, withShiftDown ? NSEventModifierFlagShift : 0)];
}
-static RetainPtr<NSWindow> window;
static _WKFocusDirection takenDirection;
@interface FocusDelegate : NSObject <WKUIDelegatePrivate>
@@ -117,7 +116,7 @@
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
{
completionHandler();
- synthesizeTab(window.get(), webView, true);
+ synthesizeTab([webView window], webView, true);
}
@end
@@ -124,9 +123,7 @@
TEST(WebKit2, Focus)
{
- window = adoptNS([[NSWindow alloc] initWithContentRect:CGRectMake(0, 0, 800, 600) styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES]);
auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
- [[window contentView] addSubview:webView.get()];
auto delegate = adoptNS([[FocusDelegate alloc] init]);
[webView setUIDelegate:delegate.get()];
NSString *html = @"<script>function loaded() { document.getElementById('in').focus(); alert('ready'); }</script>"
@@ -136,6 +133,41 @@
ASSERT_EQ(takenDirection, _WKFocusDirectionBackward);
}
+@interface SaveDataToFileDelegate : NSObject <WKUIDelegatePrivate, WKNavigationDelegate>
+@end
+
+@implementation SaveDataToFileDelegate
+
+- (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url
+{
+ NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"];
+ EXPECT_TRUE([data isEqualToData:[NSData dataWithContentsOfURL:pdfURL]]);
+ EXPECT_STREQ([suggestedFilename UTF8String], "test.pdf");
+ EXPECT_STREQ([mimeType UTF8String], "application/pdf");
+ EXPECT_STREQ([[url absoluteString] UTF8String], [[pdfURL absoluteString] UTF8String]);
+ done = true;
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+ NSPoint location = NSMakePoint(490, 70); // Location of button to download the pdf.
+ [(TestWKWebView *)webView mouseDownAtPoint:location simulatePressure:NO];
+ [(TestWKWebView *)webView mouseUpAtPoint:location];
+}
+
+@end
+
+TEST(WebKit2, SaveDataToFile)
+{
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
+ auto delegate = adoptNS([[SaveDataToFileDelegate alloc] init]);
+ [webView setUIDelegate:delegate.get()];
+ [webView setNavigationDelegate:delegate.get()];
+ NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"];
+ [webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
+ TestWebKitAPI::Util::run(&done);
+}
+
#define RELIABLE_DID_NOT_HANDLE_WHEEL_EVENT 0
// FIXME: make wheel event handling more reliable.
// https://bugs.webkit.org/show_bug.cgi?id=175967