Skip to content

Commit 0c6d477

Browse files
CzarekCzarek
authored andcommitted
Sending process messages from python.
1 parent 6643927 commit 0c6d477

9 files changed

Lines changed: 69 additions & 5 deletions

File tree

cefpython/browser.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,10 @@ cdef class PyBrowser:
615615
# virtual CefTextInputContext GetNSTextInputContext() =0;
616616
# virtual void HandleKeyEventBeforeTextInputClient(CefEventHandle keyEvent) =0;
617617
# virtual void HandleKeyEventAfterTextInputClient(CefEventHandle keyEvent) =0;
618+
619+
cdef cpp_bool SendProcessMessage(self, cef_process_id_t targetProcess,
620+
py_string name) except *:
621+
cdef CefRefPtr[CefProcessMessage] msg = CefProcessMessage_Create(
622+
PyToCefStringValue(name))
623+
return self.GetCefBrowser().get().SendProcessMessage(targetProcess,
624+
msg)

cefpython/cef3/client_handler/client_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ bool ClientHandler::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
99
CefProcessId source_process,
1010
CefRefPtr<CefProcessMessage> message) {
1111
std::string name = message.get()->GetName().ToString();
12-
printf("ClientHandler::OnProcessMessageReceived(): %s\n", name.c_str());
12+
printf("Browser: OnProcessMessageReceived(): %s\n", name.c_str());
1313
return false;
1414
}

cefpython/cef3/linux/binaries_64bit/wxpython.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def __init__(self):
104104
browserSettings={"plugins_disabled": False},
105105
navigateUrl="file://"+GetApplicationPath("wxpython.html"))
106106

107+
print("Seting up javascript bindings now..")
108+
107109
self.Bind(wx.EVT_CLOSE, self.OnClose)
108110
if USE_EVT_IDLE:
109111
# Bind EVT_IDLE only for the main application frame.

cefpython/cef3/subprocess/cefpython_app.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,29 @@ void CefPythonApp::OnContextInitialized() {
5050
void CefPythonApp::OnBeforeChildProcessLaunch(
5151
CefRefPtr<CefCommandLine> command_line) {}
5252

53+
///
54+
// Called on the browser process IO thread after the main thread has been
55+
// created for a new render process. Provides an opportunity to specify extra
56+
// information that will be passed to
57+
// CefRenderProcessHandler::OnRenderThreadCreated() in the render process. Do
58+
// not keep a reference to |extra_info| outside of this method.
59+
///
5360
void CefPythonApp::OnRenderProcessThreadCreated(
5461
CefRefPtr<CefListValue> extra_info) {
5562
REQUIRE_IO_THREAD();
63+
printf("OnRenderProcessThreadCreated()\n");
5664
}
5765

5866
// -----------------------------------------------------------------------------
5967
// CefRenderProcessHandler
6068
// -----------------------------------------------------------------------------
6169

70+
///
71+
// Called after the render process main thread has been created. |extra_info|
72+
// is a read-only value originating from
73+
// CefBrowserProcessHandler::OnRenderProcessThreadCreated(). Do not keep a
74+
// reference to |extra_info| outside of this method.
75+
///
6276
void CefPythonApp::OnRenderThreadCreated(CefRefPtr<CefListValue> extra_info) {
6377
}
6478

@@ -105,8 +119,15 @@ void CefPythonApp::OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
105119
CefRefPtr<CefDOMNode> node) {
106120
}
107121

122+
///
123+
// Called when a new message is received from a different process. Return true
124+
// if the message was handled or false otherwise. Do not keep a reference to
125+
// or attempt to access the message outside of this callback.
126+
///
108127
bool CefPythonApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
109128
CefProcessId source_process,
110129
CefRefPtr<CefProcessMessage> message) {
130+
std::string name = message.get()->GetName().ToString();
131+
printf("Renderer: OnProcessMessageReceived(): %s\n", name.c_str());
111132
return false;
112133
}

