Title: [218575] releases/WebKitGTK/webkit-2.16
Revision
218575
Author
[email protected]
Date
2017-06-20 02:10:14 -0700 (Tue, 20 Jun 2017)

Log Message

Merge r218185 - [GTK] Blob download doesn't work
https://bugs.webkit.org/show_bug.cgi?id=172442

Reviewed by Carlos Alberto Lopez Perez.

Source/WebKit2:

GTK+ API uses URIs for download destination paths, and passes that URIs to the WebKit internals. But WebKit
expects download destination location to be a local path. This is not a problem for normal downloads, because
the soup backend handles the cases of download destination being a URI and a path. For blob downloads
NetworkDataTaskBlob is used, and it always expects the download destination to be a local path, failing in
FileSystem::openFile() when a URI is passed. We need to keep using local files internally and convert to URIs
only when exposing those paths to the API.

* NetworkProcess/soup/NetworkDataTaskSoup.cpp:
(WebKit::NetworkDataTaskSoup::download): Stop handling URIs here, we should always expect local files.
* UIProcess/API/gtk/WebKitDownload.cpp:
(webkitDownloadDecideDestinationWithSuggestedFilename): Convert destination URI to filanme before pasing it to DownloadClient.
(webkitDownloadDestinationCreated): Convert the destination path to a URI before passing it to WebKitDownload::created-destionation signal.
* UIProcess/API/gtk/WebKitDownloadClient.cpp:
* UIProcess/API/gtk/WebKitDownloadPrivate.h:

Tools:

Add a unit test to check blob downloads.

* TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
(testBlobDownload):
(beforeAll):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.16/Source/WebKit2/ChangeLog (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Source/WebKit2/ChangeLog	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Source/WebKit2/ChangeLog	2017-06-20 09:10:14 UTC (rev 218575)
@@ -1,3 +1,25 @@
+2017-06-13  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Blob download doesn't work
+        https://bugs.webkit.org/show_bug.cgi?id=172442
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        GTK+ API uses URIs for download destination paths, and passes that URIs to the WebKit internals. But WebKit
+        expects download destination location to be a local path. This is not a problem for normal downloads, because
+        the soup backend handles the cases of download destination being a URI and a path. For blob downloads
+        NetworkDataTaskBlob is used, and it always expects the download destination to be a local path, failing in
+        FileSystem::openFile() when a URI is passed. We need to keep using local files internally and convert to URIs
+        only when exposing those paths to the API.
+
+        * NetworkProcess/soup/NetworkDataTaskSoup.cpp:
+        (WebKit::NetworkDataTaskSoup::download): Stop handling URIs here, we should always expect local files.
+        * UIProcess/API/gtk/WebKitDownload.cpp:
+        (webkitDownloadDecideDestinationWithSuggestedFilename): Convert destination URI to filanme before pasing it to DownloadClient.
+        (webkitDownloadDestinationCreated): Convert the destination path to a URI before passing it to WebKitDownload::created-destionation signal.
+        * UIProcess/API/gtk/WebKitDownloadClient.cpp:
+        * UIProcess/API/gtk/WebKitDownloadPrivate.h:
+
 2017-06-09  Ryosuke Niwa  <[email protected]>
 
         Crash inside WebKit::PluginView::getAuthenticationInfo

Modified: releases/WebKitGTK/webkit-2.16/Source/WebKit2/NetworkProcess/soup/NetworkDataTaskSoup.cpp (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Source/WebKit2/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Source/WebKit2/NetworkProcess/soup/NetworkDataTaskSoup.cpp	2017-06-20 09:10:14 UTC (rev 218575)
@@ -848,10 +848,8 @@
         return;
     }
 
-    if (g_path_is_absolute(m_pendingDownloadLocation.utf8().data()))
-        m_downloadDestinationFile = adoptGRef(g_file_new_for_path(m_pendingDownloadLocation.utf8().data()));
-    else
-        m_downloadDestinationFile = adoptGRef(g_file_new_for_uri(m_pendingDownloadLocation.utf8().data()));
+    CString downloadDestinationPath = m_pendingDownloadLocation.utf8();
+    m_downloadDestinationFile = adoptGRef(g_file_new_for_path(downloadDestinationPath.data()));
     GRefPtr<GFileOutputStream> outputStream;
     GUniqueOutPtr<GError> error;
     if (m_allowOverwriteDownload)
@@ -863,10 +861,9 @@
         return;
     }
 
-    GUniquePtr<char> downloadDestinationURI(g_file_get_uri(m_downloadDestinationFile.get()));
-    GUniquePtr<char> intermediateURI(g_strdup_printf("%s.wkdownload", downloadDestinationURI.get()));
-    m_downloadIntermediateFile = adoptGRef(g_file_new_for_uri(intermediateURI.get()));
-    outputStream = adoptGRef(g_file_replace(m_downloadIntermediateFile.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr()));
+    GUniquePtr<char> intermediatePath(g_strdup_printf("%s.wkdownload", downloadDestinationPath.data()));
+    m_downloadIntermediateFile = adoptGRef(g_file_new_for_path(intermediatePath.get()));
+    outputStream = adoptGRef(g_file_replace(m_downloadIntermediateFile.get(), nullptr, TRUE, G_FILE_CREATE_NONE, nullptr, &error.outPtr()));
     if (!outputStream) {
         didFailDownload(platformDownloadDestinationError(m_response, error->message));
         return;
@@ -877,7 +874,7 @@
     auto download = std::make_unique<Download>(downloadManager, m_pendingDownloadID, *this, m_session->sessionID(), suggestedFilename());
     auto* downloadPtr = download.get();
     downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download));
-    downloadPtr->didCreateDestination(String::fromUTF8(downloadDestinationURI.get()));
+    downloadPtr->didCreateDestination(m_pendingDownloadLocation);
 
     ASSERT(!m_client);
     read();

Modified: releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp	2017-06-20 09:10:14 UTC (rev 218575)
@@ -31,6 +31,7 @@
 #include <glib/gi18n-lib.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
+#include <wtf/text/CString.h>
 
 using namespace WebKit;
 using namespace WebCore;
@@ -402,21 +403,26 @@
     g_signal_emit(download, signals[FINISHED], 0, NULL);
 }
 
-CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename, bool& allowOverwrite)
+String webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename, bool& allowOverwrite)
 {
     if (download->priv->isCancelled)
-        return "";
+        return emptyString();
     gboolean returnValue;
     g_signal_emit(download, signals[DECIDE_DESTINATION], 0, suggestedFilename.data(), &returnValue);
     allowOverwrite = download->priv->allowOverwrite;
-    return download->priv->destinationURI;
+    GUniquePtr<char> destinationPath(g_filename_from_uri(download->priv->destinationURI.data(), nullptr, nullptr));
+    if (!destinationPath)
+        return emptyString();
+    return String::fromUTF8(destinationPath.get());
 }
 
