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.

Re: How does CefBrowser known its renderer process created?

Postby Czarek » Thu Aug 29, 2019 5:14 am

Just make sure that you call CefV8Context::IsValid before doing any operations. Do not keep any references to context after OnContextReleased is called.
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 9:27 am

Czarek wrote:Just make sure that you call CefV8Context::IsValid before doing any operations. Do not keep any references to context after OnContextReleased is called.


OK, I see.
Well, let's come back to the orginal question.


Streamlet wrote:
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 wrote: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?


Could you give me some suggestion?
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby magreenblatt » Thu Aug 29, 2019 9:38 am

You can pass extra_info parameters to CreateBrowser which are then delivered to CefRenderProcessHandler::OnBrowserCreated. That call should occur before OnContextCreated.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Thu Aug 29, 2019 9:55 pm

magreenblatt wrote:You can pass extra_info parameters to CreateBrowser which are then delivered to CefRenderProcessHandler::OnBrowserCreated. That call should occur before OnContextCreated.


there is no CefBrowser param through this way...
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby magreenblatt » Fri Aug 30, 2019 10:01 am

Streamlet wrote:
magreenblatt wrote:You can pass extra_info parameters to CreateBrowser which are then delivered to CefRenderProcessHandler::OnBrowserCreated. That call should occur before OnContextCreated.


there is no CefBrowser param through this way...

Sorry, I don't understand what you mean.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Sat Aug 31, 2019 9:46 pm

Oh, I'm sorry. There is a browser param, but 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 magreenblatt » Sat Aug 31, 2019 10:09 pm

Streamlet wrote:Oh, I'm sorry. There is a browser param, but browser->GetMainFrame() returns nullptr.
so I cannot do browser->GetMainFrame()->SendProcessMessage()

And why do you want to do that? OnBrowserCreated is already in the renderer process. You said previously:
Streamlet wrote:My purpose is send infomation about JS injection to render process before its OnContextCreated, and in OnContextCreated I will put JS variables into context.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Mon Sep 09, 2019 5:02 am

magreenblatt wrote:And why do you want to do that? OnBrowserCreated is already in the renderer process. You said previously:


Oh, I understand now. Tnank you, I will try it.
(I'm sorry that I thought your solution is similar with what Czarek said in the 2'nd posts and misunderstood you.)
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby Streamlet » Sat Oct 12, 2019 1:38 am

When a renderer process is created for a DevTools, the extra_info doesn't contains any data?
will DevTools create a new CefBrowser object?
Streamlet
Mentor
 
Posts: 61
Joined: Tue Aug 27, 2019 6:47 am

Re: How does CefBrowser known its renderer process created?

Postby magreenblatt » Sat Oct 12, 2019 2:05 am

Streamlet wrote:When a renderer process is created for a DevTools, the extra_info doesn't contains any data?
will DevTools create a new CefBrowser object?

This was recently changed to pass the DevTools browser the same extra_info as the parent browser. Commit: https://bitbucket.org/chromiumembedded/ ... a1f6be6319
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

PreviousNext

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 47 guests

cron