how to pass argument to child process when creating browser

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 to pass argument to child process when creating browser

Postby Marcin » Thu Jan 15, 2015 5:34 am

as follow up of the thread :
viewtopic.php?f=6&t=12570
which I consider closed I got another question.

As I need to differentiate processes packed in one executable as required by CEF3, I need to pass a parameter to the child process. I successfully did it using OnBeforeSubProcessLaunch and AppendSwitch and I test is using HasSwitch in the child process.

So far, so good.

The problem I am facing is, that I want to "differentiate" (i.e pass some extra data) child processes when calling CefBrowserHost::CreateBrowser however OnBeforeSubProcessLaunch of my CefApp has only commad_line parameter, so I do not know, what is the CefClient I created for CefBrowserHost::CreateBrowser so I do not know whether I should append or not my switch to the command line.

any advice ?
Marcin
Techie
 
Posts: 37
Joined: Fri Dec 06, 2013 5:07 am

Re: how to pass argument to child process when creating brow

Postby magreenblatt » Thu Jan 15, 2015 11:11 am

See here for your options.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: how to pass argument to child process when creating brow

Postby Marcin » Fri Jan 16, 2015 7:27 am

Yep, I know the options, however the problem is I need to be notified before the OnContextCreated is called as I want to do JavaScript binding.

so I though passing switch in command_line would be the best, but I do not know how to link it to the CefClient ...
Marcin
Techie
 
Posts: 37
Joined: Fri Dec 06, 2013 5:07 am

Re: how to pass argument to child process when creating brow

Postby magreenblatt » Fri Jan 16, 2015 11:48 am

What are you trying to customize in OnContextCreated? What size/type of data do you need to pass from the browser process?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: how to pass argument to child process when creating brow

Postby Marcin » Fri Jan 16, 2015 1:05 pm

I need just one integer value to have different implementations of CefApp, i.e. different JS binding, so just wanto somhow to pass the value once I call CreateBrowser ...

In one implementaion of Browser I have different native JavaScript objects and in another one different JavaScript objects. To my understanding, OnContextCreated is the place to do it, though all the browsers "looks" the same for me ...
Marcin
Techie
 
Posts: 37
Joined: Fri Dec 06, 2013 5:07 am

Re: how to pass argument to child process when creating brow

Postby magreenblatt » Fri Jan 16, 2015 1:14 pm

Marcin wrote:I need just one integer value to have different implementations of CefApp, i.e. different JS binding, so just wanto somhow to pass the value once I call CreateBrowser ...

The difficulty with using command-line arguments is that multiple browsers may be hosted in the same renderer process if they share the same origin, and so you wouldn't get a different command-line value for those other browsers that share the same process. Also, when the origin changes for an existing browser a new renderer process may be created.

A few possibilities:
1. Load a different URL in each browser as a means of differentiating them. For example, add a query parameter that specifies your integer value.
2. Include the integer value in your HTML/JS code and pass it to a JS function that initializes the API. For example, var api = window.getMyApi(integer).
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: how to pass argument to child process when creating brow

Postby Marcin » Fri Jan 16, 2015 4:13 pm

ok, thx I'll work out some workaround ...
Marcin
Techie
 
Posts: 37
Joined: Fri Dec 06, 2013 5:07 am

Re: how to pass argument to child process when creating brow

Postby mkoubaa » Fri Jan 23, 2015 5:01 pm

How about writing it to a file in %TEMP% right before calling 'createbrowser', and read it and add it to the CefApp object which you pass into CefExecuteProcess.

It should work as long as the time between one createbrowser and the next is longer than the time it takes for your application to reach 'CefExecuteProcess'.
mkoubaa
Techie
 
Posts: 24
Joined: Mon Dec 29, 2014 4:28 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 99 guests