summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/web_contents_delegate_qt.cpp31
-rw-r--r--tests/auto/quick/qmltests/data/tst_loadHtml.qml20
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp18
3 files changed, 68 insertions, 1 deletions
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 3d2337884..bec4d5d2f 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -76,6 +76,7 @@
#include "content/public/common/frame_navigate_params.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/web_preferences.h"
+#include "net/base/data_url.h"
#include <QDesktopServices>
#include <QTimer>
@@ -150,10 +151,38 @@ content::WebContents *WebContentsDelegateQt::OpenURLFromTab(content::WebContents
return target;
}
+static bool shouldUseActualURL(const content::NavigationEntry *entry)
+{
+ if (!entry)
+ return false;
+
+ // Show actual URL for data URLs only
+ if (!entry->GetURL().SchemeIs(url::kDataScheme))
+ return false;
+
+ // Keep view-source: prefix
+ if (entry->IsViewSourceMode())
+ return false;
+
+ // Do not show data URL of interstitial and error pages
+ if (entry->GetPageType() != content::PAGE_TYPE_NORMAL)
+ return false;
+
+ // Show invalid data URL
+ std::string mime_type, charset, data;
+ if (!net::DataURL::Parse(entry->GetURL(), &mime_type, &charset, &data))
+ return false;
+
+ // Do not show empty data URL
+ return !data.empty();
+}
+
void WebContentsDelegateQt::NavigationStateChanged(content::WebContents* source, content::InvalidateTypes changed_flags)
{
if (changed_flags & content::INVALIDATE_TYPE_URL) {
- QUrl newUrl = toQt(source->GetVisibleURL());
+ // If there is a visible entry there are special cases when we dont wan't to use the actual URL
+ content::NavigationEntry *entry = source->GetController().GetVisibleEntry();
+ QUrl newUrl = shouldUseActualURL(entry) ? toQt(entry->GetURL()) : toQt(source->GetVisibleURL());
if (m_url != newUrl) {
m_url = newUrl;
m_viewClient->urlChanged(m_url);
diff --git a/tests/auto/quick/qmltests/data/tst_loadHtml.qml b/tests/auto/quick/qmltests/data/tst_loadHtml.qml
index f814822dc..73b6139e2 100644
--- a/tests/auto/quick/qmltests/data/tst_loadHtml.qml
+++ b/tests/auto/quick/qmltests/data/tst_loadHtml.qml
@@ -35,8 +35,15 @@ TestWebEngineView {
width: 200
height: 400
+ SignalSpy {
+ id: urlChangedSpy
+ target: webEngineView
+ signalName: "urlChanged"
+ }
+
TestCase {
name: "WebEngineViewLoadHtml"
+ when: windowShown
function test_loadProgressAfterLoadHtml() {
compare(webEngineView.loadProgress, 0)
@@ -44,5 +51,18 @@ TestWebEngineView {
verify(webEngineView.waitForLoadSucceeded())
compare(webEngineView.loadProgress, 100)
}
+
+ function test_dataURLFragment() {
+ webEngineView.loadHtml("<html><body>" +
+ "<a id='link' href='#anchor'>anchor</a>" +
+ "</body></html>");
+ verify(webEngineView.waitForLoadSucceeded());
+
+ urlChangedSpy.clear();
+ var center = getElementCenter("link");
+ mouseClick(webEngineView, center.x, center.y);
+ urlChangedSpy.wait();
+ compare(webEngineView.url.toString().split("#")[1], "anchor");
+ }
}
}
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index fbed89dd3..8fc52be60 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -214,6 +214,7 @@ private Q_SLOTS:
void proxyConfigWithUnexpectedHostPortPair();
void registerProtocolHandler_data();
void registerProtocolHandler();
+ void dataURLFragment();
private:
static QPoint elementCenter(QWebEnginePage *page, const QString &id);
@@ -4267,6 +4268,23 @@ void tst_QWebEnginePage::registerProtocolHandler()
QCOMPARE(loadSpy.takeFirst().value(0).toBool(), permission);
}
+void tst_QWebEnginePage::dataURLFragment()
+{
+ m_view->resize(800, 600);
+ m_view->show();
+ QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool)));
+
+ m_page->setHtml("<html><body>"
+ "<a id='link' href='#anchor'>anchor</a>"
+ "</body></html>");
+ QTRY_COMPARE(loadFinishedSpy.count(), 1);
+
+ QSignalSpy urlChangedSpy(m_page, SIGNAL(urlChanged(QUrl)));
+ QTest::mouseClick(m_view->focusProxy(), Qt::LeftButton, 0, elementCenter(m_page, "link"));
+ QVERIFY(urlChangedSpy.wait());
+ QCOMPARE(m_page->url().fragment(), QStringLiteral("anchor"));
+}
+
static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")};
W_QTEST_MAIN(tst_QWebEnginePage, params)