11package com.didi.dimina.ui.view
22
3- import android.annotation.SuppressLint
4- import android.content.Context
5- import android.content.pm.ApplicationInfo
63import android.webkit.JavascriptInterface
7- import android.webkit.MimeTypeMap
8- import android.webkit.WebResourceRequest
9- import android.webkit.WebResourceResponse
10- import android.webkit.WebSettings
114import android.webkit.WebView
12- import android.webkit.WebViewClient
135import androidx.compose.foundation.layout.Box
146import androidx.compose.foundation.layout.fillMaxSize
157import androidx.compose.runtime.Composable
@@ -19,11 +11,7 @@ import androidx.compose.ui.Modifier
1911import androidx.compose.ui.platform.LocalContext
2012import androidx.compose.ui.viewinterop.AndroidView
2113import com.didi.dimina.common.LogUtils
22- import com.didi.dimina.common.PathUtils.FILE_PROTOCOL
23- import com.didi.dimina.common.VersionUtils
2414import org.json.JSONObject
25- import java.io.File
26- import java.io.FileInputStream
2715
2816/* *
2917 * Author: Doslin
@@ -67,7 +55,7 @@ fun DiminaWebView(
6755 // 使用缓存管理器获取WebView实例
6856 WebViewCacheManager .getWebView(context, onPageCompleted, webViewIdentifier)
6957 } else {
70- // 传统方式创建WebView
58+ // 传统方式创建WebView(使用WebViewCacheManager中的统一配置)
7159 createWebView(context, onPageCompleted)
7260 }
7361
@@ -81,38 +69,6 @@ fun DiminaWebView(
8169 }
8270}
8371
84- @SuppressLint(" SetJavaScriptEnabled" )
85- private fun createWebView (context : Context , onPageLoadFinished : () -> Unit ): WebView {
86- return WebView (context).apply {
87- // Ensure WebView has explicit layoutParams.
88- // Chromium determines viewport size during initial layout.
89- // Missing layoutParams may cause vh/vw and window.innerHeight to be incorrect.
90- layoutParams = android.view.ViewGroup .LayoutParams (
91- android.view.ViewGroup .LayoutParams .MATCH_PARENT ,
92- android.view.ViewGroup .LayoutParams .MATCH_PARENT
93- )
94- // 配置 WebView 设置
95- settings.apply {
96- javaScriptEnabled = true
97- domStorageEnabled = true
98- allowFileAccess = true
99- allowContentAccess = true
100- loadWithOverviewMode = true
101- useWideViewPort = true
102- cacheMode = WebSettings .LOAD_NO_CACHE
103- mixedContentMode = WebSettings .MIXED_CONTENT_ALWAYS_ALLOW
104- }
105-
106- if (0 != (context.applicationInfo.flags and ApplicationInfo .FLAG_DEBUGGABLE )) {
107- WebView .setWebContentsDebuggingEnabled(true )
108- LogUtils .d(TAG , " Chrome remote debugging enabled" )
109- }
110-
111- // Configure WebViewClient with file interceptor
112- webViewClient = createWebViewClientWithInterceptor { onPageLoadFinished() }
113- }
114- }
115-
11672/* *
11773 * 向渲染线程发送消息
11874 * 这个方法封装了 webview.evaluateJavascript,使其接口与 jscore.postMessage 保持一致
0 commit comments