How do I use OnBeforeChildProcessLaunch

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 do I use OnBeforeChildProcessLaunch

Postby rdh » Wed Jul 01, 2020 4:09 pm

I have my c++ app and I have my cef app:
class MyCefApp : public CefApp, CefBrowserProcessHandler
{
void OnBeforeChildProcessLaunch( CefRefPtr<CefCommandLine> command_line )
{
TRACE(L"process launching");
}
}

When I fire up cef, OnBeforeChildProcessLaunch is called for each subprocess launched. But, the input command_line pointer is always nullptr. It looks like I am supposed to implement the method. The cef_browser_process_handler.h file just notes that I should not keep a reference to the |command _line| outside of this method.

I just want to pass my subprocess an arg I can use in the subprocess and I thought this was how to do that but apparently not. I tried the the "ShellExectue" approach of building the subprocess name with the arg I want to pass in but that didn't work as I guess cef tried to kick off the subprocess using the entire string I gave it "myusubprocess.exe /x". I tried both of those because I didn't find any way to pass the arg(s) I want to pass via the CefSettings struct I use to set the subprocess name.

I'm sure this a simple thing to do so don't laugh at me too much.
rdh
Techie
 
Posts: 33
Joined: Wed Jun 10, 2020 3:18 pm

Re: How do I use OnBeforeChildProcessLaunch

Postby magreenblatt » Wed Jul 01, 2020 6:21 pm

What OS and CEF version? It should not be possible for |command_line| to be nullptr. I suggest checking that all of your build inputs (incudes, libs, etc) are correct and from a matching CEF version.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: How do I use OnBeforeChildProcessLaunch

Postby rdh » Thu Jul 02, 2020 7:23 am

I pulled cef_binary_83.3.12+g0889ff0+chromium-83.0.4103.97_windows64.tar from the download site and I am on Win10. What would not match? I thought I found some code that did a hash test to verify the version. Could be I am thinking of some other system we use.

When I start up our app and one of our commands wants to show the user a web page (we are not a browser app) in a dialog, I start up cef. My cef app is very small:

class CefMfcCefApp : public CefApp, CefBrowserProcessHandler {
public:
CefMfcCefApp()
{
}

CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
{
return this;
}
void OnBeforeChildProcessLaunch( CefRefPtr<CefCommandLine> command_line )
{
TRACE(L"CEF OnBeforeChildProcessLaunch");
}

CefRefPtr<CefBrowserProcessHandler> m_pProcessHandler = nullptr;

private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(CefMfcCefApp);
};

When I break in OnBeforeChildProcessLaunch, VS debugger Locals window shows me the command_line is null:

+ command_line {ptr_=0x0000000000000000 <NULL> } scoped_refptr<CefCommandLine>


Is this an issue with how I start CEF up? Perhaps how I do that is wrong. I ended up doing this:

m_CEF_app = new CefMfcCefApp;
CefMainArgs mainargs(hInstance);
const auto exit_code = CefExecuteProcess(mainargs, m_CEF_app.get(), sandbox_info);
if(exit_code >= 0)
return false;

which I think is totally odd since hInstance is that of my application, and it has nothing to do with CEF itself - the command line passed to our application has nothing related to cef in it. I already worry that cef will see some switch, like /automation /assembly or other switches we use and think it is meant for it. I can go back and take that hInstance out as at this point, I don't recall if I could create the CefMainArgs without using my app's hInstance.

Did I make the wrong choice trying to use cef? As I noted, I am not a browser app. I am just looking for a replacement of the Microsoft Web Browser control which is a COM object (and we being a COM application) which we use to host some of our UI (html pages) and some company web sites via the DOM and events the MS WBC provides.

I did find this link:

https://gitlab.collabora.com/web/cef/co ... 8817d52532

But it uses include files not in the cef download I pulled and appears to be internal to cef or is out of date. Right now, I want to pass the subprocess information about the DPI setting we use as the call to set the CefenableHighDPISupport routine I found and called when my subprocess fires up is not usable as it doesn't match the DPI settings we can run with. That causes an issue I have seen posted elsewhere where moving our app from one monitor to another causes cef to render a "ghost" image of the web page in our window giving a picture in picture effect. So I want to pass which setting we use to the subprocess so both processes match wrt the dpi setting. Besides, that arg, over time I might need other args passed so I thought I just sync the two settings using the command line.

Update: I created the cef args without our hInstance with no issue showing up. But, the command line pointer is still null.

I can start over. Kindly point me to the latest cef binaries so I make sure I pull the correct version and point me to the cef-project that matches it so I can build the libcef_dll_wrapper.lib as I have to build it with /MD and /MDd. The cef subprocess that gets fired up is passed a command line so something appears to be out of sync. I thought I followed the instructions carefully on pulling cef-project and converting it to a Visual Studio 2017 and a 2019 project and pulled the bitbucket binaries, of which there were two ( the second being a "minimal" download). So I have binaries that I don't build and a "cef-project" that is independent of the cef binary downloads that I can build and do have to build so I can link our app with the wrapper lib.

Here is what led me astray? https://bitbucket.org/chromiumembedded/ ... -arguments
rdh
Techie
 
Posts: 33
Joined: Wed Jun 10, 2020 3:18 pm

Re: How do I use OnBeforeChildProcessLaunch

Postby rdh » Thu Jul 02, 2020 1:49 pm

I went back to the bit bucket and pulled the "client tar" file, which has the cefclient in it and cef binaries too. Converted that to VS 2019 and built the wrapper lib so I can link and used the wrapper lib and the cef binaries and now I do indeed get a non null command line pointer. The ceflib.dll I had previously pulled and was using looks the same - same size and properties show the same version. But for whatever reason, it is now working. I dumped the other cef-project I had pulled to build the wrapper lib with /MD, which is fine with me. From now on, I'll stick to the bit bucket binary for the client.
rdh
Techie
 
Posts: 33
Joined: Wed Jun 10, 2020 3:18 pm

Re: How do I use OnBeforeChildProcessLaunch

Postby magreenblatt » Thu Jul 02, 2020 2:13 pm

If you follow the instructions for cef-project it will download the necessary CEF version when you run CMake. The instructions also tell you how to generate VS2019 project files.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 33 guests