X Tutup
Skip to content

Commit 048a47f

Browse files
CzarekCzarek
authored andcommitted
CEF 3 js bindings are complete, though python and js callbacks
are yet to be done. Tested on Linux. On Windows VS project files need to be updated and a project file for libcefpythonapp needs to be created.
1 parent 0f58a3e commit 048a47f

File tree

20 files changed

+616
-80
lines changed

20 files changed

+616
-80
lines changed

cefpython/browser.pyx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,21 @@ cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser):
5757

5858
cdef WindowHandle openerHandle
5959
cdef dict clientCallbacks
60-
IF CEF_VERSION == 1:
61-
cdef JavascriptBindings javascriptBindings
60+
cdef JavascriptBindings javascriptBindings
6261
cdef PyBrowser tempPyBrowser
6362

64-
if pyBrowser.IsPopup() and (
65-
not pyBrowser.GetUserData("__outerWindowHandle")):
63+
if pyBrowser.IsPopup() and \
64+
not pyBrowser.GetUserData("__outerWindowHandle"):
6665
openerHandle = pyBrowser.GetOpenerWindowHandle()
6766
for id, tempPyBrowser in g_pyBrowsers.items():
6867
if tempPyBrowser.GetWindowHandle() == openerHandle:
6968
clientCallbacks = tempPyBrowser.GetClientCallbacksDict()
7069
if clientCallbacks:
7170
pyBrowser.SetClientCallbacksDict(clientCallbacks)
72-
IF CEF_VERSION == 1:
73-
javascriptBindings = tempPyBrowser.GetJavascriptBindings()
74-
if javascriptBindings:
75-
if javascriptBindings.GetBindToPopups():
76-
pyBrowser.SetJavascriptBindings(javascriptBindings)
71+
javascriptBindings = tempPyBrowser.GetJavascriptBindings()
72+
if javascriptBindings:
73+
if javascriptBindings.GetBindToPopups():
74+
pyBrowser.SetJavascriptBindings(javascriptBindings)
7775
return pyBrowser
7876

7977
cpdef PyBrowser GetBrowserByWindowHandle(WindowHandle windowHandle):

cefpython/cef3/client_handler/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# -Werror - treat warnings as errors
66

77
# Cython compiler options:
8-
# -fPIC -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro
8+
# -fPIC -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions \
9+
# -Wl,-z,relro
910

1011
CC = g++
1112
CCFLAGS = -g -fPIC -Wall -Werror
@@ -14,7 +15,12 @@ SRC = client_handler.cpp
1415
OBJ = $(SRC:.cpp=.o)
1516
OUT = libclient_handler.a
1617

17-
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
18+
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 \
19+
-I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include \
20+
-I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo \
21+
-I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 \
22+
-I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
23+
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
1824

1925
.cpp.o:
2026
$(CC) $(CCFLAGS) $(INC) -c $< -o $@

cefpython/cef3/linux/binaries_32bit/wxpython.html

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,37 @@ <h3>HTML5 video and accelerated content</h3>
4141

4242

4343
<h3>Javascript bindings</h3>
44-
<a href="javascript:external.Print('printing in python console from js')">
45-
external.Print('printing in python console from js')</a>
44+
<a href="javascript:PyPrint('printing in python console from js')">
45+
PyPrint('printing in python console from js')</a><br>
46+
<a href="javascript:window.alert(window.pyProperty)">
47+
window.alert(window.pyProperty)</a><br>
48+
<a href="javascript:window.alert(JSON.stringify(window.pyConfig))">
49+
window.alert(JSON.stringify(window.pyConfig))</a><br>
50+
<a href="javascript:external.Print('printing again from js')">
51+
external.Print('printing again from js')</a><br>
52+
<a href="javascript:external.TestAllTypes(undefined, null, true, 1,
53+
((1<<31)>>>0), 2.14, 'Date not yet supported', 'string',
54+
{key1: 1, key2: 2}, {key1: {'key1.1': 'nested object'}, 'key1.2': [1]},
55+
[1, 2], [1, [2.1, 'nested array']], [{key1: [{}]}])">
56+
external.TestAllTypes</a>
57+
<small>(undefined, null, true, 1,
58+
((1&lt;&lt;31)>>>0), 2.14, 'Date not yet supported', 'string',
59+
{key1: 1, key2: 2}, {key1: {'key1.1': 'nested object'}, 'key1.2': [1]},
60+
[1, 2], [1, [2.1, 'nested array']], [{key1: [{}]}])</small>
61+
<br>
62+
<script>
63+
function JavascriptAlert(message) { window.alert(message); }
64+
</script>
65+
<pre>
66+
&lt;script&gt;
67+
function JavascriptAlert(message) { window.alert(message); }
68+
&lt;/script&gt;
69+
</pre>
70+
<a href="javascript:external.ExecuteFunction('JavascriptAlert',
71+
'python called from js and then js called from python')">
72+
external.ExecuteFunction('JavascriptAlert',
73+
'python called from js and then js called from python')</a>
4674

