diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-11-09 15:23:32 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-11-12 12:36:15 +0000 |
commit | 70a376d73718cc4ff8d96f6761b8c1896ca25c23 (patch) | |
tree | 27111f884d6c8dcb04f0d0f52217413b99452b44 | |
parent | 93745b5452c2ec69c04be2a2043c0937327ee556 (diff) |
Make QWebEngineFullScreenRequest const correct
Let QWebEngineFullScreenRequest be logically const-correct. It feels
weird to be allowed to call "accept()" or "reject()" on a constant
object.
Also allow the user to copy the request, but check whether the
page is still valid in the implementations of accept(), reject().
Change-Id: Ibf139a126734fc8e2db68ec26dc8f24cd4438942
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
7 files changed, 35 insertions, 25 deletions
diff --git a/examples/webenginewidgets/demobrowser/tabwidget.cpp b/examples/webenginewidgets/demobrowser/tabwidget.cpp index 3b2069858..95b79aaac 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.cpp +++ b/examples/webenginewidgets/demobrowser/tabwidget.cpp @@ -325,8 +325,8 @@ void TabWidget::currentChanged(int index) this, SIGNAL(loadProgress(int))); disconnect(oldWebView->page()->profile(), SIGNAL(downloadRequested(QWebEngineDownloadItem*)), this, SLOT(downloadRequested(QWebEngineDownloadItem*))); - disconnect(oldWebView->page(), SIGNAL(fullScreenRequested(const QWebEngineFullScreenRequest&)), - this, SLOT(fullScreenRequested(const QWebEngineFullScreenRequest&))); + disconnect(oldWebView->page(), SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), + this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest))); } #if defined(QWEBENGINEVIEW_STATUSBARMESSAGE) @@ -339,8 +339,8 @@ void TabWidget::currentChanged(int index) this, SIGNAL(loadProgress(int))); connect(webView->page()->profile(), SIGNAL(downloadRequested(QWebEngineDownloadItem*)), this, SLOT(downloadRequested(QWebEngineDownloadItem*))); - connect(webView->page(), SIGNAL(fullScreenRequested(const QWebEngineFullScreenRequest&)), - this, SLOT(fullScreenRequested(const QWebEngineFullScreenRequest&))); + connect(webView->page(), SIGNAL(fullScreenRequested(QWebEngineFullScreenRequest)), + this, SLOT(fullScreenRequested(QWebEngineFullScreenRequest))); for (int i = 0; i < m_actions.count(); ++i) { WebActionMapper *mapper = m_actions[i]; @@ -356,7 +356,7 @@ void TabWidget::currentChanged(int index) webView->setFocus(); } -void TabWidget::fullScreenRequested(const QWebEngineFullScreenRequest &request) +void TabWidget::fullScreenRequested(QWebEngineFullScreenRequest request) { WebPage *webPage = qobject_cast<WebPage*>(sender()); if (request.toggleOn()) { diff --git a/examples/webenginewidgets/demobrowser/tabwidget.h b/examples/webenginewidgets/demobrowser/tabwidget.h index f71ac398a..b00131130 100644 --- a/examples/webenginewidgets/demobrowser/tabwidget.h +++ b/examples/webenginewidgets/demobrowser/tabwidget.h @@ -42,8 +42,8 @@ #ifndef TABWIDGET_H #define TABWIDGET_H +#include <QtWebEngineWidgets/QWebEngineFullScreenRequest> #include <QtWidgets/QTabBar> - #include <QtWidgets/QShortcut> QT_BEGIN_NAMESPACE @@ -217,7 +217,7 @@ private slots: void lineEditReturnPressed(); void windowCloseRequested(); void moveTab(int fromIndex, int toIndex); - void fullScreenRequested(const QWebEngineFullScreenRequest& request); + void fullScreenRequested(QWebEngineFullScreenRequest request); private: QAction *m_recentlyClosedTabsAction; diff --git a/src/webenginewidgets/api/qwebenginefullscreenrequest.cpp b/src/webenginewidgets/api/qwebenginefullscreenrequest.cpp index 6223c070d..7db86e6f2 100644 --- a/src/webenginewidgets/api/qwebenginefullscreenrequest.cpp +++ b/src/webenginewidgets/api/qwebenginefullscreenrequest.cpp @@ -39,21 +39,31 @@ QT_BEGIN_NAMESPACE -QWebEngineFullScreenRequest::QWebEngineFullScreenRequest(QWebEnginePagePrivate *pagePrivate, const QUrl &origin, bool fullscreen) - : m_pagePrivate(pagePrivate) +QWebEngineFullScreenRequest::QWebEngineFullScreenRequest(QWebEnginePage *page, const QUrl &origin, bool fullscreen) + : m_page(page) , m_origin(origin) , m_toggleOn(fullscreen) { } -void QWebEngineFullScreenRequest::reject() const +void QWebEngineFullScreenRequest::reject() { - m_pagePrivate->setFullScreenMode(!m_toggleOn); + if (!m_page) { + qWarning("Cannot reject QWebEngineFullScreenRequest: Originating page is already deleted"); + return; + } + + m_page->d_func()->setFullScreenMode(!m_toggleOn); } -void QWebEngineFullScreenRequest::accept() const +void QWebEngineFullScreenRequest::accept() { - m_pagePrivate->setFullScreenMode(m_toggleOn); + if (!m_page) { + qWarning("Cannot accept QWebEngineFullScreenRequest: Originating page is already deleted"); + return; + } + + m_page->d_func()->setFullScreenMode(m_toggleOn); } QT_END_NAMESPACE diff --git a/src/webenginewidgets/api/qwebenginefullscreenrequest.h b/src/webenginewidgets/api/qwebenginefullscreenrequest.h index c6768f4d6..26f7247e0 100644 --- a/src/webenginewidgets/api/qwebenginefullscreenrequest.h +++ b/src/webenginewidgets/api/qwebenginefullscreenrequest.h @@ -38,26 +38,25 @@ #define QWEBENGINEFULLSCREENREQUEST_H #include <qtwebenginewidgetsglobal.h> -#include <qwebenginepage.h> -#include <QtCore/qurl.h> +#include <qurl.h> +#include <qpointer.h> QT_BEGIN_NAMESPACE -class QWebEnginePagePrivate; +class QWebEnginePage; class QWEBENGINEWIDGETS_EXPORT QWebEngineFullScreenRequest { Q_GADGET Q_PROPERTY(bool toggleOn READ toggleOn) Q_PROPERTY(QUrl origin READ origin) public: - Q_INVOKABLE void reject() const; - Q_INVOKABLE void accept() const; + Q_INVOKABLE void reject(); + Q_INVOKABLE void accept(); bool toggleOn() const { return m_toggleOn; } const QUrl &origin() const { return m_origin; } private: - Q_DISABLE_COPY(QWebEngineFullScreenRequest) - QWebEngineFullScreenRequest(QWebEnginePagePrivate *pagePrivate, const QUrl &origin, bool toggleOn); - QWebEnginePagePrivate *m_pagePrivate; + QWebEngineFullScreenRequest(QWebEnginePage *page, const QUrl &origin, bool toggleOn); + QPointer<QWebEnginePage> m_page; const QUrl m_origin; const bool m_toggleOn; friend class QWebEnginePagePrivate; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 75f722f8c..49c0cf5dd 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -420,7 +420,7 @@ QWebEnginePage::QWebEnginePage(QObject* parent) */ /*! - \fn QWebEnginePage::fullScreenRequested(const QWebEngineFullScreenRequest &request) + \fn QWebEnginePage::fullScreenRequested(QWebEngineFullScreenRequest request) This signal is emitted when the web page issues the request to enter fullscreen mode for a web-element, usually a video element. @@ -912,7 +912,7 @@ void QWebEnginePagePrivate::navigationRequested(int navigationType, const QUrl & void QWebEnginePagePrivate::requestFullScreenMode(const QUrl &origin, bool fullscreen) { Q_Q(QWebEnginePage); - QWebEngineFullScreenRequest request(this, origin, fullscreen); + QWebEngineFullScreenRequest request(q, origin, fullscreen); Q_EMIT q->fullScreenRequested(request); } diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 07b27deee..83faaf42e 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -252,7 +252,7 @@ Q_SIGNALS: void featurePermissionRequested(const QUrl &securityOrigin, QWebEnginePage::Feature feature); void featurePermissionRequestCanceled(const QUrl &securityOrigin, QWebEnginePage::Feature feature); - void fullScreenRequested(const QWebEngineFullScreenRequest &fullScreenRequest); + void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); void authenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator); void proxyAuthenticationRequired(const QUrl &requestUrl, QAuthenticator *authenticator, const QString &proxyHost); @@ -283,6 +283,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_webActionTriggered(bool checked)) #endif + friend class QWebEngineFullScreenRequest; friend class QWebEngineView; friend class QWebEngineViewPrivate; #ifndef QT_NO_ACCESSIBILITY diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 8b7f71365..50914a920 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -3744,7 +3744,7 @@ void tst_QWebEnginePage::fullScreenRequested() // FullscreenRequest must be a user gesture bool acceptRequest = true; connect(page, &QWebEnginePage::fullScreenRequested, - [&acceptRequest](const QWebEngineFullScreenRequest &request) { + [&acceptRequest](QWebEngineFullScreenRequest request) { if (acceptRequest) request.accept(); else request.reject(); }); |