summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2015-11-16 17:51:01 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-11 06:37:32 +0000
commit9d18f8d02b73c2c9310b772c972ea1e0d1356102 (patch)
tree7cc8c93950db0797916146620c6fb2e56ad0acc4
parent222faea4af492f3286e9adca9c3d57a0f553a52a (diff)
Add web action for saving the current web page
Add the possibility to save web pages as single HTML file, complete HTML (with resource directory) or MHTML archive. Change-Id: Ic7e7cfda9432f3534c13350a6369d79bb17fd8b3 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
-rw-r--r--src/core/browser_context_adapter_client.h9
-rw-r--r--src/core/download_manager_delegate_qt.cpp59
-rw-r--r--src/core/download_manager_delegate_qt.h9
-rw-r--r--src/core/web_contents_adapter.cpp7
-rw-r--r--src/core/web_contents_adapter.h1
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp29
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p.h12
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p_p.h1
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp9
-rw-r--r--src/webengine/api/qquickwebengineview.cpp11
-rw-r--r--src/webengine/api/qquickwebengineview_p.h1
-rw-r--r--src/webengine/doc/src/webengineview.qdoc2
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.cpp36
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.h10
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem_p.h1
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp9
-rw-r--r--src/webenginewidgets/api/qwebenginepage.h1
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp9
-rw-r--r--src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc2
19 files changed, 218 insertions, 0 deletions
diff --git a/src/core/browser_context_adapter_client.h b/src/core/browser_context_adapter_client.h
index 4a57b75c4..d237b25a1 100644
--- a/src/core/browser_context_adapter_client.h
+++ b/src/core/browser_context_adapter_client.h
@@ -58,6 +58,14 @@ public:
DownloadInterrupted
};
+ // Keep in sync with content::SavePageType
+ enum SavePageFormat {
+ UnknownSavePageFormat = -1,
+ SingleHtmlSaveFormat,
+ CompleteHtmlSaveFormat,
+ MimeHtmlSaveFormat
+ };
+
struct DownloadItemInfo {
const quint32 id;
const QUrl url;
@@ -66,6 +74,7 @@ public:
const qint64 receivedBytes;
QString path;
+ int savePageFormat;
bool accepted;
};
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index e9af98fd8..b6de27ca8 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -61,9 +61,15 @@ ASSERT_ENUMS_MATCH(content::DownloadItem::COMPLETE, BrowserContextAdapterClient:
ASSERT_ENUMS_MATCH(content::DownloadItem::CANCELLED, BrowserContextAdapterClient::DownloadCancelled)
ASSERT_ENUMS_MATCH(content::DownloadItem::INTERRUPTED, BrowserContextAdapterClient::DownloadInterrupted)
+ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_UNKNOWN, BrowserContextAdapterClient::UnknownSavePageFormat)
+ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_AS_ONLY_HTML, BrowserContextAdapterClient::SingleHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, BrowserContextAdapterClient::CompleteHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_AS_MHTML, BrowserContextAdapterClient::MimeHtmlSaveFormat)
+
DownloadManagerDelegateQt::DownloadManagerDelegateQt(BrowserContextAdapter *contextAdapter)
: m_contextAdapter(contextAdapter)
, m_currentId(0)
+ , m_weakPtrFactory(this)
{
Q_ASSERT(m_contextAdapter);
}
@@ -140,6 +146,7 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
item->GetTotalBytes(),
item->GetReceivedBytes(),
suggestedFilePath,
+ BrowserContextAdapterClient::UnknownSavePageFormat,
false /* accepted */
};
@@ -181,6 +188,57 @@ void DownloadManagerDelegateQt::GetSaveDir(content::BrowserContext* browser_cont
*skip_dir_check = true;
}
+void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_contents,
+ const base::FilePath &suggested_path,
+ const base::FilePath::StringType &default_extension,
+ bool can_save_as_complete,
+ const content::SavePackagePathPickedCallback &callback)
+{
+ Q_UNUSED(default_extension);
+ Q_UNUSED(can_save_as_complete);
+
+ QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
+ 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);
+
+ BrowserContextAdapterClient::DownloadItemInfo info = {
+ m_currentId + 1,
+ toQt(web_contents->GetURL()),
+ content::DownloadItem::IN_PROGRESS,
+ 0, /* totalBytes */
+ 0, /* receivedBytes */
+ suggestedFilePath,
+ BrowserContextAdapterClient::MimeHtmlSaveFormat,
+ false /* accepted */
+ };
+
+ Q_FOREACH (BrowserContextAdapterClient *client, clients) {
+ client->downloadRequested(info);
+ if (info.accepted)
+ break;
+ }
+
+ if (!info.accepted)
+ return;
+
+ callback.Run(toFilePath(info.path), static_cast<content::SavePageType>(info.savePageFormat),
+ base::Bind(&DownloadManagerDelegateQt::savePackageDownloadCreated,
+ m_weakPtrFactory.GetWeakPtr()));
+}
+
+void DownloadManagerDelegateQt::savePackageDownloadCreated(content::DownloadItem *item)
+{
+ OnDownloadUpdated(item);
+ item->AddObserver(this);
+}
+
void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *download)
{
QList<BrowserContextAdapterClient*> clients = m_contextAdapter->clients();
@@ -192,6 +250,7 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
download->GetTotalBytes(),
download->GetReceivedBytes(),
QString(),
+ BrowserContextAdapterClient::UnknownSavePageFormat,
true /* accepted */
};
diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h
index fea965749..700c2f5a7 100644
--- a/src/core/download_manager_delegate_qt.h
+++ b/src/core/download_manager_delegate_qt.h
@@ -38,6 +38,7 @@
#define DOWNLOAD_MANAGER_DELEGATE_QT_H
#include "content/public/browser/download_manager_delegate.h"
+#include <base/memory/weak_ptr.h>
#include <QtCore/qcompilerdetection.h> // Needed for Q_DECL_OVERRIDE
@@ -72,6 +73,12 @@ public:
base::FilePath* website_save_dir,
base::FilePath* download_save_dir,
bool* skip_dir_check) Q_DECL_OVERRIDE;
+ void ChooseSavePath(content::WebContents *web_contents,
+ const base::FilePath &suggested_path,
+ const base::FilePath::StringType &default_extension,
+ bool can_save_as_complete,
+ const content::SavePackagePathPickedCallback &callback) Q_DECL_OVERRIDE;
+
void cancelDownload(quint32 downloadId);
@@ -81,9 +88,11 @@ public:
private:
void cancelDownload(const content::DownloadTargetCallback& callback);
+ void savePackageDownloadCreated(content::DownloadItem *download);
BrowserContextAdapter *m_contextAdapter;
uint64 m_currentId;
+ base::WeakPtrFactory<DownloadManagerDelegateQt> m_weakPtrFactory;
friend class DownloadManagerDelegateInstance;
DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegateQt);
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 84c4e50f3..543ad24cb 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -44,6 +44,7 @@
#include "browser_accessibility_qt.h"
#include "browser_context_adapter.h"
#include "browser_context_qt.h"
+#include "download_manager_delegate_qt.h"
#include "media_capture_devices_dispatcher.h"
#include "qwebenginecallback_p.h"
#include "render_view_observer_host_qt.h"
@@ -489,6 +490,12 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT
d->webContents->Focus();
}
+void WebContentsAdapter::save()
+{
+ Q_D(WebContentsAdapter);
+ d->webContents->OnSavePage();
+}
+
QUrl WebContentsAdapter::activeUrl() const
{
Q_D(const WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index b6a90d3f1..df9cbb266 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -77,6 +77,7 @@ public:
void reloadAndBypassCache();
void load(const QUrl&);
void setContent(const QByteArray &data, const QString &mimeType, const QUrl &baseUrl);
+ void save();
QUrl activeUrl() const;
QUrl requestedUrl() const;
QString pageTitle() const;
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp
index da47388ee..6efa45e43 100644
--- a/src/webengine/api/qquickwebenginedownloaditem.cpp
+++ b/src/webengine/api/qquickwebenginedownloaditem.cpp
@@ -62,6 +62,7 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb
: profile(p)
, downloadId(-1)
, downloadState(QQuickWebEngineDownloadItem::DownloadCancelled)
+ , savePageFormat(QQuickWebEngineDownloadItem::UnknownSaveFormat)
, totalBytes(-1)
, receivedBytes(0)
{
@@ -249,6 +250,34 @@ void QQuickWebEngineDownloadItem::setPath(QString path)
}
}
+/*!
+ \qmlproperty enumeration WebEngineDownloadItem::savePageFormat
+
+ Describes the format that is used to save a web page.
+
+ \value UnknownSaveFormat This is not a request for downloading a complete web page.
+ \value SingleHtmlSaveFormat The page is saved as a single HTML page. Resources such as images
+ are not saved.
+ \value CompleteHtmlSaveFormat The page is saved as a complete HTML page, for example a directory
+ containing the single HTML page and the resources.
+ \value MimeHtmlSaveFormat The page is saved as a complete web page in the MIME HTML format.
+*/
+
+QQuickWebEngineDownloadItem::SavePageFormat QQuickWebEngineDownloadItem::savePageFormat() const
+{
+ Q_D(const QQuickWebEngineDownloadItem);
+ return d->savePageFormat;
+}
+
+void QQuickWebEngineDownloadItem::setSavePageFormat(QQuickWebEngineDownloadItem::SavePageFormat format)
+{
+ Q_D(QQuickWebEngineDownloadItem);
+ if (d->savePageFormat != format) {
+ d->savePageFormat = format;
+ Q_EMIT savePageFormatChanged();
+ }
+}
+
QQuickWebEngineDownloadItem::QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate *p, QObject *parent)
: QObject(parent)
, d_ptr(p)
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h
index d0be2f99a..9d1a5a211 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p.h
@@ -71,8 +71,17 @@ public:
};
Q_ENUM(DownloadState)
+ enum SavePageFormat {
+ UnknownSaveFormat = -1,
+ SingleHtmlSaveFormat,
+ CompleteHtmlSaveFormat,
+ MimeHtmlSaveFormat
+ };
+ Q_ENUM(SavePageFormat)
+
Q_PROPERTY(quint32 id READ id CONSTANT FINAL)
Q_PROPERTY(DownloadState state READ state NOTIFY stateChanged)
+ Q_PROPERTY(SavePageFormat savePageFormat READ savePageFormat WRITE setSavePageFormat NOTIFY savePageFormatChanged)
Q_PROPERTY(qint64 totalBytes READ totalBytes NOTIFY totalBytesChanged)
Q_PROPERTY(qint64 receivedBytes READ receivedBytes NOTIFY receivedBytesChanged)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
@@ -86,9 +95,12 @@ public:
qint64 receivedBytes() const;
QString path() const;
void setPath(QString path);
+ SavePageFormat savePageFormat() const;
+ void setSavePageFormat(SavePageFormat format);
Q_SIGNALS:
void stateChanged();
+ void savePageFormatChanged();
void receivedBytesChanged();
void totalBytesChanged();
void pathChanged();
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
index 230f322b5..36b9eb349 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
@@ -69,6 +69,7 @@ public:
quint32 downloadId;
QQuickWebEngineDownloadItem::DownloadState downloadState;
+ QQuickWebEngineDownloadItem::SavePageFormat savePageFormat;
qint64 totalBytes;
qint64 receivedBytes;
QString downloadPath;
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index 303f038a8..0c3f7400b 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -45,12 +45,18 @@
#include <QQmlEngine>
#include "browser_context_adapter.h"
+#include <qtwebenginecoreglobal.h>
#include "web_engine_settings.h"
using QtWebEngineCore::BrowserContextAdapter;
QT_BEGIN_NAMESPACE
+ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::UnknownSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::UnknownSavePageFormat)
+ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::SingleHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::CompleteHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::MimeHtmlSaveFormat)
+
QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext)
: m_settings(new QQuickWebEngineSettings())
, m_browserContextRef(browserContext)
@@ -94,6 +100,8 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->downloadState = QQuickWebEngineDownloadItem::DownloadRequested;
itemPrivate->totalBytes = info.totalBytes;
itemPrivate->downloadPath = info.path;
+ itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>(
+ info.savePageFormat);
QQuickWebEngineDownloadItem *download = new QQuickWebEngineDownloadItem(itemPrivate, q);
@@ -104,6 +112,7 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
QQuickWebEngineDownloadItem::DownloadState state = download->state();
info.path = download->path();
+ info.savePageFormat = itemPrivate->savePageFormat;
info.accepted = state != QQuickWebEngineDownloadItem::DownloadCancelled
&& state != QQuickWebEngineDownloadItem::DownloadRequested;
}
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 9e0da060e..b9fa3d605 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -205,6 +205,14 @@ bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu
item = new MenuItemHandler(menu);
QObject::connect(item, &MenuItemHandler::triggered, q, &QQuickWebEngineView::reload);
ui()->addMenuItem(item, QQuickWebEngineView::tr("Reload"), QStringLiteral("view-refresh"));
+
+ if (!data.linkUrl.isValid()) {
+ item = new MenuItemHandler(menu);
+ QObject::connect(item, &MenuItemHandler::triggered, [q] {
+ q->triggerWebAction(QQuickWebEngineView::SavePage);
+ });
+ ui()->addMenuItem(item, QQuickWebEngineView::tr("Save"));
+ }
} else {
item = new MenuItemHandler(menu);
QObject::connect(item, &MenuItemHandler::triggered, [q] { q->triggerWebAction(QQuickWebEngineView::Copy); });
@@ -1387,6 +1395,9 @@ void QQuickWebEngineView::triggerWebAction(WebAction action)
case RequestClose:
d->adapter->requestClose();
break;
+ case SavePage:
+ d->adapter->save();
+ break;
default:
Q_UNREACHABLE();
}
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 4c4192b4c..a2f937968 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -233,6 +233,7 @@ public:
ExitFullScreen,
RequestClose,
Unselect,
+ SavePage,
WebActionCount
};
diff --git a/src/webengine/doc/src/webengineview.qdoc b/src/webengine/doc/src/webengineview.qdoc
index d1b4e722b..e687d54d9 100644
--- a/src/webengine/doc/src/webengineview.qdoc
+++ b/src/webengine/doc/src/webengineview.qdoc
@@ -671,6 +671,8 @@
(Added in Qt 5.6)
\value ExitFullScreen
Exit the fullscreen mode. (Added in Qt 5.6)
+ \value SavePage
+ Save the current web page to disk. (Added in Qt 5.7)
\omitvalue WebActionCount
*/
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
index 6c9413280..9650f5e0e 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp
+++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
@@ -76,6 +76,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr
, downloadFinished(false)
, downloadId(-1)
, downloadState(QWebEngineDownloadItem::DownloadCancelled)
+ , savePageFormat(QWebEngineDownloadItem::MimeHtmlSaveFormat)
, downloadUrl(url)
, totalBytes(-1)
, receivedBytes(0)
@@ -201,6 +202,19 @@ quint32 QWebEngineDownloadItem::id() const
*/
/*!
+ \enum QWebEngineDownloadItem::SavePageFormat
+
+ This enum describes the format that is used to save a web page.
+
+ \value UnknownSaveFormat This is not a request for downloading a complete web page.
+ \value SingleHtmlSaveFormat The page is saved as a single HTML page. Resources such as images
+ are not saved.
+ \value CompleteHtmlSaveFormat The page is saved as a complete HTML page, for example a directory
+ containing the single HTML page and the resources.
+ \value MimeHtmlSaveFormat The page is saved as a complete web page in the MIME HTML format.
+*/
+
+/*!
Returns the download item's current state.
\sa QWebEngineDownloadItem::DownloadState
@@ -289,6 +303,28 @@ bool QWebEngineDownloadItem::isFinished() const
return d->downloadFinished;
}
+/*!
+ Returns the format the web page will be saved in if this is a download request for a web page.
+
+ \sa setSavePageFormat()
+*/
+QWebEngineDownloadItem::SavePageFormat QWebEngineDownloadItem::savePageFormat() const
+{
+ Q_D(const QWebEngineDownloadItem);
+ return d->savePageFormat;
+}
+
+/*!
+ Sets the format the web page will be saved in if this is a download request for a web page.
+
+ \sa savePageFormat()
+*/
+void QWebEngineDownloadItem::setSavePageFormat(QWebEngineDownloadItem::SavePageFormat format)
+{
+ Q_D(QWebEngineDownloadItem);
+ d->savePageFormat = format;
+}
+
QWebEngineDownloadItem::QWebEngineDownloadItem(QWebEngineDownloadItemPrivate *p, QObject *parent)
: QObject(parent)
, d_ptr(p)
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h
index 38b9a4ad8..b0c4c2988 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem.h
+++ b/src/webenginewidgets/api/qwebenginedownloaditem.h
@@ -61,6 +61,14 @@ public:
};
Q_ENUM(DownloadState)
+ enum SavePageFormat {
+ UnknownSaveFormat = -1,
+ SingleHtmlSaveFormat,
+ CompleteHtmlSaveFormat,
+ MimeHtmlSaveFormat
+ };
+ Q_ENUM(SavePageFormat)
+
quint32 id() const;
DownloadState state() const;
qint64 totalBytes() const;
@@ -69,6 +77,8 @@ public:
QString path() const;
void setPath(QString path);
bool isFinished() const;
+ SavePageFormat savePageFormat() const;
+ void setSavePageFormat(SavePageFormat format);
public Q_SLOTS:
void accept();
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h
index 87dc4114a..ab38d7d03 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h
+++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h
@@ -68,6 +68,7 @@ public:
bool downloadFinished;
quint32 downloadId;
QWebEngineDownloadItem::DownloadState downloadState;
+ QWebEngineDownloadItem::SavePageFormat savePageFormat;
QString downloadPath;
const QUrl downloadUrl;
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 7d7ffdcf0..ee5702309 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -707,6 +707,9 @@ QAction *QWebEnginePage::action(WebAction action) const
case Unselect:
text = tr("Unselect");
break;
+ case SavePage:
+ text = tr("Save &Page");
+ break;
default:
break;
}
@@ -883,6 +886,9 @@ void QWebEnginePage::triggerAction(WebAction action, bool)
case RequestClose:
d->adapter->requestClose();
break;
+ case SavePage:
+ d->adapter->save();
+ break;
default:
Q_UNREACHABLE();
}
@@ -1075,6 +1081,9 @@ QMenu *QWebEnginePage::createStandardContextMenu()
action = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), tr("&Reload"), menu);
connect(action, &QAction::triggered, d->view, &QWebEngineView::reload);
menu->addAction(action);
+
+ if (!contextMenuData.linkUrl.isValid())
+ menu->addAction(QWebEnginePage::action(SavePage));
} else {
menu->addAction(QWebEnginePage::action(Copy));
menu->addAction(QWebEnginePage::action(Unselect));
diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h
index 69f8822b1..b3c592708 100644
--- a/src/webenginewidgets/api/qwebenginepage.h
+++ b/src/webenginewidgets/api/qwebenginepage.h
@@ -113,6 +113,7 @@ public:
ExitFullScreen,
RequestClose,
Unselect,
+ SavePage,
WebActionCount
};
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index e1cde4f08..9955f7728 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -45,11 +45,17 @@
#include "qwebenginescriptcollection_p.h"
#include "browser_context_adapter.h"
+#include <qtwebenginecoreglobal.h>
#include "web_engine_visited_links_manager.h"
#include "web_engine_settings.h"
QT_BEGIN_NAMESPACE
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::UnknownSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::UnknownSavePageFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::SingleHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::CompleteHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::MimeHtmlSaveFormat)
+
using QtWebEngineCore::BrowserContextAdapter;
/*!
@@ -150,6 +156,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->downloadId = info.id;
itemPrivate->downloadState = QWebEngineDownloadItem::DownloadRequested;
itemPrivate->downloadPath = info.path;
+ itemPrivate->savePageFormat = static_cast<QWebEngineDownloadItem::SavePageFormat>(info.savePageFormat);
QWebEngineDownloadItem *download = new QWebEngineDownloadItem(itemPrivate, q);
@@ -160,6 +167,8 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
QWebEngineDownloadItem::DownloadState state = download->state();
info.path = download->path();
+ info.savePageFormat = static_cast<QtWebEngineCore::BrowserContextAdapterClient::SavePageFormat>(
+ download->savePageFormat());
info.accepted = state != QWebEngineDownloadItem::DownloadCancelled;
if (state == QWebEngineDownloadItem::DownloadRequested) {
diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
index 1eee2d187..d3c540016 100644
--- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
@@ -123,6 +123,8 @@
handler is run, and the user can confirm or reject to close the page. If the close
request is confirmed, \c windowCloseRequested is emitted. (Added in Qt 5.6)
\value Unselect Clear the current selection. (Added in Qt 5.7)
+ \value SavePage Save the current page to disk. MHTML is the default format that is used to store
+ the web page on disk. (Added in Qt 5.7)
\omitvalue WebActionCount