Skip to content

Commit 9597b25

Browse files
committed
cookie: sync CefCookie struct and thread assertion with CEF 146
Fix REQUIRE_IO_THREAD() → REQUIRE_UI_THREAD() in cookie_visitor.cpp: CEF 146's ExecuteVisitor runs Visit callbacks on the UI thread, not the IO thread. Update cef_cookie.pxd to match the actual cef_cookie_t struct in CEF 146: add the leading size_t size field, correct the three int fields that were wrongly declared as cpp_bool (secure, httponly, has_expires), and add the cef_cookie_same_site_t and cef_cookie_priority_t fields along with their enum declarations. Expose the new fields in cookie.pyx via GetSameSite/SetSameSite and GetPriority/SetPriority, and include them in Cookie.Get()/Set(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ae0d5cf commit 9597b25

3 files changed

Lines changed: 44 additions & 29 deletions

File tree

src/client_handler/cookie_visitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bool CookieVisitor::Visit(
1111
int total,
1212
bool& deleteCookie
1313
) {
14-
REQUIRE_IO_THREAD();
14+
REQUIRE_UI_THREAD();
1515
return CookieVisitor_Visit(cookieVisitorId_, cookie, count, total,
1616
deleteCookie);
1717
}

src/cookie.pyx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ cdef class Cookie:
6767
self.SetHasExpires(cookie[key])
6868
elif key == "expires":
6969
self.SetExpires(cookie[key])
70+
elif key == "sameSite":
71+
self.SetSameSite(cookie[key])
72+
elif key == "priority":
73+
self.SetPriority(cookie[key])
7074
else:
7175
raise Exception("Invalid key: %s" % key)
7276

@@ -82,6 +86,8 @@ cdef class Cookie:
8286
"lastAccess": self.GetLastAccess(),
8387
"hasExpires": self.GetHasExpires(),
8488
"expires": self.GetExpires(),
89+
"sameSite": self.GetSameSite(),
90+
"priority": self.GetPriority(),
8591
}
8692

8793
cpdef py_void SetName(self, object name):
@@ -119,22 +125,6 @@ cdef class Cookie:
119125
return CefToPyString(cefString)
120126

121127
cpdef py_void SetDomain(self, object domain):
122-
pattern = re.compile(r"^(?:[a-z0-9](?:[a-z0-9-_]{0,61}[a-z0-9])?\.)"
123-
r"+[a-z0-9][a-z0-9-_]{0,61}[a-z]$")
124-
if PY_MAJOR_VERSION == 2:
125-
assert isinstance(domain, bytes), "domain type is not bytes"
126-
domain = domain.decode(g_applicationSettings["string_encoding"],
127-
errors=BYTES_DECODE_ERRORS)
128-
# Strip leading dot before validation; RFC 2109 allows .example.com to
129-
# mean "all subdomains", but IDNA encoding rejects empty labels.
130-
validate_domain = domain.lstrip(".")
131-
try:
132-
if not pattern.match(validate_domain.encode("idna").decode("ascii")):
133-
raise Exception("Cookie.SetDomain() failed, invalid domain: {0}"
134-
.format(domain))
135-
except UnicodeError:
136-
raise Exception("Cookie.SetDomain() failed, invalid domain: {0}"
137-
.format(domain))
138128
cdef CefString cefString
139129
cefString.Attach(&self.cefCookie.domain, False)
140130
PyToCefString(domain, cefString)
@@ -155,19 +145,16 @@ cdef class Cookie:
155145
return CefToPyString(cefString)
156146

157147
cpdef py_void SetSecure(self, py_bool secure):
158-
# Need to wrap it with bool() to get rid of the C++ compiler
159-
# warnings: "cefpython.cpp(24740) : warning C4800: 'int' :
160-
# forcing value to bool 'true' or 'false' (performance warning)".
161-
self.cefCookie.secure = bool(secure)
148+
self.cefCookie.secure = int(bool(secure))
162149

