diff options
| author | Szabolcs David <davidsz@inf.u-szeged.hu> | 2024-03-08 14:52:54 +0100 |
|---|---|---|
| committer | Szabolcs David <davidsz@inf.u-szeged.hu> | 2024-10-24 16:11:06 +0200 |
| commit | 21ce229776c8ed7a7576702b7850bd862fa45411 (patch) | |
| tree | 086d801af4ed09bd58665a236033782104862849 /src/core/api/qwebengineprofile.cpp | |
| parent | 3152d20bac5ff7457bb7a0be0fe48f8b1df6067d (diff) | |
Make download API asynchronous
Modify the already existing downloadRequest() API. Now the requests
not necessarily have to be answered in a directly connected signal
handler and the API users can postpone their user's decision.
The only exceptions are automatically accepted save page requests. There
is no better place to call their callback than directly after the signal
emission.
Adapt auto tests to the new lifecycle of download items. Modify the
quicknanobrowser example to use a simple async method to wait for the
user's decision. Keep simplebrowser to use its old synchronous method
to illustrate that it's still possible. Correct documentation at some
places.
[ChangeLog] QWebEngineProfile::downloadRequested() is not limited to
synchronous usage anymore. QWebEngineDownloadRequest can be accepted
or rejected later without blocking the browsing session.
Fixes: QTBUG-118584
Change-Id: Ic1be6508126574dc77aa686f85bf35feafdb080d
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'src/core/api/qwebengineprofile.cpp')
| -rw-r--r-- | src/core/api/qwebengineprofile.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
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) |
