summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/browser_context_adapter_client.h8
-rw-r--r--src/core/download_manager_delegate_qt.cpp15
-rw-r--r--src/core/download_manager_delegate_qt.h4
-rw-r--r--src/core/web_contents_adapter.cpp7
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp24
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p.h11
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p_p.h1
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp1
-rw-r--r--src/webengine/doc/src/external-resources.qdoc10
-rw-r--r--src/webengine/plugin/plugin.cpp2
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.cpp29
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem.h9
-rw-r--r--src/webenginewidgets/api/qwebenginedownloaditem_p.h1
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp1
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp6
15 files changed, 125 insertions, 4 deletions
diff --git a/src/core/browser_context_adapter_client.h b/src/core/browser_context_adapter_client.h
index 2df8c21cb..faba08591 100644
--- a/src/core/browser_context_adapter_client.h
+++ b/src/core/browser_context_adapter_client.h
@@ -69,6 +69,13 @@ public:
MimeHtmlSaveFormat
};
+ enum DownloadType {
+ Attachment = 0,
+ DownloadAttribute,
+ UserRequested,
+ SavePage
+ };
+
struct DownloadItemInfo {
const quint32 id;
const QUrl url;
@@ -80,6 +87,7 @@ public:
QString path;
int savePageFormat;
bool accepted;
+ int downloadType;
};
virtual ~BrowserContextAdapterClient() { }
diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp
index 42b26072c..2cbfd121b 100644
--- a/src/core/download_manager_delegate_qt.cpp
+++ b/src/core/download_manager_delegate_qt.cpp
@@ -75,6 +75,7 @@ DownloadManagerDelegateQt::DownloadManagerDelegateQt(BrowserContextAdapter *cont
: m_contextAdapter(contextAdapter)
, m_currentId(0)
, m_weakPtrFactory(this)
+ , m_downloadType(BrowserContextAdapterClient::Attachment)
{
Q_ASSERT(m_contextAdapter);
}
@@ -116,6 +117,11 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
QString suggestedFilename = toQt(item->GetSuggestedFilename());
QString mimeTypeString = toQt(item->GetMimeType());
+ bool isAttachment = net::HttpContentDisposition(item->GetContentDisposition(), std::string()).is_attachment();
+
+ if (!isAttachment || !BrowserContextAdapterClient::UserRequested)
+ m_downloadType = BrowserContextAdapterClient::DownloadAttribute;
+
if (suggestedFilename.isEmpty())
suggestedFilename = toQt(net::HttpContentDisposition(item->GetContentDisposition(), std::string()).filename());
@@ -158,7 +164,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i
mimeTypeString,
suggestedFilePath,
BrowserContextAdapterClient::UnknownSavePageFormat,
- false /* accepted */
+ false /* accepted */,
+ m_downloadType
};
Q_FOREACH (BrowserContextAdapterClient *client, clients) {
@@ -246,7 +253,8 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content
QStringLiteral("application/x-mimearchive"),
suggestedFilePath,
suggestedSaveFormat,
- acceptedByDefault
+ acceptedByDefault,
+ BrowserContextAdapterClient::SavePage
};
Q_FOREACH (BrowserContextAdapterClient *client, clients) {
@@ -282,7 +290,8 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa
toQt(download->GetMimeType()),
QString(),
BrowserContextAdapterClient::UnknownSavePageFormat,
- true /* accepted */
+ true /* accepted */,
+ m_downloadType
};
Q_FOREACH (BrowserContextAdapterClient *client, clients) {
diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h
index e724b4e23..e603724e9 100644
--- a/src/core/download_manager_delegate_qt.h
+++ b/src/core/download_manager_delegate_qt.h
@@ -82,9 +82,10 @@ public:
bool can_save_as_complete,
const content::SavePackagePathPickedCallback &callback) Q_DECL_OVERRIDE;
-
void cancelDownload(quint32 downloadId);
+ void setDownloadType(int downloadType) { m_downloadType = downloadType; }
+
// Inherited from content::DownloadItem::Observer
void OnDownloadUpdated(content::DownloadItem *download) Q_DECL_OVERRIDE;
void OnDownloadDestroyed(content::DownloadItem *download) Q_DECL_OVERRIDE;
@@ -96,6 +97,7 @@ private:
uint64_t m_currentId;
base::WeakPtrFactory<DownloadManagerDelegateQt> m_weakPtrFactory;
+ int m_downloadType;
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 e37a3ad24..364d4d5b2 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -46,6 +46,7 @@
#include "browser_accessibility_qt.h"
#include "browser_context_adapter.h"
+#include "browser_context_adapter_client.h"
#include "browser_context_qt.h"
#include "download_manager_delegate_qt.h"
#include "media_capture_devices_dispatcher.h"
@@ -847,11 +848,17 @@ void WebContentsAdapter::updateWebPreferences(const content::WebPreferences & we
void WebContentsAdapter::download(const QUrl &url, const QString &suggestedFileName)
{
+ Q_D(WebContentsAdapter);
content::BrowserContext *bctx = webContents()->GetBrowserContext();
content::DownloadManager *dlm = content::BrowserContext::GetDownloadManager(bctx);
+ DownloadManagerDelegateQt *dlmd = d->browserContextAdapter->downloadManagerDelegate();
+
if (!dlm)
return;
+ dlmd->setDownloadType(BrowserContextAdapterClient::UserRequested);
+ dlm->SetDelegate(dlmd);
+
scoped_ptr<content::DownloadUrlParameters> params(
content::DownloadUrlParameters::FromWebContents(webContents(), toGurl(url)));
params->set_suggested_name(toString16(suggestedFileName));
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp
index c26255e3a..c0bca8977 100644
--- a/src/webengine/api/qquickwebenginedownloaditem.cpp
+++ b/src/webengine/api/qquickwebenginedownloaditem.cpp
@@ -66,6 +66,7 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb
, downloadId(-1)
, downloadState(QQuickWebEngineDownloadItem::DownloadCancelled)
, savePageFormat(QQuickWebEngineDownloadItem::UnknownSaveFormat)
+ , type(QQuickWebEngineDownloadItem::Attachment)
, totalBytes(-1)
, receivedBytes(0)
{
@@ -295,6 +296,29 @@ void QQuickWebEngineDownloadItem::setSavePageFormat(QQuickWebEngineDownloadItem:
}
}
+/*!
+ \qmlproperty enumeration WebEngineDownloadItem::type
+ \readonly
+ \since QtWebEngine 1.4
+
+ Describes the requested download's type.
+
+ \value Attachment The web server's response includes a \c Content-Disposition header with the \c attachment directive.
+ If \c Content-Disposition is present in the reply, the web server is indicating that
+ the client should prompt the user to save the content regardless of the content type.
+ See \l {RFC 2616 section 19.5.1} for details.
+ \value DownloadAttribute The user clicked the hyperlink.
+ See \l {HTML download Attribute} for details.
+ \value UserRequested The user initiated the download.
+ \value SavePage The user saved a web page.
+ */
+
+QQuickWebEngineDownloadItem::DownloadType QQuickWebEngineDownloadItem::type() const
+{
+ Q_D(const QQuickWebEngineDownloadItem);
+ return d->type;
+}
+
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 0b01fe6fc..61e019b9e 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p.h
@@ -82,6 +82,14 @@ public:
};
Q_ENUM(SavePageFormat)
+ enum DownloadType {
+ Attachment = 0,
+ DownloadAttribute,
+ UserRequested,
+ SavePage
+ };
+ Q_ENUM(DownloadType)
+
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 REVISION 2 FINAL)
@@ -89,6 +97,7 @@ public:
Q_PROPERTY(qint64 receivedBytes READ receivedBytes NOTIFY receivedBytesChanged)
Q_PROPERTY(QString mimeType READ mimeType NOTIFY mimeTypeChanged REVISION 1)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
+ Q_PROPERTY(DownloadType type READ type NOTIFY typeChanged REVISION 3 FINAL)
Q_INVOKABLE void accept();
Q_INVOKABLE void cancel();
@@ -102,6 +111,7 @@ public:
void setPath(QString path);
SavePageFormat savePageFormat() const;
void setSavePageFormat(SavePageFormat format);
+ DownloadType type() const;
Q_SIGNALS:
void stateChanged();
@@ -110,6 +120,7 @@ Q_SIGNALS:
void totalBytesChanged();
Q_REVISION(1) void mimeTypeChanged();
void pathChanged();
+ Q_REVISION(3) void typeChanged();
private:
QQuickWebEngineDownloadItem(QQuickWebEngineDownloadItemPrivate*, QObject *parent = 0);
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
index bdae54ca4..1789af462 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
@@ -73,6 +73,7 @@ public:
quint32 downloadId;
QQuickWebEngineDownloadItem::DownloadState downloadState;
QQuickWebEngineDownloadItem::SavePageFormat savePageFormat;
+ QQuickWebEngineDownloadItem::DownloadType type;
qint64 totalBytes;
qint64 receivedBytes;
QString mimeType;
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index c1f8f3179..b39fb02fd 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -180,6 +180,7 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->downloadPath = info.path;
itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>(
info.savePageFormat);
+ itemPrivate->type = static_cast<QQuickWebEngineDownloadItem::DownloadType>(info.downloadType);
QQuickWebEngineDownloadItem *download = new QQuickWebEngineDownloadItem(itemPrivate, q);
diff --git a/src/webengine/doc/src/external-resources.qdoc b/src/webengine/doc/src/external-resources.qdoc
index c4cfe24af..8933513a4 100644
--- a/src/webengine/doc/src/external-resources.qdoc
+++ b/src/webengine/doc/src/external-resources.qdoc
@@ -101,3 +101,13 @@
\title WebEngine
\internal
*/
+
+/*!
+ \externalpage https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1
+ \title RFC 2616 section 19.5.1
+*/
+
+/*!
+ \externalpage http://www.w3schools.com/tags/att_a_download.asp
+ \title HTML download Attribute
+*/
diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp
index b71689a34..6fae500f3 100644
--- a/src/webengine/plugin/plugin.cpp
+++ b/src/webengine/plugin/plugin.cpp
@@ -92,6 +92,8 @@ public:
tr("Cannot create a separate instance of WebEngineDownloadItem"));
qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 2>(uri, 1, 3, "WebEngineDownloadItem",
tr("Cannot create a separate instance of WebEngineDownloadItem"));
+ qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 3>(uri, 1, 4, "WebEngineDownloadItem",
+ tr("Cannot create a separate instance of WebEngineDownloadItem"));
qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest>(uri, 1, 1, "WebEngineNewViewRequest", tr("Cannot create separate instance of WebEngineNewViewRequest"));
qmlRegisterUncreatableType<QQuickWebEngineSettings>(uri, 1, 1, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
qmlRegisterUncreatableType<QQuickWebEngineSettings, 1>(uri, 1, 2, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings"));
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
index 3b75480f9..5efe4337d 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp
+++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp
@@ -80,6 +80,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr
, downloadId(-1)
, downloadState(QWebEngineDownloadItem::DownloadCancelled)
, savePageFormat(QWebEngineDownloadItem::MimeHtmlSaveFormat)
+ , type(QWebEngineDownloadItem::Attachment)
, downloadUrl(url)
, totalBytes(-1)
, receivedBytes(0)
@@ -219,6 +220,22 @@ quint32 QWebEngineDownloadItem::id() const
*/
/*!
+ \enum QWebEngineDownloadItem::DownloadType
+ \since 5.8
+
+ Describes the requested download's type.
+
+ \value Attachment The web server's response includes a \c Content-Disposition header with the \c attachment directive.
+ If \c Content-Disposition is present in the reply, the web server is indicating that
+ the client should prompt the user to save the content regardless of the content type.
+ See \l {RFC 2616 section 19.5.1} for details.
+ \value DownloadAttribute The user clicked the hyperlink.
+ See \l {HTML download Attribute} for details.
+ \value UserRequested The user initiated the download.
+ \value SavePage The user saved a web page.
+*/
+
+/*!
Returns the download item's current state.
\sa QWebEngineDownloadItem::DownloadState
@@ -343,6 +360,18 @@ void QWebEngineDownloadItem::setSavePageFormat(QWebEngineDownloadItem::SavePageF
d->savePageFormat = format;
}
+/*!
+ Returns the requested download's type.
+ \since 5.8
+
+ */
+
+QWebEngineDownloadItem::DownloadType QWebEngineDownloadItem::type() const
+{
+ Q_D(const QWebEngineDownloadItem);
+ return d->type;
+}
+
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 80b5c06c5..4b58748ad 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem.h
+++ b/src/webenginewidgets/api/qwebenginedownloaditem.h
@@ -72,6 +72,14 @@ public:
};
Q_ENUM(SavePageFormat)
+ enum DownloadType {
+ Attachment = 0,
+ DownloadAttribute,
+ UserRequested,
+ SavePage
+ };
+ Q_ENUM(DownloadType)
+
quint32 id() const;
DownloadState state() const;
qint64 totalBytes() const;
@@ -83,6 +91,7 @@ public:
bool isFinished() const;
SavePageFormat savePageFormat() const;
void setSavePageFormat(SavePageFormat format);
+ DownloadType type() const;
public Q_SLOTS:
void accept();
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h
index ddb3b443a..9ddb45444 100644
--- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h
+++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h
@@ -72,6 +72,7 @@ public:
quint32 downloadId;
QWebEngineDownloadItem::DownloadState downloadState;
QWebEngineDownloadItem::SavePageFormat savePageFormat;
+ QWebEngineDownloadItem::DownloadType type;
QString downloadPath;
const QUrl downloadUrl;
QString mimeType;
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 7e87aed50..83b6f9714 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -185,6 +185,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->downloadPath = info.path;
itemPrivate->mimeType = info.mimeType;
itemPrivate->savePageFormat = static_cast<QWebEngineDownloadItem::SavePageFormat>(info.savePageFormat);
+ itemPrivate->type = static_cast<QWebEngineDownloadItem::DownloadType>(info.downloadType);
QWebEngineDownloadItem *download = new QWebEngineDownloadItem(itemPrivate, q);
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index 1937dca04..b872f6620 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -396,6 +396,12 @@ static QStringList expectedAPI = QStringList()
<< "QQuickWebEngineDownloadItem.MimeHtmlSaveFormat --> SavePageFormat"
<< "QQuickWebEngineDownloadItem.savePageFormat --> SavePageFormat"
<< "QQuickWebEngineDownloadItem.savePageFormatChanged() --> void"
+ << "QQuickWebEngineDownloadItem.Attachment --> DownloadType"
+ << "QQuickWebEngineDownloadItem.DownloadAttribute --> DownloadType"
+ << "QQuickWebEngineDownloadItem.UserRequested --> DownloadType"
+ << "QQuickWebEngineDownloadItem.SavePage --> DownloadType"
+ << "QQuickWebEngineDownloadItem.type --> DownloadType"
+ << "QQuickWebEngineDownloadItem.typeChanged() --> void"
<< "QQuickWebEngineHistory.items --> QQuickWebEngineHistoryListModel*"
<< "QQuickWebEngineHistory.backItems --> QQuickWebEngineHistoryListModel*"
<< "QQuickWebEngineHistory.forwardItems --> QQuickWebEngineHistoryListModel*"