4775

48-
49-
<br><br><br><br><br><br><br><br>
50-
<br><br><br><br><br><br><br><br>
51-
<br><br><br><br><br><br><br><br>
52-
5376
</body>
5477
</html>

cefpython/cef3/linux/binaries_32bit/wxpython.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ def __init__(self):
105105
navigateUrl="file://"+GetApplicationPath("wxpython.html"))
106106

107107
jsBindings = cefpython.JavascriptBindings(
108-
bindToFrames=False, bindToPopups=False)
109-
jsBindings.SetObject("external", JavascriptBindings(self.browser))
108+
bindToFrames=False, bindToPopups=True)
109+
jsBindings.SetFunction("PyPrint", PyPrint)
110+
jsBindings.SetProperty("pyProperty", "This was set in Python")
111+
jsBindings.SetProperty("pyConfig", ["This was set in Python",
112+
{"name": "Nested dictionary", "isNested": True},
113+
[1,"2", None]])
114+
jsBindings.SetObject("external", JavascriptExternal(self.browser))
110115
self.browser.SetJavascriptBindings(jsBindings)
111116

112117
self.Bind(wx.EVT_CLOSE, self.OnClose)
@@ -133,7 +138,10 @@ def OnClose(self, event):
133138
def OnIdle(self, event):
134139
cefpython.MessageLoopWork()
135140

136-
class JavascriptBindings:
141+
def PyPrint(message):
142+
print(message)
143+
144+
class JavascriptExternal:
137145
mainBrowser = None
138146

139147
def __init__(self, mainBrowser):
@@ -142,6 +150,12 @@ def __init__(self, mainBrowser):
142150
def Print(self, message):
143151
print(message)
144152

153+
def TestAllTypes(self, *args):
154+
print(args)
155+
156+
def ExecuteFunction(self, *args):
157+
self.mainBrowser.GetMainFrame().ExecuteFunction(*args)
158+
145159
class MyApp(wx.App):
146160
timer = None
147161
timerID = 1
@@ -180,7 +194,7 @@ def OnExit(self):
180194
cefpython.g_debug = True
181195
cefpython.g_debugFile = GetApplicationPath("debug.log")
182196
settings = {
183-
"log_severity": cefpython.LOGSEVERITY_INFO,
197+
"log_severity": cefpython.LOGSEVERITY_INFO, # LOGSEVERITY_VERBOSE
184198
"log_file": GetApplicationPath("debug.log"),
185199
"release_dcheck_enabled": True, # Enable only when debugging.
186200
# This directories must be set on Linux

cefpython/cef3/linux/binaries_64bit/wxpython.html

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,36 @@ <h3>HTML5 video and accelerated content</h3>
4242

4343
<h3>Javascript bindings</h3>
4444
<a href="javascript:PyPrint('printing in python console from js')">
45-
PyPrint('printing in python console from js')</a>
45+
PyPrint('printing in python console from js')</a><br>
46+
<a href="javascript:window.alert(window.pyProperty)">
47+
window.alert(window.pyProperty)</a><br>
48+
<a href="javascript:window.alert(JSON.stringify(window.pyConfig))">
49+
window.alert(JSON.stringify(window.pyConfig))</a><br>
50+
<a href="javascript:external.Print('printing again from js')">
51+
external.Print('printing again from js')</a><br>
52+
<a href="javascript:external.TestAllTypes(undefined, null, true, 1,
53+
((1<<31)>>>0), 2.14, 'Date not yet supported', 'string',
54+
{key1: 1, key2: 2}, {key1: {'key1.1': 'nested object'}, 'key1.2': [1]},
55+
[1, 2], [1, [2.1, 'nested array']], [{key1: [{}]}])">
56+
external.TestAllTypes</a>
57+
<small>(undefined, null, true, 1,
58+
((1&lt;&lt;31)>>>0), 2.14, 'Date not yet supported', 'string',
59+
{key1: 1, key2: 2}, {key1: {'key1.1': 'nested object'}, 'key1.2': [1]},
60+
[1, 2], [1, [2.1, 'nested array']], [{key1: [{}]}])</small>
61+
<br>
62+
<script>
63+
function JavascriptAlert(message) { window.alert(message); }
64+
</script>
65+
<pre>
66+
&lt;script&gt;
67+
function JavascriptAlert(message) { window.alert(message); }
68+
&lt;/script&gt;
69+
</pre>
70+
<a href="javascript:external.ExecuteFunction('JavascriptAlert',
71+
'python called from js and then js called from python')">
72+
external.ExecuteFunction('JavascriptAlert',
73+
'python called from js and then js called from python')</a>
4674

