diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 35 | ||||
-rw-r--r-- | src/core/web_contents_adapter.cpp | 3 | ||||
-rw-r--r-- | src/core/web_contents_adapter.h | 2 | ||||
-rw-r--r-- | src/core/web_contents_delegate_qt.h | 21 |
4 files changed, 51 insertions, 10 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) { diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 15125b9d8..e37a3ad24 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -535,9 +535,10 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT d->webContents->Unselect(); } -void WebContentsAdapter::save() +void WebContentsAdapter::save(const QString &filePath, int savePageFormat) { Q_D(WebContentsAdapter); + d->webContentsDelegate->setSavePageInfo(SavePageInfo(filePath, savePageFormat)); d->webContents->OnSavePage(); } diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index 0de1fb1d5..63b99d013 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -85,7 +85,7 @@ public: void reloadAndBypassCache(); void load(const QUrl&); void setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl); - void save(); + void save(const QString &filePath = QString(), int savePageFormat = -1); QUrl activeUrl() const; QUrl requestedUrl() const; QString pageTitle() const; diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index 73ad5a9ac..b60f31ac3 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -69,6 +69,23 @@ namespace QtWebEngineCore { class WebContentsAdapterClient; +class SavePageInfo +{ +public: + SavePageInfo() + : requestedFormat(-1) + { + } + + SavePageInfo(const QString &filePath, int format) + : requestedFilePath(filePath), requestedFormat(format) + { + } + + QString requestedFilePath; + int requestedFormat; +}; + class WebContentsDelegateQt : public content::WebContentsDelegate , public content::WebContentsObserver { @@ -125,6 +142,9 @@ public: void launchExternalURL(const QUrl &url, ui::PageTransition page_transition, bool is_main_frame); FaviconManager *faviconManager(); + void setSavePageInfo(const SavePageInfo &spi) { m_savePageInfo = spi; } + const SavePageInfo &savePageInfo() { return m_savePageInfo; } + private: WebContentsAdapter *createWindow(content::WebContents *new_contents, WindowOpenDisposition disposition, const gfx::Rect& initial_pos, bool user_gesture); @@ -133,6 +153,7 @@ private: int m_lastReceivedFindReply; QVector<int64_t> m_loadingErrorFrameList; QScopedPointer<FaviconManager> m_faviconManager; + SavePageInfo m_savePageInfo; }; } // namespace QtWebEngineCore |