Skip to content

Commit c9c624c

Browse files
committed
Core - Add Cookie.SameSite and Cookie.Priority
Resolves #3254
1 parent 5a73a1b commit c9c624c

File tree

6 files changed

+77
-3
lines changed

6 files changed

+77
-3
lines changed

CefSharp.Core/CookieManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace CefSharp
5353

5454
c.creation = CefTime(DateTimeUtils::ToCefTime(cookie->Creation));
5555
c.last_access = CefTime(DateTimeUtils::ToCefTime(cookie->LastAccess));
56+
c.same_site = (cef_cookie_same_site_t)cookie->SameSite;
57+
c.priority = (cef_cookie_priority_t)cookie->Priority;
5658

5759
return _cookieManager->SetCookie(StringUtils::ToNative(url), c, wrapper);
5860
}

CefSharp.Core/Internals/TypeConversion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ namespace CefSharp
290290
cookie->HttpOnly = cefCookie.httponly == 1;
291291
cookie->Creation = ConvertCefTimeToDateTime(cefCookie.creation);
292292
cookie->LastAccess = ConvertCefTimeToDateTime(cefCookie.last_access);
293+
cookie->SameSite = (CefSharp::Enums::CookieSameSite)cefCookie.same_site;
294+
cookie->Priority = (CefSharp::Enums::CookiePriority)cefCookie.priority;
293295

294296
if (cefCookie.has_expires)
295297
{

CefSharp/CefSharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@
590590
<Compile Include="DevTools\WebAuthn\VirtualAuthenticatorOptions.cs" />
591591
<Compile Include="DevTools\WebAuthn\WebAuthn.cs" />
592592
<Compile Include="Enums\CompositionUnderlineStyle.cs" />
593+
<Compile Include="Enums\CookiePriority.cs" />
594+
<Compile Include="Enums\CookieSameSite.cs" />
593595
<Compile Include="Enums\SchemeOptions.cs" />
594596
<Compile Include="Handler\RequestContextHandler.cs" />
595597
<Compile Include="Internals\CefThread.cs" />

CefSharp/Cookie.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
using System;
66
using System.Diagnostics;
7+
using CefSharp.Enums;
78

89
namespace CefSharp
910
{
1011
/// <summary>
11-
/// Class used to Represent a cookie the built in .Net Cookie
12-
/// class isn't used as some of it's properties have internal setters
12+
/// Class used to Represent a cookie.
13+
/// The built in .Net Cookie class isn't used as some of it's properties have
14+
/// internal setters
1315
/// </summary>
1416
[DebuggerDisplay("Domain = {Domain}, Path = {Path}, Name = {Name}, Secure = {Secure}, HttpOnly = {HttpOnly}," +
1517
"Creation = {Creation}, Expires = {Expires}, LastAccess = {LastAccess}", Name = "Cookie")]
@@ -41,7 +43,7 @@ public sealed class Cookie
4143
/// </summary>
4244
public bool HttpOnly { get; set; }
4345
/// <summary>
44-
/// Expires or null of no expiry
46+
/// Expires or null if no expiry
4547
/// </summary>
4648
public DateTime? Expires { get; set; }
4749
/// <summary>
@@ -52,5 +54,13 @@ public sealed class Cookie
5254
/// The cookie last access date. This is automatically populated by the system on access.
5355
/// </summary>
5456
public DateTime LastAccess { get; set; }
57+
/// <summary>
58+
/// Same site.
59+
/// </summary>
60+
public CookieSameSite SameSite { get; set; }
61+
/// <summary>
62+
/// Priority
63+
/// </summary>
64+
public CookiePriority Priority { get; set; }
5565
}
5666
}

CefSharp/Enums/CookiePriority.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright © 2020 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
namespace CefSharp.Enums
6+
{
7+
/// <summary>
8+
/// Cookie priority values.
9+
/// </summary>
10+
public enum CookiePriority
11+
{
12+
/// <summary>
13+
/// Low Priority
14+
/// </summary>
15+
Low = -1,
16+
/// <summary>
17+
/// Medium Priority
18+
/// </summary>
19+
Medium = 0,
20+
/// <summary>
21+
/// High Priority
22+
/// </summary>
23+
High = 1,
24+
}
25+
}

CefSharp/Enums/CookieSameSite.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright © 2020 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
namespace CefSharp.Enums
6+
{
7+
/// <summary>
8+
/// Cookie same site values.
9+
/// </summary>
10+
///<remarks>
11+
/// See https://source.chromium.org/chromium/chromium/src/+/master:net/cookies/cookie_constants.h
12+
///</remarks>
13+
public enum CookieSameSite
14+
{
15+
/// <summary>
16+
/// Unspecified
17+
/// </summary>
18+
Unspecified = 0,
19+
/// <summary>
20+
/// Cookies will be sent in all contexts, i.e sending cross-origin is allowed.
21+
/// None used to be the default value, but recent browser versions made Lax the default value to have reasonably robust defense against some classes of cross-site request forgery (CSRF) attacks.
22+
/// </summary>
23+
NoRestriction,
24+
/// <summary>
25+
/// Cookies are allowed to be sent with top-level navigations and will be sent along with GET request initiated by third party website. This is the default value in modern browsers.
26+
/// </summary>
27+
LaxMode,
28+
/// <summary>
29+
/// Cookies will only be sent in a first-party context and not be sent along with requests initiated by third party websites.
30+
/// </summary>
31+
StrictMode
32+
}
33+
}

0 commit comments

Comments
 (0)