diff options
-rw-r--r-- | src/core/api/qwebenginepage.cpp | 28 | ||||
-rw-r--r-- | src/core/api/qwebenginepage.h | 5 | ||||
-rw-r--r-- | tests/auto/widgets/loadsignals/tst_loadsignals.cpp | 15 |
3 files changed, 42 insertions, 6 deletions
diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp index 5298849f8..d073b4996 100644 --- a/src/core/api/qwebenginepage.cpp +++ b/src/core/api/qwebenginepage.cpp @@ -301,20 +301,23 @@ QColor QWebEnginePagePrivate::backgroundColor() const return m_backgroundColor; } -void QWebEnginePagePrivate::loadStarted(QWebEngineLoadingInfo /* info */) +void QWebEnginePagePrivate::loadStarted(QWebEngineLoadingInfo info) { Q_Q(QWebEnginePage); isLoading = true; - QTimer::singleShot(0, q, &QWebEnginePage::loadStarted); + QTimer::singleShot(0, q, [q, info = std::move(info)] () { + Q_EMIT q->loadStarted(); + Q_EMIT q->loadingChanged(info); + }); } void QWebEnginePagePrivate::loadFinished(QWebEngineLoadingInfo info) { Q_Q(QWebEnginePage); isLoading = false; - bool success = info.status() == QWebEngineLoadingInfo::LoadSucceededStatus; - QTimer::singleShot(0, q, [q, success] () { - emit q->loadFinished(success); + QTimer::singleShot(0, q, [q, info = std::move(info)] () { + Q_EMIT q->loadFinished(info.status() == QWebEngineLoadingInfo::LoadSucceededStatus); + Q_EMIT q->loadingChanged(info); }); } @@ -1863,6 +1866,21 @@ void QWebEnginePage::download(const QUrl& url, const QString& filename) d->adapter->download(url, filename); } +/*! + \property QWebEnginePage::loading + \since 6.2 + + \brief Whether the page is currently loading. + + The \l loadingChanged() signal is emitted when loading the page begins, ends, or fails. + + \sa QWebEngineLoadingInfo, loadStarted, loadFinished +*/ +bool QWebEnginePage::isLoading() const +{ + return d_ptr->isLoading; +} + void QWebEnginePage::load(const QUrl& url) { Q_D(QWebEnginePage); diff --git a/src/core/api/qwebenginepage.h b/src/core/api/qwebenginepage.h index 9b9e6a3d3..fb01c283d 100644 --- a/src/core/api/qwebenginepage.h +++ b/src/core/api/qwebenginepage.h @@ -63,6 +63,7 @@ class QWebEngineClientCertificateSelection; class QWebEngineFindTextResult; class QWebEngineFullScreenRequest; class QWebEngineHistory; +class QWebEngineLoadingInfo; class QWebEngineNavigationRequest; class QWebEngineNewWindowRequest; class QWebEnginePage; @@ -93,6 +94,7 @@ class Q_WEBENGINECORE_EXPORT QWebEnginePage : public QObject { Q_PROPERTY(LifecycleState lifecycleState READ lifecycleState WRITE setLifecycleState NOTIFY lifecycleStateChanged) Q_PROPERTY(LifecycleState recommendedState READ recommendedState NOTIFY recommendedStateChanged) Q_PROPERTY(qint64 renderProcessPid READ renderProcessPid NOTIFY renderProcessPidChanged) + Q_PROPERTY(bool loading READ isLoading NOTIFY loadingChanged FINAL) public: enum WebAction { @@ -259,6 +261,8 @@ public: void setFeaturePermission(const QUrl &securityOrigin, Feature feature, PermissionPolicy policy); + bool isLoading() const; + void load(const QUrl &url); void load(const QWebEngineHttpRequest &request); void download(const QUrl &url, const QString &filename = QString()); @@ -325,6 +329,7 @@ Q_SIGNALS: void loadStarted(); void loadProgress(int progress); void loadFinished(bool ok); + void loadingChanged(const QWebEngineLoadingInfo &loadingInfo); void linkHovered(const QString &url); void selectionChanged(); diff --git a/tests/auto/widgets/loadsignals/tst_loadsignals.cpp b/tests/auto/widgets/loadsignals/tst_loadsignals.cpp index 12a497dd9..0daf0ce05 100644 --- a/tests/auto/widgets/loadsignals/tst_loadsignals.cpp +++ b/tests/auto/widgets/loadsignals/tst_loadsignals.cpp @@ -31,12 +31,18 @@ #include "httpserver.h" #include <util.h> #include "qdebug.h" +#include "qwebengineloadinginfo.h" #include "qwebenginepage.h" #include "qwebengineprofile.h" #include "qwebenginesettings.h" #include "qwebengineview.h" -enum { LoadStarted, LoadSucceeded, LoadFailed }; +enum { + LoadStarted = QWebEngineLoadingInfo::LoadStartedStatus, + LoadStopped = QWebEngineLoadingInfo::LoadStoppedStatus, + LoadSucceeded = QWebEngineLoadingInfo::LoadSucceededStatus, + LoadFailed = QWebEngineLoadingInfo::LoadFailedStatus, +}; static const QList<int> SignalsOrderOnce({ LoadStarted, LoadSucceeded}); static const QList<int> SignalsOrderTwice({ LoadStarted, LoadSucceeded, LoadStarted, LoadSucceeded }); static const QList<int> SignalsOrderOnceFailure({ LoadStarted, LoadFailed }); @@ -49,13 +55,16 @@ public: int navigationRequestCount = 0; QList<int> signalsOrder; QList<int> loadProgress; + QList<QWebEngineLoadingInfo> loadingInfos; explicit TestPage(QObject *parent = nullptr) : TestPage(nullptr, parent) { } TestPage(QWebEngineProfile *profile, QObject *parent = nullptr) : QWebEnginePage(profile, parent) { connect(this, &QWebEnginePage::loadStarted, [this] () { signalsOrder.append(LoadStarted); }); connect(this, &QWebEnginePage::loadProgress, [this] (int p) { loadProgress.append(p); }); connect(this, &QWebEnginePage::loadFinished, [this] (bool r) { signalsOrder.append(r ? LoadSucceeded : LoadFailed); }); + connect(this, &QWebEnginePage::loadingChanged, [this] (const QWebEngineLoadingInfo &i) { loadingInfos.append(i); }); } + ~TestPage() { Q_ASSERT(signalsOrder.size() == loadingInfos.size()); } void reset() { @@ -63,6 +72,7 @@ public: navigationRequestCount = 0; signalsOrder.clear(); loadProgress.clear(); + loadingInfos.clear(); } protected: @@ -174,6 +184,9 @@ void tst_LoadSignals::loadStartedAndFinishedCount() QCOMPARE(loadStartedSpy.size(), expectedLoadCount); QCOMPARE(loadFinishedSpy.size(), expectedLoadCount); QCOMPARE(page.signalsOrder, expectedSignals); + QCOMPARE(page.signalsOrder.size(), page.loadingInfos.size()); + for (int i = 0; i < page.signalsOrder.size(); ++i) + QCOMPARE(page.signalsOrder[i], page.loadingInfos[i].status()); } /** |