cefpython/cefpython.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ def CreateBrowserSync(windowInfo, browserSettings, navigateUrl):
241241
cdef PyBrowser pyBrowser = GetPyBrowser(cefBrowser)
242242
pyBrowser.SetUserData("__outerWindowHandle", int(windowInfo.parentWindowHandle))
243243

244+
IF CEF_VERSION == 3:
245+
# Test whether process message sent before renderer thread is created
246+
# will be delivered - OK.
247+
# Debug("Sending 'CreateBrowserSync() done' message to the Renderer")
248+
# assert pyBrowser.SendProcessMessage(cef_types.PID_RENDERER,
249+
# "CreateBrowserSync() done")
250+
pass
251+
244252
return pyBrowser
245253

246254
def MessageLoop():

cefpython/cython_includes/cef_browser.pxd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ from cef_platform cimport CefKeyInfo
1717
IF CEF_VERSION == 1:
1818
from cef_types_wrappers cimport CefRect
1919

20+
IF CEF_VERSION == 3:
21+
from cef_process_message cimport CefProcessMessage, CefProcessId
22+
2023
IF UNAME_SYSNAME == "Windows":
2124
from cef_win cimport CefWindowHandle, CefWindowInfo
2225
ELIF UNAME_SYSNAME == "Linux":
@@ -133,8 +136,8 @@ cdef extern from "include/cef_browser.h":
133136

134137
# CefRefPtr<CefFrame> GetFrame(int64 identifier) =0;
135138
# virtual CefRefPtr<CefClient> GetClient() =0;
136-
# virtual bool SendProcessMessage(CefProcessId target_process,
137-
# CefRefPtr<CefProcessMessage> message) =0;
139+
cpp_bool SendProcessMessage(CefProcessId target_process,
140+
CefRefPtr[CefProcessMessage] message)
138141

139142
# class CefRunFileDialogCallback : public virtual CefBase {
140143
# virtual void OnFileDialogDismissed(
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2012-2013 The CEF Python authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
from cef_types cimport cef_process_id_t
6+
from cef_ptr cimport CefRefPtr
7+
from cef_string cimport CefString
8+
from libcpp cimport bool as cpp_bool
9+
from cef_values cimport CefListValue
10+
from cef_types cimport cef_process_id_t
11+
12+
cdef extern from "include/cef_process_message.h":
13+
cdef CefRefPtr[CefProcessMessage] CefProcessMessage_Create \
14+
"CefProcessMessage::Create"(const CefString& name)
15+
cdef cppclass CefProcessMessage:
16+
cpp_bool IsValid()
17+
cpp_bool IsReadOnly()
18+
CefRefPtr[CefProcessMessage] Copy()
19+
CefString GetName()
20+
CefRefPtr[CefListValue] GetArgumentList()
21+
ctypedef cef_process_id_t CefProcessId

cefpython/cython_includes/cef_values.pxd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ from libcpp.vector cimport vector
99
from cef_types cimport cef_value_type_t
1010

1111
cdef extern from "include/cef_values.h":
12-
CefRefPtr[CefDictionaryValue] CefDictionaryValue_Create "CefDictionaryValue::Create"()
13-
CefRefPtr[CefListValue] CefListValue_Create "CefListValue::Create"()
12+
cdef CefRefPtr[CefDictionaryValue] CefDictionaryValue_Create \
13+
"CefDictionaryValue::Create"()
14+
cdef CefRefPtr[CefListValue] CefListValue_Create "CefListValue::Create"()
1415

1516
cdef extern from "include/cef_values.h":
1617
cdef cppclass CefBinaryValue:

cefpython/imports.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ IF UNAME_SYSNAME == "Windows":
143143
IF CEF_VERSION == 3:
144144
from cef_values cimport *
145145
from cefpython_app cimport *
146+
from cef_process_message cimport *

0 commit comments

Comments
 (0)