forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_handler.pyx
More file actions
96 lines (91 loc) · 3.65 KB
/
load_handler.pyx
File metadata and controls
96 lines (91 loc) · 3.65 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
# 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"
cdef public void LoadHandler_OnLoadingStateChange(
CefRefPtr[CefBrowser] cefBrowser,
cpp_bool isLoading,
cpp_bool canGoBack,
cpp_bool canGoForward
) except * with gil:
cdef PyBrowser pyBrowser
cdef object callback
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnLoadingStateChange")
callback = pyBrowser.GetClientCallback("OnLoadingStateChange")
if callback:
callback(browser=pyBrowser,
is_loading=isLoading,
can_go_back=canGoBack,
can_go_forward=canGoForward)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void LoadHandler_OnLoadStart(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame
) except * with gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef object clientCallback
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnLoadStart")
pyFrame = GetPyFrame(cefFrame)
clientCallback = pyBrowser.GetClientCallback("OnLoadStart")
if clientCallback:
clientCallback(browser=pyBrowser, frame=pyFrame)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void LoadHandler_OnLoadEnd(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
int httpStatusCode
) except * with gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef object clientCallback
try:
pyBrowser = GetPyBrowser(cefBrowser, "OnLoadEnd")
pyFrame = GetPyFrame(cefFrame)
clientCallback = pyBrowser.GetClientCallback("OnLoadEnd")
if clientCallback:
clientCallback(browser=pyBrowser,
frame=pyFrame,
http_code=httpStatusCode)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public void LoadHandler_OnLoadError(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
cef_types.cef_errorcode_t cefErrorCode,
const CefString& cefErrorText,
const CefString& cefFailedUrl
) except * with gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef list errorTextOut
cdef object clientCallback
try:
# If webpage loading or file download is aborted by user
# the error code will be ERR_ABORTED. In such cases calls
# to OnLoadError should be ignored and not handled by user
# scripts. The wxpython example implements such behavior.
pyBrowser = GetPyBrowser(cefBrowser, "OnLoadError")
pyFrame = GetPyFrame(cefFrame)
errorTextOut = [CefToPyString(cefErrorText)]
clientCallback = pyBrowser.GetClientCallback("OnLoadError")
if clientCallback:
clientCallback(
browser=pyBrowser,
frame=pyFrame,
error_code=cefErrorCode,
error_text_out=errorTextOut,
failed_url=CefToPyString(cefFailedUrl))
# Providing custom error messsage not yet supported in CEF 3.
# | PyToCefString(errorTextOut[0], cefErrorText)
except:
(exc_type, exc_value, exc_trace) = sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)