Roll your own browser: An embedding how-to

Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Warning: This document is out of date. You should instead build XULRunner and use it for all new embedding. You should not need to, and should not, use embedding/config.

What bits do I need?

One of the requirements of building a SDK is the ability to identify and package up required files. Like that isn't totally obvious, nonetheless it has to be done. Here is that effort.

I have created a directory under embedding called config. Contained within this directory are a couple of makefiles:

The XPInstall packager follows the same format. However in our case, we only have one named XPI package.

After the build is done, you can change directory into mozilla/embedding/config, and do a make. This will produce a directory in DIST named Embed. It should include all of the base support that you need to get a web browser started up.

Included is the sample test application (gtkEmbed or winEmbed).

What initializations do I have to do?

Somewhere during the start of your application, you must initialize XPCOM. You will also want to shut this down when you quit.

Other initialization must be done to start up event queues and load some string bundles. All of this is somewhat generic and has been isolated into a static library that you can simply call on.

If you build mozilla/embedding/base/, a static library (on windows) called baseembed_s.lib is built. Just link this library to your application. There are two functions that are needed:

nsresult NS_InitEmbedding(const char *aPath);
nsresult NS_TermEmbedding();

Pretty self-explanatory. The aPath parameter will be passed to NS_InitXPCOM. NS_InitEmbedding() must be called from the main thread of your application, otherwise it won't work.

Do you have any simple examples of embedding Mozilla?

There are many examples of products already using Gecko for embedding. Here's a partial list. The sections marked 'Mozilla Examples' refer to clients and sample code to be found within the Mozilla source tree.

Linux

External projects

Mozilla Examples

  • GtkMozEmbed widget: Gtk widget wrapper for the Mozilla Gecko Engine.
  • TestGtkEmbed: Basic browser built with the GtkMozEmbed widget. URL location field, menu bar, html area, supports SSL.

Windows

External projects

  • K-Meleon browser: the Windows answer to Galeon. Fast IE-look-alike browser, uses IE and NS bookmarking system, fast loading time, privacy features, Java support and complete control of the menus and "hotkeys". Implemented with Mozilla embedding APIs. (Screenshots)
  • Neoplanet browser: A Gecko add-on for the NeoPlanet browser.
  • ActiveState's Komodo: Development environment, based on Mozilla's XUL. (Screenshot)
  • Macromedia HomeSite HTML Editor: Internal browser for the Homesite Studio application is implemented by embedding Mozilla. (Mozilla blurb)
  • Bradsoft's TopStyle CSS builder: Implements an internal browser using Mozilla ActiveX embedding control.Obsolete since Gecko 7.0
  • NXZILLA: A set of libraries that allow Mozilla to be used with a NanoX server.
  • ActiveX control: An ActiveX control allowing for embedding the Gecko layout engine.Obsolete since Gecko 7.0
  • LLMozLib & uBrowser: a static library that allows you to embed Gecko and render pages to memory. Includes test applications that illustrate how to use it. Versions for Windows and Mac with Linux to follow.

Mozilla Examples

  • mfcEmbed: Standard Mozilla embedding example application for win32. Basic browser, menus, toolbar, URLbar, html area.
  • winEmbed: Obsoleted by mfcEmbed. A bare-bones browser with URLbar and html area.
  • ActiveX control: An ActiveX control for Mozilla using the Gecko layout engine. More information at 1 and 2.

Mac

External projects

marbrow

: Mac port of

X2Web

(ja, ko) embedding Mozilla.

Mozilla Examples

  • PPEmbed: Standard Mozilla sample application implemented with Metroworks' Powerplant.
  • Camino: A project aimed at delivering a best-of-breed browser on the Mac OS X platform. Camino uses Cocoazilla, a variant of Fizzilla that consists of a UNIX back end wed to a Cocoa front end.

Java

Examples

  • Java Webclient: Provides a browser-neutral Java API that enables generic web browsing capability.
  • BrowserG!: A Java application that uses Webclient for HTML rendering and surfing capabilities.


If you find any missing item, please send me an email.

Original Document Information

  • Author(s): Doug Turner
  • Original Document: , , and
  • Last Updated Date: December 8, 2004
  • Copyright Information: Copyright (C) Doug Turner