Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to embed Gecko in a Win32 C++ app?

1,584 views
Skip to first unread message

Pedro P. Ribeiro

unread,
Jan 29, 2010, 11:41:57 AM1/29/10
to dev-em...@lists.mozilla.org
Hey guys!

I'm having a hard time trying to understand how this works. What I need is
simple to write a Win32 C++ application, like a Wizard, but with the
interface designed in HTML and JavaScript.

I've already done that using WebKit and IE, but now I also want to use Gecko
for comparison purposes.

The thing is that I can't find a clear start point. The informations seems
to be conflicting, sometimes I read about Gecko, sometimes XULRunner, and
I'm not sure what should I use. Is there a SDK, or a set of libraries that I
can just include to my project?

I appreciate the attetion.

BR,
Pedro.

Jerry Evans

unread,
Jan 31, 2010, 10:37:58 AM1/31/10
to

Hello Pedro

Can you share the work you did with Webkit?

Thx++

Jerry.

Pedro P. Ribeiro

unread,
Feb 1, 2010, 7:08:30 AM2/1/10
to dev-em...@lists.mozilla.org
Hi Jerry,

Unfotunately I can't share the project code, but I can find the samples I
used initally for studying if you are interested.

About Gecko, any ideas?

> _______________________________________________
> dev-embedding mailing list
> dev-em...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-embedding
>

Timothy Madden

unread,
Feb 1, 2010, 1:12:48 PM2/1/10
to Pedro P. Ribeiro, dev-em...@lists.mozilla.org

What I did, on Windows with Visual Studio 2008 with mozilla-1.9.1, was
download the mozilla sources for Firefox and follow the build
instructions referred to from there. You might need to search a little
for the sources on the mozilla web site, but they are there. Also I have
read on the web site that you can simply download the SDK if you want,
but I guess you will still need the sources for any form of useful
debugging (unless you can just write your programs without any mistake
:) ). Having the debugger download the public symbol files from
Microsoft online symbol store for all the system .dll files will also help.


The mozilla sources can be used to build more than one application, i.e.
you can build thunderbird, firefox, calendar, seamonkey, etc. One of
these applications, that you can also build with just the sources for
Firefox, is called xulrunner and is the SDK you need for embedding. The
build process presented on the site just worked for me and I will not
repeat it here. You have to expect some more work than a simple
setup-like installation, though ...

After building xulrunner application you can also proceed to building
the SDK with *make sdk* in the build directory. The resulting .zip file
is what you need to unpack and include in your project.

I chose to include the .zip as is in my project and define a custom
build step that invokes a makefile to unpack the archive anytime it is
needed, so as to not actually include all those many files in my project.

You then include the libraries from the sdk/lib/ folder, and the files
from include/ and sdk/include/ folders. The SDK has a strange directory
structure that is not clearly documented. They say somewhere on the site
that those include directories are sufficient, but I found I also need
to use the subdirectories as include dirs.

What they do not say is that you have to pay attention to the order of
libraries. If you get it wrong you will get undefined symbols. Here is
the order I use:
xpcom.lib
xpcomglue_s.lib
embed_base_s.lib
crmf.lib
ssl3.lib
mozreg_s.lib
plc4.lib
plds4.lib
smime3.lib
nspr4.lib
nss3.lib
nssutil3.lib
unicharutil_external_s.lib
xul.lib
js3250.lib

They say that instead of xpcom and xpcomglue_s you can also link against
just xpcomglue, but do not use all three of them at once. I also had to
disable linking of the default library msvcrt.lib (which is normal that
it should not be linked on Debug configuration).

For the include directories I use I will give you the list but I think
it is less important for you because I also need to use some internal
stuff from Mozilla, that you should probably not need, so the list here
is longer than what you need:


$(ProjectDir)..\Redist\dbg\xulrunner-sdk\sdk\include
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include\xpcom
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include\gfx
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include\widget
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include\layout
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include\content
$(ProjectDir)..\Redist\dbg\xulrunner-sdk\include\dom


I have not seen these actually documented on the web site (the sources
also do not include documentation).

