| | | 1 | | // SPDX-FileCopyrightText: 2026 Alper Çelik |
| | | 2 | | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| | | 3 | | |
| | | 4 | | //! Cookie declarations (owned by the cookies worker). |
| | | 5 | | //! |
| | | 6 | | //! The runtime keeps its own copy of the profile's cookies: Qt's |
| | | 7 | | //! `QWebEngineCookieStore` can only enumerate asynchronously and never signals |
| | | 8 | | //! completion, so instead of blocking we mirror the store from its |
| | | 9 | | //! `cookieAdded` / `cookieRemoved` signals and answer reads from that copy. |
| | | 10 | | //! |
| | | 11 | | //! C++ translation units include the cxx-generated header for this bridge: |
| | | 12 | | //! `#include "tauri-runtime-qt/src/bridge/cookies.rs.h"`. |
| | | 13 | | |
| | | 14 | | #[cxx::bridge] |
| | | 15 | | pub mod ffi { |
| | | 16 | | unsafe extern "C++" { |
| | | 17 | | include!("qt_cookies.hpp"); |
| | | 18 | | |
| | | 19 | | /// Starts mirroring the cookie store of the webview behind this handle |
| | | 20 | | /// (the `QWebEngineView*` value returned by `qt_webview_native_handle`). |
| | 21 | 21 | | fn qt_cookies_watch(webview_ptr: u64); |
| | | 22 | | |
| | | 23 | | /// Adds a cookie to the store (`QWebEngineCookieStore::setCookie`). |
| | | 24 | | /// `expires_ms` is Unix epoch milliseconds, or -1 for a session cookie. |
| | | 25 | | /// `same_site`: 0 = default/unset, 1 = none, 2 = lax, 3 = strict. |
| | 42 | 26 | | fn qt_cookies_set( |
| | 42 | 27 | | webview_ptr: u64, |
| | 42 | 28 | | name: &str, |
| | 42 | 29 | | value: &str, |
| | 42 | 30 | | domain: &str, |
| | 42 | 31 | | path: &str, |
| | 42 | 32 | | secure: bool, |
| | 42 | 33 | | http_only: bool, |
| | 42 | 34 | | same_site: i32, |
| | 42 | 35 | | expires_ms: i64, |
| | 42 | 36 | | ); |
| | | 37 | | |
| | | 38 | | /// Deletes a cookie from the store. |
| | 21 | 39 | | fn qt_cookies_delete(webview_ptr: u64, name: &str, domain: &str, path: &str); |
| | | 40 | | |
| | | 41 | | /// Deletes every cookie of the profile. |
| | 21 | 42 | | fn qt_cookies_clear_all(webview_ptr: u64); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | extern "Rust" { |
| | | 46 | | /// A cookie entered the store (including the initial load). |
| | | 47 | | #[allow(clippy::too_many_arguments)] |
| | | 48 | | fn qt_on_cookie_added( |
| | | 49 | | webview_ptr: u64, |
| | | 50 | | name: &str, |
| | | 51 | | value: &str, |
| | | 52 | | domain: &str, |
| | | 53 | | path: &str, |
| | | 54 | | secure: bool, |
| | | 55 | | http_only: bool, |
| | | 56 | | same_site: i32, |
| | | 57 | | expires_ms: i64, |
| | | 58 | | ); |
| | | 59 | | |
| | | 60 | | /// A cookie left the store. |
| | | 61 | | fn qt_on_cookie_removed(webview_ptr: u64, name: &str, domain: &str, path: &str); |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | /// Defined in the same module as the bridge, as cxx requires. |
| | 84 | 66 | | pub fn qt_on_cookie_added( |
| | 84 | 67 | | webview_ptr: u64, |
| | 84 | 68 | | name: &str, |
| | 84 | 69 | | value: &str, |
| | 84 | 70 | | domain: &str, |
| | 84 | 71 | | path: &str, |
| | 84 | 72 | | secure: bool, |
| | 84 | 73 | | http_only: bool, |
| | 84 | 74 | | same_site: i32, |
| | 84 | 75 | | expires_ms: i64, |
| | 84 | 76 | | ) { |
| | 84 | 77 | | crate::ops::cookies::on_cookie_added( |
| | 84 | 78 | | webview_ptr, |
| | 84 | 79 | | name, |
| | 84 | 80 | | value, |
| | 84 | 81 | | domain, |
| | 84 | 82 | | path, |
| | 84 | 83 | | secure, |
| | 84 | 84 | | http_only, |
| | 84 | 85 | | same_site, |
| | 84 | 86 | | expires_ms, |
| | | 87 | | ); |
| | 84 | 88 | | } |
| | | 89 | | |
| | | 90 | | /// Defined in the same module as the bridge, as cxx requires. |
| | 84 | 91 | | pub fn qt_on_cookie_removed(webview_ptr: u64, name: &str, domain: &str, path: &str) { |
| | 84 | 92 | | crate::ops::cookies::on_cookie_removed(webview_ptr, name, domain, path); |
| | 84 | 93 | | } |