Allow WebView attachment document loads

This commit is contained in:
Xisheng-Zhao
2026-06-20 03:45:21 +08:00
parent 47bb6088df
commit ffb4ce404f
2 changed files with 8 additions and 2 deletions
@@ -39,6 +39,12 @@ final class AttachmentPreview {
}
}
static boolean isWebViewInternalDocumentUrl(String url) {
if (url == null) return false;
String value = url.trim().toLowerCase(java.util.Locale.ROOT);
return value.equals("about:blank") || value.startsWith("data:text/html");
}
static String xmlPreviewDocument(String xml) {
return "<!doctype html><html><head><meta charset=\"utf-8\">"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
@@ -9572,11 +9572,11 @@ private class AttachmentPreviewWebViewClient(
}
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
val url = request.url?.toString().orEmpty()
return if (AttachmentPreview.isLocalPreviewUrl(url)) null else WebResourceResponse("text/plain", "UTF-8", null)
return null
}
private fun handleNavigation(url: String): Boolean {
if (AttachmentPreview.isWebViewInternalDocumentUrl(url)) return false
if (AttachmentPreview.isLocalPreviewUrl(url)) return false
openExternalUrl(context, url)
return true