Title: [212041] trunk
Revision
212041
Author
cdu...@apple.com
Date
2017-02-09 20:00:52 -0800 (Thu, 09 Feb 2017)

Log Message

[Mac][WK2] Use MIME type to add file extension to downloads' suggested filenames when missing
https://bugs.webkit.org/show_bug.cgi?id=168077
<rdar://problem/30412595>

Reviewed by Alex Christensen.

Source/WebCore:

Add utility function to MIMETypeRegistry that appends an extension to
a filename if necessary, based on a provided MIME type.

Tests: fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html
       http/tests/download/anchor-download-no-extension.html

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::appendFileExtensionIfNecessary):
* platform/MIMETypeRegistry.h:
* platform/cocoa/MIMETypeRegistryCocoa.mm:
(WebCore::MIMETypeRegistry::appendFileExtensionIfNecessary):

Source/WebKit2:

Use MIME type to add file extension to downloads' suggested filenames when missing:
- https://html.spec.whatwg.org/#as-a-download (step 19)

This new behavior matches Chrome.

* NetworkProcess/Downloads/BlobDownloadClient.cpp:
(WebKit::BlobDownloadClient::didReceiveResponseAsync):
* NetworkProcess/Downloads/Download.cpp:
(WebKit::Download::didReceiveResponse):
(WebKit::Download::decideDestinationWithSuggestedFilename):
* NetworkProcess/Downloads/Download.h:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::findPendingDownloadLocation):
* UIProcess/Downloads/DownloadProxy.cpp:
(WebKit::DownloadProxy::didStart):
(WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
* UIProcess/Downloads/DownloadProxy.h:
* UIProcess/Downloads/DownloadProxy.messages.in:

LayoutTests:

Rebaseline a couple of download tests where suggested filenames now have an extension
and extend test coverage.

* fast/dom/HTMLAnchorElement/anchor-download-expected.txt:
* fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt:
* fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension-expected.txt: Added.
* fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html: Added.
* fast/dom/HTMLAnchorElement/anchor-nodownload-set-expected.txt:
* http/tests/download/anchor-download-no-extension-expected.txt: Added.
* http/tests/download/anchor-download-no-extension.html: Added.
* platform/ios-simulator-wk2/TestExpectations:
* platform/mac-wk1/TestExpectations:
* platform/win/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (212040 => 212041)


--- trunk/LayoutTests/ChangeLog	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/ChangeLog	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1,3 +1,25 @@
+2017-02-09  Chris Dumez  <cdu...@apple.com>
+
+        [Mac][WK2] Use MIME type to add file extension to downloads' suggested filenames when missing
+        https://bugs.webkit.org/show_bug.cgi?id=168077
+        <rdar://problem/30412595>
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline a couple of download tests where suggested filenames now have an extension
+        and extend test coverage.
+
+        * fast/dom/HTMLAnchorElement/anchor-download-expected.txt:
+        * fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt:
+        * fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension-expected.txt: Added.
+        * fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html: Added.
+        * fast/dom/HTMLAnchorElement/anchor-nodownload-set-expected.txt:
+        * http/tests/download/anchor-download-no-extension-expected.txt: Added.
+        * http/tests/download/anchor-download-no-extension.html: Added.
+        * platform/ios-simulator-wk2/TestExpectations:
+        * platform/mac-wk1/TestExpectations:
+        * platform/win/TestExpectations:
+
 2017-02-09  Philip Rogers  <p...@google.com>
 
         SVG clip-path references can clip out later content

Modified: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-expected.txt (212040 => 212041)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-expected.txt	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-expected.txt	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1,4 +1,4 @@
 Download started.
-Downloading URL with suggested filename "unknown"
+Downloading URL with suggested filename "unknown.html"
 Download completed.
 Blob URL

Modified: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt (212040 => 212041)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click-expected.txt	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1,5 +1,5 @@
 Download started.
-Downloading URL with suggested filename "unknown"
+Downloading URL with suggested filename "unknown.html"
 Download completed.
 Test that user triggered synthetic clicks on an anchor with a download attribute are not ignored.
 

Added: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension-expected.txt (0 => 212041)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension-expected.txt	2017-02-10 04:00:52 UTC (rev 212041)
@@ -0,0 +1,6 @@
+Download started.
+Downloading URL with suggested filename "abe.png"
+Download completed.
+The suggested filename above should be "abe.png" and the download should succeed.
+
+File backed blob URL

Added: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html (0 => 212041)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html	2017-02-10 04:00:52 UTC (rev 212041)
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type='text/_javascript_'>
+if (window.testRunner) {
+  testRunner.dumpAsText();
+  testRunner.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<p>The suggested filename above should be "abe.png" and the download should succeed.</p>
+<a id="blob-url" download="abe">File backed blob URL</a>
+<script>
+function click(elmt)
+{
+    if (!window.eventSender) {
+        alert('Click the link to run the test.');
+        return;
+    }
+    eventSender.mouseMoveTo(elmt.offsetLeft + 5, elmt.offsetTop + 5);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
+
+function runTest()
+{
+    file = internals.createFile("../resources/abe.png");
+    var link = document.getElementById("blob-url");
+    link.href = ""
+    click(link);
+}
+runTest();
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-nodownload-set-expected.txt (212040 => 212041)


--- trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-nodownload-set-expected.txt	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/fast/dom/HTMLAnchorElement/anchor-nodownload-set-expected.txt	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1,4 +1,4 @@
 Download started.
-Downloading URL with suggested filename "unknown"
+Downloading URL with suggested filename "unknown.html"
 Download completed.
 Blob URL

Added: trunk/LayoutTests/http/tests/download/anchor-download-no-extension-expected.txt (0 => 212041)


--- trunk/LayoutTests/http/tests/download/anchor-download-no-extension-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-no-extension-expected.txt	2017-02-10 04:00:52 UTC (rev 212041)
@@ -0,0 +1,6 @@
+Download started.
+Downloading URL with suggested filename "image.png"
+Download completed.
+The suggested filename above should be "image.png" and the download should succeed.
+
+Link with download attribute.

Added: trunk/LayoutTests/http/tests/download/anchor-download-no-extension.html (0 => 212041)


--- trunk/LayoutTests/http/tests/download/anchor-download-no-extension.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/download/anchor-download-no-extension.html	2017-02-10 04:00:52 UTC (rev 212041)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type='text/_javascript_'>
+if (window.testRunner) {
+  testRunner.dumpAsText();
+  testRunner.waitUntilDone();
+}
+</script>
+</head>
+<body>
+<p>The suggested filename above should be "image.png" and the download should succeed.</p>
+<a id="download-url" href="" download="image">Link with download attribute.</a>
+<script>
+function click(elmt)
+{
+    if (!window.eventSender) {
+        alert('Click the link to run the test.');
+        return;
+    }
+    eventSender.mouseMoveTo(elmt.offsetLeft + 5, elmt.offsetTop + 5);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
+
+function runTest()
+{
+    var link = document.getElementById("download-url");
+    click(link);
+}
+runTest();
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations (212040 => 212041)


--- trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1814,10 +1814,12 @@
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-download.html [ Skip ]
+webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-nodownload-set.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-nodownload.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
 webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
+webkit.org/b/156067 http/tests/download/anchor-download-no-extension.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 (212040 => 212041)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2017-02-10 04:00:52 UTC (rev 212041)
@@ -210,6 +210,8 @@
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
 webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-file-blob-download.html [ Skip ]
+webkit.org/b/156069 fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html [ Skip ]
+webkit.org/b/156069 http/tests/download/anchor-download-no-extension.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/LayoutTests/platform/win/TestExpectations (212040 => 212041)


--- trunk/LayoutTests/platform/win/TestExpectations	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/LayoutTests/platform/win/TestExpectations	2017-02-10 04:00:52 UTC (rev 212041)
@@ -445,6 +445,8 @@
 fast/dom/HTMLAnchorElement/anchor-download-synthetic-click.html [ Skip ]
 fast/dom/HTMLAnchorElement/anchor-download-user-triggered-synthetic-click.html [ Skip ]
 fast/dom/HTMLAnchorElement/anchor-file-blob-download.html [ Skip ]
+fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html [ Skip ]
+http/tests/download/anchor-download-no-extension.html [ Skip ]
 http/tests/download/area-download.html [ Skip ]
 http/tests/security/anchor-download-allow-data.html [ Skip ]
 http/tests/security/anchor-download-allow-sameorigin.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (212040 => 212041)


--- trunk/Source/WebCore/ChangeLog	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebCore/ChangeLog	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1,3 +1,23 @@
+2017-02-09  Chris Dumez  <cdu...@apple.com>
+
+        [Mac][WK2] Use MIME type to add file extension to downloads' suggested filenames when missing
+        https://bugs.webkit.org/show_bug.cgi?id=168077
+        <rdar://problem/30412595>
+
+        Reviewed by Alex Christensen.
+
+        Add utility function to MIMETypeRegistry that appends an extension to
+        a filename if necessary, based on a provided MIME type.
+
+        Tests: fast/dom/HTMLAnchorElement/anchor-file-blob-download-no-extension.html
+               http/tests/download/anchor-download-no-extension.html
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::appendFileExtensionIfNecessary):
+        * platform/MIMETypeRegistry.h:
+        * platform/cocoa/MIMETypeRegistryCocoa.mm:
+        (WebCore::MIMETypeRegistry::appendFileExtensionIfNecessary):
+
 2017-02-09  Youenn Fablet  <you...@apple.com>
 
         [WebRTC][Mac] Activate libwebrtc

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (212040 => 212041)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2017-02-10 04:00:52 UTC (rev 212041)
@@ -788,4 +788,13 @@
 
 #endif
 
+#if !PLATFORM(COCOA)
+
+String MIMETypeRegistry::appendFileExtensionIfNecessary(const String& filename, const String&)
+{
+    return filename;
+}
+
+#endif
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (212040 => 212041)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.h	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h	2017-02-10 04:00:52 UTC (rev 212041)
@@ -105,6 +105,8 @@
     // FIXME: Unclear what the concept of a normalized MIME type is; currently it's a platform-specific notion.
     static String getNormalizedMIMEType(const String&);
 
+    WEBCORE_EXPORT static String appendFileExtensionIfNecessary(const String& filename, const String& mimeType);
+
 private:
     // Check to see if the MIME type is not suitable for being loaded as a text
     // document in a frame. Only valid for MIME types begining with "text/".

Modified: trunk/Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm (212040 => 212041)


--- trunk/Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm	2017-02-10 04:00:52 UTC (rev 212041)
@@ -71,4 +71,19 @@
     return false;
 }
 
+String MIMETypeRegistry::appendFileExtensionIfNecessary(const String& filename, const String& mimeType)
+{
+    if (filename.isEmpty())
+        return emptyString();
+
+    if (filename.reverseFind('.') != notFound)
+        return filename;
+
+    String preferredExtension = getPreferredExtensionForMIMEType(mimeType);
+    if (preferredExtension.isEmpty())
+        return filename;
+
+    return filename + "." + preferredExtension;
 }
+
+}

Modified: trunk/Source/WebKit2/ChangeLog (212040 => 212041)


--- trunk/Source/WebKit2/ChangeLog	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/ChangeLog	2017-02-10 04:00:52 UTC (rev 212041)
@@ -1,3 +1,30 @@
+2017-02-09  Chris Dumez  <cdu...@apple.com>
+
+        [Mac][WK2] Use MIME type to add file extension to downloads' suggested filenames when missing
+        https://bugs.webkit.org/show_bug.cgi?id=168077
+        <rdar://problem/30412595>
+
+        Reviewed by Alex Christensen.
+
+        Use MIME type to add file extension to downloads' suggested filenames when missing:
+        - https://html.spec.whatwg.org/#as-a-download (step 19)
+
+        This new behavior matches Chrome.
+
+        * NetworkProcess/Downloads/BlobDownloadClient.cpp:
+        (WebKit::BlobDownloadClient::didReceiveResponseAsync):
+        * NetworkProcess/Downloads/Download.cpp:
+        (WebKit::Download::didReceiveResponse):
+        (WebKit::Download::decideDestinationWithSuggestedFilename):
+        * NetworkProcess/Downloads/Download.h:
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::findPendingDownloadLocation):
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::didStart):
+        (WebKit::DownloadProxy::decideDestinationWithSuggestedFilename):
+        * UIProcess/Downloads/DownloadProxy.h:
+        * UIProcess/Downloads/DownloadProxy.messages.in:
+
 2017-02-09  Youenn Fablet  <you...@apple.com>
 
         [WebRTC][Mac] Activate libwebrtc

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/BlobDownloadClient.cpp (212040 => 212041)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/BlobDownloadClient.cpp	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/BlobDownloadClient.cpp	2017-02-10 04:00:52 UTC (rev 212041)
@@ -31,7 +31,9 @@
 #include "DataReference.h"
 #include "Download.h"
 #include "WebErrors.h"
+#include <WebCore/MIMETypeRegistry.h>
 #include <WebCore/ResourceError.h>
+#include <WebCore/ResourceResponse.h>
 #include <WebCore/SharedBuffer.h>
 
 namespace WebKit {
@@ -46,7 +48,8 @@
 void BlobDownloadClient::didReceiveResponseAsync(ResourceHandle*, ResourceResponse&& response)
 {
     m_download.didReceiveResponse(WTFMove(response));
-    m_download.decideDestinationWithSuggestedFilenameAsync(m_download.suggestedName().isEmpty() ? "unknown" : m_download.suggestedName());
+    String suggestedFilename = MIMETypeRegistry::appendFileExtensionIfNecessary(m_download.suggestedName().isEmpty() ? ASCIILiteral("unknown") : m_download.suggestedName(), response.mimeType());
+    m_download.decideDestinationWithSuggestedFilenameAsync(suggestedFilename);
 }
 
 void BlobDownloadClient::didDecideDownloadDestination(const String& destinationPath, bool allowOverwrite)

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/Download.cpp (212040 => 212041)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/Download.cpp	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/Download.cpp	2017-02-10 04:00:52 UTC (rev 212041)
@@ -161,6 +161,7 @@
 {
     RELEASE_LOG_IF_ALLOWED("didReceiveResponse: Created (id = %" PRIu64 ")", downloadID().downloadID());
 
+    m_responseMIMEType = response.mimeType();
     send(Messages::DownloadProxy::DidReceiveResponse(response));
 }
 
@@ -177,7 +178,7 @@
 {
     String destination;
     SandboxExtension::Handle sandboxExtensionHandle;
-    if (!sendSync(Messages::DownloadProxy::DecideDestinationWithSuggestedFilename(filename), Messages::DownloadProxy::DecideDestinationWithSuggestedFilename::Reply(destination, allowOverwrite, sandboxExtensionHandle)))
+    if (!sendSync(Messages::DownloadProxy::DecideDestinationWithSuggestedFilename(filename, m_responseMIMEType), Messages::DownloadProxy::DecideDestinationWithSuggestedFilename::Reply(destination, allowOverwrite, sandboxExtensionHandle)))
         return String();
 
     m_sandboxExtension = SandboxExtension::create(sandboxExtensionHandle);

Modified: trunk/Source/WebKit2/NetworkProcess/Downloads/Download.h (212040 => 212041)


--- trunk/Source/WebKit2/NetworkProcess/Downloads/Download.h	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/NetworkProcess/Downloads/Download.h	2017-02-10 04:00:52 UTC (rev 212041)
@@ -146,6 +146,7 @@
     WebCore::SessionID m_sessionID;
 #else // USE(NETWORK_SESSION)
     WebCore::ResourceRequest m_request;
+    String m_responseMIMEType;
 #if PLATFORM(COCOA)
     RetainPtr<NSURLDownload> m_nsURLDownload;
     RetainPtr<WKDownloadAsDelegate> m_delegate;

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (212040 => 212041)


--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp	2017-02-10 04:00:52 UTC (rev 212041)
@@ -53,6 +53,7 @@
 #include <WebCore/DNS.h>
 #include <WebCore/DiagnosticLoggingClient.h>
 #include <WebCore/LogInitialization.h>
+#include <WebCore/MIMETypeRegistry.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/PlatformCookieJar.h>
 #include <WebCore/ResourceRequest.h>
@@ -512,7 +513,8 @@
     downloadProxyConnection()->send(Messages::DownloadProxy::DidReceiveResponse(response), destinationID);
 
     downloadManager().willDecidePendingDownloadDestination(networkDataTask, WTFMove(completionHandler));
-    downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), networkDataTask.suggestedFilename()), destinationID);
+    String suggestedFilename = MIMETypeRegistry::appendFileExtensionIfNecessary(networkDataTask.suggestedFilename(), response.mimeType());
+    downloadProxyConnection()->send(Messages::DownloadProxy::DecideDestinationWithSuggestedFilenameAsync(networkDataTask.pendingDownloadID(), suggestedFilename), destinationID);
 }
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp (212040 => 212041)


--- trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp	2017-02-10 04:00:52 UTC (rev 212041)
@@ -37,6 +37,7 @@
 #include "WebProcessPool.h"
 #include "WebProtectionSpace.h"
 #include <WebCore/FileSystem.h>
+#include <WebCore/MIMETypeRegistry.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 
@@ -91,7 +92,7 @@
     m_processPool->downloadClient().processDidCrash(m_processPool.get(), this);
 }
 
-void DownloadProxy::didStart(const ResourceRequest& request, const AtomicString& suggestedFilename)
+void DownloadProxy::didStart(const ResourceRequest& request, const String& suggestedFilename)
 {
     m_request = request;
     m_suggestedFilename = suggestedFilename;
@@ -193,7 +194,7 @@
 
 #if !USE(NETWORK_SESSION)
 
-void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle)
+void DownloadProxy::decideDestinationWithSuggestedFilename(const String& filename, const String& mimeType, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle)
 {
     allowOverwrite = false;
 
@@ -200,10 +201,7 @@
     if (!m_processPool)
         return;
 
-    String suggestedFilename = filename;
-    if (!m_suggestedFilename.isNull())
-        suggestedFilename = m_suggestedFilename;
-    
+    String suggestedFilename = MIMETypeRegistry::appendFileExtensionIfNecessary(m_suggestedFilename.isNull() ? filename : m_suggestedFilename, mimeType);
     destination = m_processPool->downloadClient().decideDestinationWithSuggestedFilename(m_processPool.get(), this, suggestedFilename, allowOverwrite);
 
     if (!destination.isNull())

Modified: trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h (212040 => 212041)


--- trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.h	2017-02-10 04:00:52 UTC (rev 212041)
@@ -77,7 +77,7 @@
     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
 
     // Message handlers.
-    void didStart(const WebCore::ResourceRequest&, const AtomicString& suggestedFilename);
+    void didStart(const WebCore::ResourceRequest&, const String& suggestedFilename);
     void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&, uint64_t challengeID);
     void didReceiveResponse(const WebCore::ResourceResponse&);
     void didReceiveData(uint64_t length);
