summaryrefslogtreecommitdiffstats
path: root/src/core/download_manager_delegate_qt.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-03-31 17:36:22 +0200
committerJoerg Bornemann <joerg.bornemann@qt.io>2016-06-16 15:53:32 +0000
commit3398abfc1b5b789d11592aada0b5860e36a50041 (patch)
tree0c18602e09e9f3a250d8de6fa8618e2895aa07dc /src/core/download_manager_delegate_qt.cpp
parent939d104cc5a8208a0bef94ca14889ccd584a3526 (diff)
Introduce QWebEnginePage::save
Add the convenience method QWebEnginePage::save for saving pages without the need to explicitly handle download requests. Task-number: QTBUG-51798 Change-Id: I8910ce8cb7c9370d72f2b209c4d2de07c614f6d6 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/download_manager_delegate_qt.cpp')
-rw-r--r--src/core/download_manager_delegate_qt.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 857af2e18..42b26072c 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -56,6 +56,7 @@
#include "browser_context_adapter_client.h"
#include "browser_context_qt.h"
#include "type_conversion.h"
+#include "web_contents_delegate_qt.h"
#include "qtwebenginecoreglobal.h"
namespace QtWebEngineCore {
@@ -211,12 +212,30 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
if (clients.isEmpty())
return;
- const QString suggestedFileName
- = QFileInfo(toQt(suggested_path.AsUTF8Unsafe())).completeBaseName()
- + QStringLiteral(".mhtml");
- const QDir defaultDownloadDirectory
- = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
- const QString suggestedFilePath = defaultDownloadDirectory.absoluteFilePath(suggestedFileName);
+ WebContentsDelegateQt *contentsDelegate = static_cast<WebContentsDelegateQt *>(
+ web_contents->GetDelegate());
+ const SavePageInfo &spi = contentsDelegate->savePageInfo();
+
+ bool acceptedByDefault = false;
+ QString suggestedFilePath = spi.requestedFilePath;
+ if (suggestedFilePath.isEmpty()) {
+ suggestedFilePath = QFileInfo(toQt(suggested_path.AsUTF8Unsafe())).completeBaseName()
+ + QStringLiteral(".mhtml");
+ } else {
+ acceptedByDefault = true;
+ }
+ if (QFileInfo(suggestedFilePath).isRelative()) {
+ const QDir downloadDir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
+ suggestedFilePath = downloadDir.absoluteFilePath(suggestedFilePath);
+ }
+
+ BrowserContextAdapterClient::SavePageFormat suggestedSaveFormat
+ = static_cast<BrowserContextAdapterClient::SavePageFormat>(spi.requestedFormat);
+ if (suggestedSaveFormat == BrowserContextAdapterClient::UnknownSavePageFormat)
+ suggestedSaveFormat = BrowserContextAdapterClient::MimeHtmlSaveFormat;
+
+ // Clear the delegate's SavePageInfo. It's only valid for the page currently being saved.
+ contentsDelegate->setSavePageInfo(SavePageInfo());
BrowserContextAdapterClient::DownloadItemInfo info = {
m_currentId + 1,
@@ -226,8 +245,8 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
0, /* receivedBytes */
QStringLiteral("application/x-mimearchive"),
suggestedFilePath,
- BrowserContextAdapterClient::MimeHtmlSaveFormat,
- false /* accepted */
+ suggestedSaveFormat,
+ acceptedByDefault
};
Q_FOREACH (BrowserContextAdapterClient *client, clients) {