<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[208882] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208882">208882</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2016-11-17 23:50:57 -0800 (Thu, 17 Nov 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Downloads started by context menu actions should also have a web view associated
https://bugs.webkit.org/show_bug.cgi?id=164364
Reviewed by Michael Catanzaro.
Source/WebKit2:
When a request is converted to a download WebPageProxy calls handleDownloadRequest() and clients handle that to
associate the web view to the download. When a download is started by a context menu action, WebPageProxy calls
WebProcessPool::download() with this as initiatingPage parameter, but clients are not notified in this case.
* UIProcess/API/gtk/WebKitDownload.cpp:
(webkitDownloadCreateForRequest): Deleted.
* UIProcess/API/gtk/WebKitDownloadPrivate.h:
* UIProcess/API/gtk/WebKitWebContext.cpp:
(webkitWebContextStartDownload): Use webkitWebContextGetOrCreateDownload() after WebProcessPool::download()
because the WebKitDownload could have already been created by the web view download handler at this point.
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_download_uri): We no longer need to associate the web view to the download here.
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::download): If an initiatingPage has been passed, call handleDownloadRequest() to notify
the page client.
Tools:
Add a GTK+ unit tests to check that downloads started by the context menu have a web view associated.
* TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
(downloadLocalFileSuccessfully):
(testDownloadOverwriteDestinationDisallowed):
(testDownloadLocalFileError):
(testDownloadRemoteFile):
(testDownloadRemoteFileError):
(testDownloadMIMEType):
(contextMenuCallback):
(testContextMenuDownloadActions):
(beforeAll):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadPrivateh">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebContextcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebProcessPoolcpp">trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkTestDownloadscpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Source/WebKit2/ChangeLog        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2016-11-17 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ Downloads started by context menu actions should also have a web view associated
+ https://bugs.webkit.org/show_bug.cgi?id=164364
+
+ Reviewed by Michael Catanzaro.
+
+ When a request is converted to a download WebPageProxy calls handleDownloadRequest() and clients handle that to
+ associate the web view to the download. When a download is started by a context menu action, WebPageProxy calls
+ WebProcessPool::download() with this as initiatingPage parameter, but clients are not notified in this case.
+
+ * UIProcess/API/gtk/WebKitDownload.cpp:
+ (webkitDownloadCreateForRequest): Deleted.
+ * UIProcess/API/gtk/WebKitDownloadPrivate.h:
+ * UIProcess/API/gtk/WebKitWebContext.cpp:
+ (webkitWebContextStartDownload): Use webkitWebContextGetOrCreateDownload() after WebProcessPool::download()
+ because the WebKitDownload could have already been created by the web view download handler at this point.
+ * UIProcess/API/gtk/WebKitWebView.cpp:
+ (webkit_web_view_download_uri): We no longer need to associate the web view to the download here.
+ * UIProcess/WebProcessPool.cpp:
+ (WebKit::WebProcessPool::download): If an initiatingPage has been passed, call handleDownloadRequest() to notify
+ the page client.
+
</ins><span class="cx"> 2016-11-17 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> REGRESSION: API test _WKDownload.ConvertResponseToDownload is a flaky timeout
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -322,13 +322,6 @@
</span><span class="cx"> return download;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-WebKitDownload* webkitDownloadCreateForRequest(DownloadProxy* downloadProxy, const ResourceRequest& request)
-{
- WebKitDownload* download = webkitDownloadCreate(downloadProxy);
- download->priv->request = adoptGRef(webkitURIRequestCreateForResourceRequest(request));
- return download;
-}
-
</del><span class="cx"> void webkitDownloadSetResponse(WebKitDownload* download, WebKitURIResponse* response)
</span><span class="cx"> {
</span><span class="cx"> download->priv->response = response;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitDownloadPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -27,7 +27,6 @@
</span><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx">
</span><span class="cx"> WebKitDownload* webkitDownloadCreate(WebKit::DownloadProxy*);
</span><del>-WebKitDownload* webkitDownloadCreateForRequest(WebKit::DownloadProxy*, const WebCore::ResourceRequest&);
</del><span class="cx"> bool webkitDownloadIsCancelled(WebKitDownload*);
</span><span class="cx"> void webkitDownloadSetResponse(WebKitDownload*, WebKitURIResponse*);
</span><span class="cx"> void webkitDownloadSetWebView(WebKitDownload*, WebKitWebView*);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -579,10 +579,11 @@
</span><span class="cx"> */
</span><span class="cx"> WebKitDownload* webkit_web_context_download_uri(WebKitWebContext* context, const gchar* uri)
</span><span class="cx"> {
</span><del>- g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
- g_return_val_if_fail(uri, 0);
</del><ins>+ g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
+ g_return_val_if_fail(uri, nullptr);
</ins><span class="cx">
</span><del>- return webkitWebContextStartDownload(context, uri, 0);
</del><ins>+ GRefPtr<WebKitDownload> download = webkitWebContextStartDownload(context, uri, nullptr);
+ return download.leakRef();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1237,10 +1238,7 @@
</span><span class="cx"> WebKitDownload* webkitWebContextStartDownload(WebKitWebContext* context, const char* uri, WebPageProxy* initiatingPage)
</span><span class="cx"> {
</span><span class="cx"> WebCore::ResourceRequest request(String::fromUTF8(uri));
</span><del>- DownloadProxy* downloadProxy = context->priv->processPool->download(initiatingPage, request);
- WebKitDownload* download = webkitDownloadCreateForRequest(downloadProxy, request);
- downloadsMap().set(downloadProxy, download);
- return download;
</del><ins>+ return webkitWebContextGetOrCreateDownload(context->priv->processPool->download(initiatingPage, request));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void webkitWebContextRemoveDownload(DownloadProxy* downloadProxy)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -3351,13 +3351,11 @@
</span><span class="cx"> */
</span><span class="cx"> WebKitDownload* webkit_web_view_download_uri(WebKitWebView* webView, const char* uri)
</span><span class="cx"> {
</span><del>- g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
- g_return_val_if_fail(uri, 0);
</del><ins>+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), nullptr);
+ g_return_val_if_fail(uri, nullptr);
</ins><span class="cx">
</span><del>- WebKitDownload* download = webkitWebContextStartDownload(webView->priv->context.get(), uri, getPage(webView));
- webkitDownloadSetWebView(download, webView);
-
- return download;
</del><ins>+ GRefPtr<WebKitDownload> download = webkitWebContextStartDownload(webView->priv->context.get(), uri, getPage(webView));
+ return download.leakRef();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessPoolcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -812,6 +812,9 @@
</span><span class="cx"> DownloadProxy* downloadProxy = createDownloadProxy(request);
</span><span class="cx"> SessionID sessionID = initiatingPage ? initiatingPage->sessionID() : SessionID::defaultSessionID();
</span><span class="cx">
</span><ins>+ if (initiatingPage)
+ initiatingPage->handleDownloadRequest(downloadProxy);
+
</ins><span class="cx"> if (networkProcess()) {
</span><span class="cx"> ResourceRequest updatedRequest(request);
</span><span class="cx"> // Request's firstPartyForCookies will be used as Original URL of the download request.
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Tools/ChangeLog        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2016-11-17 Carlos Garcia Campos <cgarcia@igalia.com>
+
+ Downloads started by context menu actions should also have a web view associated
+ https://bugs.webkit.org/show_bug.cgi?id=164364
+
+ Reviewed by Michael Catanzaro.
+
+ Add a GTK+ unit tests to check that downloads started by the context menu have a web view associated.
+
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp:
+ (downloadLocalFileSuccessfully):
+ (testDownloadOverwriteDestinationDisallowed):
+ (testDownloadLocalFileError):
+ (testDownloadRemoteFile):
+ (testDownloadRemoteFileError):
+ (testDownloadMIMEType):
+ (contextMenuCallback):
+ (testContextMenuDownloadActions):
+ (beforeAll):
+
</ins><span class="cx"> 2016-11-17 Ryosuke Niwa <rniwa@webkit.org>
</span><span class="cx">
</span><span class="cx"> Add an experimental API to find elements across shadow boundaries
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkTestDownloadscpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp (208881 => 208882)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp        2016-11-18 07:25:42 UTC (rev 208881)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDownloads.cpp        2016-11-18 07:50:57 UTC (rev 208882)
</span><span class="lines">@@ -159,16 +159,16 @@
</span><span class="cx"> webkit_download_set_destination(download, destinationURI.get());
</span><span class="cx"> }
</span><span class="cx">
</span><del>- WebKitDownload* downloadURIAndWaitUntilFinishes(const CString& requestURI)
</del><ins>+ GRefPtr<WebKitDownload> downloadURIAndWaitUntilFinishes(const CString& requestURI)
</ins><span class="cx"> {
</span><del>- WebKitDownload* download = webkit_web_context_download_uri(m_webContext.get(), requestURI.data());
- assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download));
</del><ins>+ GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_context_download_uri(m_webContext.get(), requestURI.data()));
+ assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
</ins><span class="cx">
</span><del>- g_assert(!webkit_download_get_allow_overwrite(download));
- webkit_download_set_allow_overwrite(download, m_allowOverwrite);
- g_assert(webkit_download_get_allow_overwrite(download) == m_allowOverwrite);
</del><ins>+ g_assert(!webkit_download_get_allow_overwrite(download.get()));
+ webkit_download_set_allow_overwrite(download.get(), m_allowOverwrite);
+ g_assert(webkit_download_get_allow_overwrite(download.get()) == m_allowOverwrite);
</ins><span class="cx">
</span><del>- WebKitURIRequest* request = webkit_download_get_request(download);
</del><ins>+ WebKitURIRequest* request = webkit_download_get_request(download.get());
</ins><span class="cx"> g_assert(request);
</span><span class="cx"> ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
</span><span class="cx">
</span><span class="lines">@@ -200,7 +200,7 @@
</span><span class="cx"> GRefPtr<GFile> source = adoptGRef(g_file_new_for_path(sourcePath.get()));
</span><span class="cx"> GRefPtr<GFileInfo> sourceInfo = adoptGRef(g_file_query_info(source.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), 0, 0));
</span><span class="cx"> GUniquePtr<char> sourceURI(g_file_get_uri(source.get()));
</span><del>- GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(sourceURI.get()));
</del><ins>+ GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes(sourceURI.get());
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
</span><span class="lines">@@ -321,7 +321,7 @@
</span><span class="cx"> GUniquePtr<char> sourcePath(g_build_filename(Test::getResourcesDir().data(), filename, nullptr));
</span><span class="cx"> GRefPtr<GFile> source = adoptGRef(g_file_new_for_path(sourcePath.get()));
</span><span class="cx"> GUniquePtr<char> sourceURI(g_file_get_uri(source.get()));
</span><del>- GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(sourceURI.get()));
</del><ins>+ GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes(sourceURI.get());
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
</span><span class="lines">@@ -338,7 +338,7 @@
</span><span class="cx"> static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer)
</span><span class="cx"> {
</span><span class="cx"> test->m_expectedError = DownloadErrorTest::NetworkError;
</span><del>- GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes("file:///foo/bar"));
</del><ins>+ GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes("file:///foo/bar");
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
</span><span class="lines">@@ -353,7 +353,7 @@
</span><span class="cx"> GUniquePtr<char> path(g_build_filename(Test::getResourcesDir().data(), "test.pdf", nullptr));
</span><span class="cx"> GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.get()));
</span><span class="cx"> GUniquePtr<char> uri(g_file_get_uri(file.get()));
</span><del>- download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get()));
</del><ins>+ download = test->downloadURIAndWaitUntilFinishes(uri.get());
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> g_assert_cmpint(events.size(), ==, 4);
</span><span class="lines">@@ -366,7 +366,7 @@
</span><span class="cx"> test->checkDestinationAndDeleteFile(download.get(), "bar");
</span><span class="cx">
</span><span class="cx"> test->m_expectedError = DownloadErrorTest::DownloadCancelled;
</span><del>- download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get()));
</del><ins>+ download = test->downloadURIAndWaitUntilFinishes(uri.get());
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> g_assert_cmpint(events.size(), ==, 4);
</span><span class="lines">@@ -439,7 +439,7 @@
</span><span class="cx">
</span><span class="cx"> static void testDownloadRemoteFile(DownloadTest* test, gconstpointer)
</span><span class="cx"> {
</span><del>- GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf")));
</del><ins>+ GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf"));
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
</span><span class="lines">@@ -463,7 +463,7 @@
</span><span class="cx"> static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer)
</span><span class="cx"> {
</span><span class="cx"> test->m_expectedError = DownloadErrorTest::NetworkError;
</span><del>- GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/foo")));
</del><ins>+ GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/foo"));
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
</span><span class="lines">@@ -478,7 +478,7 @@
</span><span class="cx"> g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1);
</span><span class="cx">
</span><span class="cx"> test->m_expectedError = DownloadErrorTest::InvalidDestination;
</span><del>- download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf")));
</del><ins>+ download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf"));
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> g_assert_cmpint(events.size(), ==, 4);
</span><span class="lines">@@ -491,7 +491,7 @@
</span><span class="cx"> test->checkDestinationAndDeleteFile(download.get(), "bar");
</span><span class="cx">
</span><span class="cx"> test->m_expectedError = DownloadErrorTest::DownloadCancelled;
</span><del>- download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/cancel-after-destination")));
</del><ins>+ download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/cancel-after-destination"));
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> g_assert_cmpint(events.size(), ==, 4);
</span><span class="lines">@@ -564,6 +564,7 @@
</span><span class="cx"> static void testWebViewDownloadURI(WebViewDownloadTest* test, gconstpointer)
</span><span class="cx"> {
</span><span class="cx"> GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_view_download_uri(test->m_webView, kServer->getURIForPath("/test.pdf").data()));
</span><ins>+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
</ins><span class="cx"> test->waitUntilDownloadStarted();
</span><span class="cx"> g_assert(test->m_webView == webkit_download_get_web_view(download.get()));
</span><span class="cx"> test->waitUntilDownloadFinished();
</span><span class="lines">@@ -643,7 +644,7 @@
</span><span class="cx">
</span><span class="cx"> static void testDownloadMIMEType(DownloadTest* test, gconstpointer)
</span><span class="cx"> {
</span><del>- GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/unknown")));
</del><ins>+ GRefPtr<WebKitDownload> download = test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/unknown"));
</ins><span class="cx"> g_assert(!webkit_download_get_web_view(download.get()));
</span><span class="cx">
</span><span class="cx"> Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
</span><span class="lines">@@ -668,6 +669,62 @@
</span><span class="cx"> test->checkDestinationAndDeleteFile(download.get(), kServerSuggestedFilename);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static gboolean contextMenuCallback(WebKitWebView* webView, WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult* hitTestResult, WebViewDownloadTest* test)
+{
+ g_assert(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult));
+ g_assert(webkit_hit_test_result_context_is_link(hitTestResult));
+ GList* items = webkit_context_menu_get_items(contextMenu);
+ GRefPtr<WebKitContextMenuItem> contextMenuItem;
+ for (GList* l = items; l; l = g_list_next(l)) {
+ g_assert(WEBKIT_IS_CONTEXT_MENU_ITEM(l->data));
+ auto* item = WEBKIT_CONTEXT_MENU_ITEM(l->data);
+ if (webkit_context_menu_item_get_stock_action(item) == WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK) {
+ contextMenuItem = item;
+ break;
+ }
+ }
+ g_assert(contextMenuItem.get());
+ webkit_context_menu_remove_all(contextMenu);
+ webkit_context_menu_append(contextMenu, contextMenuItem.get());
+ test->quitMainLoop();
+ return FALSE;
+}
+
+static void testContextMenuDownloadActions(WebViewDownloadTest* test, gconstpointer)
+{
+ test->showInWindowAndWaitUntilMapped();
+
+ static const char* linkHTMLFormat = "<html><body><a style='position:absolute; left:1; top:1' href='%s'>Download Me</a></body></html>";
+ GUniquePtr<char> linkHTML(g_strdup_printf(linkHTMLFormat, kServer->getURIForPath("/test.pdf").data()));
+ test->loadHtml(linkHTML.get(), kServer->getURIForPath("/").data());
+ test->waitUntilLoadFinished();
+
+ g_signal_connect(test->m_webView, "context-menu", G_CALLBACK(contextMenuCallback), test);
+ g_idle_add([](gpointer userData) -> gboolean {
+ auto* test = static_cast<WebViewDownloadTest*>(userData);
+ test->clickMouseButton(1, 1, 3);
+ return FALSE;
+ }, test);
+ g_main_loop_run(test->m_mainLoop);
+
+ g_idle_add([](gpointer userData) -> gboolean {
+ auto* test = static_cast<WebViewDownloadTest*>(userData);
+ // Select and activate the context menu action.
+ test->keyStroke(GDK_KEY_Down);
+ test->keyStroke(GDK_KEY_Return);
+ 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));
+ g_assert_cmpint(g_file_info_get_size(downloadFileInfo.get()), >, 0);
+ g_file_delete(downloadFile.get(), nullptr, nullptr);
+}
+
</ins><span class="cx"> void beforeAll()
</span><span class="cx"> {
</span><span class="cx"> kServer = new WebKitTestServer();
</span><span class="lines">@@ -683,6 +740,7 @@
</span><span class="cx"> PolicyResponseDownloadTest::add("Downloads", "policy-decision-download", testPolicyResponseDownload);
</span><span class="cx"> PolicyResponseDownloadTest::add("Downloads", "policy-decision-download-cancel", testPolicyResponseDownloadCancel);
</span><span class="cx"> DownloadTest::add("Downloads", "mime-type", testDownloadMIMEType);
</span><ins>+ WebViewDownloadTest::add("Downloads", "contex-menu-download-actions", testContextMenuDownloadActions);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void afterAll()
</span></span></pre>
</div>
</div>
</body>
</html>