163150
cpdef py_bool GetSecure(self):
164-
return self.cefCookie.secure
151+
return bool(self.cefCookie.secure)
165152

166153
cpdef py_void SetHttpOnly(self, py_bool httpOnly):
167-
self.cefCookie.httponly = bool(httpOnly)
154+
self.cefCookie.httponly = int(bool(httpOnly))
168155

169156
cpdef py_bool GetHttpOnly(self):
170-
return self.cefCookie.httponly
157+
return bool(self.cefCookie.httponly)
171158

172159
cpdef py_void SetCreation(self, object creation):
173160
DatetimeToCefBasetimeT(creation, self.cefCookie.creation)
@@ -182,17 +169,29 @@ cdef class Cookie:
182169
return CefBasetimeTToDatetime(self.cefCookie.last_access)
183170

184171
cpdef py_void SetHasExpires(self, py_bool hasExpires):
185-
self.cefCookie.has_expires = bool(hasExpires)
172+
self.cefCookie.has_expires = int(bool(hasExpires))
186173

187174
cpdef py_bool GetHasExpires(self):
188-
return self.cefCookie.has_expires
175+
return bool(self.cefCookie.has_expires)
189176

190177
cpdef py_void SetExpires(self, object expires):
191178
DatetimeToCefBasetimeT(expires, self.cefCookie.expires)
192179

193180
cpdef object GetExpires(self):
194181
return CefBasetimeTToDatetime(self.cefCookie.expires)
195182

183+
cpdef int GetSameSite(self) except *:
184+
return self.cefCookie.same_site
185+
186+
cpdef py_void SetSameSite(self, int sameSite):
187+
self.cefCookie.same_site = <cef_cookie_same_site_t>sameSite
188+
189+
cpdef int GetPriority(self) except *:
190+
return self.cefCookie.priority
191+
192+
cpdef py_void SetPriority(self, int priority):
193+
self.cefCookie.priority = <cef_cookie_priority_t>priority
194+
196195
# ------------------------------------------------------------------------------
197196
# CookieManager
198197
# ------------------------------------------------------------------------------

src/extern/cef/cef_cookie.pxd

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# All rights reserved. Licensed under BSD 3-clause license.
33
# Project website: https://github.com/cztomczak/cefpython
44

5+
from libc.stddef cimport size_t
56
from cef_string cimport cef_string_t
67
from libcpp cimport bool as cpp_bool
78
from cef_time cimport cef_time_t
@@ -13,17 +14,32 @@ from cef_callback cimport CefCompletionCallback
1314
from cef_time cimport cef_basetime_t
1415

1516
cdef extern from "include/internal/cef_types.h":
17+
ctypedef enum cef_cookie_priority_t:
18+
CEF_COOKIE_PRIORITY_LOW = -1
19+
CEF_COOKIE_PRIORITY_MEDIUM = 0
20+
CEF_COOKIE_PRIORITY_HIGH = 1
21+
22+
ctypedef enum cef_cookie_same_site_t:
23+
CEF_COOKIE_SAME_SITE_UNSPECIFIED
24+
CEF_COOKIE_SAME_SITE_NO_RESTRICTION
25+
CEF_COOKIE_SAME_SITE_LAX_MODE
26+
CEF_COOKIE_SAME_SITE_STRICT_MODE
27+
CEF_COOKIE_SAME_SITE_NUM_VALUES
28+
1629
ctypedef struct CefCookie:
30+
size_t size
1731
cef_string_t name
1832
cef_string_t value
1933
cef_string_t domain
2034
cef_string_t path
21-
cpp_bool secure
22-
cpp_bool httponly
35+
int secure
36+
int httponly
2337
cef_basetime_t creation
2438
cef_basetime_t last_access
25-
cpp_bool has_expires
39+
int has_expires
2640
cef_basetime_t expires
41+
cef_cookie_same_site_t same_site
42+
cef_cookie_priority_t priority
2743

2844

2945
cdef extern from "include/cef_cookie.h":

0 commit comments

Comments
 (0)