3

I have been experimenting with CEFGlue in C# recently particularly from the JS>Native integration.

I have tried 3 approaches but none seems to be appropriate.

  1. Through XHR and Custom SchemeHandler - generally great but seems to blocks both the renderer and browser for long running tasks.
  2. Through V8 callbacks - awesome but blocks the renderer for long running tasks
  3. Through cefQuery aka Asynchronous Bindings - does not block the renderer or browser but does not seem to have support for passing any parameters.

I have a trivial requirement it seems.

  1. Asynchronous execution i.e. neither browser nor renderer are to block on long running tasks.
  2. I need to pass parameters and process return values in Javascript.

Is there a feature of CEFGlue that I can experiment with that will allow me to accomplish this task?

Thanks.

Moonwalker
  • 3,462
  • 4
  • 25
  • 31

2 Answers2

4

I have posted an answer to my own question on Google CEF group. The solution works quite well.

CEF Google Group

Moonwalker
  • 3,462
  • 4
  • 25
  • 31
1

A solution for this is to reuse the AJAX plumbing built into Chromium Embedded.

CEF is a built from Chrome so everything is geared towards the client app communicating with a server. If you structure your web code communicating with your c# code to look like this, then you get to reuse a lot of the best practices from web development.

It's possible to implement an in-process web server and use that handle both page requests and AJAX requests that can facilitate communication with your c# code.

I have implemented that for a project at work which we open sourced. GitHub

The way it works is pretty simple:

  • Create a HTTP server that runs in memory. We use OWIN for this.
  • Create an implementation of IRequestHandler that intercepts any requests to your known domain and serves from the internal web server instead. See ours here

Using OWIN allows you to layer on top lots of frameworks and libraries that make it easy to build out your app. Things like Web API make it trivial for the app hosted in the CEF frame to communicate asynchronously with your c# code via JSON. We don't use that at the minute and use JavaScript bindings, but using AJAX going to WebAPI is better.

Kevin Boyle
  • 457
  • 2
  • 7