summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-25 10:47:45 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-25 10:47:45 +0100
commit5ca2d76b78df1839b92b04d7d6e7710f5d402c98 (patch)
tree69cd30c70fff2cb66ff498f5a120d822ccc2eaac /src/webenginewidgets
parentecfb3ba8a7eb116c838a1acd5b82ca59ce76b082 (diff)
parent6766290699acd0d73c81cf690012d52729e518b9 (diff)
Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts: src/3rdparty Change-Id: Ib9c9eca457c1c42dab948e6cb56d44b57d5da32a
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp19
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp11
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp21
-rw-r--r--src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h1
4 files changed, 43 insertions, 9 deletions
diff --git a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp
index e47f135e8..bf3514f71 100644
--- a/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp
+++ b/src/webenginewidgets/api/qtwebenginewidgetsglobal.cpp
@@ -48,17 +48,22 @@ namespace QtWebEngineCore
}
QT_BEGIN_NAMESPACE
+
+Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
+
static void initialize()
{
- //On window/ANGLE, calling QtWebEngine::initialize from DllMain will result in a crash.
- //To ensure it doesn't, we check that when loading the library
- //QCoreApplication is not yet instantiated, ensuring the call will be deferred
-#if defined(Q_OS_WIN)
- if (QCoreApplication::instance()
- && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
+ if (QCoreApplication::instance()) {
+ //On window/ANGLE, calling QtWebEngine::initialize from DllMain will result in a crash.
+ if (!qt_gl_global_share_context()) {
+ qWarning("Qt WebEngine seems to be initialized from a plugin. Please "
+ "set Qt::AA_ShareOpenGLContexts using QCoreApplication::setAttribute "
+ "before constructing QGuiApplication.");
+ }
return;
}
-#endif
+
+ //QCoreApplication is not yet instantiated, ensuring the call will be deferred
qAddPreRoutine(QtWebEngineCore::initialize);
}
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index ca160c362..0188cfef8 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -154,7 +154,16 @@ QWebEnginePagePrivate::~QWebEnginePagePrivate()
RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQtDelegateClient *client)
{
- return new RenderWidgetHostViewQtDelegateWidget(client);
+ // Set the QWebEngineView as the parent for a popup delegate, so that the new popup window
+ // responds properly to clicks in case the QWebEngineView is inside a modal QDialog. Setting the
+ // parent essentially notifies the OS that the popup window is part of the modal session, and
+ // should allow interaction.
+ // The new delegate will not be deleted by the parent view though, because we unset the parent
+ // when the parent is destroyed. The delegate will be destroyed by Chromium when the popup is
+ // dismissed.
+ // If the delegate is not for a popup, but for a newly created QWebEngineView, the parent is 0
+ // just like before.
+ return new RenderWidgetHostViewQtDelegateWidget(client, this->view);
}
void QWebEnginePagePrivate::titleChanged(const QString &title)
diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
index eb3a3931a..8c8e9fb71 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
@@ -138,6 +138,21 @@ RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(Rende
setAttribute(Qt::WA_AcceptTouchEvents);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_AlwaysShowToolTips);
+
+ if (parent) {
+ // Unset the popup parent if the parent is being destroyed, thus making sure a double
+ // delete does not happen.
+ // Also in case the delegate is destroyed before its parent (when a popup is simply
+ // dismissed), this connection will automatically be removed by ~QObject(), preventing
+ // a use-after-free.
+ connect(parent, &QObject::destroyed,
+ this, &RenderWidgetHostViewQtDelegateWidget::removeParentBeforeParentDelete);
+ }
+}
+
+void RenderWidgetHostViewQtDelegateWidget::removeParentBeforeParentDelete()
+{
+ setParent(Q_NULLPTR);
}
void RenderWidgetHostViewQtDelegateWidget::initAsChild(WebContentsAdapterClient* container)
@@ -164,7 +179,11 @@ void RenderWidgetHostViewQtDelegateWidget::initAsPopup(const QRect& screenRect)
// to be destroyed.
setAttribute(Qt::WA_ShowWithoutActivating);
setFocusPolicy(Qt::NoFocus);
- setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
+
+ // macOS doesn't like Qt::ToolTip when QWebEngineView is inside a modal dialog, specifically by
+ // not forwarding click events to the popup. So we use Qt::Tool which behaves the same way, but
+ // works on macOS too.
+ setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
setGeometry(screenRect);
show();
diff --git a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
index 77907ec5a..68e6a176b 100644
--- a/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
+++ b/src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
@@ -87,6 +87,7 @@ protected:
private slots:
void onWindowPosChanged();
+ void removeParentBeforeParentDelete();
private:
RenderWidgetHostViewQtDelegateClient *m_client;