diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/api/qwebenginedownloadrequest.cpp | 51 | ||||
| -rw-r--r-- | src/core/api/qwebenginedownloadrequest_p.h | 5 | ||||
| -rw-r--r-- | src/core/api/qwebengineprofile.cpp | 24 | ||||
| -rw-r--r-- | src/core/download_manager_delegate_qt.cpp | 213 | ||||
| -rw-r--r-- | src/core/download_manager_delegate_qt.h | 9 | ||||
| -rw-r--r-- | src/core/profile_adapter.cpp | 9 | ||||
| -rw-r--r-- | src/core/profile_adapter.h | 3 | ||||
| -rw-r--r-- | src/core/profile_adapter_client.h | 14 | ||||
| -rw-r--r-- | src/webenginequick/api/qquickwebengineprofile.cpp | 21 |
9 files changed, 200 insertions, 149 deletions
diff --git a/src/core/api/qwebenginedownloadrequest.cpp b/src/core/api/qwebenginedownloadrequest.cpp index cbf46b448..107549f7e 100644 --- a/src/core/api/qwebenginedownloadrequest.cpp +++ b/src/core/api/qwebenginedownloadrequest.cpp @@ -9,6 +9,7 @@ #include "profile_adapter.h" #include "web_contents_adapter_client.h" +#include <QDir> #include <QFileInfo> QT_BEGIN_NAMESPACE @@ -81,11 +82,9 @@ static inline QWebEngineDownloadRequest::DownloadInterruptReason toDownloadInter requests, which it does by emitting the \l{QWebEngineProfile::downloadRequested}{downloadRequested} signal together with a newly created QWebEngineDownloadRequest. The application can then - examine this item and decide whether to accept it or not. A signal handler - must explicitly call accept() on the item for \QWE to actually start - downloading and writing data to disk. If no signal handler calls accept(), - then the download request will be automatically rejected and nothing will be - written to disk. + examine this item and decide whether to accept it or not. When a decision is + made, the application must explicitly call accept() or cancel() on the item + for \QWE to actually start downloading or rejecting the request. \note Some properties, such as setting the path and file name where the file will be saved (see \l downloadDirectory() and \l downloadFileName()), can @@ -93,18 +92,10 @@ static inline QWebEngineDownloadRequest::DownloadInterruptReason toDownloadInter \section2 Object Life Cycle - All items are guaranteed to be valid during the emission of the - \l{QWebEngineProfile::downloadRequested}{downloadRequested} signal. If - accept() is \e not called by any signal handler, then the item will be - deleted \e immediately after signal emission. This means that the - application \b{must not} keep references to rejected download items. It also - means the application should not use a queued connection to this signal. - - If accept() \e is called by a signal handler, then the QWebEngineProfile - will take ownership of the item. However, it is safe for the application to - delete the item at any time, except during the handling of the - \l{QWebEngineProfile::downloadRequested}{downloadRequested} signal. The - QWebEngineProfile being a long-lived object, it is in fact recommended that + In each and every case, the QWebEngineProfile takes the ownership of the item. + However, it is safe for the application to delete the item at any time, except + during the handling of the \l{QWebEngineProfile::downloadRequested}{downloadRequested} + signal. The QWebEngineProfile being a long-lived object, it is in fact recommended that the application delete any items it is no longer interested in. \note Deleting an item will also automatically cancel a download since 5.12.2, @@ -119,6 +110,12 @@ static inline QWebEngineDownloadRequest::DownloadInterruptReason toDownloadInter into a special file format (\l savePageFormat). To check if a download is for a file or a web page, use \l isSavePageDownload. + Web page save requests are accepted automatically and started from + \l DownloadInProgress state by convenience reasons. The first directly connected + \l{QWebEngineProfile::downloadRequested}{downloadRequested} signal handler + can prevent this by calling cancel(), otherwise the save operation will start + writing data to the disk. + \sa QWebEngineProfile, QWebEngineProfile::downloadRequested, QWebEnginePage::download, QWebEnginePage::save */ @@ -137,7 +134,9 @@ void QWebEngineDownloadRequestPrivate::update(const ProfileAdapterClient::Downlo { Q_Q(QWebEngineDownloadRequest); - Q_ASSERT(downloadState != QWebEngineDownloadRequest::DownloadRequested); + // Don't change download state until users accept/cancel the request + if (!answered && downloadState == QWebEngineDownloadRequest::DownloadRequested) + return; if (toDownloadInterruptReason(info.downloadInterruptReason) != interruptReason) { interruptReason = toDownloadInterruptReason(info.downloadInterruptReason); @@ -178,6 +177,20 @@ void QWebEngineDownloadRequestPrivate::setFinished() Q_EMIT q_ptr->isFinishedChanged(); } +void QWebEngineDownloadRequestPrivate::answer() +{ + if (answered) + return; + + if (profileAdapter) { + QString path = QDir(downloadDirectory).filePath(downloadFileName); + bool accepted = downloadState != QWebEngineDownloadRequest::DownloadCancelled + && downloadState != QWebEngineDownloadRequest::DownloadRequested; + profileAdapter->acceptDownload(downloadId, accepted, useDownloadTargetCallback, path, savePageFormat); + answered = true; + } +} + /*! Accepts the current download request, which will start the download. @@ -197,6 +210,7 @@ void QWebEngineDownloadRequest::accept() d->downloadState = QWebEngineDownloadRequest::DownloadInProgress; Q_EMIT stateChanged(d->downloadState); + d->answer(); } /*! @@ -239,6 +253,7 @@ void QWebEngineDownloadRequest::cancel() Q_EMIT stateChanged(d->downloadState); d->setFinished(); } + d->answer(); } /*! diff --git a/src/core/api/qwebenginedownloadrequest_p.h b/src/core/api/qwebenginedownloadrequest_p.h index eef6c9bb5..e829f94b1 100644 --- a/src/core/api/qwebenginedownloadrequest_p.h +++ b/src/core/api/qwebenginedownloadrequest_p.h @@ -36,6 +36,7 @@ public: void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info); void setFinished(); + void answer(); bool downloadFinished = false; quint32 downloadId = -1; @@ -56,10 +57,14 @@ public: bool isCustomFileName = false; qint64 totalBytes = -1; qint64 receivedBytes = 0; + // The user initiated the download by saving the page bool isSavePageDownload = false; + // Which type of callback should be called when the request is answered + bool useDownloadTargetCallback = true; QWebEngineDownloadRequest *q_ptr; QPointer<QtWebEngineCore::ProfileAdapter> profileAdapter; QtWebEngineCore::WebContentsAdapterClient *adapterClient = nullptr; + bool answered = false; Q_DECLARE_PUBLIC(QWebEngineDownloadRequest) }; diff --git a/src/core/api/qwebengineprofile.cpp b/src/core/api/qwebengineprofile.cpp index b0824af35..1c5807a93 100644 --- a/src/core/api/qwebengineprofile.cpp +++ b/src/core/api/qwebengineprofile.cpp @@ -17,7 +17,7 @@ #include "visited_links_manager_qt.h" #include "web_engine_settings.h" -#include <QDir> +#include <QFileInfo> #include <QtWebEngineCore/qwebengineurlscheme.h> QT_BEGIN_NAMESPACE @@ -220,6 +220,12 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) { Q_Q(QWebEngineProfile); + if (!q->receivers(SIGNAL(downloadRequested(QWebEngineDownloadRequest *)))) { + m_profileAdapter->acceptDownload(info.id, info.accepted, info.useDownloadTargetCallback, info.path, + info.savePageFormat); + return; + } + Q_ASSERT(!m_ongoingDownloads.contains(info.id)); QWebEngineDownloadRequestPrivate *itemPrivate = new QWebEngineDownloadRequestPrivate(m_profileAdapter); @@ -235,6 +241,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) itemPrivate->mimeType = info.mimeType; itemPrivate->savePageFormat = static_cast<QWebEngineDownloadRequest::SavePageFormat>(info.savePageFormat); itemPrivate->isSavePageDownload = info.isSavePageDownload; + itemPrivate->useDownloadTargetCallback = info.useDownloadTargetCallback; if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::WidgetsClient) itemPrivate->adapterClient = info.page; else @@ -247,18 +254,9 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) Q_EMIT q->downloadRequested(download); - QWebEngineDownloadRequest::DownloadState state = download->state(); - - info.path = QDir(download->downloadDirectory()).filePath(download->downloadFileName()); - info.savePageFormat = static_cast<QtWebEngineCore::ProfileAdapterClient::SavePageFormat>( - download->savePageFormat()); - info.accepted = state != QWebEngineDownloadRequest::DownloadCancelled; - - if (state == QWebEngineDownloadRequest::DownloadRequested) { - // Delete unaccepted downloads. - info.accepted = false; - delete download; - } + // Callbacks of automatically accepted save operations have to be called here + if (info.isSavePageDownload && info.accepted) + itemPrivate->answer(); } void QWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info) diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index 7ccd063ff..88c8b0039 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -58,6 +58,8 @@ void DownloadManagerDelegateQt::cancelDownload(download::DownloadTargetCallback bool DownloadManagerDelegateQt::cancelDownload(quint32 downloadId) { + m_pendingDownloads.erase(downloadId); + m_pendingSaves.erase(downloadId); if (download::DownloadItem *download = findDownloadById(downloadId)) { download->Cancel(/* user_cancel */ true); return true; @@ -81,6 +83,8 @@ void DownloadManagerDelegateQt::removeDownload(quint32 downloadId) { if (download::DownloadItem *download = findDownloadById(downloadId)) download->Remove(); + m_pendingDownloads.erase(downloadId); + m_pendingSaves.erase(downloadId); } bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem *item, @@ -164,69 +168,69 @@ bool DownloadManagerDelegateQt::DetermineDownloadTarget(download::DownloadItem * QList<ProfileAdapterClient*> clients = m_profileAdapter->clients(); if (!clients.isEmpty()) { Q_ASSERT(m_currentId == item->GetId()); - ProfileAdapterClient::DownloadItemInfo info = { - item->GetId(), - toQt(item->GetURL()), - item->GetState(), - item->GetTotalBytes(), - item->GetReceivedBytes(), - mimeTypeString, - suggestedFilePath, - ProfileAdapterClient::UnknownSavePageFormat, - acceptedByDefault, - false /* paused */, - false /* done */, - isSavePageDownload, - item->GetLastReason(), - adapterClient, - suggestedFilename, - item->GetStartTime().ToTimeT() - }; - for (ProfileAdapterClient *client : std::as_const(clients)) { - client->downloadRequested(info); - if (info.accepted) - break; - } - - QFileInfo suggestedFile(info.path); - - if (info.accepted && !suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) { -#if defined(Q_OS_WIN) - // TODO: Remove this when https://bugreports.qt.io/browse/QTBUG-85997 is fixed. - QDir suggestedDir = QDir(suggestedFile.absolutePath()); - if (!suggestedDir.isRoot() || !suggestedDir.exists()) { -#endif - qWarning("Creating download path failed, download cancelled: %s", suggestedFile.absolutePath().toUtf8().data()); - info.accepted = false; -#if defined(Q_OS_WIN) - } -#endif - } - - if (!info.accepted) { - cancelDownload(std::move(*callback)); - return true; - } - - base::FilePath filePathForCallback(toFilePathString(suggestedFile.absoluteFilePath())); - download::DownloadTargetInfo target_info; - target_info.target_disposition = download::DownloadItem::TARGET_DISPOSITION_OVERWRITE; - target_info.danger_type = download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT; - target_info.insecure_download_status = download::DownloadItem::VALIDATED; - target_info.mime_type = item->GetMimeType(); - target_info.intermediate_path = - filePathForCallback.AddExtension(toFilePathString("download")); - target_info.display_name = base::FilePath(); - target_info.target_path = filePathForCallback; - target_info.interrupt_reason = download::DOWNLOAD_INTERRUPT_REASON_NONE; - std::move(*callback).Run(std::move(target_info)); + ProfileAdapterClient::DownloadItemInfo info = {}; + info.id = item->GetId(); + info.url = toQt(item->GetURL()); + info.state = item->GetState(); + info.totalBytes = item->GetTotalBytes(); + info.receivedBytes = item->GetReceivedBytes(); + info.mimeType = mimeTypeString; + info.path = suggestedFilePath; + info.savePageFormat = ProfileAdapterClient::UnknownSavePageFormat; + info.accepted = acceptedByDefault; + info.paused = false; + info.done = false; + info.isSavePageDownload = isSavePageDownload; + info.useDownloadTargetCallback = true; + info.downloadInterruptReason = item->GetLastReason(); + info.page = adapterClient; + info.suggestedFileName = suggestedFilename; + info.startTime = item->GetStartTime().ToTimeT(); + + m_pendingDownloads.emplace(m_currentId, std::move(*callback)); + clients[0]->downloadRequested(info); } else cancelDownload(std::move(*callback)); return true; } +void DownloadManagerDelegateQt::downloadTargetDetermined(quint32 downloadId, bool accepted, + const QString &path) +{ + if (!m_pendingDownloads.contains(downloadId)) + return; + auto callback = std::move(m_pendingDownloads.find(downloadId)->second); + m_pendingDownloads.erase(downloadId); + + download::DownloadItem *item = findDownloadById(downloadId); + if (!accepted || !item) { + cancelDownload(std::move(callback)); + return; + } + + QFileInfo suggestedFile(path); + if (!suggestedFile.absoluteDir().mkpath(suggestedFile.absolutePath())) { + qWarning() << "Creating download path failed, download cancelled:" << suggestedFile.absolutePath(); + cancelDownload(std::move(callback)); + return; + } + base::FilePath targetPath(toFilePathString(suggestedFile.absoluteFilePath())); + + download::DownloadTargetInfo target_info; + target_info.target_disposition = download::DownloadItem::TARGET_DISPOSITION_OVERWRITE; + target_info.danger_type = download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT; + target_info.insecure_download_status = download::DownloadItem::VALIDATED; + target_info.mime_type = item->GetMimeType(); + target_info.intermediate_path = + targetPath.AddExtension(toFilePathString("download")); + target_info.display_name = base::FilePath(); + target_info.target_path = targetPath; + target_info.interrupt_reason = download::DOWNLOAD_INTERRUPT_REASON_NONE; + std::move(callback).Run(std::move(target_info)); +} + void DownloadManagerDelegateQt::GetSaveDir(content::BrowserContext* browser_context, base::FilePath* website_save_dir, base::FilePath* download_save_dir) @@ -279,38 +283,46 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content if (web_contents) adapterClient = static_cast<WebContentsDelegateQt *>(web_contents->GetDelegate())->adapterClient(); + ProfileAdapterClient::DownloadItemInfo info = {}; // Chromium doesn't increase download ID when saving page. - ProfileAdapterClient::DownloadItemInfo info = { - ++m_currentId, - toQt(web_contents->GetURL()), - download::DownloadItem::IN_PROGRESS, - -1, /* totalBytes */ - 0, /* receivedBytes */ - QStringLiteral("application/x-mimearchive"), - suggestedFilePath, - suggestedSaveFormat, - acceptedByDefault, - false, /* paused */ - false, /* done */ - true, /* isSavePageDownload */ - ProfileAdapterClient::NoReason, - adapterClient, - QFileInfo(suggestedFilePath).fileName(), - QDateTime::currentMSecsSinceEpoch() - }; - - for (ProfileAdapterClient *client : std::as_const(clients)) { - client->downloadRequested(info); - if (info.accepted) - break; + info.id = ++m_currentId; + info.url = toQt(web_contents->GetURL()); + info.state = download::DownloadItem::IN_PROGRESS; + info.totalBytes = -1; + info.receivedBytes = 0; + info.mimeType = QStringLiteral("application/x-mimearchive"); + info.path = suggestedFilePath; + info.savePageFormat = suggestedSaveFormat; + info.accepted = acceptedByDefault; + info.paused = false; + info.done = false; + info.isSavePageDownload = true; + info.useDownloadTargetCallback = false; + info.downloadInterruptReason = ProfileAdapterClient::NoReason; + info.page = adapterClient; + info.suggestedFileName = QFileInfo(suggestedFilePath).fileName(); + info.startTime = QDateTime::currentMSecsSinceEpoch(); + + m_pendingSaves.emplace(m_currentId, std::move(callback)); + clients[0]->downloadRequested(info); +} + +void DownloadManagerDelegateQt::savePathDetermined(quint32 downloadId, bool accepted, + const QString &path, int format) +{ + if (!accepted) { + m_pendingSaves.erase(downloadId); + return; } - if (!info.accepted) + if (!m_pendingSaves.contains(downloadId)) return; + auto callback = std::move(m_pendingSaves.find(downloadId)->second); + m_pendingSaves.erase(downloadId); content::SavePackagePathPickedParams params; - params.file_path = toFilePath(info.path); - params.save_type = static_cast<content::SavePageType>(info.savePageFormat); + params.file_path = toFilePath(path); + params.save_type = static_cast<content::SavePageType>(format); std::move(callback).Run(std::move(params), base::BindOnce(&DownloadManagerDelegateQt::savePackageDownloadCreated, m_weakPtrFactory.GetWeakPtr())); @@ -331,24 +343,25 @@ void DownloadManagerDelegateQt::OnDownloadUpdated(download::DownloadItem *downlo if (webContents) adapterClient = static_cast<WebContentsDelegateQt *>(webContents->GetDelegate())->adapterClient(); - ProfileAdapterClient::DownloadItemInfo info = { - download->GetId(), - toQt(download->GetURL()), - download->GetState(), - download->GetTotalBytes(), - download->GetReceivedBytes(), - toQt(download->GetMimeType()), - QString(), - ProfileAdapterClient::UnknownSavePageFormat, - true /* accepted */, - download->IsPaused(), - download->IsDone(), - 0 /* downloadType (unused) */, - download->GetLastReason(), - adapterClient, - toQt(download->GetSuggestedFilename()), - download->GetStartTime().ToTimeT() - }; + ProfileAdapterClient::DownloadItemInfo info = {}; + // Chromium doesn't increase download ID when saving page. + info.id = download->GetId(); + info.url = toQt(download->GetURL()); + info.state = download->GetState(); + info.totalBytes = download->GetTotalBytes(); + info.receivedBytes = download->GetReceivedBytes(); + info.mimeType = toQt(download->GetMimeType()); + info.path = QString(); + info.savePageFormat = ProfileAdapterClient::UnknownSavePageFormat; + info.accepted = true; + info.paused = download->IsPaused(); + info.done = download->IsDone(); + info.isSavePageDownload = false; // unused + info.useDownloadTargetCallback = false; // unused + info.downloadInterruptReason = download->GetLastReason(); + info.page = adapterClient; + info.suggestedFileName = toQt(download->GetSuggestedFilename()); + info.startTime = download->GetStartTime().ToTimeT(); for (ProfileAdapterClient *client : std::as_const(clients)) { client->downloadUpdated(info); diff --git a/src/core/download_manager_delegate_qt.h b/src/core/download_manager_delegate_qt.h index e7dfad29d..3b7ccc1c4 100644 --- a/src/core/download_manager_delegate_qt.h +++ b/src/core/download_manager_delegate_qt.h @@ -7,7 +7,11 @@ #include "content/public/browser/download_manager_delegate.h" #include <base/memory/weak_ptr.h> +#include <QString> #include <QtGlobal> +#include <map> + +#include "profile_adapter_client.h" namespace base { class FilePath; @@ -51,6 +55,9 @@ public: void resumeDownload(quint32 downloadId); void removeDownload(quint32 downloadId); + void downloadTargetDetermined(quint32 downloadId, bool accepted, const QString &path); + void savePathDetermined(quint32 downloadId, bool accepted, const QString &path, int format); + // Inherited from content::DownloadItem::Observer void OnDownloadUpdated(download::DownloadItem *download) override; void OnDownloadDestroyed(download::DownloadItem *download) override; @@ -62,6 +69,8 @@ private: ProfileAdapter *m_profileAdapter; uint32_t m_currentId; + std::map<quint32, download::DownloadTargetCallback> m_pendingDownloads; + std::map<quint32, content::SavePackagePathPickedCallback> m_pendingSaves; base::WeakPtrFactory<DownloadManagerDelegateQt> m_weakPtrFactory; }; diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp index 3f2fa259f..db917b346 100644 --- a/src/core/profile_adapter.cpp +++ b/src/core/profile_adapter.cpp @@ -221,6 +221,15 @@ void ProfileAdapter::removeDownload(quint32 downloadId) downloadManagerDelegate()->removeDownload(downloadId); } +void ProfileAdapter::acceptDownload(quint32 downloadId, bool accepted, bool useDownloadTargetCallback, + const QString &path, int savePageFormat) +{ + if (useDownloadTargetCallback) + downloadManagerDelegate()->downloadTargetDetermined(downloadId, accepted, path); + else + downloadManagerDelegate()->savePathDetermined(downloadId, accepted, path, savePageFormat); +} + ProfileAdapter *ProfileAdapter::createDefaultProfileAdapter() { return WebEngineContext::current()->createDefaultProfileAdapter(); diff --git a/src/core/profile_adapter.h b/src/core/profile_adapter.h index 066286321..4301cd8a2 100644 --- a/src/core/profile_adapter.h +++ b/src/core/profile_adapter.h @@ -77,6 +77,9 @@ public: void pauseDownload(quint32 downloadId); void resumeDownload(quint32 downloadId); void removeDownload(quint32 downloadId); + void acceptDownload(quint32 downloadId, bool accepted, + bool useDownloadTargetCallback, const QString &path, + int savePageFormat); ProfileQt *profile(); bool ensureDataPathExists(); diff --git a/src/core/profile_adapter_client.h b/src/core/profile_adapter_client.h index 06ac0de8b..aaeefb544 100644 --- a/src/core/profile_adapter_client.h +++ b/src/core/profile_adapter_client.h @@ -82,19 +82,19 @@ public: }; struct DownloadItemInfo { - const quint32 id; - const QUrl url; - const int state; - const qint64 totalBytes; - const qint64 receivedBytes; - const QString mimeType; - + quint32 id; + QUrl url; + int state; + qint64 totalBytes; + qint64 receivedBytes; + QString mimeType; QString path; int savePageFormat; bool accepted; bool paused; bool done; bool isSavePageDownload; + bool useDownloadTargetCallback; int downloadInterruptReason; WebContentsAdapterClient *page; QString suggestedFileName; diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp index e3f151646..da638d176 100644 --- a/src/webenginequick/api/qquickwebengineprofile.cpp +++ b/src/webenginequick/api/qquickwebengineprofile.cpp @@ -246,6 +246,12 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) { Q_Q(QQuickWebEngineProfile); + if (!q->receivers(SIGNAL(downloadRequested(QQuickWebEngineDownloadRequest *)))) { + m_profileAdapter->acceptDownload(info.id, info.accepted, info.useDownloadTargetCallback, info.path, + info.savePageFormat); + return; + } + Q_ASSERT(!m_ongoingDownloads.contains(info.id)); QWebEngineDownloadRequestPrivate *itemPrivate = new QWebEngineDownloadRequestPrivate(m_profileAdapter); @@ -262,6 +268,7 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) itemPrivate->savePageFormat = static_cast<QWebEngineDownloadRequest::SavePageFormat>( info.savePageFormat); itemPrivate->isSavePageDownload = info.isSavePageDownload; + itemPrivate->useDownloadTargetCallback = info.useDownloadTargetCallback; if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::QmlClient) itemPrivate->adapterClient = info.page; else @@ -275,17 +282,9 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) QQmlEngine::setObjectOwnership(download, QQmlEngine::JavaScriptOwnership); Q_EMIT q->downloadRequested(download); - QWebEngineDownloadRequest::DownloadState state = download->state(); - info.path = QDir(download->downloadDirectory()).filePath(download->downloadFileName()); - info.savePageFormat = itemPrivate->savePageFormat; - info.accepted = state != QWebEngineDownloadRequest::DownloadCancelled - && state != QWebEngineDownloadRequest::DownloadRequested; - - if (state == QWebEngineDownloadRequest::DownloadRequested) { - // Delete unaccepted downloads. - info.accepted = false; - delete download; - } + // Callbacks of automatically accepted save operations have to be called here + if (info.isSavePageDownload && info.accepted) + itemPrivate->answer(); } void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info) |
