File tree Expand file tree Collapse file tree
webview-compose/src/jvmMain/kotlin/io/github/kdroidfilter/webview/web Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import androidx.compose.ui.awt.SwingPanel
1515import io.github.kdroidfilter.webview.cookie.WryCookieManager
1616import io.github.kdroidfilter.webview.jsbridge.WebViewJsBridge
1717import io.github.kdroidfilter.webview.jsbridge.parseJsMessage
18+ import io.github.kdroidfilter.webview.request.WebRequest
19+ import io.github.kdroidfilter.webview.request.WebRequestInterceptResult
1820import kotlinx.coroutines.delay
1921
2022actual class WebViewFactoryParam (
@@ -121,8 +123,33 @@ actual fun ActualWebView(
121123 }
122124
123125 DisposableEffect (nativeWebView) {
124- val listener: (String ) -> Boolean = {
125- true
126+ val listener: (String ) -> Boolean = a@{
127+ if (navigator.requestInterceptor == null ) {
128+ return @a true
129+ }
130+
131+ val webRequest =
132+ WebRequest (
133+ url = it,
134+ headers = mutableMapOf (),
135+ isForMainFrame = true ,
136+ isRedirect = true ,
137+ method = " GET" ,
138+ )
139+
140+ return @a when (val interceptResult = navigator.requestInterceptor.onInterceptUrlRequest(webRequest, navigator)) {
141+ WebRequestInterceptResult .Allow -> true
142+
143+ WebRequestInterceptResult .Reject -> false
144+
145+ is WebRequestInterceptResult .Modify -> {
146+ interceptResult.request.let { modified ->
147+ navigator.stopLoading()
148+ navigator.loadUrl(modified.url, modified.headers)
149+ }
150+ false // no jump?
151+ }
152+ }
126153 }
127154 nativeWebView.addNavigateListener(listener)
128155 onDispose {
You can’t perform that action at this time.
0 commit comments