OnContextCreated in the subprocess-case not called

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.

OnContextCreated in the subprocess-case not called

Postby OneLiner » Thu Mar 21, 2019 8:48 am

Hello CEF-forum,

I am in the middle of integrating cef into a mfc-application and i do actually face the problem, that
the virtual method OnContextCreated(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefV8Context> context),
which gets overridden by my CefApp-derived class "MyCefApp" is NOT getting called at all.

MyCefApp indeed is derived from CefBrowserProcessHandler and from CefRenderProcessHandler,
and also contains the foll. lines in its header-file:

virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE {return this;}
// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() OVERRIDE;
== so MyCefApp declares/sets itself as BrowserProcessHandler / RenderProcessHandler.

I am loading a simple html-test-page, that should execute a small Javascript, which should result in a (alert()-) Message-Box being shown.
As i load the same html-test-page in the context of another smaller Test-CEF-application, i can exclude the possibility, that this html-test-page does contains an error.

The two applications are differing in the fact, that the one where OnContextCreated gets not called
uses the subprocess - approach.
CefString(&settings.browser_subprocess_path).FromASCII("SubProcessFactory.exe");

Transferring the subprocess - approach to the smaller Test-CEF-application (... where OnContextCreated was getting called before )
- everything else unchanged - the result was: OnContextCreated was not getting called anymore.

To me It seems, that using a subprocess prevents that OnContextCreated gets called.?!?
So my question is, what can i do, that OnContextCreated gets called using the subprocess-approach.

(We need to user the subprocess-approach...)
Last edited by OneLiner on Thu Mar 21, 2019 10:16 am, edited 1 time in total.
OneLiner
Techie
 
Posts: 33
Joined: Mon Jan 28, 2019 5:58 am

Re: OnContextCreated not called

Postby magreenblatt » Thu Mar 21, 2019 10:06 am

How are you initializing CEF and running the message loop?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnContextCreated in the subprocess-case not called

Postby OneLiner » Thu Mar 21, 2019 10:18 am

The initialization-code is like this:

bool MyApp::InitializeCef() {
// Initialize Chrome
m_CEFApp = new CefMfcCefApp;
CefMainArgs mainargs(GetModuleHandle(NULL));

// See if this is a Chrome process starting. If so, we're done with our (and MFC) initialization.
const auto exit_code = CefExecuteProcess(mainargs, m_CEFApp.get(), nullptr);
if (exit_code >= 0)
return false;

CefSettings settings;
settings.multi_threaded_message_loop = false;
settings.no_sandbox = true;
CefString(&settings.cache_path) = m_WorkDir;
CefString(&settings.browser_subprocess_path).FromASCII("MyCefStarter.exe");
return CefInitialize(mainargs, settings, m_CEFApp.get(), nullptr);
}
OneLiner
Techie
 
Posts: 33
Joined: Mon Jan 28, 2019 5:58 am

Re: OnContextCreated in the subprocess-case not called

Postby magreenblatt » Thu Mar 21, 2019 10:37 am

You need to also run the message loop. See https://bitbucket.org/chromiumembedded/ ... ntegration
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnContextCreated in the subprocess-case not called

Postby OneLiner » Thu Mar 21, 2019 10:52 am

Well i do call the message-loop, like this:

BOOL MyApp::PumpMessage()
{
auto result = CWinAppEx::PumpMessage();

// If there are other messages on queue then return right away
// otherwise CEF has a habit of eating keystrokes not meant for it
MSG msg;
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
return result;

// Allow Cef to do his thing
CefDoMessageLoopWork();

return result;
}

Since my html-test-page is successfully CEF-rendered, i suppose that i am doing it right.
But unfortunately, using the subprocess-case, the V8/Javascript related OnContextCreated-Method is not getting called...
OneLiner
Techie
 
Posts: 33
Joined: Mon Jan 28, 2019 5:58 am

Re: OnContextCreated in the subprocess-case not called

