Embedd Chrome within Java (Swing or SWT).

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

Embedd Chrome within Java (Swing or SWT).

Postby rupertlssmith » Wed May 16, 2012 7:01 am

Hi,

Does CEF come with support to embed a browser within a Java application? Swing or SWT? Note this is different from running Java Applets within the browser, its the browser I wish to place within a standalone Java application.

I have managed to do this previously with Eclipse SWT, by using a browser component in the UI. Chrome/Webkit can be selected as the browser to use, or the platform default may be used. AFAIK, Webkit support is not available under Windows? at least the FAQ says you must first install Safari to use it. This method dynamically links to a browser already installed on the system.

What I would like to do is to statically embed a Chrome/Webkit based browser within my application, on all platforms (Linux/Windows/Mac), and avoid linking to the platform default. That way I can guarantee that the application will work very consistently on all platforms, and it won't be pot-luck as to what browser the system provides.

What I am doing, is creating a Java+HTML+javascript based web app, and deploying it with an embedded web server and embedded browser, so the whole thing runs as if it were a native desktop application. Why? because this is only one way in which my webapp can be run, it can also be hosted and accessed through a normal web browser, in other deployment scenarios. I would also aim to enhance the UI somewhat when running in standalone mode, for example, custom menus and keyboard short-cuts, some integration into the native platform, and so on.

Does CEF only provide a C++ API? I suppose I can always call that through Java JNI and get it running that way. Thought I'd ask first, in case some of this hard work has already been done.

Interesting project and thanks for your help.

Rupert
rupertlssmith
Newbie
 
Posts: 3
Joined: Wed May 16, 2012 6:44 am

Re: Embedd Chrome within Java (Swing or SWT).

Postby magreenblatt » Wed May 16, 2012 12:50 pm

This concept has been explored by the Java Chromium Embedded project: http://code.google.com/p/javachromiumembedded/

In summary, parenting a native window to a Java application is possible on Windows (and probably Linux) but not Mac OS-X. There are a few interesting options for future exploration:

1. Use off-screen rendering. Java paints a buffer provided by CEF and sends CEF mouse/keyboard events.
2. Show the CEF browser window as an underlay of the Java window. Not sure if Java supports this capability. This might be a better option in the long run as it will allow use of accelerated compositing in the CEF window.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Embedd Chrome within Java (Swing or SWT).

Postby rupertlssmith » Wed May 16, 2012 1:05 pm

magreenblatt wrote:In summary, parenting a native window to a Java application is possible on Windows (and probably Linux) but not Mac OS-X.


Really? I thought that it can be done with something like a -start-in-first-thread option? Which means that the main Java thread is also the main UI thread. Perhaps I'm wrong I don't know too much about Mac OS.

Thanks for the link the Java embedded project. I'll give that a go, although it looks like a fairly minimal implementation, but that might be all I need.

Rupert
rupertlssmith
Newbie
 
Posts: 3
Joined: Wed May 16, 2012 6:44 am

Re: Embedd Chrome within Java (Swing or SWT).

Postby magreenblatt » Wed May 16, 2012 1:27 pm

rupertlssmith wrote:
magreenblatt wrote:In summary, parenting a native window to a Java application is possible on Windows (and probably Linux) but not Mac OS-X.


Really? I thought that it can be done with something like a -start-in-first-thread option? Which means that the main Java thread is also the main UI thread. Perhaps I'm wrong I don't know too much about Mac OS.

I think the problem may be more related to customizing NSApplication, but it's been a while.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Embedd Chrome within Java (Swing or SWT).

Postby rupertlssmith » Wed May 16, 2012 5:33 pm

magreenblatt wrote:
rupertlssmith wrote:
magreenblatt wrote:In summary, parenting a native window to a Java application is possible on Windows (and probably Linux) but not Mac OS-X.


Really? I thought that it can be done with something like a -start-in-first-thread option? Which means that the main Java thread is also the main UI thread. Perhaps I'm wrong I don't know too much about Mac OS.

I think the problem may be more related to customizing NSApplication, but it's been a while.


I'll take your word for it. I know its possible to 'embed' a browser on Macs with the Eclipse SWT browser abstraction, but also I think in that case the native window is not being parented, it is the parent window. I've seen that 'start in first thread' option on the FAQ there.
rupertlssmith
Newbie
 
Posts: 3
Joined: Wed May 16, 2012 6:44 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 139 guests