generated from JetBrains/compose-multiplatform-template
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from DatL4g/main Support custom request contex…
…t handler Updated jcef to latest version and KCEF for improved custom request context handler
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
webview/src/desktopMain/kotlin/com/multiplatform/webview/web/CefRequestExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.multiplatform.webview.web | ||
|
||
import com.multiplatform.webview.setting.WebSettings | ||
import dev.datlag.kcef.KCEFResourceRequestHandler | ||
import org.cef.browser.CefBrowser | ||
import org.cef.browser.CefFrame | ||
import org.cef.browser.CefRequestContext | ||
import org.cef.network.CefRequest | ||
|
||
internal fun createModifiedRequestContext(settings: WebSettings): CefRequestContext { | ||
return CefRequestContext.createContext { browser, frame, request, isNavigation, isDownload, requestInitiator, disableDefaultHandling -> | ||
object : KCEFResourceRequestHandler( | ||
getGlobalDefaultHandler(browser, frame, request, isNavigation, isDownload, requestInitiator, disableDefaultHandling), | ||
) { | ||
override fun onBeforeResourceLoad( | ||
browser: CefBrowser?, | ||
frame: CefFrame?, | ||
request: CefRequest?, | ||
): Boolean { | ||
if (request != null) { | ||
settings.customUserAgentString?.let(request::setUserAgentString) | ||
} | ||
return super.onBeforeResourceLoad(browser, frame, request) | ||
} | ||
} | ||
} | ||
} | ||
|
||
internal fun CefRequest.setUserAgentString(userAgent: String) { | ||
setHeaderByName("User-Agent", userAgent, true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters