browser_window_core/
cookie.rs1pub mod c;
2
3
4use std::{
5 borrow::Cow,
6 error::Error,
7 fmt,
8 time::SystemTime
9};
10
11pub use c::*;
12
13
14
15pub type CookieStorageCallbackFn = unsafe fn( cj: CookieJarImpl, data: *mut (), Result<(), CookieStorageError> );
16pub type CookieDeleteCallbackFn = unsafe fn(cj: CookieJarImpl, data: *mut (), deleted: usize);
17pub type CookieIteratorNextCallbackFn = unsafe fn(cj: CookieIteratorImpl, data: *mut (), Option<CookieImpl>);
18
19pub trait CookieExt {
20 fn new(name: &str, value: &str) -> CookieImpl;
21
22 fn creation_time(&self) -> SystemTime;
23 fn expires(&self) -> Option<SystemTime>;
24 fn domain<'a>(&'a self) -> Cow<'a, str>;
25 fn free(&mut self);
26 fn is_http_only(&self) -> bool;
27 fn name<'a>(&'a self) -> Cow<'a, str>;
28 fn path<'a>(&'a self) -> Cow<'a, str>;
29 fn is_secure(&self) -> bool;
30 fn value<'a>(&'a self) -> Cow<'a, str>;
31
32 fn make_http_only(&mut self) -> &mut Self;
33 fn make_secure(&mut self) -> &mut Self;
34 fn set_creation_time(&mut self, time: &SystemTime) -> &mut Self;
35 fn set_expires(&mut self, time: &SystemTime) -> &mut Self;
36 fn set_domain(&mut self, domain: &str) -> &mut Self;
37 fn set_name(&mut self, name: &str) -> &mut Self;
38 fn set_path(&mut self, path: &str) -> &mut Self;
39 fn set_value(&mut self, value: &str) -> &mut Self;
40}
41
42pub trait CookieJarExt {
43 fn delete(&mut self, url: &str, name: &str, complete_cb: CookieDeleteCallbackFn, cb_data: *mut ());
44 fn free(&mut self);
45 fn global() -> CookieJarImpl;
46 fn iterator<'a>(&'a self, url: &str, include_http_only: bool) -> CookieIteratorImpl;
47 fn iterator_all<'a>(&'a self) -> CookieIteratorImpl;
48 fn store(&mut self, url: &str, cookie: &CookieImpl, success_cb: Option<CookieStorageCallbackFn>, cb_data: *mut ());
49}
50
51pub trait CookieIteratorExt {
52 fn free(&mut self);
53 fn next(&mut self, on_next: CookieIteratorNextCallbackFn, cb_data: *mut ()) -> bool;
54}
55
56#[derive(Debug)]
57pub enum CookieStorageError {
58 Unknown
59}
60
61
62
63impl fmt::Display for CookieStorageError {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 write!(f, "unable to set cookie (url invalid?)")
66 }
67}
68
69impl Error for CookieStorageError {
70 fn source(&self) -> Option<&(dyn Error + 'static)> { None }
71}