Postby magreenblatt » Thu Mar 21, 2019 11:42 am

OneLiner wrote:Since my html-test-page is successfully CEF-rendered, i suppose that i am doing it right.
But unfortunately, using the subprocess-case, the V8/Javascript related OnContextCreated-Method is not getting called...

OnContextCreated will be called in the renderer process. How is SubProcessFactory.exe implemented? How are you testing that the method is not getting called?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnContextCreated in the subprocess-case not called

Postby OneLiner » Thu Mar 21, 2019 12:19 pm

Maybe my comprehension was and still is wrong,
but SubProcessFactory.exe is only implemented like this:

Code: Select all
#include "stdafx.h"
#include "aDISCl_CefStarter.h"
#include "include/cef_base.h"
#include "include/cef_app.h"

class CefStarterApp : public CefApp {
public:
  CefStarterApp() {}

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

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow){

  // Structure for passing command-line arguments.
  // The definition of this structure is platform-specific.
  CefMainArgs main_args(GetModuleHandle(NULL));

  // Optional implementation of the CefApp interface. 
  CefRefPtr<CefApp> app = new CefStarterApp();

  // Execute the sub-process logic. This will block until the sub-process should exit.
  return CefExecuteProcess(main_args, app.get(), nullptr);
}


/****************************************************************************************
Whereas our "main-application", the one we wanted to extend using CEF - actually uses this implementation:
Code: Select all
class CefMfcCefApp : public CefApp
  , public CefBrowserProcessHandler
  , public CefRenderProcessHandler {
public:
  CefMfcCefApp() {}

  // CefApp methods:
  virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() OVERRIDE { return this; }
  virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() OVERRIDE { return this; }

private:
  // Include the default reference counting implementation.
  IMPLEMENT_REFCOUNTING(CefMfcCefApp);
  CefRefPtr<CaClHtmlCEFClientHandler> m_cefHandler;
  CefRefPtr<CaClHtmlCEFV8_JavaScript_Handler>     m_V8_JavaScript_Handler;

public:
  // CefBrowserProcessHandler methods:
  virtual void OnContextInitialized() OVERRIDE;

  // CefRenderProcessHandler methods:
  virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
  virtual void OnContextReleased(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) OVERRIDE;
  virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) OVERRIDE;

  // Astec methods:
  CefRefPtr<CefBrowser> CreateBrowser(CaClHtmlCEFClientHandler::Delegate* delegate, CefWindowInfo const & info, CefBrowserSettings const & settings, CefString const & url);
  void DetachDelegate(CaClHtmlCEFClientHandler::Delegate* pDelegate);
};


Do i have to move the CefRenderProcessHandler-related code to the CefStarterApp-class inside SubProcessFactory.exe?
OneLiner
Techie
 
Posts: 33
Joined: Mon Jan 28, 2019 5:58 am

Re: OnContextCreated in the subprocess-case not called

Postby magreenblatt » Thu Mar 21, 2019 12:41 pm

OneLiner wrote:Do i have to move the CefRenderProcessHandler-related code to the CefStarterApp-class inside SubProcessFactory.exe?

Yes.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: OnContextCreated in the subprocess-case not called

Postby OneLiner » Fri Mar 22, 2019 8:19 am

Thank you magreenblatt, that solved my problem.
OneLiner
Techie
 
Posts: 33
Joined: Mon Jan 28, 2019 5:58 am

Re: OnContextCreated in the subprocess-case not called

Postby jeroenclarysse » Fri Jun 14, 2019 7:50 am

I feel like a doofus, but I can't get this to work :-(

is there anyone who has a cefsimple folder in which this works ? Trying desperately to get C++ calls from javascript running so some sample code would be very very very appreciated (I don't know if these forums show email addresses ? )
jeroenclarysse
Newbie
 
Posts: 2
Joined: Thu Mar 28, 2019 4:07 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 115 guests