summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@qt.io>2022-03-16 16:36:50 +0100
committerChristian Strømme <christian.stromme@qt.io>2022-08-08 22:26:10 +0200
commitf80cd0f766094e01da1008d14123a12740a2b771 (patch)
tree22a253ed6a043c2026c196784c50fb9d7c001a87
parent21360e2bcefec2020902400e84d441f68891b551 (diff)
Android: Make is possible to change setAllowFileAccess()
Before API level 30 the WebView on Android allowed file access, but that has since been turned off by default. As a bare minimum we can allow the user that has been depending on local file access to revert that by setting an environment variable. Fixes: QTBUG-97487 Change-Id: Id1d3d6e04d93c487117ed3285ff52dd03a7dbe8a Reviewed-by: Andy Shaw <andy.shaw@qt.io>
-rw-r--r--src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java9
-rw-r--r--src/webview/doc/src/qtwebview-overview.qdoc9
2 files changed, 18 insertions, 0 deletions
diff --git a/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java
index fe93552..f7d2e33 100644
--- a/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java
+++ b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java
@@ -220,6 +220,15 @@ public class QtAndroidWebViewController
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
+ // Before API level 30 accessing local files was enabled by default.
+ final boolean allowFileAccess = (System.getenv("QT5_ANDROID_WEBVIEW_ALLOW_FILE_ACCESS") != null);
+ if (allowFileAccess)
+ webSettings.setAllowFileAccess(allowFileAccess);
+
+ final boolean allowFileAccessFromFileUrls = (System.getenv("QT5_ANDROID_WEBVIEW_ALLOW_FILE_ACCESS_FROM_URLS") != null);
+ if (allowFileAccessFromFileUrls)
+ webSettings.setAllowFileAccessFromFileURLs(allowFileAccessFromFileUrls);
+
if (Build.VERSION.SDK_INT > 10) {
try {
m_webViewOnResume = m_webView.getClass().getMethod("onResume");
diff --git a/src/webview/doc/src/qtwebview-overview.qdoc b/src/webview/doc/src/qtwebview-overview.qdoc
index dc59f3c..b008064 100644
--- a/src/webview/doc/src/qtwebview-overview.qdoc
+++ b/src/webview/doc/src/qtwebview-overview.qdoc
@@ -62,6 +62,15 @@
is not supported. Doing this will have unpredictable results which may differ
from platform to platform.
+ \section1 Platform notes
+
+ \secion2 Android
+
+ From API level 30 the native Android WebView will have file access disabled by default.
+ Since there are no APIs in QtWebView to override the file access property, the two environment variables
+ QT5_ANDROID_WEBVIEW_ALLOW_FILE_ACCESS and QT5_ANDROID_WEBVIEW_ALLOW_FILE_ACCESS_FROM_URLS are provided
+ which, when set, re-enables file access support again.
+
\section1 Examples
Take a look at the \l{Qt WebView Examples} for a demonstration on