Background process on the native function at Chromium Embedded Framework

故事扮演 提交于 2019-12-06 05:48:31

The issue is that the javascript callback happens on the Render process of the CEF Client. This process is directly responsible for all user interaction, the clicks, JS execution, and the like. Even if you post to another thread (in the same process), it's not making a huge difference it seems.

What you would want to do is send this over to the Browser process and do the processing there. The CEF3 Faqs covers this communication,in case you have not had need to do this before:

[...] How do I send information between the browser and render processes in CEF3?

To provide information dynamically use process messages (CefProcessMessage) which are associated with a specific CefBrowser instance and are sent using the CefBrowser::SendProcessMessage() method. [...] A message sent from the render process to the browser process will arrive in CefClient::OnProcessMessageReceived(). [...]

Seems like this is quite a big deal in Adobe Brackets-Shell (a reasonably popular open source WebIDE that uses CEF3) - their guide to V8 extensions goes through this very nicely.

Whenever a native function is called, AppShellExtensionHandler::Execute() is invoked. This code runs in the render process, so only the most trivial extension code should be executed here. For Brackets, only getElapsedMilliseconds() is handled here. All others calls are passed to the browser process via a CefProcessMessage.

The AppShellExtensionHandler mentioned here is equivalent to your AppExtensionHandler. I would highly recommend going through their code for extension handling - it's been done quite elegantly. Fair Warning: I am related to Adobe professionally, though Brackets.io is an open-source venture.

Hope this helps - Cheers!

Take a look at this post. It works like a charm. Solves all my JS to native issues and uses a structured param passing approach..and it addresses precisely the issue you are having too ... you simply have to create a user thread (Task) to handle things in background ...

JS to native via V8Context - async!

I tested this myself and it works really well..unless I am missing something...

While the post describes C# it should be really straight forward to translate it to C++

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!