JS callback executon on native code events

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

JS callback executon on native code events

Postby hnsr » Tue Oct 09, 2012 4:14 am

In my cef3-based project I need to execute JS-supplied callbacks in the main/visible frame (or frames? or maybe just the frame that has input focus) when events are received in native code in the browser process (basically I want to receive input events in JS from a generic USB HID input device that is being polled on a separate thread in the browser process), but I'm having some trouble wrapping my head around how to make this work. I've read the JS integration docs and I understand that I need to get a reference to the V8 context and the supplied JS function (that handles the events) by exposing a 'register' function (http://code.google.com/p/chromiumembedd ... _Callbacks).

Since the registering and calling of this callback all happens in the render process, I am facing some difficulty on how to make the connection from the browser process to the render process, it seems I will need to send a process message (to PID_RENDERER), but I'm not sure how to make this go to the correct render process, or how to figure out if the current render process is for a frame that has input focus (but from the chromium docs on their multiprocess architecture, I gather that there is also not necessarily a one-to-one mapping between frames and render processes)

I've tried to look at the cefclient application but I keep getting lost or end up going in circles (it doesn't help that I'm a bit new to C++/Multi-threaded programming).

Hopefully someone here can give me some pointers on the correct way to go about this :)

EDIT: Oops, I didn't pay attention what board I was posting to; this post should probably be moved to the support forum
hnsr
Newbie
 
Posts: 6
Joined: Thu Oct 04, 2012 7:08 am

Re: JS callback executon on native code events

Postby magreenblatt » Thu Oct 11, 2012 12:01 pm

Process messages are sent via CefBrowser::SendProcessMessage. When received by the other process the message will already be associated with the correct CefBrowser (an argument to CefClient::OnProcessMessageReceived in the browser process and CefRenderProcessHandler::OnProcessMessageReceived in the render process). Each frame has a unique identifier returned via CefFrame::GetIdentifier(). So, pass the frame identifier as part of your process message and retrieve the associated frame using CefBrowser::GetFrame in the other process.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: JS callback executon on native code events

Postby hnsr » Fri Oct 12, 2012 9:16 am

Ah, I see, I didn't consider passing along the frame ID. I think that removes the last stumbling block I had. Thanks!
hnsr
Newbie
 
Posts: 6
Joined: Thu Oct 04, 2012 7:08 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 148 guests