With these include dirs, the files I need to include are (again, these
are more than what you need):

/* Include XPCOM and Gecko/Mozilla headers */

// Tell XPCOM the current platform is Windows
# ifndef XP_WIN
# define XP_WIN
# endif

// Save current warning level and set it to 3 (default)
# pragma warning(push, 3)
# pragma warning(disable: 4996) // 'function' was declared deprecated
// some XPCOM headers use strdup which
// by VS2008 should be deprecated

# include "nsError.h"
# include "nsIInterfaceRequestor.h"
# include "xpcom/nsIInterfaceRequestorUtils.h"
# include "nsWeakReference.h"
# include "nsCOMPtr.h"

# include "gfx/nsIRenderingContext.h"
# include "widget/nsIWidget.h"
# include "widget/nsIBaseWindow.h"

# include "nsIWebBrowser.h"
# include "nsIWebBrowserSetup.h"
# include "nsIWebBrowserChrome.h"
# include "nsIEmbeddingSiteWindow.h"

# include "nsIDOMEventListener.h"
# include "nsIDOMWindow.h"

# include "content/nsPIDOMEventTarget.h"
# include "content/nsINode.h"
# include "content/nsIContent.h"
# include "content/nsIDocument.h"
# include "nsComponentManagerUtils.h"
# include "layout/nsIPresShell.h"
# include "docshell/nsIDocShell.h"
# include "docshell/nsIWebNavigation.h"
# include "dom/nsIDOMNode.h"
# include "dom/nsIDOMElement.h"
# include "dom/nsIDOMEvent.h"
# include "dom/nsIDOMDocument.h"
# include "dom/nsIDOMWindow2.h"
# include "dom/nsIDOMWindowCollection.h"
# include "dom/nsIDOMEventTarget.h"
# include "nsIWebBrowserFocus.h"
# include "nsEmbedAPI.h"
# include "nsEmbedCID.h"

# include "nsStringAPI.h"

// Restore warning level
# pragma warning(pop)

Yes, it is a long list, and it is strange you have to include all that
line by line. I made a separate precompiled header for this list

As you can see you should also define XP_WIN in your project.

All these lists are made on an as-needed bases, or ad-hoc if you want.
The documentation on the subject is exemplary lacking from the MDC. The
entire documentation site is search-based and I found that more often
than not what I need is not documented (or not documented yet) and can
not be found.

With the documentation so scarce, you definetly need a good source code
browser (I use ctags with vim) and search the interfaces in the header
files for one that does what you need, then, include the file you find
is appropriate to provide you that interface.

After getting these you just need to call

NS_InitEmbedding/NS_TermEmbedding,
do_CreateInstance(NS_WEBBROWSER_CONTRACTID)
nsIWebBrowser::SetContainerWindow,
do_QueryInterface for nsIBaseWindow,
nsIBaseWindow::Init
nsIBaseWindow::Create
do_QueryInterface for nsIWebNavigation
nsIWebNavigation::LoadURI

and implement yourself a component exposing nsIWebBrowserChrome,
nsIWeakReference and nsIInterfaceRequestor. Also nsIDOMEventListener
might be helpfull.

However these actual programming details are better documented if you
search the MDC site.

It is not exactly a robust product as they say, actually it is immature,
but it works, so good luck with it.

Hope that helps anyone.

Timothy Madden

Timothy Madden

unread,
Feb 1, 2010, 1:17:16 PM2/1/10
to Pedro P. Ribeiro, dev-em...@lists.mozilla.org

I also need to use subdirectories as include dirs.

# include "nsStringAPI.h"

immature with respect to embedding, but it works, so good luck with

Pedro P. Ribeiro

unread,
Feb 1, 2010, 1:34:43 PM2/1/10
to Timothy Madden, dev-em...@lists.mozilla.org
Thanks Timothy!

Yeah, this is far from being trivial..

If fact, this is one of the aspects that I'm trying to evaluate and compare
with WebKit and IE. So far, Gecko solution seems to be much more complex.

