Communication: Application thread to Renderer main thread

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Communication: Application thread to Renderer main thread

Postby swtsvn » Mon May 04, 2015 4:04 pm

Hi all,
I need to pass message from main application thread to render process's main thread (TID_RENDERER). Execution of asynchronous process happens in main thread, and the results are sent back to Javascript callback (which can only be run on renderer thread inside a context).
So I need a way to send information to the render thread either directly or indirectly via a new thread in CEf-Render process that can communicate with the TID_RENDERER.

This is the closest to what I was looking for: viewtopic.php?f=6&t=10695
Quoting:
"As long and I can send the data from the libuv thread in the render process to the main render thread via some kind of message or event then I think I'm good."

magreenblatt suggests using WebWorker thread, but it is not found in latest, and reverting back the cef version is not a executable option in my project.

Is there any other known way of message passing from application thread to renderthread, or from render process child thread to render thread, or a way to do the run-loop in CefRenderProcessHandler sub class, to handle the custom message-queue in a while loop ?

The project sets multi_threaded_message_loop to true, hence each thread should be handled separately.

Any help is greatly appreciated.
swtsvn
Techie
 
Posts: 21
Joined: Wed Apr 22, 2015 4:56 pm

Re: Communication: Application thread to Renderer main threa

Postby magreenblatt » Mon May 04, 2015 5:04 pm

CEF does not run a message loop on the main application thread because you're setting multi_threaded_message_loop to true. You will need to implement your own message loop for passing messages from the CEF UI thread to the main application thread in the browser process. You can then use process messages to communicate between the CEF browser process UI thread and renderer process main thread as described here: https://bitbucket.org/chromiumembedded/ ... e-messages
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Communication: Application thread to Renderer main threa

Postby swtsvn » Mon May 04, 2015 6:19 pm

Hi magreenblatt,
Thank you for the input.
I am planning to implement custom message-queue that will be processed in Application thread(non cef, non browser thread). I could pass messages from Cef-Renderer-main thread to the application thread(non cef) using this queue.

I am using SendProcessMessage to communicate between cef-browser ui thread and cef-render process-main thread for a different feature.

But the issue arises when I need to contact the render thread again from the application thread(non cef), to execute the javascript callback using ExecuteFunctionWithContext().

CefPostTask is not working (returning false). It could be because the thread I am calling from in application thread and non Cef one. So it might not understand TID_RENDERER.

I am not able use WebWorker thread because of CEF version.

Any ideas?
swtsvn
Techie
 
Posts: 21
Joined: Wed Apr 22, 2015 4:56 pm

Re: Communication: Application thread to Renderer main threa

Postby magreenblatt » Mon May 04, 2015 7:28 pm

You need to SendProcessMessage back to the renderer process first, and then execute JS functions in the renderer process.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Communication: Application thread to Renderer main threa

Postby swtsvn » Fri May 22, 2015 10:51 am

Thanks magreenblatt.
swtsvn
Techie
 
Posts: 21
Joined: Wed Apr 22, 2015 4:56 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 40 guests