Diff
Modified: trunk/Source/WebCore/ChangeLog (207647 => 207648)
--- trunk/Source/WebCore/ChangeLog 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebCore/ChangeLog 2016-10-21 01:15:54 UTC (rev 207648)
@@ -1,3 +1,18 @@
+2016-10-20 Chris Dumez <cdu...@apple.com>
+
+ "Download Linked File" context menu action should use 'download' attribute as suggested filename
+ https://bugs.webkit.org/show_bug.cgi?id=163742
+ <rdar://problem/28840734>
+
+ Reviewed by Darin Adler.
+
+ Add convenience method to HitTestResult to return the URL element's
+ download attribute.
+
+ * rendering/HitTestResult.cpp:
+ (WebCore::HitTestResult::URLElementDownloadAttribute):
+ * rendering/HitTestResult.h:
+
2016-10-20 Nan Wang <n_w...@apple.com>
AX: VoiceOver is not detecting ARIA treeview if it contains role="presentation"
Modified: trunk/Source/WebCore/rendering/HitTestResult.cpp (207647 => 207648)
--- trunk/Source/WebCore/rendering/HitTestResult.cpp 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebCore/rendering/HitTestResult.cpp 2016-10-21 01:15:54 UTC (rev 207648)
@@ -786,6 +786,14 @@
return node->parentElement();
}
+const AtomicString& HitTestResult::URLElementDownloadAttribute() const
+{
+ auto* urlElement = URLElement();
+ if (!is<HTMLAnchorElement>(urlElement))
+ return nullAtom;
+ return urlElement->attributeWithoutSynchronization(HTMLNames::downloadAttr);
+}
+
bool HitTestResult::mediaSupportsEnhancedFullscreen() const
{
#if PLATFORM(MAC) && ENABLE(VIDEO) && ENABLE(VIDEO_PRESENTATION_MODE)
Modified: trunk/Source/WebCore/rendering/HitTestResult.h (207647 => 207648)
--- trunk/Source/WebCore/rendering/HitTestResult.h 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebCore/rendering/HitTestResult.h 2016-10-21 01:15:54 UTC (rev 207648)
@@ -66,6 +66,8 @@
Scrollbar* scrollbar() const { return m_scrollbar.get(); }
bool isOverWidget() const { return m_isOverWidget; }
+ WEBCORE_EXPORT const AtomicString& URLElementDownloadAttribute() const;
+
// Forwarded from HitTestLocation
bool isRectBasedTest() const { return m_hitTestLocation.isRectBasedTest(); }
Modified: trunk/Source/WebKit2/ChangeLog (207647 => 207648)
--- trunk/Source/WebKit2/ChangeLog 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/ChangeLog 2016-10-21 01:15:54 UTC (rev 207648)
@@ -1,3 +1,31 @@
+2016-10-20 Chris Dumez <cdu...@apple.com>
+
+ "Download Linked File" context menu action should use 'download' attribute as suggested filename
+ https://bugs.webkit.org/show_bug.cgi?id=163742
+ <rdar://problem/28840734>
+
+ Reviewed by Darin Adler.
+
+ Update "Download Linked File" context menu action to use the anchor
+ element's 'download' attribute as suggested filename for the download.
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::NetworkProcess::downloadRequest):
+ * NetworkProcess/NetworkProcess.h:
+ * NetworkProcess/NetworkProcess.messages.in:
+ * Shared/WebHitTestResultData.cpp:
+ (WebKit::WebHitTestResultData::WebHitTestResultData):
+ (WebKit::WebHitTestResultData::encode):
+ (WebKit::WebHitTestResultData::decode):
+ * Shared/WebHitTestResultData.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::contextMenuItemSelected):
+ * UIProcess/WebProcessPool.cpp:
+ (WebKit::WebProcessPool::download):
+ * UIProcess/WebProcessPool.h:
+ * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
+ (WebKit::InjectedBundleHitTestResult::linkSuggestedFilename):
+
2016-10-19 Myles C. Maxfield <mmaxfi...@apple.com>
[macOS] [iOS] Disable variation fonts on macOS El Capitan and iOS 9
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (207647 => 207648)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp 2016-10-21 01:15:54 UTC (rev 207648)
@@ -459,9 +459,9 @@
completionHandler();
}
-void NetworkProcess::downloadRequest(SessionID sessionID, DownloadID downloadID, const ResourceRequest& request)
+void NetworkProcess::downloadRequest(SessionID sessionID, DownloadID downloadID, const ResourceRequest& request, const String& suggestedFilename)
{
- downloadManager().startDownload(sessionID, downloadID, request);
+ downloadManager().startDownload(sessionID, downloadID, request, suggestedFilename);
}
void NetworkProcess::resumeDownload(SessionID sessionID, DownloadID downloadID, const IPC::DataReference& resumeData, const String& path, const WebKit::SandboxExtension::Handle& sandboxExtensionHandle)
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h (207647 => 207648)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.h 2016-10-21 01:15:54 UTC (rev 207648)
@@ -170,7 +170,7 @@
// FIXME: This should take a session ID so we can identify which disk cache to delete.
void clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler);
- void downloadRequest(WebCore::SessionID, DownloadID, const WebCore::ResourceRequest&);
+ void downloadRequest(WebCore::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedFilename);
void resumeDownload(WebCore::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, const SandboxExtension::Handle&);
void cancelDownload(DownloadID);
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in (207647 => 207648)
--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.messages.in 2016-10-21 01:15:54 UTC (rev 207648)
@@ -41,7 +41,7 @@
DeleteWebsiteData(WebCore::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
DeleteWebsiteDataForOrigins(WebCore::SessionID sessionID, OptionSet<WebKit::WebsiteDataType> websiteDataTypes, Vector<WebCore::SecurityOriginData> origins, Vector<String> cookieHostNames, uint64_t callbackID)
- DownloadRequest(WebCore::SessionID sessionID, WebKit::DownloadID downloadID, WebCore::ResourceRequest request)
+ DownloadRequest(WebCore::SessionID sessionID, WebKit::DownloadID downloadID, WebCore::ResourceRequest request, String suggestedFilename)
ResumeDownload(WebCore::SessionID sessionID, WebKit::DownloadID downloadID, IPC::DataReference resumeData, String path, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
CancelDownload(WebKit::DownloadID downloadID)
Modified: trunk/Source/WebKit2/Shared/WebHitTestResultData.cpp (207647 => 207648)
--- trunk/Source/WebKit2/Shared/WebHitTestResultData.cpp 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/Shared/WebHitTestResultData.cpp 2016-10-21 01:15:54 UTC (rev 207648)
@@ -46,6 +46,7 @@
, absoluteMediaURL(hitTestResult.absoluteMediaURL().string())
, linkLabel(hitTestResult.textContent())
, linkTitle(hitTestResult.titleDisplayString())
+ , linkSuggestedFilename(hitTestResult.URLElementDownloadAttribute())
, isContentEditable(hitTestResult.isContentEditable())
, elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
, isScrollbar(hitTestResult.scrollbar())
@@ -65,6 +66,7 @@
, absoluteMediaURL(hitTestResult.absoluteMediaURL().string())
, linkLabel(hitTestResult.textContent())
, linkTitle(hitTestResult.titleDisplayString())
+ , linkSuggestedFilename(hitTestResult.URLElementDownloadAttribute())
, isContentEditable(hitTestResult.isContentEditable())
, elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
, isScrollbar(hitTestResult.scrollbar())
@@ -100,6 +102,7 @@
encoder << absoluteMediaURL;
encoder << linkLabel;
encoder << linkTitle;
+ encoder << linkSuggestedFilename;
encoder << isContentEditable;
encoder << elementBoundingBox;
encoder << isScrollbar;
@@ -133,6 +136,7 @@
|| !decoder.decode(hitTestResultData.absoluteMediaURL)
|| !decoder.decode(hitTestResultData.linkLabel)
|| !decoder.decode(hitTestResultData.linkTitle)
+ || !decoder.decode(hitTestResultData.linkSuggestedFilename)
|| !decoder.decode(hitTestResultData.isContentEditable)
|| !decoder.decode(hitTestResultData.elementBoundingBox)
|| !decoder.decode(hitTestResultData.isScrollbar)
Modified: trunk/Source/WebKit2/Shared/WebHitTestResultData.h (207647 => 207648)
--- trunk/Source/WebKit2/Shared/WebHitTestResultData.h 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/Shared/WebHitTestResultData.h 2016-10-21 01:15:54 UTC (rev 207648)
@@ -50,6 +50,7 @@
String absoluteMediaURL;
String linkLabel;
String linkTitle;
+ String linkSuggestedFilename;
bool isContentEditable;
WebCore::IntRect elementBoundingBox;
bool isScrollbar;
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (207647 => 207648)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2016-10-21 01:15:54 UTC (rev 207648)
@@ -4587,7 +4587,8 @@
return;
}
if (item.action() == ContextMenuItemTagDownloadLinkToDisk) {
- m_process->processPool().download(this, URL(URL(), m_activeContextMenuContextData.webHitTestResultData().absoluteLinkURL));
+ auto& hitTestResult = m_activeContextMenuContextData.webHitTestResultData();
+ m_process->processPool().download(this, URL(URL(), hitTestResult.absoluteLinkURL), hitTestResult.linkSuggestedFilename);
return;
}
if (item.action() == ContextMenuItemTagDownloadMediaToDisk) {
Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp (207647 => 207648)
--- trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp 2016-10-21 01:15:54 UTC (rev 207648)
@@ -814,7 +814,7 @@
return process->createWebPage(pageClient, WTFMove(pageConfiguration));
}
-DownloadProxy* WebProcessPool::download(WebPageProxy* initiatingPage, const ResourceRequest& request)
+DownloadProxy* WebProcessPool::download(WebPageProxy* initiatingPage, const ResourceRequest& request, const String& suggestedFilename)
{
DownloadProxy* downloadProxy = createDownloadProxy(request);
SessionID sessionID = initiatingPage ? initiatingPage->sessionID() : SessionID::defaultSessionID();
@@ -827,7 +827,7 @@
updatedRequest.setFirstPartyForCookies(URL(URL(), initiatingPage->pageLoadState().url()));
else
updatedRequest.setFirstPartyForCookies(URL());
- networkProcess()->send(Messages::NetworkProcess::DownloadRequest(sessionID, downloadProxy->downloadID(), updatedRequest), 0);
+ networkProcess()->send(Messages::NetworkProcess::DownloadRequest(sessionID, downloadProxy->downloadID(), updatedRequest, suggestedFilename), 0);
return downloadProxy;
}
Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.h (207647 => 207648)
--- trunk/Source/WebKit2/UIProcess/WebProcessPool.h 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.h 2016-10-21 01:15:54 UTC (rev 207648)
@@ -166,7 +166,7 @@
const String& injectedBundlePath() const { return m_configuration->injectedBundlePath(); }
- DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&);
+ DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&, const String& suggestedFilename = { });
DownloadProxy* resumeDownload(const API::Data* resumeData, const String& path);
void setInjectedBundleInitializationUserData(PassRefPtr<API::Object> userData) { m_injectedBundleInitializationUserData = userData; }
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp (207647 => 207648)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp 2016-10-21 01:15:54 UTC (rev 207648)
@@ -34,8 +34,6 @@
#include <WebCore/Frame.h>
#include <WebCore/FrameLoader.h>
#include <WebCore/FrameView.h>
-#include <WebCore/HTMLAnchorElement.h>
-#include <WebCore/HTMLNames.h>
#include <WebCore/URL.h>
#include <wtf/text/WTFString.h>
@@ -143,10 +141,7 @@
String InjectedBundleHitTestResult::linkSuggestedFilename() const
{
- auto* urlElement = m_hitTestResult.URLElement();
- if (!is<HTMLAnchorElement>(urlElement))
- return String();
- return urlElement->attributeWithoutSynchronization(HTMLNames::downloadAttr);
+ return m_hitTestResult.URLElementDownloadAttribute();
}
IntRect InjectedBundleHitTestResult::imageRect() const
Modified: trunk/Tools/ChangeLog (207647 => 207648)
--- trunk/Tools/ChangeLog 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Tools/ChangeLog 2016-10-21 01:15:54 UTC (rev 207648)
@@ -1,3 +1,21 @@
+2016-10-20 Chris Dumez <cdu...@apple.com>
+
+ "Download Linked File" context menu action should use 'download' attribute as suggested filename
+ https://bugs.webkit.org/show_bug.cgi?id=163742
+ <rdar://problem/28840734>
+
+ Reviewed by Darin Adler.
+
+ Add API test coverage.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2/link-with-download-attribute.html: Added.
+ * TestWebKitAPI/Tests/WebKit2/mac/ContextMenuDownload.mm: Added.
+ (TestWebKitAPI::didFinishLoadForFrame):
+ (TestWebKitAPI::getContextMenuFromProposedMenu):
+ (TestWebKitAPI::decideDestinationWithSuggestedFilename):
+ (TestWebKitAPI::TEST):
+
2016-10-20 Commit Queue <commit-qu...@webkit.org>
Unreviewed, rolling out r207589.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (207647 => 207648)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-10-21 01:15:21 UTC (rev 207647)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-10-21 01:15:54 UTC (rev 207648)
@@ -403,6 +403,8 @@
7CCE7F2F1A411B1000447C4C /* WKBrowsingContextLoadDelegateTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC3C4C7014575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm */; };
7CEFA9661AC0B9E200B910FD /* _WKUserContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CEFA9641AC0B9E200B910FD /* _WKUserContentExtensionStore.mm */; };
7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
+ 8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */; };
+ 8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */; };
835CF9671D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 835CF9661D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp */; };
837A35F11D9A1E7D00663C57 /* DownloadRequestBlobURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 837A35F01D9A1E6400663C57 /* DownloadRequestBlobURL.html */; };
83CF1C301C4F1B8B00688447 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83CF1C2C1C4F19AE00688447 /* StringUtilities.mm */; };
@@ -562,6 +564,7 @@
dstPath = TestWebKitAPI.resources;
dstSubfolderSpec = 7;
files = (
+ 8349D3C41DB9728E004A9F65 /* link-with-download-attribute.html in Copy Resources */,
AD57AC221DA7466E00FF1BDE /* many-iframes.html in Copy Resources */,
F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */,
F4F137921D9B683E002BEC57 /* large-video-test-now-playing.html in Copy Resources */,
@@ -1005,6 +1008,8 @@
7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
+ 8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuDownload.mm; sourceTree = "<group>"; };
+ 8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "link-with-download-attribute.html"; sourceTree = "<group>"; };
835CF9661D25FCD6001A65D4 /* RestoreSessionStateWithoutNavigation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RestoreSessionStateWithoutNavigation.cpp; sourceTree = "<group>"; };
837A35F01D9A1E6400663C57 /* DownloadRequestBlobURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestBlobURL.html; sourceTree = "<group>"; };
83B88A331C80056D00BB2418 /* HTMLParserIdioms.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLParserIdioms.cpp; sourceTree = "<group>"; };
@@ -1842,6 +1847,7 @@
4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */,
BCBD372E125ABBE600D2C29F /* icon.png */,
CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */,
+ 8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */,
378E647816326FDF00B6C676 /* link-with-title.html */,
9361002814DC957B0061379D /* lots-of-iframes.html */,
93AF4ECF1506F123007FD57E /* lots-of-images.html */,
@@ -2031,6 +2037,7 @@
C0C5D3BB14598B6F00A802A6 /* mac */ = {
isa = PBXGroup;
children = (
+ 8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */,
BCAA485714A044D40088FAC4 /* EditorCommands.mm */,
C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */,
C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */,
@@ -2415,6 +2422,7 @@
7C83E0BE1D0A651300FEBCF3 /* IndexedDBMultiProcess.mm in Sources */,
7C83E0BF1D0A652200FEBCF3 /* IndexedDBPersistence.mm in Sources */,
7CCE7EFB1A411AE600447C4C /* InjectedBundleBasic.cpp in Sources */,
+ 8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */,
7CCE7EFC1A411AE600447C4C /* InjectedBundleFrameHitTest.cpp in Sources */,
7CCE7EFD1A411AE600447C4C /* InjectedBundleInitializationUserDataCallbackWins.cpp in Sources */,
2EFF06D41D8AEDBB0004BB30 /* TestWKWebViewMac.mm in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/link-with-download-attribute.html (0 => 207648)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/link-with-download-attribute.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/link-with-download-attribute.html 2016-10-21 01:15:54 UTC (rev 207648)
@@ -0,0 +1,10 @@
+<html>
+ <body>
+ <a id="testAnchor" style="display: block; height: 100%; width: 100%" download="downloadAttributeValue.txt"></a>
+ <script>
+ var blob = new Blob(["Hello world!"], {type: "application/octet-stream"});
+ var link = document.getElementById("testAnchor");
+ link.href = ""
+ </script>
+ </body>
+</html>
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/ContextMenuDownload.mm (0 => 207648)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/ContextMenuDownload.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/ContextMenuDownload.mm 2016-10-21 01:15:54 UTC (rev 207648)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "_javascript_Test.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include <WebKit/WKContextMenuItem.h>
+#include <WebKit/WKDownload.h>
+#include <WebKit/WKPage.h>
+#include <WebKit/WKPageContextMenuClient.h>
+#include <WebKit/WKPreferencesPrivate.h>
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static bool didFinishLoad;
+static bool didDecideDownloadDestination;
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
+{
+ didFinishLoad = true;
+}
+
+static void getContextMenuFromProposedMenu(WKPageRef page, WKArrayRef proposedMenu, WKArrayRef* newMenu, WKHitTestResultRef hitTestResult, WKTypeRef userData, const void* clientInfo)
+{
+ size_t count = WKArrayGetSize(proposedMenu);
+ for (size_t i = 0; i < count; ++i) {
+ WKContextMenuItemRef contextMenuItem = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(proposedMenu, i));
+ switch (WKContextMenuItemGetTag(contextMenuItem)) {
+ case kWKContextMenuItemTagDownloadLinkToDisk:
+ // Click "Download Linked File" context menu entry.
+ WKPageSelectContextMenuItem(page, contextMenuItem);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef download, WKStringRef suggestedFilename, bool*, const void*)
+{
+ // Make sure the suggested filename is provided and matches the value of the download attribute in the HTML.
+ EXPECT_WK_STREQ("downloadAttributeValue.txt", suggestedFilename);
+
+ WKDownloadCancel(download);
+ didDecideDownloadDestination = true;
+
+ return Util::toWK("/tmp/WebKitAPITest/ContextMenuDownload").leakRef();
+}
+
+// Checks that the HTML download attribute is used as suggested filename when selecting
+// the "Download Linked File" item in the context menu.
+TEST(WebKit2, ContextMenuDownloadHTMLDownloadAttribute)
+{
+ WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextWithInjectedBundle());
+
+ WKContextDownloadClientV0 client;
+ memset(&client, 0, sizeof(client));
+ client.base.version = 0;
+ client.decideDestinationWithSuggestedFilename = decideDestinationWithSuggestedFilename;
+ WKContextSetDownloadClient(context.get(), &client.base);
+
+ WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(Util::toWK("MyGroup").get()));
+ PlatformWebView webView(context.get(), pageGroup.get());
+
+ WKPageLoaderClientV0 loaderClient;
+ memset(&loaderClient, 0, sizeof(loaderClient));
+ loaderClient.base.version = 0;
+ loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+ WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);
+
+ WKPageContextMenuClientV3 contextMenuClient;
+ memset(&contextMenuClient, 0, sizeof(contextMenuClient));
+ contextMenuClient.base.version = 3;
+ contextMenuClient.getContextMenuFromProposedMenu = getContextMenuFromProposedMenu;
+ WKPageSetPageContextMenuClient(webView.page(), &contextMenuClient.base);
+
+ WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("link-with-download-attribute", "html"));
+
+ WKPageLoadURL(webView.page(), url.get());
+ Util::run(&didFinishLoad);
+
+ // Right click on link.
+ webView.simulateButtonClick(kWKEventMouseButtonRightButton, 50, 50, 0);
+ Util::run(&didDecideDownloadDestination);
+}
+
+}