@@ -1469,6 +1469,57 @@ impl InnerWebView {
14691469 Ok ( cookie_builder. build ( ) )
14701470 }
14711471
1472+ unsafe fn cookie_into_win32 (
1473+ cookie_manager : & ICoreWebView2CookieManager ,
1474+ cookie : & cookie:: Cookie < ' _ > ,
1475+ ) -> windows:: core:: Result < ICoreWebView2Cookie > {
1476+ let name = HSTRING :: from ( cookie. name ( ) ) ;
1477+ let value = HSTRING :: from ( cookie. value ( ) ) ;
1478+ let domain = match cookie. domain ( ) {
1479+ Some ( domain) => HSTRING :: from ( domain) ,
1480+ None => HSTRING :: new ( ) ,
1481+ } ;
1482+ let path = match cookie. path ( ) {
1483+ Some ( path) => HSTRING :: from ( path) ,
1484+ None => HSTRING :: new ( ) ,
1485+ } ;
1486+
1487+ let win32_cookie = cookie_manager. CreateCookie ( & name, & value, & domain, & path) ?;
1488+
1489+ let expires = if let Some ( max_age) = cookie. max_age ( ) {
1490+ let expires_ = cookie:: time:: OffsetDateTime :: now_utc ( )
1491+ . saturating_add ( max_age)
1492+ . unix_timestamp ( ) ;
1493+ Some ( expires_)
1494+ } else if let Some ( dt) = cookie. expires_datetime ( ) {
1495+ Some ( dt. unix_timestamp ( ) )
1496+ } else {
1497+ None
1498+ } ;
1499+ if let Some ( expires) = expires {
1500+ win32_cookie. SetExpires ( expires as f64 ) ?;
1501+ }
1502+
1503+ if let Some ( http_only) = cookie. http_only ( ) {
1504+ win32_cookie. SetIsHttpOnly ( http_only) ?;
1505+ }
1506+
1507+ if let Some ( same_site) = cookie. same_site ( ) {
1508+ let same_site = match same_site {
1509+ cookie:: SameSite :: Lax => COREWEBVIEW2_COOKIE_SAME_SITE_KIND_LAX ,
1510+ cookie:: SameSite :: Strict => COREWEBVIEW2_COOKIE_SAME_SITE_KIND_STRICT ,
1511+ cookie:: SameSite :: None => COREWEBVIEW2_COOKIE_SAME_SITE_KIND_NONE ,
1512+ } ;
1513+ win32_cookie. SetSameSite ( same_site) ?;
1514+ }
1515+
1516+ if let Some ( secure) = cookie. secure ( ) {
1517+ win32_cookie. SetIsSecure ( secure) ?;
1518+ }
1519+
1520+ Ok ( win32_cookie)
1521+ }
1522+
14721523 pub fn cookies_for_url ( & self , url : & str ) -> Result < Vec < cookie:: Cookie < ' static > > > {
14731524 let uri = HSTRING :: from ( url) ;
14741525 self . cookies_inner ( PCWSTR :: from_raw ( uri. as_ptr ( ) ) )
@@ -1519,6 +1570,26 @@ impl InnerWebView {
15191570 webview2_com:: wait_with_pump ( rx) . map_err ( Into :: into)
15201571 }
15211572
1573+ pub fn set_cookie ( & self , cookie : & cookie:: Cookie < ' _ > ) -> Result < ( ) > {
1574+ let webview = self . webview . cast :: < ICoreWebView2_2 > ( ) ?;
1575+ unsafe {
1576+ let cookie_manager = webview. CookieManager ( ) ?;
1577+ let cookie = Self :: cookie_into_win32 ( & cookie_manager, cookie) ?;
1578+ cookie_manager. AddOrUpdateCookie ( & cookie) ?;
1579+ }
1580+ Ok ( ( ) )
1581+ }
1582+
1583+ pub fn delete_cookie ( & self , cookie : & cookie:: Cookie < ' _ > ) -> Result < ( ) > {
1584+ let webview = self . webview . cast :: < ICoreWebView2_2 > ( ) ?;
1585+ unsafe {
1586+ let cookie_manager = webview. CookieManager ( ) ?;
1587+ let cookie = Self :: cookie_into_win32 ( & cookie_manager, cookie) ?;
1588+ cookie_manager. DeleteCookie ( & cookie) ?;
1589+ }
1590+ Ok ( ( ) )
1591+ }
1592+
15221593 pub fn reparent ( & self , parent : isize ) -> Result < ( ) > {
15231594 let parent = HWND ( parent as _ ) ;
15241595
0 commit comments