Skip to content

Commit 82a9c47

Browse files
authored
Merge branch 'kdroidFilter:main' into main
2 parents bc8c98d + 6e0049d commit 82a9c47

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

wrywebview/src/main/kotlin/io/github/kdroidfilter/webview/wry/WryWebViewPanel.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ class WryWebViewPanel(
285285
} ?: emptyList()
286286
}
287287

288+
fun getCookies(): List<WebViewCookie> {
289+
return webviewId?.let {
290+
try {
291+
NativeBindings.getCookies(it)
292+
} catch (e: Exception) {
293+
log("getCookies failed: ${e.message}")
294+
emptyList()
295+
}
296+
} ?: emptyList()
297+
}
298+
288299
fun clearCookiesForUrl(url: String) {
289300
val action = { webviewId?.let { NativeBindings.clearCookiesForUrl(it, url) } }
290301
if (SwingUtilities.isEventDispatchThread()) {
@@ -856,6 +867,10 @@ private object NativeBindings {
856867
return io.github.kdroidfilter.webview.wry.getCookiesForUrl(id, url)
857868
}
858869

870+
fun getCookies(id: ULong): List<WebViewCookie> {
871+
return io.github.kdroidfilter.webview.wry.getCookies(id)
872+
}
873+
859874
fun clearCookiesForUrl(id: ULong, url: String) {
860875
io.github.kdroidfilter.webview.wry.clearCookiesForUrl(id, url)
861876
}

wrywebview/src/main/rust/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,25 @@ pub fn drain_ipc_messages(id: u64) -> Result<Vec<String>, WebViewError> {
847847
// Cookies
848848
// ============================================================================
849849

850+
fn get_cookies_inner(id: u64) -> Result<Vec<WebViewCookie>, WebViewError> {
851+
wry_log!("[wrywebview] get_cookies id={}", id);
852+
with_webview(id, |webview| {
853+
let cookies = webview.cookies().map_err(WebViewError::from)?;
854+
Ok(cookies.iter().map(cookie_record_from).collect())
855+
})
856+
}
857+
858+
#[uniffi::export]
859+
pub fn get_cookies(id: u64) -> Result<Vec<WebViewCookie>, WebViewError> {
860+
#[cfg(target_os = "linux")]
861+
{
862+
return run_on_gtk_thread(move || get_cookies_inner(id));
863+
}
864+
865+
#[cfg(not(target_os = "linux"))]
866+
run_on_main_thread(move || get_cookies_inner(id))
867+
}
868+
850869
fn get_cookies_for_url_inner(id: u64, url: String) -> Result<Vec<WebViewCookie>, WebViewError> {
851870
wry_log!("[wrywebview] get_cookies_for_url id={} url={}", id, url);
852871
with_webview(id, |webview| {

0 commit comments

Comments
 (0)