-void webkitDownloadDestinationCreated(WebKitDownload* download, const CString& destinationURI)
+void webkitDownloadDestinationCreated(WebKitDownload* download, const String& destinationPath)
 {
     if (download->priv->isCancelled)
         return;
-    g_signal_emit(download, signals[CREATED_DESTINATION], 0, destinationURI.data(), nullptr);
+    GUniquePtr<char> destinationURI(g_filename_to_uri(destinationPath.utf8().data(), nullptr, nullptr));
+    ASSERT(destinationURI);
+    g_signal_emit(download, signals[CREATED_DESTINATION], 0, destinationURI.get());
 }
 
 /**

Modified: releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp	2017-06-20 09:10:14 UTC (rev 218575)
@@ -77,13 +77,13 @@
     String decideDestinationWithSuggestedFilename(WebProcessPool*, DownloadProxy* downloadProxy, const String& filename, bool& allowOverwrite) override
     {
         GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
-        return String::fromUTF8(webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), filename.utf8(), allowOverwrite));
+        return webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), filename.utf8(), allowOverwrite);
     }
 
     void didCreateDestination(WebProcessPool*, DownloadProxy* downloadProxy, const String& path) override
     {
         GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
-        webkitDownloadDestinationCreated(download.get(), path.utf8());
+        webkitDownloadDestinationCreated(download.get(), path);
     }
 
     void didFail(WebProcessPool*, DownloadProxy* downloadProxy, const ResourceError& error) override

Modified: releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h	2017-06-20 09:10:14 UTC (rev 218575)
@@ -24,7 +24,6 @@
 #include "WebKitPrivate.h"
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceRequest.h>
-#include <wtf/text/CString.h>
 
 WebKitDownload* webkitDownloadCreate(WebKit::DownloadProxy*);
 bool webkitDownloadIsCancelled(WebKitDownload*);
@@ -34,7 +33,7 @@
 void webkitDownloadFailed(WebKitDownload*, const WebCore::ResourceError&);
 void webkitDownloadCancelled(WebKitDownload*);
 void webkitDownloadFinished(WebKitDownload*);
-CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename, bool& allowOverwrite);
-void webkitDownloadDestinationCreated(WebKitDownload*, const CString& destinationURI);
+String webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename, bool& allowOverwrite);
+void webkitDownloadDestinationCreated(WebKitDownload*, const String& destinationPath);
 
 #endif // WebKitDownloadPrivate_h

Modified: releases/WebKitGTK/webkit-2.16/Tools/ChangeLog (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Tools/ChangeLog	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Tools/ChangeLog	2017-06-20 09:10:14 UTC (rev 218575)
@@ -1,3 +1,16 @@
+2017-06-13  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Blob download doesn't work
+        https://bugs.webkit.org/show_bug.cgi?id=172442
+
+        Reviewed by Carlos Alberto Lopez Perez.
+
+        Add a unit test to check blob downloads.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
+        (testBlobDownload):
+        (beforeAll):
+
 2017-06-12  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Stop dismissing menus attached to the web view for every injected event

Modified: releases/WebKitGTK/webkit-2.16/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp (218574 => 218575)


--- releases/WebKitGTK/webkit-2.16/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp	2017-06-20 09:02:24 UTC (rev 218574)
+++ releases/WebKitGTK/webkit-2.16/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp	2017-06-20 09:10:14 UTC (rev 218575)
@@ -727,6 +727,42 @@
     g_file_delete(downloadFile.get(), nullptr, nullptr);
 }
 
+static void testBlobDownload(WebViewDownloadTest* test, gconstpointer)
+{
+    test->showInWindowAndWaitUntilMapped();
+
+    static const char* linkBlobHTML =
+        "<html><body>"
+        "<a id='downloadLink' style='position:absolute; left:1; top:1' download='foo.pdf'>Download Me</a>"
+        "<script>"
+        "  blob = new Blob(['Hello world'], {type: 'text/plain'});"
+        "  document.getElementById('downloadLink').href = ""
+        "</script>"
+        "</body></html>";
+    test->loadHtml(linkBlobHTML, kServer->getURIForPath("/").data());
+    test->waitUntilLoadFinished();
+
+    g_idle_add([](gpointer userData) -> gboolean {
+        auto* test = static_cast<WebViewDownloadTest*>(userData);
+        test->clickMouseButton(1, 1, 1);
+        return FALSE;
+    }, test);
+    test->waitUntilDownloadStarted();
+
+    g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
+    test->waitUntilDownloadFinished();
+
+    GRefPtr<GFile> downloadFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(test->m_download.get())));
+    GRefPtr<GFileInfo> downloadFileInfo = adoptGRef(g_file_query_info(downloadFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), nullptr, nullptr));
+    GUniquePtr<char> downloadPath(g_file_get_path(downloadFile.get()));
+    GUniqueOutPtr<char> downloadContents;
+    gsize downloadContentsLength;
+    g_assert(g_file_get_contents(downloadPath.get(), &downloadContents.outPtr(), &downloadContentsLength, nullptr));
+    g_assert_cmpint(g_file_info_get_size(downloadFileInfo.get()), ==, downloadContentsLength);
+    g_assert_cmpstr(downloadContents.get(), ==, "Hello world");
+    g_file_delete(downloadFile.get(), nullptr, nullptr);
+}
+
 void beforeAll()
 {
     kServer = new WebKitTestServer();
@@ -743,6 +779,7 @@
     PolicyResponseDownloadTest::add("Downloads", "policy-decision-download-cancel", testPolicyResponseDownloadCancel);
     DownloadTest::add("Downloads", "mime-type", testDownloadMIMEType);
     WebViewDownloadTest::add("Downloads", "contex-menu-download-actions", testContextMenuDownloadActions);
+    WebViewDownloadTest::add("Downloads", "blob-download", testBlobDownload);
 }
 
 void afterAll()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to