diff options
Diffstat (limited to 'src/webenginewidgets/api')
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem.cpp | 23 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginedownloaditem_p.h | 4 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 34 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage_p.h | 1 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile.cpp | 40 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineprofile_p.h | 5 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineview.cpp | 2 |
7 files changed, 79 insertions, 30 deletions
diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index 55d4fcca8..deb92bfd3 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -197,11 +197,8 @@ void QWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::DownloadI Q_EMIT q->downloadProgress(receivedBytes, totalBytes); } - if (info.done != downloadFinished) { - downloadFinished = info.done; - if (downloadFinished) - Q_EMIT q->finished(); - } + if (info.done) + setFinished(); if (downloadPaused != info.paused) { downloadPaused = info.paused; @@ -209,6 +206,15 @@ void QWebEngineDownloadItemPrivate::update(const ProfileAdapterClient::DownloadI } } +void QWebEngineDownloadItemPrivate::setFinished() +{ + if (downloadFinished) + return; + + downloadFinished = true; + Q_EMIT q_ptr->finished(); +} + /*! Accepts the current download request, which will start the download. @@ -262,6 +268,7 @@ void QWebEngineDownloadItem::cancel() } else { d->downloadState = QWebEngineDownloadItem::DownloadCancelled; Q_EMIT stateChanged(d->downloadState); + d->setFinished(); } } @@ -653,8 +660,10 @@ QWebEngineDownloadItem::QWebEngineDownloadItem(QWebEngineDownloadItemPrivate *p, */ QWebEngineDownloadItem::~QWebEngineDownloadItem() { - if (auto profileAdapter = d_ptr->profile->profileAdapter()) - profileAdapter->removeDownload(d_ptr->downloadId); + // MEMO Items are owned by profile by default and will be destroyed on profile's destruction + // It's not safe to access profile in that case, so we rely on profile to clean up items + if (!isFinished()) + cancel(); } QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebenginedownloaditem_p.h b/src/webenginewidgets/api/qwebenginedownloaditem_p.h index bdcda5be6..b3bc8a3fe 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem_p.h +++ b/src/webenginewidgets/api/qwebenginedownloaditem_p.h @@ -53,7 +53,7 @@ #include "qtwebenginewidgetsglobal.h" -#include "qwebenginedownloaditem_p.h" +#include "qwebenginedownloaditem.h" #include "qwebengineprofile_p.h" #include <QString> @@ -84,6 +84,8 @@ public: QWebEnginePage *page; void update(const QtWebEngineCore::ProfileAdapterClient::DownloadItemInfo &info); + + void setFinished(); }; QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index b1e7cce4e..696b6723f 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -177,6 +177,8 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile) ensureInitialized(); wasShown(); }); + + profile->d_ptr->addWebContentsAdapterClient(this); } QWebEnginePagePrivate::~QWebEnginePagePrivate() @@ -185,6 +187,7 @@ QWebEnginePagePrivate::~QWebEnginePagePrivate() profile->d_ptr->profileAdapter()->removePageRequestInterceptor(); delete history; delete settings; + profile->d_ptr->removeWebContentsAdapterClient(this); } RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client) @@ -479,6 +482,13 @@ void QWebEnginePagePrivate::authenticationRequired(QSharedPointer<Authentication controller->accept(networkAuth.user(), networkAuth.password()); } +void QWebEnginePagePrivate::releaseProfile() +{ + qDebug("Release of profile requested but WebEnginePage still not deleted. Expect troubles !"); + // this is not the way to go, but might avoid the crash if user code does not make any calls to page. + delete q_ptr->d_ptr.take(); +} + void QWebEnginePagePrivate::showColorDialog(QSharedPointer<ColorChooserController> controller) { #if QT_CONFIG(colordialog) @@ -845,7 +855,7 @@ QWebEnginePage::QWebEnginePage(QObject* parent) \property QWebEnginePage::contentsSize \since 5.7 - The size of the page contents. + \brief The size of the page contents. */ /*! @@ -907,11 +917,13 @@ QWebEnginePage::QWebEnginePage(QWebEngineProfile *profile, QObject* parent) QWebEnginePage::~QWebEnginePage() { - Q_D(QWebEnginePage); - setDevToolsPage(nullptr); - d->adapter->stopFinding(); - QWebEnginePagePrivate::bindPageAndView(this, nullptr); - QWebEnginePagePrivate::bindPageAndWidget(this, nullptr); + if (d_ptr) { + // d_ptr might be exceptionally null if profile adapter got deleted first + setDevToolsPage(nullptr); + d_ptr->adapter->stopFinding(); + QWebEnginePagePrivate::bindPageAndView(this, nullptr); + QWebEnginePagePrivate::bindPageAndWidget(this, nullptr); + } } QWebEngineHistory *QWebEnginePage::history() const @@ -994,7 +1006,7 @@ void QWebEnginePage::setWebChannel(QWebChannel *channel, uint worldId) /*! \property QWebEnginePage::backgroundColor - \brief the page's background color behind the document's body. + \brief The page's background color behind the document's body. \since 5.6 You can set the background color to Qt::transparent or to a translucent @@ -1045,7 +1057,7 @@ void QWebEnginePage::save(const QString &filePath, /*! \property QWebEnginePage::audioMuted - \brief whether the current page audio is muted. + \brief Whether the current page audio is muted. \since 5.7 The default value is \c false. @@ -1067,7 +1079,7 @@ void QWebEnginePage::setAudioMuted(bool muted) { /*! \property QWebEnginePage::recentlyAudible - \brief the current page's \e {audible state}, that is, whether audio was recently played + \brief The current page's \e {audible state}, that is, whether audio was recently played or not. \since 5.7 @@ -2022,7 +2034,7 @@ QUrl QWebEnginePage::requestedUrl() const /*! \property QWebEnginePage::iconUrl - \brief the URL of the icon associated with the page currently viewed + \brief The URL of the icon associated with the page currently viewed. By default, this property contains an empty URL. @@ -2036,7 +2048,7 @@ QUrl QWebEnginePage::iconUrl() const /*! \property QWebEnginePage::icon - \brief the icon associated with the page currently viewed + \brief The icon associated with the page currently viewed. \since 5.7 By default, this property contains a null icon. If the web page specifies more than one icon, diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index d597383e2..0db462a0a 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -130,6 +130,7 @@ public: void passOnFocus(bool reverse) override; void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID) override; void authenticationRequired(QSharedPointer<QtWebEngineCore::AuthenticationDialogController>) override; + void releaseProfile() override; void runMediaAccessPermissionRequest(const QUrl &securityOrigin, MediaRequestFlags requestFlags) override; void runGeolocationPermissionRequest(const QUrl &securityOrigin) override; void runUserNotificationPermissionRequest(const QUrl &securityOrigin) override; diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index e183a66e1..50de63e9a 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -182,13 +182,6 @@ QWebEngineProfilePrivate::~QWebEngineProfilePrivate() m_profileAdapter->removeClient(this); } - for (QWebEngineDownloadItem *download : qAsConst(m_ongoingDownloads)) { - if (download) - download->cancel(); - } - - m_ongoingDownloads.clear(); - if (m_profileAdapter != QtWebEngineCore::ProfileAdapter::defaultProfileAdapter()) delete m_profileAdapter; @@ -203,6 +196,23 @@ ProfileAdapter* QWebEngineProfilePrivate::profileAdapter() const void QWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId) { m_ongoingDownloads.remove(downloadId); + if (m_profileAdapter) + m_profileAdapter->removeDownload(downloadId); +} + +void QWebEngineProfilePrivate::cleanDownloads() +{ + for (auto download : m_ongoingDownloads.values()) { + if (!download) + continue; + + if (!download->isFinished()) + download->cancel(); + + if (m_profileAdapter) + m_profileAdapter->removeDownload(download->id()); + } + m_ongoingDownloads.clear(); } void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) @@ -226,6 +236,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) QWebEngineDownloadItem *download = new QWebEngineDownloadItem(itemPrivate, q); m_ongoingDownloads.insert(info.id, download); + QObject::connect(download, &QWebEngineDownloadItem::destroyed, q, [id = info.id, this] () { downloadDestroyed(id); }); Q_EMIT q->downloadRequested(download); @@ -239,7 +250,6 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) if (state == QWebEngineDownloadItem::DownloadRequested) { // Delete unaccepted downloads. info.accepted = false; - m_ongoingDownloads.remove(info.id); delete download; } } @@ -257,9 +267,18 @@ void QWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info) } download->d_func()->update(info); +} - if (download->isFinished()) - m_ongoingDownloads.remove(info.id); +void QWebEngineProfilePrivate::addWebContentsAdapterClient(QtWebEngineCore::WebContentsAdapterClient *adapter) +{ + Q_ASSERT(m_profileAdapter); + m_profileAdapter->addWebContentsAdapterClient(adapter); +} + +void QWebEngineProfilePrivate::removeWebContentsAdapterClient(QtWebEngineCore::WebContentsAdapterClient *adapter) +{ + Q_ASSERT(m_profileAdapter); + m_profileAdapter->removeWebContentsAdapterClient(adapter); } /*! @@ -308,6 +327,7 @@ QWebEngineProfile::QWebEngineProfile(QWebEngineProfilePrivate *privatePtr, QObje */ QWebEngineProfile::~QWebEngineProfile() { + d_ptr->cleanDownloads(); } /*! diff --git a/src/webenginewidgets/api/qwebengineprofile_p.h b/src/webenginewidgets/api/qwebengineprofile_p.h index 3dd024ffd..91c43cf0a 100644 --- a/src/webenginewidgets/api/qwebengineprofile_p.h +++ b/src/webenginewidgets/api/qwebengineprofile_p.h @@ -84,11 +84,16 @@ public: void downloadDestroyed(quint32 downloadId); + void cleanDownloads(); + void downloadRequested(DownloadItemInfo &info) override; void downloadUpdated(const DownloadItemInfo &info) override; void showNotification(QSharedPointer<QtWebEngineCore::UserNotificationController> &) override; + void addWebContentsAdapterClient(QtWebEngineCore::WebContentsAdapterClient *adapter) override; + void removeWebContentsAdapterClient(QtWebEngineCore::WebContentsAdapterClient *adapter) override; + private: QWebEngineProfile *q_ptr; QWebEngineSettings *m_settings; diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index 576baad17..966b30100 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -238,7 +238,7 @@ QUrl QWebEngineView::iconUrl() const /*! \property QWebEngineView::icon - \brief the icon associated with the page currently viewed + \brief The icon associated with the page currently viewed. \since 5.7 By default, this property contains a null icon. |