desktopMain.com.multiplatform.webview.web.CefRequestExt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compose-webview-multiplatform-desktop Show documentation
Show all versions of compose-webview-multiplatform-desktop Show documentation
WebView for JetBrains Compose Multiplatform
package com.multiplatform.webview.web
import com.multiplatform.webview.setting.WebSettings
import org.cef.browser.CefBrowser
import org.cef.browser.CefFrame
import org.cef.browser.CefRequestContext
import org.cef.handler.*
import org.cef.misc.BoolRef
import org.cef.network.CefCookie
import org.cef.network.CefRequest
import org.cef.network.CefResponse
internal fun createModifiedRequestContext(
settings: WebSettings
): CefRequestContext {
val resourceRequestHandler = object : CefResourceRequestHandlerAdapter() {
override fun onBeforeResourceLoad(
browser: CefBrowser?,
frame: CefFrame?,
request: CefRequest?
): Boolean {
if (request != null) {
settings.customUserAgentString?.let(request::setUserAgentString)
}
return false
}
}
return CefRequestContext.createContext(
object : CefRequestContextHandlerAdapter() {
override fun getResourceRequestHandler(
browser: CefBrowser?,
frame: CefFrame?,
request: CefRequest?,
isNavigation: Boolean,
isDownload: Boolean,
requestInitiator: String?,
disableDefaultHandling: BoolRef?
): CefResourceRequestHandler {
return resourceRequestHandler
}
}
)
}
internal fun CefRequest.setUserAgentString(userAgent: String) {
setHeaderByName("User-Agent", userAgent, true)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy