forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcookie_access_filter.pyx
More file actions
91 lines (86 loc) · 3.17 KB
/
Copy pathcookie_access_filter.pyx
File metadata and controls
91 lines (86 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright (c) 2018 CEF Python, see the Authors file.
# All rights reserved. Licensed under BSD 3-clause license.
# Project website: https://github.com/cztomczak/cefpython
include "../cefpython.pyx"
include "../browser.pyx"
include "../frame.pyx"
include "../process_message_utils.pyx"
cdef public cpp_bool CookieAccessFilter_CanSendCookie(
CefRefPtr[CefBrowser] cef_browser,
CefRefPtr[CefFrame] cef_frame,
CefRefPtr[CefRequest] cef_request,
const CefCookie& cef_cookie
) except * with gil:
cdef PyBrowser browser
cdef PyFrame frame
cdef PyRequest request
cdef PyCookie cookie
cdef object callback
cdef py_bool retval
try:
Debug("CookieAccessFilter_CanSendCookie")
# Issue #455: CefRequestHandler callbacks still executed after
# browser was closed.
if IsBrowserClosed(cef_browser):
return False
if not cef_frame.get().GetBrowser().get():
return True # default: allow cookie
browser = GetPyBrowser(cef_browser, "CanSendCookie")
frame = GetPyFrame(cef_frame)
request = CreatePyRequest(cef_request)
cookie = CreatePyCookie(cef_cookie)
callback = browser.GetClientCallback("CanSendCookie")
if callback:
retval = callback(
browser=browser,
frame=frame,
request=request,
cookie=cookie)
return bool(retval)
else:
# Return True by default
return True
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool CookieAccessFilter_CanSaveCookie(
CefRefPtr[CefBrowser] cef_browser,
CefRefPtr[CefFrame] cef_frame,
CefRefPtr[CefRequest] cef_request,
CefRefPtr[CefResponse] cef_response,
const CefCookie& cef_cookie
) except * with gil:
cdef PyBrowser browser
cdef PyFrame frame
cdef PyRequest request
cdef PyResponse response
cdef PyCookie cookie
cdef object callback
cdef py_bool retval
try:
# Issue #455: CefRequestHandler callbacks still executed after
# browser was closed.
if IsBrowserClosed(cef_browser):
return False
if not cef_frame.get().GetBrowser().get():
return True # default: allow cookie
browser = GetPyBrowser(cef_browser, "CanSaveCookie")
frame = GetPyFrame(cef_frame)
request = CreatePyRequest(cef_request)
response = CreatePyResponse(cef_response)
cookie = CreatePyCookie(cef_cookie)
callback = browser.GetClientCallback("CanSaveCookie")
if callback:
retval = callback(
browser=browser,
frame=frame,
request=request,
response=response,
cookie=cookie)
return bool(retval)
else:
# Return True by default
return True
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)