summaryrefslogtreecommitdiffstats
path: root/src/webengine/api/qquickwebengineview.cpp
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2019-12-18 20:31:13 +0100
committerMichal Klocek <michal.klocek@qt.io>2020-01-14 19:42:04 +0100
commit445235bc012fcdc73acc881f865a21769c46a6d3 (patch)
tree931ad5942ed3a5a11939cbd8c3d238657bdf2177 /src/webengine/api/qquickwebengineview.cpp
parentd2f6a5c7b97d61c4e983243d444dd51592a44bab (diff)
Rework url changed logic
Due security changes to prevent url spoofing, our implementation is getting extra invalidate url requests. Unfortunately, this breaks our url handling, which now gets lots of new back and fort url changed signals and make several unit test failures. After tedious investigation of Chromium omnibox handing and trying out different approaches, it seems that only sensible solution is to follow Chromium logic and make NavigationStateChanged to update 'ui' in asynchronous matter. This change tries not break any tests and simplify url handling. The only side effect of this change is that WebEnginePage::setContent will get extra 'url' signal of initial 'urlData' and later 'baseUrl' change is emitted. Fix one of qml tests which did not expect to have url on LoadStartedStatus. Task-number: QTBUG-63388 Task-number: QTBUG-48995 Change-Id: Id347f4325c036e16bfae7bf2f694905e0f21f8d7 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/webengine/api/qquickwebengineview.cpp')
-rw-r--r--src/webengine/api/qquickwebengineview.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index b05bbfdbc..83ada3c11 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -369,11 +369,14 @@ void QQuickWebEngineViewPrivate::titleChanged(const QString &title)
Q_EMIT q->titleChanged();
}
-void QQuickWebEngineViewPrivate::urlChanged(const QUrl &url)
+void QQuickWebEngineViewPrivate::urlChanged()
{
Q_Q(QQuickWebEngineView);
- Q_UNUSED(url);
- Q_EMIT q->urlChanged();
+ QUrl url = adapter->activeUrl();
+ if (m_url != url) {
+ m_url = url;
+ Q_EMIT q->urlChanged();
+ }
}
void QQuickWebEngineViewPrivate::iconChanged(const QUrl &url)
@@ -885,7 +888,7 @@ void QQuickWebEngineViewPrivate::initializationFinished()
emit q->titleChanged();
emit q->urlChanged();
emit q->iconChanged();
- QQuickWebEngineLoadRequest loadRequest(adapter->activeUrl(), QQuickWebEngineView::LoadSucceededStatus);
+ QQuickWebEngineLoadRequest loadRequest(m_url, QQuickWebEngineView::LoadSucceededStatus);
emit q->loadingChanged(&loadRequest);
emit q->loadProgressChanged();
@@ -1017,9 +1020,6 @@ void QQuickWebEngineViewPrivate::updateEditActions()
QUrl QQuickWebEngineView::url() const
{
Q_D(const QQuickWebEngineView);
- if (d->adapter->isInitialized())
- return d->adapter->activeUrl();
- else
return d->m_url;
}
@@ -1029,13 +1029,15 @@ void QQuickWebEngineView::setUrl(const QUrl& url)
if (url.isEmpty())
return;
+ if (d->m_url != url) {
+ d->m_url = url;
+ d->m_html.clear();
+ emit urlChanged();
+ }
+
if (d->adapter->isInitialized()) {
d->adapter->load(url);
- return;
}
-
- d->m_url = url;
- d->m_html.clear();
}
QUrl QQuickWebEngineView::icon() const
@@ -1147,14 +1149,13 @@ void QQuickWebEngineViewPrivate::updateAdapter()
{
// When the profile changes we need to create a new WebContentAdapter and reload the active URL.
bool wasInitialized = adapter->isInitialized();
- QUrl activeUrl = adapter->activeUrl();
adapter = QSharedPointer<WebContentsAdapter>::create();
adapter->setClient(this);
if (wasInitialized) {
if (!m_html.isEmpty())
- adapter->setContent(m_html.toUtf8(), defaultMimeType, activeUrl);
- else if (activeUrl.isValid())
- adapter->load(activeUrl);
+ adapter->setContent(m_html.toUtf8(), defaultMimeType, m_url);
+ else if (m_url.isValid())
+ adapter->load(m_url);
else
adapter->loadDefault();
}