summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Klocek <[email protected]>2024-10-31 16:27:57 +0100
committerQt Cherry-pick Bot <[email protected]>2024-11-07 19:21:31 +0000
commit1bc5783d40198abfa9fbdaf344b76791083c42f1 (patch)
tree984098544874a42c1db09f3995a9f56ca726b8b9
parentaf20d36cccb1f789994ec467526a86da86880aa1 (diff)
Fix WebView.loadData* encoding on android
As referenced in android docs: https://developer.android.com/reference/android/webkit/WebView loaded HTML data has to be base64 encoded or use url encoding. To keep things aligned with webengine backend use percent encoding, however "base64" would also give correct result (unfortunately webengine assumes percent encoding). Fixes: QTBUG-129303 Change-Id: Ided7ef12324d5b4854240700e5de7183069ad34a Reviewed-by: Christian Strømme <[email protected]> (cherry picked from commit 9feccda3138fe0d6c88bf8ba99eb4b57965e95a6) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--src/plugins/android/qandroidwebview.cpp13
-rw-r--r--tests/auto/webview/qwebview/tst_qwebview.cpp15
2 files changed, 20 insertions, 8 deletions
diff --git a/src/plugins/android/qandroidwebview.cpp b/src/plugins/android/qandroidwebview.cpp
index e4a9bf9..47b0e61 100644
--- a/src/plugins/android/qandroidwebview.cpp
+++ b/src/plugins/android/qandroidwebview.cpp
@@ -137,13 +137,12 @@ void QAndroidWebViewPrivate::setUrl(const QUrl &url)
void QAndroidWebViewPrivate::loadHtml(const QString &html, const QUrl &baseUrl)
{
const QString mimeTypeString = u"text/html;charset=UTF-8"_s;
-
- baseUrl.isEmpty() ? m_viewController.callMethod<void>("loadData", html, mimeTypeString,
- jstring(nullptr))
- : m_viewController.callMethod<void>("loadDataWithBaseURL",
- baseUrl.toString(),
- html, mimeTypeString,
- jstring(nullptr), jstring(nullptr));
+ const QString encoded = QUrl::toPercentEncoding(html);
+ baseUrl.isEmpty()
+ ? m_viewController.callMethod<void>("loadData", encoded, mimeTypeString,
+ jstring(nullptr))
+ : m_viewController.callMethod<void>("loadDataWithBaseURL", baseUrl.toString(), encoded,
+ mimeTypeString, jstring(nullptr), jstring(nullptr));
}
bool QAndroidWebViewPrivate::canGoBack() const
diff --git a/tests/auto/webview/qwebview/tst_qwebview.cpp b/tests/auto/webview/qwebview/tst_qwebview.cpp
index ac4c8e3..fd942ec 100644
--- a/tests/auto/webview/qwebview/tst_qwebview.cpp
+++ b/tests/auto/webview/qwebview/tst_qwebview.cpp
@@ -130,10 +130,23 @@ void tst_QWebView::loadHtml()
QWebView view;
#endif
QCOMPARE(view.loadProgress(), 0);
- view.loadHtml(QString("<html><head><title>WebViewTitle</title></head><body />"));
+ QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(const QWebViewLoadRequestPrivate &)));
+ const QByteArray content(
+ QByteArrayLiteral("<html><title>WebViewTitle</title>"
+ "<body><span style=\"color:#ff0000\">Hello</span></body></html>"));
+ view.loadHtml(content);
QTRY_COMPARE(view.loadProgress(), 100);
QTRY_VERIFY(!view.isLoading());
QCOMPARE(view.title(), QStringLiteral("WebViewTitle"));
+ QTRY_COMPARE(loadChangedSingalSpy.size(), 2);
+ // take load finished
+ const QWebViewLoadRequestPrivate &lr = loadChangedSingalSpy.at(1).at(0).value<QWebViewLoadRequestPrivate>();
+ QCOMPARE(lr.m_status, QWebView::LoadSucceededStatus);
+
+ QByteArray encoded("data:text/html;charset=UTF-8,");
+ encoded.append(content.toPercentEncoding());
+ QVERIFY(view.url().isValid());
+ QCOMPARE(QUrl(encoded), view.url());
}
void tst_QWebView::loadRequest()