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
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.
Can you share the work you did with Webkit?
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?
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:
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:
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
// 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
do_QueryInterface for nsIBaseWindow,
do_QueryInterface for nsIWebNavigation
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.
I also need to use subdirectories as include dirs.
# include "nsStringAPI.h"
immature with respect to embedding, but it works, so good luck with
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?
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
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
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.
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
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.