4775

48-
49-
<br><br><br><br><br><br><br><br>
50-
<br><br><br><br><br><br><br><br>
51-
<br><br><br><br><br><br><br><br>
52-
5376
</body>
5477
</html>

cefpython/cef3/linux/binaries_64bit/wxpython.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ def __init__(self):
105105
navigateUrl="file://"+GetApplicationPath("wxpython.html"))
106106

107107
jsBindings = cefpython.JavascriptBindings(
108-
bindToFrames=False, bindToPopups=False)
108+
bindToFrames=False, bindToPopups=True)
109109
jsBindings.SetFunction("PyPrint", PyPrint)
110-
jsBindings.SetObject("external", JavascriptBindings(self.browser))
110+
jsBindings.SetProperty("pyProperty", "This was set in Python")
111+
jsBindings.SetProperty("pyConfig", ["This was set in Python",
112+
{"name": "Nested dictionary", "isNested": True},
113+
[1,"2", None]])
114+
jsBindings.SetObject("external", JavascriptExternal(self.browser))
111115
self.browser.SetJavascriptBindings(jsBindings)
112116

113117
self.Bind(wx.EVT_CLOSE, self.OnClose)
@@ -137,7 +141,7 @@ def OnIdle(self, event):
137141
def PyPrint(message):
138142
print(message)
139143

140-
class JavascriptBindings:
144+
class JavascriptExternal:
141145
mainBrowser = None
142146

143147
def __init__(self, mainBrowser):
@@ -146,6 +150,12 @@ def __init__(self, mainBrowser):
146150
def Print(self, message):
147151
print(message)
148152

153+
def TestAllTypes(self, *args):
154+
print(args)
155+
156+
def ExecuteFunction(self, *args):
157+
self.mainBrowser.GetMainFrame().ExecuteFunction(*args)
158+
149159
class MyApp(wx.App):
150160
timer = None
151161
timerID = 1

cefpython/cef3/subprocess/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
# -Wall - show important warnings
55
# -Werror - treat warnings as errors
66

7-
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
7+
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 \
8+
-I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include \
9+
-I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo \
10+
-I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 \
11+
-I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
12+
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
813

9-
LIB = -L./../linux/setup/lib_64bit -L./../linux/setup/lib_32bit -L./../linux/binaries_64bit -L./../linux/binaries_32bit
14+
LIB = -L./../linux/setup/lib_64bit -L./../linux/setup/lib_32bit \
15+
-L./../linux/binaries_64bit -L./../linux/binaries_32bit
1016

1117
subprocess:
1218
# -fPIC is required only for libraries included by Cython.
13-
g++ -Wall -Werror $(INC) $(LIB) main.cpp cefpython_app.cpp v8function_handler.cpp -lcef_dll_wrapper -lcef -o subprocess -Wl,-rpath,.
19+
g++ -Wall -Werror $(INC) $(LIB) main.cpp cefpython_app.cpp \
20+
v8function_handler.cpp v8utils.cpp -lcef_dll_wrapper -lcef \
21+
-o subprocess -Wl,-rpath,.

cefpython/cef3/subprocess/Makefile-libcefpythonapp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@
55
# -Werror - treat warnings as errors
66

77
# Cython compiler options:
8-
# -fPIC -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro
8+
# -fPIC -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions \
9+
# -Wl,-z,relro
910

1011
CC = g++
1112
CCFLAGS = -g -fPIC -Wall -Werror
1213

13-
SRC = cefpython_app.cpp v8function_handler.cpp
14+
SRC = cefpython_app.cpp v8function_handler.cpp v8utils.cpp
1415
OBJ = $(SRC:.cpp=.o)
1516
OUT = libcefpythonapp.a
1617

17-
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
18+
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 \
19+
-I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include \
20+
-I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo \
21+
-I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 \
22+
-I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
23+
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
1824

1925
.cpp.o:
2026
$(CC) $(CCFLAGS) $(INC) -c $< -o $@

0 commit comments

Comments
 (0)
X Tutup