Skip to content

Commit 556e8f7

Browse files
committed
Working on javascript bindings.
1 parent 2b89460 commit 556e8f7

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

cefexample/cefadvanced.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<li>javascript callbacks
2828
<li>popup and modal windows
2929
<li>loading content from zip (optionally encrypted)
30+
<li>F12 devtools
3031
</ul>
3132

3233
<iframe src="cefsimple.html"></iframe>

javascriptbindings.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import types
2+
3+
class JavascriptBindings:
4+
5+
# By default we bind only to top frame.
6+
__bindToFrames = False
7+
__bindToPopups = False
8+
__functions = {}
9+
__properties = {}
10+
__v8properties = {}
11+
12+
def __init__(self, bindToFrames=False, bindToPopups=False):
13+
14+
self.__bindToFrames = bindToFrames
15+
self.__bindToPopups = bindToPopups
16+
17+
def SetFunction(self, name, func):
18+
19+
self.__functions[name] = func
20+
21+
def SetProperty(self, name, value):
22+
23+
allowed = self.__IsTypeAllowed(value) # returns True or string.
24+
if allowed != True:
25+
raise Exception("JavascriptBindings.SetProperty(): not allowed type: %s" % allowed)
26+
self.__properties[name] = value
27+
28+
def GetProperty(self, name):
29+
30+
# We must query CefV8Value for the real current value of property,
31+
# it could have been changed in javascript, use self.__v8properties.
32+
pass
33+
34+
def __IsTypeAllowed(self, value):
35+
36+
# Return value: True - allowed, string - not allowed
37+
38+
# Not using type().__name__ here as it is not consistent, for int it is "int" but for None it is "NoneType".
39+
valueType = type(value)
40+
if valueType == types.ListType:
41+
for val in value:
42+
valueType2 = self.__IsTypeAllowed(val):
43+
if valueType2 != True:
44+
return valueType2.__name__
45+
return True
46+
elif valueType == types.BoolType:
47+
return True
48+
elif valueType == types.DoubleType:
49+
return True
50+
elif valueType == types.IntType:
51+
return True
52+
elif valueType == types.NoneType:
53+
return True
54+
elif valueType == types.DictType:
55+
for key in value:
56+
valueType2 = self.__IsTypeAllowed(value[key]):
57+
if valueType2 != True:
58+
return valueType2.__name__
59+
return True
60+
elif valueType == types.StringType:
61+
return True
62+
else:
63+
return valueType.__name__
64+
return valueType.__name__

unfinished.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ utils.pyx > GetPyBrowserByCefBrowser() > Popups:
77
# handlers dictionary to both parameters.
88

99
# What about popups created by popups? How do we do the inheritance in this case?
10+
11+
browser.pyx > CloseBrowser()
12+
13+
Commented out CefBrowser.CloseBrowser() to fix (maybe?) the memory read errors
14+
when closing application window. But CefBrowser.CloseBrowser() needs to be called
15+
for popup windows...?

0 commit comments

Comments
 (0)