How does CefBrowser known its renderer process created?

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.

How does CefBrowser known its renderer process created?

Postby Streamlet » Tue Aug 27, 2019 6:55 am

There is no info about CefBrowser with CefBrowserProcessHandler::OnRenderProcessThreadCreated.
Is there any api or notification that related with CefBrowser?
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Czarek » Tue Aug 27, 2019 10:28 am

You can use CefRenderProcessHandler::OnBrowserCreated and send IPC message to the Browser precess. In CefClient::OnProcessMessageReceived there is CefBrowser parameter.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Wed Aug 28, 2019 1:39 am

OK, Thank you
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Wed Aug 28, 2019 3:29 am

Czarek wrote:You can use CefRenderProcessHandler::OnBrowserCreated and send IPC message to the Browser precess. In CefClient::OnProcessMessageReceived there is CefBrowser parameter.


Excuese me please,

in OnBrowserCreated, browser->GetMainFrame() returns nullptr,so I cannot do browser->GetMainFrame()->SendProcessMessage
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Wed Aug 28, 2019 3:43 am

My purpose is send infomation about JS injection to render process before its OnContextCreated, and in OnContextCreated I will put JS variables into context.

Curently my walkaround is, send IPC message when OnRenderViewReady, the IPC message usually arrived before OnContextCreated.
But when a browser navigates to a new URL and triggers creation of new site instance, the IPC message arrived after OnContextCreated.

So I need to judge if IPC message have arrived in OnContextCreated.
If it does, then I can set JS env to context;
if not, I do this inside OnProcessMessageReceived, so I need to save context in OnContextCreated and use it in OnProcessMessageReceived, calling context->GetTaskRunner()->PostTask, context->Enter(), do with context, context->Exit()

The solution looks too complex...

Is there a simple way to send message to render process before OnContextCreated?
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Czarek » Wed Aug 28, 2019 4:13 am

You shouldn't save context. You can call CefFrame::GetV8Context. If the JS injection is the same for each browser then just send data via extra_args in CefBrowserProcessHandler::OnRenderProcessThreadCreated. To inject JS you can call CefFrame::ExecuteJavaScript.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Wed Aug 28, 2019 9:25 pm

Czarek wrote:You shouldn't save context. You can call CefFrame::GetV8Context.


Thank you for your pointing out my mistake. I will correct my code.

Czarek wrote:If the JS injection is the same for each browser then just send data via extra_args in CefBrowserProcessHandler::OnRenderProcessThreadCreated. To inject JS you can call CefFrame::ExecuteJavaScript.


Unfortunately not. It differs for CefBrowser instances.
Our injection is not JavaScript code, but native code with v8 context.
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Wed Aug 28, 2019 9:36 pm

Streamlet wrote:
Czarek wrote:You shouldn't save context. You can call CefFrame::GetV8Context.

Thank you for your pointing out my mistake. I will correct my code.


I understand it is a not good practice to save context and already corrected my code.
For further discuss, I'd like to ask if it will cause any actual problem if I do so?
In fact, I saved a map from frame id to its v8 context, will it work?
What is CefV8Context represent for? A v8::Local<v8::context>?
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Czarek » Wed Aug 28, 2019 10:50 pm

Streamlet wrote:Our injection is not JavaScript code, but native code with v8 context.

What do you mean by that?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Thu Aug 29, 2019 2:52 am

Czarek wrote:
Streamlet wrote:Our injection is not JavaScript code, but native code with v8 context.

What do you mean by that?


Oh, I mean my injection can not be done by simply calling CefFrame::ExecuteJavaScript.
Need to get CefV8Context and modify its global object, by C++ code.
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 36 guests