renderer->browser synchronous communications

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.

renderer->browser synchronous communications

Postby GuyHERMANN » Fri Jul 12, 2013 7:38 am

Hi,

I would like to know if it would be possible -only using CEF mecanisms- to SYNCHRONOUSLY retrieve browser data in a JS function executed in the renderer.

Steps:
-S1:Renderer process executes JS :
...
result = nativeSynchronousFunction(); /// this function should get data from browser and return it
...
-S2:Renderer process enters C++ coded CefV8Handler::Execute for nativeSynchronousFunction:
C++ uses a mecanism to SYNCHONOUSLY retrieve data from browser
-S3:Browser process synchronously returns the data
-S4:Renderer process receives the browser data
C++ returns the retrieved data

I tried using an URLRequest but the CefURLRequestClient callbacks are only called if we go out of the nativeSynchronousFunction
I tried to create a dedicated thread (using OS-specific thread creation) but the CefURLRequest cannot be created on an invalid CEF thread

I'd like to know if:
-using a synchronous message IPC_SYNC_MESSAGE_CONTROL1_1 would be a working solution
-another mecanism/solution exist

Thanks for your help.

PS1: the existing JS code 'result = nativeSynchronousFunction();' cannot be changed to make it work in an asynchronous way.
PS2: I have a fallback solution consisting in using TCP communications but I would prefer using CEF mecanisms that do not break the sandboxing ones
GuyHERMANN
Newbie
 
Posts: 5
Joined: Fri Jul 05, 2013 4:04 am

Re: renderer->browser synchronous communications

Postby magreenblatt » Fri Jul 12, 2013 10:20 am

magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: renderer->browser synchronous communications

Postby GuyHERMANN » Wed Jul 17, 2013 4:39 am

ok
so I understand that IPC messages are not available on CEF and that JS API should better be asynchronous

Since our existing calling code is synchronous, I will try the last suggestion of the topic consisting in using an XMLHttpRequest (in a JS extension i my case) intercepted, interpreted and answered by the browser -> this way I guess that I will be able to create renderer JS extensions that synchronously retrieve data from the browser
GuyHERMANN
Newbie
 
Posts: 5
Joined: Fri Jul 05, 2013 4:04 am

Re: renderer->browser synchronous communications

Postby magreenblatt » Wed Jul 17, 2013 9:09 am

Sync XMLHttpRequest will work but there are performance consequences (your app will be slow). You should seriously consider creating an async version of your JS API.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: renderer->browser synchronous communications

Postby GuyHERMANN » Thu Jul 18, 2013 12:59 am

Ideally I would also prefer a asynchronous JS API but our context is that we plan to replace an existing implementation of the IDE part of our product that contains an embedded browser consisting of a library based on webkit/JSCore by another lib based on CEF/v8 (CAPI). Many features of the IDE consist of HTML/JS pages which JS-API natively and synchronously communicates with the IDE-process (to get specific data from it) -> this has been do so because, as you certainly know, webkit has not a multi-process sandboxed architecture so it made sense at that time to develop a synchronous API. So making our JS API asynchronous has consequences on a vast and already existing JS codebase.

To render one page, there will be let's say a dozen of XMLHttpRequests sent to the browser and handled for most of them without any external-network IO so I hope that there won't be too much slowness due to CEF use -> if the XMLHttpRequests data is available quickly, will it be sent without any delay to the renderer or is there some internal polling ?

I also thought about using webworkers to have browser communications done in parallel to JS execution (which was the reason of this topic viewtopic.php?f=6&t=10826) but JS-extensions do not apply to webworkers in CEF : indeed I would have done synchronization between JS thread and webworker thread natively. Furthermore I do not know if JS renderer thread being natively blocked and waiting for webworker thread retreiving browser data completion would have worked
GuyHERMANN
Newbie
 
Posts: 5
Joined: Fri Jul 05, 2013 4:04 am

Re: renderer->browser synchronous communications

Postby sunswam » Tue Sep 05, 2017 12:19 am

I am trying to do the same synchronous call from the render process to browser process to get some data. As my application is already using synchronous JS API's which i am not able to change as it requires re-architecture.. currently i am looking at the suggestion of using XmlHttpRequest method to invoke a function into browser process to get the data. I am not clear how i can invoke a C++ function that can return data from the browser process to the javascript layer. I followed the instructions and sample code as per the link: https://bitbucket.org/chromiumembedded/ ... s-requests but that one invokes a javascript function which has callback. I am not clear on how the XmlHttpRequest needs to be constructed in this specifically not clear on what the URL parameter would be? xmlhttprequest.open(....). Please excuse my ignorance on this topic. Any advise/inputs would be much appreciated..
sunswam
Newbie
 
Posts: 7
Joined: Fri Jan 13, 2017 5:35 pm

Re: renderer->browser synchronous communications

Postby magreenblatt » Tue Sep 05, 2017 12:47 pm

Scroll down a bit further to https://bitbucket.org/chromiumembedded/ ... t-handling. You specify a URL to the XMLHttpRequest that is then handled by a custom scheme handler or GetResourceHandler in the browser process C++ code. The CefResourceManager class can help you with that.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: renderer->browser synchronous communications

Postby sunswam » Fri Sep 08, 2017 7:07 pm

Thank you very much. i am able to do the synchronous call using the custom scheme handler.
sunswam
Newbie
 
Posts: 7
Joined: Fri Jan 13, 2017 5:35 pm


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 16 guests