Execute some code on the main thread

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.

Execute some code on the main thread

Postby ayoung24 » Fri Jul 23, 2010 10:08 am

Is there an easy way to get some arbitrary code to run on the main thread using only the CEF API?

It seems v8 functions which return other v8 objects must be called on the main thread (correct me if I'm wrong). In order to work around this, I've registered an extension which invokes a callback function which takes one parameter: the pointer of the actual callback function. When I want to run some v8 functions, I call execute_java_script with a javascript string, containing the address of the code block I want to execute converted to a string. This callback function seems to always be called on the main thread, so from there I can get the address of the code block address and invoke it.

The extension looks something like this:

Code: Select all
var mainThread;
if (!mainThread)
   mainThread = {};
(function() {
   mainThread.callback = function(funcptr) {
      native function callback(a);
      return callback(funcptr);
   };
})();


I execute it using a javascript string that looks something like this:

Code: Select all
mainThread.callback(348273987);


Where that number is a string-serialized pointer to the real callback. It's unfortunate that this works because it's so horrible. Is there a better way?
ayoung24
Techie
 
Posts: 13
Joined: Sat Oct 17, 2009 6:26 pm

Re: Execute some code on the main thread

Postby magreenblatt » Fri Jul 23, 2010 10:15 am

Coming in the near future (potentially this weekend).

http://code.google.com/p/chromiumembedd ... tail?id=25
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Execute some code on the main thread

Postby ayoung24 » Fri Jul 23, 2010 10:42 am

I should have checked before posting. Good to see, nonetheless. Looking forward to it.
ayoung24
Techie
 
Posts: 13
Joined: Sat Oct 17, 2009 6:26 pm

Re: Execute some code on the main thread

Postby magreenblatt » Sat Jul 24, 2010 11:50 am

Added in revision 90.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

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