Skip to content

Commit e0abf89

Browse files
committed
Popup windows load ClientHandler from its parent (Issue 41).
Fix for UTF-8 chars when setting window title using WindowUtils.SetTitle() (Issue 42). Minor cleanup in cefadvanced.py example.
1 parent 1ccef32 commit e0abf89

File tree

10 files changed

+368
-140
lines changed

10 files changed

+368
-140
lines changed

cefpython/browser.pyx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# License: New BSD License.
33
# Website: http://code.google.com/p/cefpython/
44

5-
# If you try to keep PyBrowser() objects inside c_vector you will get segmentation
6-
# faults, as they will be garbage collected.
5+
# If you try to keep PyBrowser() objects inside c_vector you will
6+
# get segmentation faults, as they will be garbage collected.
77

88
cdef dict g_pyBrowsers = {}
99

@@ -15,6 +15,7 @@ cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser):
1515

1616
cdef PyBrowser pyBrowser
1717
cdef int browserId
18+
cdef int id
1819

1920
browserId = cefBrowser.get().GetIdentifier()
2021
if browserId in g_pyBrowsers:
@@ -30,6 +31,34 @@ cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser):
3031
pyBrowser.cefBrowser = cefBrowser
3132
g_pyBrowsers[browserId] = pyBrowser
3233

34+
# Inherit client callbacks and javascript bindings
35+
# from parent browser.
36+
37+
# Checking __outerWindowHandle as we should not inherit
38+
# client callbacks and javascript bindings if the browser
39+
# was created explicitily by calling CreateBrowserSync().
40+
41+
# Popups inherit client callbacks by default.
42+
43+
# Popups inherit javascript bindings only when "bindToPopups"
44+
# constructor param was set to True.
45+
46+
cdef WindowHandle openerHandle
47+
cdef dict clientCallbacks
48+
cdef JavascriptBindings javascriptBindings
49+
50+
if pyBrowser.IsPopup() and (
51+
not pyBrowser.GetUserData("__outerWindowHandle")):
52+
openerHandle = pyBrowser.GetOpenerWindowHandle()
53+
for id, tempPyBrowser in g_pyBrowsers.items():
54+
if tempPyBrowser.GetWindowHandle() == openerHandle:
55+
clientCallbacks = tempPyBrowser.GetClientCallbacksDict()
56+
if clientCallbacks:
57+
pyBrowser.SetClientCallbacksDict(clientCallbacks)
58+
javascriptBindings = tempPyBrowser.GetJavascriptBindings()
59+
if javascriptBindings.GetBindToPopups():
60+
pyBrowser.SetJavascriptBindings(javascriptBindings)
61+
3362
return pyBrowser
3463

3564
cpdef PyBrowser GetBrowserByWindowHandle(int windowHandle):
@@ -133,6 +162,9 @@ cdef class PyBrowser:
133162
if name in self.clientCallbacks:
134163
return self.clientCallbacks[name]
135164

165+
cpdef py_void SetClientCallbacksDict(self, dict clientCallbacks):
166+
self.clientCallbacks = clientCallbacks
167+
136168
cpdef dict GetClientCallbacksDict(self):
137169
return self.clientCallbacks
138170

0 commit comments

Comments
 (0)