diff options
-rw-r--r-- | src/core/browser_context_adapter.cpp | 10 | ||||
-rw-r--r-- | src/core/browser_context_adapter.h | 2 | ||||
-rw-r--r-- | src/core/browser_context_adapter_client.h | 2 | ||||
-rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 22 | ||||
-rw-r--r-- | src/core/download_manager_delegate_qt.h | 2 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem.cpp | 82 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p.h | 8 | ||||
-rw-r--r-- | src/webengine/api/qquickwebenginedownloaditem_p_p.h | 2 | ||||
-rw-r--r-- | src/webengine/plugin/plugin.cpp | 2 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.cpp | 87 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.h | 4 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 5 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile_p.h | 1 |
14 files changed, 214 insertions, 16 deletions
diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index bec76ad81..f76969c74 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -184,6 +184,16 @@ void BrowserContextAdapter::cancelDownload(quint32 downloadId) downloadManagerDelegate()->cancelDownload(downloadId); } +void BrowserContextAdapter::pauseDownload(quint32 downloadId) +{ + downloadManagerDelegate()->pauseDownload(downloadId); +} + +void BrowserContextAdapter::resumeDownload(quint32 downloadId) +{ + downloadManagerDelegate()->resumeDownload(downloadId); +} + QSharedPointer<BrowserContextAdapter> BrowserContextAdapter::defaultContext() { return WebEngineContext::current()->defaultBrowserContext(); diff --git a/src/core/browser_context_adapter.h b/src/core/browser_context_adapter.h index f6ebfd51c..5960014b9 100644 --- a/src/core/browser_context_adapter.h +++ b/src/core/browser_context_adapter.h @@ -86,6 +86,8 @@ public: void removeClient(BrowserContextAdapterClient *adapterClient); void cancelDownload(quint32 downloadId); + void pauseDownload(quint32 downloadId); + void resumeDownload(quint32 downloadId); BrowserContextQt *browserContext(); diff --git a/src/core/browser_context_adapter_client.h b/src/core/browser_context_adapter_client.h index e1fd02f96..02bee8ed6 100644 --- a/src/core/browser_context_adapter_client.h +++ b/src/core/browser_context_adapter_client.h @@ -118,6 +118,8 @@ public: QString path; int savePageFormat; bool accepted; + bool paused; + bool done; int downloadType; int downloadInterruptReason; }; diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 77469a8ea..67c809032 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -92,6 +92,22 @@ void DownloadManagerDelegateQt::cancelDownload(quint32 downloadId) download->Cancel(/* user_cancel */ true); } +void DownloadManagerDelegateQt::pauseDownload(quint32 downloadId) +{ + content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_contextAdapter->browserContext()); + content::DownloadItem *download = dlm->GetDownload(downloadId); + if (download) + download->Pause(); +} + +void DownloadManagerDelegateQt::resumeDownload(quint32 downloadId) +{ + content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(m_contextAdapter->browserContext()); + content::DownloadItem *download = dlm->GetDownload(downloadId); + if (download) + download->Resume(); +} + bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* item, const content::DownloadTargetCallback& callback) { @@ -155,6 +171,8 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(content::DownloadItem* i suggestedFilePath, BrowserContextAdapterClient::UnknownSavePageFormat, false /* accepted */, + false /* paused */, + false /* done */, m_downloadType, item->GetLastReason() }; @@ -245,6 +263,8 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content suggestedFilePath, suggestedSaveFormat, acceptedByDefault, + false, /* paused */ + false, /* done */ BrowserContextAdapterClient::SavePage, BrowserContextAdapterClient::NoReason }; @@ -283,6 +303,8 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(content::DownloadItem *downloa QString(), BrowserContextAdapterClient::UnknownSavePageFormat, true /* accepted */, + download->IsPaused(), + download->IsDone(), m_downloadType, download->GetLastReason() }; diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h index cd21d330c..aec83cb41 100644 --- a/src/core/download_manager_delegate_qt.h +++ b/src/core/download_manager_delegate_qt.h @@ -83,6 +83,8 @@ public: const content::SavePackagePathPickedCallback &callback) override; void cancelDownload(quint32 downloadId); + void pauseDownload(quint32 downloadId); + void resumeDownload(quint32 downloadId); void setDownloadType(int downloadType) { m_downloadType = downloadType; } diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp index bc40e6771..5afb19531 100644 --- a/src/webengine/api/qquickwebenginedownloaditem.cpp +++ b/src/webengine/api/qquickwebenginedownloaditem.cpp @@ -39,6 +39,8 @@ #include "qquickwebenginedownloaditem_p.h" #include "qquickwebenginedownloaditem_p_p.h" + +#include "browser_context_adapter.h" #include "qquickwebengineprofile_p.h" using QtWebEngineCore::BrowserContextAdapterClient; @@ -103,6 +105,8 @@ QQuickWebEngineDownloadItemPrivate::QQuickWebEngineDownloadItemPrivate(QQuickWeb , interruptReason(QQuickWebEngineDownloadItem::NoReason) , totalBytes(-1) , receivedBytes(0) + , downloadFinished(false) + , downloadPaused(false) { } @@ -145,6 +149,16 @@ void QQuickWebEngineDownloadItemPrivate::update(const BrowserContextAdapterClien totalBytes = info.totalBytes; Q_EMIT q->totalBytesChanged(); } + + if (info.done != downloadFinished) { + downloadFinished = info.done; + Q_EMIT q->isFinishedChanged(); + } + + if (info.paused != downloadPaused) { + downloadPaused = info.paused; + Q_EMIT q->isPausedChanged(); + } } void QQuickWebEngineDownloadItemPrivate::updateState(QQuickWebEngineDownloadItem::DownloadState newState) @@ -199,6 +213,46 @@ void QQuickWebEngineDownloadItem::cancel() } } + +/*! + \qmlmethod void WebEngineDownloadItem::pause() + \since QtWebEngine 1.6 + + Pauses the download. +*/ + +void QQuickWebEngineDownloadItem::pause() +{ + Q_D(QQuickWebEngineDownloadItem); + + QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (state != QQuickWebEngineDownloadItem::DownloadInProgress) + return; + + if (d->profile) + d->profile->d_ptr->browserContext()->pauseDownload(d->downloadId); +} + +/*! + \qmlmethod void WebEngineDownloadItem::resume() + \since QtWebEngine 1.6 + + Resumes the download if it was paused or interrupted. +*/ +void QQuickWebEngineDownloadItem::resume() +{ + Q_D(QQuickWebEngineDownloadItem); + + QQuickWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (d->downloadFinished || (state != QQuickWebEngineDownloadItem::DownloadInProgress && state != QQuickWebEngineDownloadItem::DownloadInterrupted)) + return; + + if (d->profile) + d->profile->d_ptr->browserContext()->resumeDownload(d->downloadId); +} + /*! \qmlproperty int WebEngineDownloadItem::id @@ -426,6 +480,34 @@ QString QQuickWebEngineDownloadItem::interruptReasonString() const static_cast<BrowserContextAdapterClient::DownloadInterruptReason>(interruptReason())); } +/*! + \qmlproperty bool WebEngineDownloadItem::isFinished + \readonly + \since QtWebEngine 1.6 + + Whether this download is finished (completed, cancelled, or non-resumable interrupted state). + */ + +bool QQuickWebEngineDownloadItem::isFinished() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadFinished; +} + +/*! + \qmlproperty bool WebEngineDownloadItem::isPaused + \readonly + \since QtWebEngine 1.6 + + Whether this download is paused. + */ + +bool QQuickWebEngineDownloadItem::isPaused() const +{ + Q_D(const QQuickWebEngineDownloadItem); + return d->downloadPaused; +} + 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 889d0bcb7..972b130aa 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p.h @@ -131,9 +131,13 @@ public: Q_PROPERTY(DownloadType type READ type NOTIFY typeChanged REVISION 3 FINAL) Q_PROPERTY(DownloadInterruptReason interruptReason READ interruptReason NOTIFY interruptReasonChanged REVISION 4 FINAL) Q_PROPERTY(QString interruptReasonString READ interruptReasonString NOTIFY interruptReasonChanged REVISION 4 FINAL) + Q_PROPERTY(bool isFinished READ isFinished NOTIFY isFinishedChanged REVISION 5 FINAL) + Q_PROPERTY(bool isPaused READ isPaused NOTIFY isPausedChanged REVISION 5 FINAL) Q_INVOKABLE void accept(); Q_INVOKABLE void cancel(); + Q_INVOKABLE void pause(); + Q_INVOKABLE void resume(); quint32 id() const; DownloadState state() const; @@ -147,6 +151,8 @@ public: DownloadType type() const; DownloadInterruptReason interruptReason() const; QString interruptReasonString() const; + bool isFinished() const; + bool isPaused() const; Q_SIGNALS: void stateChanged(); @@ -157,6 +163,8 @@ Q_SIGNALS: void pathChanged(); Q_REVISION(3) void typeChanged(); Q_REVISION(4) void interruptReasonChanged(); + Q_REVISION(5) void isFinishedChanged(); + Q_REVISION(5) void isPausedChanged(); 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 4fb609492..6b4f7c8d3 100644 --- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h +++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h @@ -79,6 +79,8 @@ public: qint64 receivedBytes; QString mimeType; QString downloadPath; + bool downloadFinished; + bool downloadPaused; void update(const QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info); void updateState(QQuickWebEngineDownloadItem::DownloadState newState); diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp index 668d55458..e58b2ab61 100644 --- a/src/webengine/plugin/plugin.cpp +++ b/src/webengine/plugin/plugin.cpp @@ -102,6 +102,8 @@ public: tr("Cannot create a separate instance of WebEngineDownloadItem")); qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 4>(uri, 1, 5, "WebEngineDownloadItem", tr("Cannot create a separate instance of WebEngineDownloadItem")); + qmlRegisterUncreatableType<QQuickWebEngineDownloadItem, 5>(uri, 1, 6, "WebEngineDownloadItem", + tr("Cannot create a separate instance of WebEngineDownloadItem")); qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest>(uri, 1, 1, "WebEngineNewViewRequest", msgUncreatableType("WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineNewViewRequest, 1>(uri, 1, 5, "WebEngineNewViewRequest", tr("Cannot create separate instance of WebEngineNewViewRequest")); qmlRegisterUncreatableType<QQuickWebEngineSettings>(uri, 1, 1, "WebEngineSettings", tr("Cannot create a separate instance of WebEngineSettings")); diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index c1d9a3698..a5569e408 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -38,10 +38,12 @@ ****************************************************************************/ #include "qwebenginedownloaditem.h" - #include "qwebenginedownloaditem_p.h" + +#include "browser_context_adapter.h" #include "qwebengineprofile_p.h" + QT_BEGIN_NAMESPACE using QtWebEngineCore::BrowserContextAdapterClient; @@ -116,6 +118,7 @@ QWebEngineDownloadItemPrivate::QWebEngineDownloadItemPrivate(QWebEngineProfilePr , type(QWebEngineDownloadItem::Attachment) , interruptReason(QWebEngineDownloadItem::NoReason) , downloadUrl(url) + , downloadPaused(false) , totalBytes(-1) , receivedBytes(0) { @@ -145,10 +148,16 @@ void QWebEngineDownloadItemPrivate::update(const BrowserContextAdapterClient::Do Q_EMIT q->downloadProgress(receivedBytes, totalBytes); } - downloadFinished = downloadState != QWebEngineDownloadItem::DownloadInProgress; + if (info.done != downloadFinished) { + downloadFinished = info.done; + if (downloadFinished) + Q_EMIT q->finished(); + } - if (downloadFinished) - Q_EMIT q->finished(); + if (downloadPaused != info.paused) { + downloadPaused = info.paused; + Q_EMIT q->isPausedChanged(downloadPaused); + } } /*! @@ -184,13 +193,50 @@ void QWebEngineDownloadItem::cancel() || state == QWebEngineDownloadItem::DownloadCancelled) return; - d->downloadState = QWebEngineDownloadItem::DownloadCancelled; - Q_EMIT stateChanged(d->downloadState); - // We directly cancel the download request if the user cancels // before it even started, so no need to notify the profile here. if (state == QWebEngineDownloadItem::DownloadInProgress) - d->profile->cancelDownload(d->downloadId); + d->profile->browserContext()->cancelDownload(d->downloadId); + else { + d->downloadState = QWebEngineDownloadItem::DownloadCancelled; + Q_EMIT stateChanged(d->downloadState); + } +} + +/*! + \since 5.10 + Pauses the current download. Has no effect if the state is not \c DownloadInProgress. + + \sa resume() +*/ + +void QWebEngineDownloadItem::pause() +{ + Q_D(QWebEngineDownloadItem); + + QWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (state != QWebEngineDownloadItem::DownloadInProgress) + return; + + d->profile->browserContext()->pauseDownload(d->downloadId); +} + +/*! + \since 5.10 + Resumes the current download if it was paused or interrupted. + + \sa pause(), isPaused(), state() +*/ +void QWebEngineDownloadItem::resume() +{ + Q_D(QWebEngineDownloadItem); + + QWebEngineDownloadItem::DownloadState state = d->downloadState; + + if (d->downloadFinished || (state != QWebEngineDownloadItem::DownloadInProgress && state != QWebEngineDownloadItem::DownloadInterrupted)) + return; + d->profile->browserContext()->resumeDownload(d->downloadId); } /*! @@ -206,12 +252,21 @@ quint32 QWebEngineDownloadItem::id() const /*! \fn QWebEngineDownloadItem::finished() - This signal is emitted whenever the download finishes. + This signal is emitted when the download finishes. \sa state(), isFinished() */ /*! + \fn QWebEngineDownloadItem::isPausedChanged(bool isPaused) + \since 5.10 + + This signal is emitted whenever \a isPaused changes. + + \sa pause(), isPaused() +*/ + +/*! \fn QWebEngineDownloadItem::stateChanged(DownloadState state) This signal is emitted whenever the download's \a state changes. @@ -407,7 +462,7 @@ void QWebEngineDownloadItem::setPath(QString path) } /*! - Returns whether this download is finished (not in progress). + Returns whether this download is finished (completed, cancelled, or non-resumable interrupted state). \sa finished(), state(), */ @@ -419,6 +474,18 @@ bool QWebEngineDownloadItem::isFinished() const } /*! + Returns whether this download is paused. + + \sa pause() +*/ + +bool QWebEngineDownloadItem::isPaused() const +{ + Q_D(const QWebEngineDownloadItem); + return d->downloadPaused; +} + +/*! Returns the format the web page will be saved in if this is a download request for a web page. \since 5.7 diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.h b/src/webenginewidgets/api/qwebenginedownloaditem.h index a4b6c08aa..2aca2bb2a 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem.h @@ -120,6 +120,7 @@ public: QString path() const; void setPath(QString path); bool isFinished() const; + bool isPaused() const; SavePageFormat savePageFormat() const; void setSavePageFormat(SavePageFormat format); DownloadType type() const; @@ -129,11 +130,14 @@ public: public Q_SLOTS: void accept(); void cancel(); + void pause(); + void resume(); Q_SIGNALS: void finished(); void stateChanged(QWebEngineDownloadItem::DownloadState state); void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); + void isPausedChanged(bool isPaused); private: Q_DISABLE_COPY(QWebEngineDownloadItem) diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h index 038332da3..da765e5c5 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h @@ -77,6 +77,7 @@ public: QString downloadPath; const QUrl downloadUrl; QString mimeType; + bool downloadPaused; qint64 totalBytes; qint64 receivedBytes; diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index cd4fc8b02..dae0cbdfc 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -172,11 +172,6 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate() m_ongoingDownloads.clear(); } -void QWebEngineProfilePrivate::cancelDownload(quint32 downloadId) -{ - browserContext()->cancelDownload(downloadId); -} - void QWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId) { m_ongoingDownloads.remove(downloadId); diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h index 4d31c5a81..c5a75f6d4 100644 --- a/src/webenginewidgets/api/qwebengineprofile_p.h +++ b/src/webenginewidgets/api/qwebengineprofile_p.h @@ -76,7 +76,6 @@ public: QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext() const { return m_browserContextRef; } QWebEngineSettings *settings() const { return m_settings; } - void cancelDownload(quint32 downloadId); void downloadDestroyed(quint32 downloadId); void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE; |