Skip to content

Commit

Permalink
Add CookieManager.GetBlockingManager (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Aug 19, 2018
1 parent 2778bc5 commit f5d4696
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ Additional information for v31.2 release:
* [GetExpires](api/Cookie.md#getexpires)
* [CookieManager (class)](api/CookieManager.md#cookiemanager-class)
* [GetGlobalManager](api/CookieManager.md#getglobalmanager)
* [GetBlockingManager](api/CookieManager.md#getblockingmanager)
* [CreateManager](api/CookieManager.md#createmanager)
* [SetSupportedSchemes](api/CookieManager.md#setsupportedschemes)
* [VisitAllCookies](api/CookieManager.md#visitallcookies)
Expand Down
1 change: 1 addition & 0 deletions api/API-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
* [GetExpires](Cookie.md#getexpires)
* [CookieManager (class)](CookieManager.md#cookiemanager-class)
* [GetGlobalManager](CookieManager.md#getglobalmanager)
* [GetBlockingManager](CookieManager.md#getblockingmanager)
* [CreateManager](CookieManager.md#createmanager)
* [SetSupportedSchemes](CookieManager.md#setsupportedschemes)
* [VisitAllCookies](CookieManager.md#visitallcookies)
Expand Down
36 changes: 30 additions & 6 deletions api/CookieManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

# CookieManager (class)

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

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

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

| | |
| --- | --- |
| __Return__ | static [CookieManager](CookieManager.md) |
| __Return__ | [CookieManager](CookieManager.md) |

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

Description from upstream CEF:
> Returns the global cookie manager. By default data will be stored at
> CefSettings.cache_path if specified or in memory otherwise. If |callback|
> is non-NULL it will be executed asnychronously on the IO thread after the
> manager's storage has been initialized. Using this method is equivalent to
> calling CefRequestContext::GetGlobalContext()->GetDefaultCookieManager()

### GetBlockingManager

| | |
| --- | --- |
| __Return__ | [CookieManager](CookieManager.md) |

Description from upstream CEF:
> Returns a cookie manager that neither stores nor retrieves cookies. All
> usage of cookies will be blocked including cookies accessed via the network
> (request/response headers), via JavaScript (document.cookie), and via
> CefCookieManager methods. No cookies will be displayed in DevTools. If you
> wish to only block cookies sent via the network use the CefRequestHandler
> CanGetCookies and CanSetCookie methods instead.

### CreateManager

| Parameter | Type |
| --- | --- |
| path | string |
| persistSessionCookies=False | bool |
| __Return__ | static [CookieManager](CookieManager.md) |
| __Return__ | [CookieManager](CookieManager.md) |

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

The callback arg is not implemented.
The callback arg is not implemented yet.
4 changes: 2 additions & 2 deletions examples/wxpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def scale_window_size_for_high_dpi(width, height):
if not WINDOWS:
return width, height
(_, _, max_width, max_height) = wx.GetClientDisplayRect().Get()
# noinspection PyUnresolvedReferences, PyArgumentList
# noinspection PyUnresolvedReferences
(width, height) = cef.DpiAware.Scale((width, height))
if width > max_width:
width = max_width
Expand Down Expand Up @@ -174,7 +174,7 @@ def create_menu(self):
def embed_browser(self):
window_info = cef.WindowInfo()
(width, height) = self.browser_panel.GetClientSize().Get()
assert self.browser_panel.GetHandle(), "Window handle not available yet"
assert self.browser_panel.GetHandle(), "Window handle not available"
window_info.SetAsChild(self.browser_panel.GetHandle(),
[0, 0, width, height])
self.browser = cef.CreateBrowserSync(window_info,
Expand Down
3 changes: 2 additions & 1 deletion src/cef_v59..v66_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ NEW FEATURES
+ unittests/osr_test.py - new test for off-screen rendering mode
+ cefpython.SetGlobalClientHandler
+ Browser.Invalidate
+ CookieManager.FlushStore

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

cef_cookie.h
- GetBlockingManager
+ GetBlockingManager

cef_display_handler.h
+ OnAutoResize
Expand Down
32 changes: 26 additions & 6 deletions src/cookie.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,12 @@ cdef class Cookie:
# CookieManager
# ------------------------------------------------------------------------------

class CookieManager:
@staticmethod
def GetGlobalManager():
class CookieManager(object):
"""Class used for managing cookies. To instantiate this class
call CreateManager() static method."""

@classmethod
def GetGlobalManager(cls):
global g_globalCookieManager
cdef CefRefPtr[CefCookieManager] cefCookieManager
if not g_globalCookieManager:
Expand All @@ -192,11 +195,28 @@ class CookieManager:
g_globalCookieManager = CreatePyCookieManager(cefCookieManager)
return g_globalCookieManager

@staticmethod
def CreateManager(py_string path, py_bool persistSessionCookies=False):
@classmethod
def GetBlockingManager(cls):
return CreatePyCookieManager(CefCookieManager_GetBlockingManager())

@classmethod
def CreateManager(cls, py_string path,
py_bool persist_session_cookies=False):
"""
Create a new cookie manager.
:param path:
:type path: str
:param persist_session_cookies:
:type path: bool
:return: CookieManager object
:rtype: CookieManager
"""
# When PyCharm generates a stub for the cefpython module
# it doesn't use the above docstring for code inspections.
# No idea why.
cdef CefRefPtr[CefCookieManager] cefCookieManager
cefCookieManager = CefCookieManager_CreateManager(
PyToCefStringValue(path), bool(persistSessionCookies),
PyToCefStringValue(path), bool(persist_session_cookies),
<CefRefPtr[CefCompletionCallback]?>NULL)
if <void*>cefCookieManager != NULL and cefCookieManager.get():
return CreatePyCookieManager(cefCookieManager)
Expand Down
6 changes: 6 additions & 0 deletions src/extern/cef/cef_cookie.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ cdef extern from "include/cef_cookie.h":
cdef CefRefPtr[CefCookieManager] CefCookieManager_GetGlobalManager \
"CefCookieManager::GetGlobalManager"(
CefRefPtr[CefCompletionCallback] callback)

cdef CefRefPtr[CefCookieManager] CefCookieManager_GetBlockingManager \
"CefCookieManager::GetBlockingManager"()


cdef CefRefPtr[CefCookieManager] CefCookieManager_CreateManager \
"CefCookieManager::CreateManager"(
const CefString& path,
cpp_bool persist_session_cookies,
CefRefPtr[CefCompletionCallback] callback)

cdef cppclass CefCookieManager:
void SetSupportedSchemes(const cpp_vector[CefString]& schemes,
CefRefPtr[CefCompletionCallback] callback)
Expand Down
9 changes: 9 additions & 0 deletions unittests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ def test_main(self):
self.assertEqual(req_data, req.GetPostData())
subtest_message("cef.Request.SetPostData(dict) ok")

# Cookie manager
self.assertIsInstance(cef.CookieManager.CreateManager(path=""),
cef.PyCookieManager)
self.assertIsInstance(cef.CookieManager.GetGlobalManager(),
cef.PyCookieManager)
self.assertIsInstance(cef.CookieManager.GetBlockingManager(),
cef.PyCookieManager)
subtest_message("cef.CookieManager ok")

# Run message loop
run_message_loop()

Expand Down

0 comments on commit f5d4696

Please sign in to comment.