From 93af3896ee8a1344601344a5878d82dee813248d Mon Sep 17 00:00:00 2001 From: David Rosca Date: Sat, 31 Mar 2018 11:53:12 +0200 Subject: [PATCH] WebView: Use direct url download when contents is not web page Directly download file when contents is not a web page, eg. image, text file, video, ... Requires building against QtWebEngine 5.10. CCBUG: 391300 --- src/lib/webengine/webview.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index 24f499aea..aa286bb2d 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -511,7 +511,21 @@ void WebView::copyLinkToClipboard() void WebView::savePageAs() { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + page()->runJavaScript(QSL("document.contentType"), WebPage::SafeJsWorld, [this](const QVariant &res) { + const QSet webPageTypes = { + QSL("text/html"), + QSL("application/xhtml+xml") + }; + if (res.isNull() || webPageTypes.contains(res.toString())) { + triggerPageAction(QWebEnginePage::SavePage); + } else { + page()->download(url()); + } + }); +#else triggerPageAction(QWebEnginePage::SavePage); +#endif } void WebView::copyImageToClipboard()