multi threaded message loop and V8 context

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.

multi threaded message loop and V8 context

Postby ronwilsoncpp » Mon Jul 30, 2018 7:51 am

Hi!

I'm trying to execute JS function on the TID_RENDERER(also tried on TID_UI) with setting:

Code: Select all
CefSettings cefSettings;
cefSettings.multi_threaded_message_loop = TRUE;
cefSettings.single_process = TRUE;


all sample over Internet tell me that it's must return V8 context:

Code: Select all
static void _OnExecJSFunc_Worker(CefRefPtr<CefBrowser> browser, SExecJSParams * params, bool * retVal)
{
   REQUIRE_RENDERER_THREAD();
   CefRefPtr<CefFrame> frame = browser->GetMainFrame();
   CefRefPtr<CefV8Context> context = frame->GetV8Context();
}


but context of main frame always zero, i post task with helper from tests like this:

RunOnThread(TID_RENDERER, base::Bind(_OnExecJSFunc_Worker, cefHandler->GetBrowser(), params, &retVal), event);

Tried on 66, latest 67 Windows x86 builds. On https://github.com/adobe/brackets-app/blob/master/src/mac/cefclient/cefclient.cpp example it's done very easily.

Can anybody help about it? What I'm doing wrong? Why context always zero?

P.S. page loaded and complete.
ronwilsoncpp
Newbie
 
Posts: 3
Joined: Mon Jul 30, 2018 7:41 am

Re: multi threaded message loop and V8 context

Postby magreenblatt » Mon Jul 30, 2018 12:08 pm

Single-process mode is not supported. CefFrame::GetV8Context will return null if you are not in the renderer process. See https://bitbucket.org/chromiumembedded/ ... gration.md
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: multi threaded message loop and V8 context

Postby ronwilsoncpp » Wed Aug 01, 2018 6:54 am

Thank you, switched to multiprocess model, now it's "fork" on Windows itself, but now my task never starting on renderer:

Code: Select all
void RunOnTID(CefThreadId cefTID, const base::Callback<void(void)>& functImpl, CefRefPtr<CefWaitableEvent> event)
{
   if( !CefCurrentlyOn(cefTID) )
   {
      CefPostTask(cefTID, base::Bind(RunOnTID, cefTID, functImpl, event));
      return;
   }

   functImpl.Run();
   SignalEvent(event);
}


Code: Select all
static void _OnExecJSFunc_Worker(CefRefPtr<CefBrowser> browser, SExecJSParams * params, bool * retVal)
{
// !!!never called!!!
   REQUIRE_RENDERER_THREAD();
}

RunOnTID(TID_RENDERER, base::Bind(_OnExecJSFunc_Worker, cefHandler->GetBrowser(), params, &retVal), event);


So, how can i launch task on renderer process when action with V8 needed?

Thank you.
ronwilsoncpp
Newbie
 
Posts: 3
Joined: Mon Jul 30, 2018 7:41 am

Re: multi threaded message loop and V8 context

Postby ronwilsoncpp » Wed Aug 01, 2018 8:48 am

I solve my task by registering general function in CEF which received string with piece of JS code and return result of eval on the context when I call it :lol: hey!!
ronwilsoncpp
Newbie
 
Posts: 3
Joined: Mon Jul 30, 2018 7:41 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 81 guests