summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc9
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp29
2 files changed, 33 insertions, 5 deletions
diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
index 9d5c41713..789d9794e 100644
--- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
@@ -376,11 +376,6 @@
to the main frame or a child frame. If the function returns \c true, the navigation request is
accepted and \c url is loaded. The default implementation accepts all navigation requests.
- This function is called for absolute URLs that are prefixed with \c {http://} or \c {https://}
- and for unrecognized schemes, such as \c {mailto:}, which will be handled by QDesktopServices
- if accepted. To have this function called also upon receiving navigation requests to local URLs,
- prefix the URLs with \c {http://}.
-
Navigation requests can be delegated to the Qt application instead of having the HTML handler
engine process them by overloading this function. This is necessary when an HTML document is
used as part of the user interface, and not to display external data, for example, when
@@ -391,6 +386,10 @@
signal that returns \c false is to be expected even after delegating the
request.
+ \note When using setHtml or setContent with relative links, make
+ sure to specify a base url, otherwise the links will be considered
+ invalid and no navigation requests will be emitted.
+
The \l{QWebEngineUrlRequestInterceptor} class offers further options for intercepting and
manipulating requests.
*/
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 621c2dbd7..a3c45918b 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -93,6 +93,7 @@ private Q_SLOTS:
void comboBoxPopupPositionAfterChildMove();
void acceptNavigationRequest();
void acceptNavigationRequestNavigationType();
+ void acceptNavigationRequestRelativeToNothing();
void geolocationRequestJS_data();
void geolocationRequestJS();
void loadFinished();
@@ -602,6 +603,34 @@ void tst_QWebEnginePage::acceptNavigationRequestNavigationType()
}
}
+// Relative url without base url.
+//
+// See also: QTBUG-48435
+void tst_QWebEnginePage::acceptNavigationRequestRelativeToNothing()
+{
+ TestPage page;
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+
+ page.setHtml(QString("<html><body><a id='link' href='S0'>limited time offer</a></body></html>"),
+ /* baseUrl: */ QUrl());
+ QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
+ page.runJavaScript(QStringLiteral("document.getElementById(\"link\").click()"));
+ QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 2, 20000);
+ page.setHtml(QString("<html><body><a id='link' href='S0'>limited time offer</a></body></html>"),
+ /* baseUrl: */ QString("qrc:/"));
+ QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 3, 20000);
+ page.runJavaScript(QStringLiteral("document.getElementById(\"link\").click()"));
+ QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 4, 20000);
+
+ // The two setHtml and the second click are counted, while the
+ // first click is ignored due to the empty base url.
+ QCOMPARE(page.navigations.count(), 3);
+ QCOMPARE(page.navigations[0].type, QWebEnginePage::NavigationTypeTyped);
+ QCOMPARE(page.navigations[1].type, QWebEnginePage::NavigationTypeTyped);
+ QCOMPARE(page.navigations[2].type, QWebEnginePage::NavigationTypeLinkClicked);
+ QCOMPARE(page.navigations[2].url, QUrl(QString("qrc:/S0")));
+}
+
void tst_QWebEnginePage::popupFormSubmission()
{
TestPage page;