@@ -92,7 +92,7 @@
 #endif
     void willSendRequest(const WebCore::ResourceRequest& redirectRequest, const WebCore::ResourceResponse& redirectResponse);
 #else
-    void decideDestinationWithSuggestedFilename(const String& filename, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle);
+    void decideDestinationWithSuggestedFilename(const String& filename, const String& mimeType, String& destination, bool& allowOverwrite, SandboxExtension::Handle& sandboxExtensionHandle);
 #endif
     void decideDestinationWithSuggestedFilenameAsync(DownloadID, const String& suggestedFilename);
 
@@ -102,7 +102,7 @@
 
     RefPtr<API::Data> m_resumeData;
     WebCore::ResourceRequest m_request;
-    AtomicString m_suggestedFilename;
+    String m_suggestedFilename;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in (212040 => 212041)


--- trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in	2017-02-10 03:39:17 UTC (rev 212040)
+++ trunk/Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in	2017-02-10 04:00:52 UTC (rev 212041)
@@ -35,7 +35,7 @@
     DidReceiveData(uint64_t length)
     ShouldDecodeSourceDataOfMIMEType(String mimeType) -> (bool result)
 #if !USE(NETWORK_SESSION)
-    DecideDestinationWithSuggestedFilename(String filename) -> (String destination, bool allowOverwrite, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
+    DecideDestinationWithSuggestedFilename(String filename, String mimeType) -> (String destination, bool allowOverwrite, WebKit::SandboxExtension::Handle sandboxExtensionHandle)
 #endif
     DidCreateDestination(String path)
     DidFinish()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to