forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlifespan_handler.pyx
More file actions
139 lines (130 loc) · 5.49 KB
/
lifespan_handler.pyx
File metadata and controls
139 lines (130 loc) · 5.49 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Copyright (c) 2012 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"
# noinspection PyUnresolvedReferences
from cef_types cimport WindowOpenDisposition
# noinspection PyUnresolvedReferences
cimport cef_types
# WindowOpenDisposition
WOD_UNKNOWN = cef_types.WOD_UNKNOWN
WOD_CURRENT_TAB = cef_types.WOD_CURRENT_TAB
WOD_SINGLETON_TAB = cef_types.WOD_SINGLETON_TAB
WOD_NEW_FOREGROUND_TAB = cef_types.WOD_NEW_FOREGROUND_TAB
WOD_NEW_BACKGROUND_TAB = cef_types.WOD_NEW_BACKGROUND_TAB
WOD_NEW_POPUP = cef_types.WOD_NEW_POPUP
WOD_NEW_WINDOW = cef_types.WOD_NEW_WINDOW
WOD_SAVE_TO_DISK = cef_types.WOD_SAVE_TO_DISK
WOD_OFF_THE_RECORD = cef_types.WOD_OFF_THE_RECORD
WOD_IGNORE_ACTION = cef_types.WOD_IGNORE_ACTION
cdef public cpp_bool LifespanHandler_OnBeforePopup(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
const CefString& targetUrl,
const CefString& targetFrameName,
cef_types.cef_window_open_disposition_t targetDisposition,
cpp_bool userGesture,
const int popupFeaturesNotImpl,
CefWindowInfo& windowInfo,
CefRefPtr[CefClient]& client,
CefBrowserSettings& settings,
cpp_bool* noJavascriptAccess
) except * with gil:
# Empty place-holders: popupFeatures, client.
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame,
cdef py_string pyTargetUrl
cdef py_string pyTargetFrameName
cdef list pyNoJavascriptAccess # out bool pyNoJavascriptAccess[0]
cdef list pyWindowInfo
cdef list pyBrowserSettings
cdef object callback
cdef py_bool returnValue
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnBeforePopup")
pyFrame = GetPyFrame(cefFrame)
pyTargetUrl = CefToPyString(targetUrl)
pyTargetFrameName = CefToPyString(targetFrameName)
pyNoJavascriptAccess = [noJavascriptAccess[0]]
pyWindowInfo = []
pyBrowserSettings = []
callback = pyBrowser.GetClientCallback("OnBeforePopup")
if callback:
returnValue = bool(callback(
browser=pyBrowser,
frame=pyFrame,
target_url=pyTargetUrl,
target_frame_name=pyTargetFrameName,
target_disposition=targetDisposition,
user_gesture=userGesture,
popup_features=None,
window_info_out=pyWindowInfo,
client=None,
browser_settings_out=pyBrowserSettings,
no_javascript_access_out=pyNoJavascriptAccess))
noJavascriptAccess[0] = <cpp_bool>bool(pyNoJavascriptAccess[0])
if len(pyBrowserSettings):
SetBrowserSettings(pyBrowserSettings[0], &settings)
if len(pyWindowInfo):
SetCefWindowInfo(windowInfo, pyWindowInfo[0])
return bool(returnValue)
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void LifespanHandler_OnAfterCreated(
CefRefPtr[CefBrowser] cefBrowser
) except * with gil:
cdef PyBrowser pyBrowser
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnAfterCreated")
callback = GetGlobalClientCallback("OnAfterCreated")
if callback:
callback(browser=pyBrowser)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool LifespanHandler_DoClose(
CefRefPtr[CefBrowser] cefBrowser
) except * with gil:
cdef PyBrowser pyBrowser
try:
pyBrowser = GetPyBrowser(cefBrowser, "DoClose")
callback = pyBrowser.GetClientCallback("DoClose")
if callback:
return bool(callback(browser=pyBrowser))
return False
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void LifespanHandler_OnBeforeClose(
CefRefPtr[CefBrowser] cefBrowser
) except * with gil:
cdef PyBrowser pyBrowser
cdef object callback
try:
Debug("LifespanHandler_OnBeforeClose")
# NOTE: browser_id may not necessarily be in g_pyBrowsers currently.
# I haven't yet debugged it but the logic in Shutdown that
# tries to force close browsers and removes references might
# have something to do with it. Such scenario is reproducible
# with the following steps:
# 1. Run wxpython.py example
# 2. Google "js alert" and open w3schools
# 3. Open demo popup
# 4. Close main window (not popup)
pyBrowser = GetPyBrowser(cefBrowser, "OnBeforeClose")
callback = pyBrowser.GetClientCallback("OnBeforeClose")
if callback:
callback(browser=pyBrowser)
RemovePythonCallbacksForBrowser(pyBrowser.GetIdentifier())
RemovePyFramesForBrowser(pyBrowser.GetIdentifier())
RemovePyBrowser(pyBrowser.GetIdentifier())
if g_MessageLoop_called and not len(g_pyBrowsers):
# Automatically quit message loop when last browser was closed.
# This is required for hello_world.py example to work.
QuitMessageLoop()
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)