Skip to content

Commit f5d4696

Browse files
committed
Add CookieManager.GetBlockingManager (cztomczak#403)
1 parent 2778bc5 commit f5d4696

File tree

8 files changed

+77
-15
lines changed

8 files changed

+77
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ Additional information for v31.2 release:
509509
* [GetExpires](api/Cookie.md#getexpires)
510510
* [CookieManager (class)](api/CookieManager.md#cookiemanager-class)
511511
* [GetGlobalManager](api/CookieManager.md#getglobalmanager)
512+
* [GetBlockingManager](api/CookieManager.md#getblockingmanager)
512513
* [CreateManager](api/CookieManager.md#createmanager)
513514
* [SetSupportedSchemes](api/CookieManager.md#setsupportedschemes)
514515
* [VisitAllCookies](api/CookieManager.md#visitallcookies)

api/API-index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
* [GetExpires](Cookie.md#getexpires)
198198
* [CookieManager (class)](CookieManager.md#cookiemanager-class)
199199
* [GetGlobalManager](CookieManager.md#getglobalmanager)
200+
* [GetBlockingManager](CookieManager.md#getblockingmanager)
200201
* [CreateManager](CookieManager.md#createmanager)
201202
* [SetSupportedSchemes](CookieManager.md#setsupportedschemes)
202203
* [VisitAllCookies](CookieManager.md#visitallcookies)

api/CookieManager.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
# CookieManager (class)
55

6-
This class cannot be instantiated directly, use the CreateManager()
7-
static method for this purpose.
6+
Class used for managing cookies. The methods of this class may be called on
7+
any thread unless otherwise indicated.
88

9-
The cookie tests can be found in the wxpython.py script.
9+
Use the `CookieManager.CreateManager` static method to instantiate
10+
this class.
1011

1112
TODO: in upstream CEF some methods here have a callback parameter
1213
that when non-NULL will execute asynchronously on the IO thread
@@ -17,6 +18,7 @@ also have an OnComplete callback.
1718
Table of contents:
1819
* [Methods](#methods)
1920
* [GetGlobalManager](#getglobalmanager)
21+
* [GetBlockingManager](#getblockingmanager)
2022
* [CreateManager](#createmanager)
2123
* [SetSupportedSchemes](#setsupportedschemes)
2224
* [VisitAllCookies](#visitallcookies)
@@ -34,19 +36,41 @@ Table of contents:
3436

3537
| | |
3638
| --- | --- |
37-
| __Return__ | static [CookieManager](CookieManager.md) |
39+
| __Return__ | [CookieManager](CookieManager.md) |
3840

3941
Returns the global cookie manager. By default data will be stored at
4042
[ApplicationSettings](ApplicationSettings.md).cache_path if specified or in memory otherwise.
4143

44+
Description from upstream CEF:
45+
> Returns the global cookie manager. By default data will be stored at
46+
> CefSettings.cache_path if specified or in memory otherwise. If |callback|
47+
> is non-NULL it will be executed asnychronously on the IO thread after the
48+
> manager's storage has been initialized. Using this method is equivalent to
49+
> calling CefRequestContext::GetGlobalContext()->GetDefaultCookieManager()
50+
51+
52+
### GetBlockingManager
53+
54+
| | |
55+
| --- | --- |
56+
| __Return__ | [CookieManager](CookieManager.md) |
57+
58+
Description from upstream CEF:
59+
> Returns a cookie manager that neither stores nor retrieves cookies. All
60+
> usage of cookies will be blocked including cookies accessed via the network
61+
> (request/response headers), via JavaScript (document.cookie), and via
62+
> CefCookieManager methods. No cookies will be displayed in DevTools. If you
63+
> wish to only block cookies sent via the network use the CefRequestHandler
64+
> CanGetCookies and CanSetCookie methods instead.
65+
4266

4367
### CreateManager
4468

4569
| Parameter | Type |
4670
| --- | --- |
4771
| path | string |
4872
| persistSessionCookies=False | bool |
49-
| __Return__ | static [CookieManager](CookieManager.md) |
73+
| __Return__ | [CookieManager](CookieManager.md) |
5074

5175
Creates a new cookie manager. Otherwise, data will be stored at the
5276
specified |path|. To persist session cookies (cookies without an expiry
@@ -181,4 +205,4 @@ Flush the backing store (if any) to disk. If |callback| is non-NULL it will
181205
be executed asnychronously on the IO thread after the flush is complete.
182206
Returns false if cookies cannot be accessed.
183207

184-
The callback arg is not implemented.
208+
The callback arg is not implemented yet.

examples/wxpython.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def scale_window_size_for_high_dpi(width, height):
7979
if not WINDOWS:
8080
return width, height
8181
(_, _, max_width, max_height) = wx.GetClientDisplayRect().Get()
82-
# noinspection PyUnresolvedReferences, PyArgumentList
82+
# noinspection PyUnresolvedReferences
8383
(width, height) = cef.DpiAware.Scale((width, height))
8484
if width > max_width:
8585
width = max_width
@@ -174,7 +174,7 @@ def create_menu(self):
174174
def embed_browser(self):
175175
window_info = cef.WindowInfo()
176176
(width, height) = self.browser_panel.GetClientSize().Get()
177-
assert self.browser_panel.GetHandle(), "Window handle not available yet"
177+
assert self.browser_panel.GetHandle(), "Window handle not available"
178178
window_info.SetAsChild(self.browser_panel.GetHandle(),
179179
[0, 0, width, height])
180180
self.browser = cef.CreateBrowserSync(window_info,

src/cef_v59..v66_changes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ NEW FEATURES
7373
+ unittests/osr_test.py - new test for off-screen rendering mode
7474
+ cefpython.SetGlobalClientHandler
7575
+ Browser.Invalidate
76+
+ CookieManager.FlushStore
7677

7778
internal/cef_types.h
7879
+ cef_log_severity_t: new key LOGSEVERITY_DEBUG (no need to expose,
@@ -98,7 +99,7 @@ cef_browser.h
9899
- IsBackgroundHost
99100

100101
cef_cookie.h
101-
- GetBlockingManager
102+
+ GetBlockingManager
102103

103104
cef_display_handler.h
104105
+ OnAutoResize

src/cookie.pyx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,12 @@ cdef class Cookie:
181181
# CookieManager
182182
# ------------------------------------------------------------------------------
183183

184-
class CookieManager:
185-
@staticmethod
186-
def GetGlobalManager():
184+
class CookieManager(object):
185+
"""Class used for managing cookies. To instantiate this class
186+
call CreateManager() static method."""
187+
188+
@classmethod
189+
def GetGlobalManager(cls):
187190
global g_globalCookieManager
188191
cdef CefRefPtr[CefCookieManager] cefCookieManager
189192
if not g_globalCookieManager:
@@ -192,11 +195,28 @@ class CookieManager:
192195
g_globalCookieManager = CreatePyCookieManager(cefCookieManager)
193196
return g_globalCookieManager
194197

195-
@staticmethod
196-
def CreateManager(py_string path, py_bool persistSessionCookies=False):
198+
@classmethod
199+
def GetBlockingManager(cls):
200+
return CreatePyCookieManager(CefCookieManager_GetBlockingManager())
201+
202+
@classmethod
203+
def CreateManager(cls, py_string path,
204+
py_bool persist_session_cookies=False):
205+
"""
206+
Create a new cookie manager.
207+
:param path:
208+
:type path: str
209+
:param persist_session_cookies:
210+
:type path: bool
211+
:return: CookieManager object
212+
:rtype: CookieManager
213+
"""
214+
# When PyCharm generates a stub for the cefpython module
215+
# it doesn't use the above docstring for code inspections.
216+
# No idea why.
197217
cdef CefRefPtr[CefCookieManager] cefCookieManager
198218
cefCookieManager = CefCookieManager_CreateManager(
199-
PyToCefStringValue(path), bool(persistSessionCookies),
219+
PyToCefStringValue(path), bool(persist_session_cookies),
200220
<CefRefPtr[CefCompletionCallback]?>NULL)
201221
if <void*>cefCookieManager != NULL and cefCookieManager.get():
202222
return CreatePyCookieManager(cefCookieManager)

src/extern/cef/cef_cookie.pxd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ cdef extern from "include/cef_cookie.h":
2727
cdef CefRefPtr[CefCookieManager] CefCookieManager_GetGlobalManager \
2828
"CefCookieManager::GetGlobalManager"(
2929
CefRefPtr[CefCompletionCallback] callback)
30+
31+
cdef CefRefPtr[CefCookieManager] CefCookieManager_GetBlockingManager \
32+
"CefCookieManager::GetBlockingManager"()
33+
34+
3035
cdef CefRefPtr[CefCookieManager] CefCookieManager_CreateManager \
3136
"CefCookieManager::CreateManager"(
3237
const CefString& path,
3338
cpp_bool persist_session_cookies,
3439
CefRefPtr[CefCompletionCallback] callback)
40+
3541
cdef cppclass CefCookieManager:
3642
void SetSupportedSchemes(const cpp_vector[CefString]& schemes,
3743
CefRefPtr[CefCompletionCallback] callback)

unittests/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ def test_main(self):
197197
self.assertEqual(req_data, req.GetPostData())
198198
subtest_message("cef.Request.SetPostData(dict) ok")
199199

200+
# Cookie manager
201+
self.assertIsInstance(cef.CookieManager.CreateManager(path=""),
202+
cef.PyCookieManager)
203+
self.assertIsInstance(cef.CookieManager.GetGlobalManager(),
204+
cef.PyCookieManager)
205+
self.assertIsInstance(cef.CookieManager.GetBlockingManager(),
206+
cef.PyCookieManager)
207+
subtest_message("cef.CookieManager ok")
208+
200209
# Run message loop
201210
run_message_loop()
202211

0 commit comments

Comments
 (0)