Some queries regarding CEF

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.

Some queries regarding CEF

Postby DarthCoder » Tue Jun 21, 2011 12:25 am

We have an MFC based game client that currently embeds Gecko for rendering web pages in the client. I am currently working on a CEF based prototype to evaluate the feasibility of migrating to CEF. I have a few queries related to the same. Just to give some background, all the browser embedding support is all built into a Multi threaded DLL and the MFC client uses C++ interfaces provided by the DLL.

Since the DLL was built with /MD flag, I have already rebuilt cef_wrapper with the same flag and was able to successfully link the stub library to our DLL. I am also able to instantiate browser windows. Now to my queries

1. One of the most important things that we require is the ability to invoke In Page Java Script functions from the client C++ code. For instance if the loaded page has a Java Script function called MyFunction which takes some arguments and returns a result. I should be able to somehow invoke the function from my client C++ code, pass the requisite arguments and get the result back (Have to wait till the function is executed). From what I have explored there is a Execute method in the Frame class, but it takes the JS code itself instead of a function name. Is there any way to achieve this? If it is not already there, is there some way to get it by modifying the CEF/Chromium codebase.

2. When I create a browser Instance using CefBrowser::CreateBrowser, I guess the browser instance is created asynchronously. Is there any way to make the application wait till the browser instance is actually created? The issue we are facing is that our DLL exposes separate interfaces for Creating Browser instance and for navigating to an URL. So in a lot of cases, the client has code sequences comprised of a browser instance creation call followed by a url navigation call. If the URL navigation call happens before the browser instance is actually created, then that would lead to a crash. I guess this is because the multi-threading flag is enabled while calling CefInitialize. For the time being, overcome the issue by delegating the browser creation to the navigation function call. Alternatively If we do choose to run CEF in single threaded mode, how do I get the Cef events to happen at regular intervals, I am aware that there is a method to force the Cef work, but what is the best way to call it. Should I just use a timer?

3. There is the question of distributable size as well. Size is very important to us as the client installs/upgrades over the internet. Our Gecko distributable's amount to 4.3Mb in size after compression. Bare minimal CEF distributables (libcef.dll and icudt.dll) take up 12Mb odd after the same sort of compression. I have been reading the other thread where it was stated that the size can be reduced by switching of webkit features that are not required. How do I go about it. Do I simply regenerate the project files and build the cef wrapper project or is something else required?
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am

Re: Some queries regarding CEF

Postby magreenblatt » Wed Jun 22, 2011 8:11 am

#1: Call the in-page JavaScript using ExecuteJavaScript and return the result using any of the following; JS callback function and CefV8Context (see v8_unittest.cc for an example), JS window binding, JS extension.

#2: Create the browser on the UI thread using CreateBrowserSync().

#3: Modify the WebKit build/features_override.gypi file and then rebuild Chromium and CEF.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Some queries regarding CEF

Postby DarthCoder » Thu Jun 23, 2011 6:27 am

magreenblatt wrote:#1: Call the in-page JavaScript using ExecuteJavaScript and return the result using any of the following; JS callback function and CefV8Context (see v8_unittest.cc for an example), JS window binding, JS extension.


I have gone through that and its somewhat confusing on how that would be of help to me. It looks as if the facility is meant to callback native C++ functions from JS.

Let me give some more context to my own use use.

- I cannot modify the web pages in any way. They are assumed to be frozen.
- I have to make the java script function calls mostly in response to a browser event, say for example In the On load Complete callback, I have to call some some JS function that is already present in the page and get back the data returned by the function. Since the callback is part of the UI thread, I have tried to call the java script function directly by building a exposed wrapper interfaces over the frames executeScriptAndReturnValue method and calling it. However the function is returning an valid result.

Next I also tried the CefV8Task thing described here

http://code.google.com/p/chromiumembedd ... ail?id=151

This works for me and I get the result in the HandleResult method, but I want to stall execution and wait till the JavaScript execution is completed and a value (or error) is returned. However since the call itself is made from a browser callback handler which is running in the UI thread and the task itself is queued to be run on the UI thread, I cannot stall the execution to wait for the result. Is there some clear cut way to execute the script and get they result immediately instead of queuing up a task to be executed later. since the callback handlers are running on the UI thread, shouldn't the call to executeScriptAndReturnValue succeed without having to schedule a task and put it on a queue to be executed later on?



magreenblatt wrote:#2: Create the browser on the UI thread using CreateBrowserSync().


What about running CefDoMessageLoopWork? Where should I call it for optimal operation. While my DLL is neutral, the client itself is built in MFC.
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am

Re: Some queries regarding CEF

Postby magreenblatt » Thu Jun 23, 2011 8:29 am

DarthCoder wrote:Next I also tried the CefV8Task thing described here

http://code.google.com/p/chromiumembedd ... ail?id=151

This works for me and I get the result in the HandleResult method, but I want to stall execution and wait till the JavaScript execution is completed and a value (or error) is returned. However since the call itself is made from a browser callback handler which is running in the UI thread and the task itself is queued to be run on the UI thread, I cannot stall the execution to wait for the result. Is there some clear cut way to execute the script and get they result immediately instead of queuing up a task to be executed later. since the callback handlers are running on the UI thread, shouldn't the call to executeScriptAndReturnValue succeed without having to schedule a task and put it on a queue to be executed later on?

What thread are you attempting to call executeScriptAndReturnValue() on? This and all WebKit-related code can only be executed on the UI thread. The best approach is to design your application so that it can function with asynchronous notification. If you must block on the UI thread then you can use operating system capabilities. On Windows, for instance, you can use CreateEvent() and WaitForSingleObject().

DarthCoder wrote:What about running CefDoMessageLoopWork? Where should I call it for optimal operation. While my DLL is neutral, the client itself is built in MFC.

CefDoMessageLoopWork() can be called from an override of CWinApp::PreTranslateMessage(). Note that using CefDoMessageLoopWork() does not give optimal performance for animations, etc.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Some queries regarding CEF

Postby DarthCoder » Thu Jun 23, 2011 11:39 pm

The call to executeScriptAndReturnValue is happening on UI Thread only since I make the calls from inside browser event notification callbacks sent by Cef (which are themselves running on the UI Thread). Also WaitForSingleObject would not work because the the call is happening on the UI Thread only, so if I call this function, I would be blocking the UI thread and the Java Script task is never going to execute. Ideally since I am running the function on UI Thread, it should be working right?
DarthCoder
Techie
 
Posts: 23
Joined: Mon Jun 20, 2011 4:57 am


Return to Support Forum

Who is online

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