But what would you say about using XULRunner, build a regular XUL
application and use XPCOM to link the UI with the C++ logic behind? Is that
the case you've mentioned and pointed debugging as the big issue?

Timothy Madden

unread,
Feb 1, 2010, 2:29:33 PM2/1/10
to
Pedro P. Ribeiro wrote:
> Thanks Timothy!
>
> Yeah, this is far from being trivial..
>
> If fact, this is one of the aspects that I'm trying to evaluate and compare
> with WebKit and IE. So far, Gecko solution seems to be much more complex.
>
> But what would you say about using XULRunner, build a regular XUL
> application and use XPCOM to link the UI with the C++ logic behind? Is that
> the case you've mentioned and pointed debugging as the big issue?
>
> On Mon, Feb 1, 2010 at 16:17, Timothy Madden <termin...@gmail.com> wrote:
>
[...]

It is not hard, it just takes a few days to build and read XPCOM
documentation until you can implement those nsIWebBrowserChrome and
nsIEmbeddingSiteWindow interfaces, which are pretty trivial in the end.
Of course, the outcome depends on your patience and your experience as a
developer.

Do you know how to use WebKit ? This Gecko thing is quite hard for me
and I would also like some other embedding solution if better ...

Sorry what I have tried I already presented. Embedding XUL applications
would be something as new for me as for you. I only used C++ and I am
still to see how would I create any XUL or JavaScript "applications". I
must admit your idea is interesting but as I said I would be happier if
I could find some better embedding solution. One the other hand I doubt
I cound find such a solution that will allow me to get into its
internals like Gecko does.

Timothy Madden

Jerry Evans

unread,
Feb 4, 2010, 9:49:44 AM2/4/10
to
On 01/02/2010 12:08, Pedro P. Ribeiro wrote:
> Hi Jerry,
>
> Unfotunately I can't share the project code, but I can find the samples I
> used initally for studying if you are interested.
>
> About Gecko, any ideas?
>
/* snip */

Hi Pedro

Rats.

I have been working a Gecko for ages but I never get enough time to
reach a solution.

Right now I am strongly biased towards the Chromium port of Webkit as
this builds pretty much out of the box. Also it can use VS2008 hence
integrates much more easily with the rest of the (large) code base.
There is still a Cygwin dependency I'd like to remove but Chrome/Webkit
uses Skia which is, IMVHO, a much better rendering engine than Cairo.

HTH + ATB

Jerry

Dmitry Dartz

unread,
Feb 5, 2010, 6:03:34 AM2/5/10
to
> Thanks Timothy!
>
> Yeah, this is far from being trivial..
>
> If fact, this is one of the aspects that I'm trying to evaluate and
> compare
> with WebKit and IE. So far, Gecko solution seems to be much more complex.
>
> But what would you say about using XULRunner, build a regular XUL
> application and use XPCOM to link the UI with the C++ logic behind? Is
> that
> the case you've mentioned and pointed debugging as the big issue?
>

I'm also interested in WebKit samples.
Could you please show the way from say 5000ft hight of view?
Just a direction in which we'd try to go.


malashen...@gmail.com

unread,
Mar 5, 2013, 8:13:40 AM3/5/13
to
пятница, 5 февраля 2010 г., 15:03:34 UTC+4 пользователь Dmitry Dartz написал:
> I'm also interested in WebKit samples.
> Could you please show the way from say 5000ft hight of view?
> Just a direction in which we'd try to go.

You may see excelent example by B.Fulgham:
https://github.com/bfulgham/CallJS

Also, you may be interest about WebKit build under VS2010 or 2012, so WebKit still officialy require VS2005. See this:
http://blog.ashodnakashian.com/2012/09/building-webkit-with-vs2012/
http://blog.ashodnakashian.com/2012/01/building-webkit-on-windows-7-with-vs2010/

mhmin...@gmail.com

unread,
Jun 12, 2013, 6:50:54 AM6/12/13
to
I compile the CallJS and when executing got error.
"This application has failed to start because the application configuration is incorrect."
What the matter?
0 new messages