Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ class WryWebViewPanel(
} ?: emptyList()
}

fun getCookies(): List<WebViewCookie> {
return webviewId?.let {
try {
NativeBindings.getCookies(it)
} catch (e: Exception) {
log("getCookies failed: ${e.message}")
emptyList()
}
} ?: emptyList()
}

fun clearCookiesForUrl(url: String) {
val action = { webviewId?.let { NativeBindings.clearCookiesForUrl(it, url) } }
if (SwingUtilities.isEventDispatchThread()) {
Expand Down Expand Up @@ -792,6 +803,10 @@ private object NativeBindings {
return io.github.kdroidfilter.webview.wry.getCookiesForUrl(id, url)
}

fun getCookies(id: ULong): List<WebViewCookie> {
return io.github.kdroidfilter.webview.wry.getCookies(id)
}

fun clearCookiesForUrl(id: ULong, url: String) {
io.github.kdroidfilter.webview.wry.clearCookiesForUrl(id, url)
}
Expand Down
19 changes: 19 additions & 0 deletions wrywebview/src/main/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,25 @@ pub fn drain_ipc_messages(id: u64) -> Result<Vec<String>, WebViewError> {
// Cookies
// ============================================================================

fn get_cookies_inner(id: u64) -> Result<Vec<WebViewCookie>, WebViewError> {
wry_log!("[wrywebview] get_cookies id={}", id);
with_webview(id, |webview| {
let cookies = webview.cookies().map_err(WebViewError::from)?;
Ok(cookies.iter().map(cookie_record_from).collect())
})
}

#[uniffi::export]
pub fn get_cookies(id: u64) -> Result<Vec<WebViewCookie>, WebViewError> {
#[cfg(target_os = "linux")]
{
return run_on_gtk_thread(move || get_cookies_inner(id));
}

#[cfg(not(target_os = "linux"))]
run_on_main_thread(move || get_cookies_inner(id))
}

fn get_cookies_for_url_inner(id: u64, url: String) -> Result<Vec<WebViewCookie>, WebViewError> {
wry_log!("[wrywebview] get_cookies_for_url id={} url={}", id, url);
with_webview(id, |webview| {
Expand Down