diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2018-09-20 10:26:37 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2018-10-29 09:43:04 +0000 |
commit | 36d230c44c7e2f6fccf224b4a0ab5efe77117e0a (patch) | |
tree | 1a782829d2838908a461799bf4b8fd651dad6958 /src/webenginewidgets/api/qwebenginepage.cpp | |
parent | 2a6193b00e1d756e9a7a6032640b413c184ae4f0 (diff) |
Stop showing speculative frames
Chromium creates "speculative" frames (RenderFrameHost and company) for pending
cross-process navigations (and maybe other navigations too). For example, a
redirect from http://qt.io to https://qt.io will trigger this, as described in
the bug report.
These speculative frames are loading in the background and only shown once they
are officially ready (as decided by the RenderFrameHostManager and signaled to
WebContentsObserver::RenderViewHostChanged). At least, this is how it's supposed
to work and how it works in Chrome. In WebEngine, however, we actually show
these speculative frames as soon as they are created and before they are ready.
This runs into the problem that the if the speculative frame is dropped (instead
of committed), then Chromium will not ask us to re-show the old frame (since it
hasn't actually asked to us to show the new frame, it naturally assumes we are
still showing the old one).
Fixes: QTBUG-68727
Change-Id: I9d53035ce60e3a002d5412d4473d940a32644b5d
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 84 |
1 files changed, 79 insertions, 5 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 3a2a07520..a6267c223 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -273,8 +273,6 @@ RenderWidgetHostViewQtDelegate *QWebEnginePagePrivate::CreateRenderWidgetHostVie // 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); } @@ -718,12 +716,87 @@ const QObject *QWebEnginePagePrivate::holdingQObject() const return q; } +void QWebEnginePagePrivate::widgetChanged(RenderWidgetHostViewQtDelegate *newWidgetBase) +{ + Q_Q(QWebEnginePage); + bindPageAndWidget(q, static_cast<RenderWidgetHostViewQtDelegateWidget *>(newWidgetBase)); +} + void QWebEnginePagePrivate::ensureInitialized() const { if (!adapter->isInitialized()) adapter->loadDefault(); } +void QWebEnginePagePrivate::bindPageAndView(QWebEnginePage *page, QWebEngineView *view) +{ + auto oldView = page ? page->d_func()->view : nullptr; + auto oldPage = view ? view->d_func()->page : nullptr; + + // Change pointers first. + + if (page && oldView != view) { + if (oldView) + oldView->d_func()->page = nullptr; + page->d_func()->view = view; + } + + if (view && oldPage != page) { + if (oldPage) + oldPage->d_func()->view = nullptr; + view->d_func()->page = page; + } + + // Then notify. + + auto widget = page ? page->d_func()->widget : nullptr; + auto oldWidget = oldPage ? oldPage->d_func()->widget : nullptr; + + if (page && oldView != view && oldView) { + oldView->d_func()->pageChanged(page, nullptr); + if (widget) + oldView->d_func()->widgetChanged(widget, nullptr); + } + + if (view && oldPage != page) { + view->d_func()->pageChanged(oldPage, page); + if (oldWidget != widget) + view->d_func()->widgetChanged(oldWidget, widget); + } +} + +void QWebEnginePagePrivate::bindPageAndWidget(QWebEnginePage *page, RenderWidgetHostViewQtDelegateWidget *widget) +{ + auto oldPage = widget ? widget->m_page : nullptr; + auto oldWidget = page ? page->d_func()->widget : nullptr; + + // Change pointers first. + + if (widget && oldPage != page) { + if (oldPage) + oldPage->d_func()->widget = nullptr; + widget->m_page = page; + } + + if (page && oldWidget != widget) { + if (oldWidget) + oldWidget->m_page = nullptr; + page->d_func()->widget = widget; + } + + // Then notify. + + if (widget && oldPage != page && oldPage) { + if (auto oldView = oldPage->d_func()->view) + oldView->d_func()->widgetChanged(widget, nullptr); + } + + if (page && oldWidget != widget) { + if (auto view = page->d_func()->view) + view->d_func()->widgetChanged(oldWidget, widget); + } +} + QWebEnginePage::QWebEnginePage(QObject* parent) : QObject(parent) , d_ptr(new QWebEnginePagePrivate()) @@ -895,7 +968,8 @@ QWebEnginePage::~QWebEnginePage() Q_D(QWebEnginePage); setDevToolsPage(nullptr); d->adapter->stopFinding(); - QWebEngineViewPrivate::removePageFromView(this); + QWebEnginePagePrivate::bindPageAndView(this, nullptr); + QWebEnginePagePrivate::bindPageAndWidget(this, nullptr); } QWebEngineHistory *QWebEnginePage::history() const @@ -1064,9 +1138,9 @@ bool QWebEnginePage::recentlyAudible() const return d->adapter->isInitialized() && d->adapter->recentlyAudible(); } -void QWebEnginePage::setView(QWidget *view) +void QWebEnginePage::setView(QWidget *newViewBase) { - QWebEngineViewPrivate::bind(qobject_cast<QWebEngineView*>(view), this); + QWebEnginePagePrivate::bindPageAndView(this, qobject_cast<QWebEngineView *>(newViewBase)); } QWidget *QWebEnginePage::view() const |