-
-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathjavascript_callback.pyx
More file actions
59 lines (51 loc) · 2.15 KB
/
javascript_callback.pyx
File metadata and controls
59 lines (51 loc) · 2.15 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
# Copyright (c) 2013 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 JavascriptCallback CreateJavascriptCallback(int callbackId,
CefRefPtr[CefBrowser] cefBrowser, object frameId,
py_string functionName):
# frameId is int64
cdef JavascriptCallback jsCallback = JavascriptCallback()
jsCallback.callbackId = callbackId
cdef PyBrowser browser = GetPyBrowser(cefBrowser)
jsCallback.frame = browser.GetFrameByIdentifier(frameId)
jsCallback.functionName = functionName
Debug("Created javascript callback, callbackId=%s, functionName=%s" % \
(callbackId, functionName))
return jsCallback
cdef class JavascriptCallback:
"""A javascript callback object may still live while browser/frame
are destroyed. Always check frame/browser for None value."""
cdef int callbackId
cdef PyFrame frame
cdef py_string functionName
def Call(self, *args):
# Send process message "ExecuteJavascriptCallback".
if self.frame:
browser = self.frame.GetBrowser()
if browser:
browser.SendProcessMessage(
cef_types.PID_RENDERER,
self.frame.GetIdentifier(),
"ExecuteJavascriptCallback",
[self.callbackId] + list(args))
else:
# This code probably ain't needed
raise Exception("JavascriptCallback.Call() FAILED: browser"
" not found, callbackId = %s"
% self.callbackId)
else:
# This code probably ain't needed
raise Exception("JavascriptCallback.Call() FAILED: frame not found"
", callbackId = %s" % self.callbackId)
def GetFunctionName(self):
return self.functionName
def GetName(self):
"""@deprecated."""
return self.GetFunctionName()
def GetId(self):
return self.callbackId
def GetFrame(self):
return self.frame