Extending Mozilla or How To Do The Impossible

Contents
Introductions
XPCOM & Modules
Examples
Wrap-up

Mozilla
Open Source Project Initiated by Netscape
”The fastest Web Browser”
Many products in addition to Web browser:
Bonsai (tree control)
Tinderbox (tree status)
Bugzilla (bug database)
...

DocZilla
”A Component”
SGML/XML/HTML Browser with HyTime link support
Differencies to standard Mozilla Browser:
DTD and SGML declaration handling
Supports additional image formats
Enhanced link support
Structured and index-based search

XPCOM & Modules

COM (1/2)
Binary compatible components
Interface and implementation completely separated
Enables distributed computing
Multiple implementations possible
Objects can support multiple interfaces
No versioning problems; globally unique interface identifiers
Strict rules about in/out parameters
Reference counting

COM (2/2)
Language/compiler independent
New ”dynamic_cast” for interfaces (QueryInterface)

XPCOM
Simplified COM
Cross-platfrom
”Binary compatible with COM”

Hello Sample (1/3)
Interface (mozIHello)
Written in IDL
Inherits from nsISupports
Pure abstract class
IID
Implementation (mozHello)
Reference counts
QueryInterface
CID

Hello Sample (2/3)
NSGetFactory(…)
new mozHelloFactory();
NSRegisterSelf(…)
nsComponentManager::RegisterComponent(…);
CLSID, class name, ProgID, path...
NSUnregisterSelf(…)
nsComponentManager::UnregisterComponent(…);
NSCanUnload(…)
Return PR_TRUE if the component can be unloaded.
NSGetModule(…) will replace all these…

Hello Sample (3/3)
Factory (mozHelloFactory, inherts from nsIFactory)
CreateInstance(…);
LockFactory(…);
Creating a mozHello instance
C++
nsComponentManager::CreateInstance(…);
JavaScript
Components.classes[…].createInstance();

Modules
NSPR
XPCOM
Parser Engine
Widgets
Graphics
Layout
Webshell
?

Available Samples
XPCOM Hello
Embedded webshell
Frankenbrowser
+ Adam Lock’s ActiveX samples…
http://www.iol.ie/~locka/mozilla/mozilla.htm
+ Alexander Larsson’s Embedding Gecko in a GTK app. (mozilla/webshell/embed/gtk)

Embedded Web Shell
”Easy way to embed web browser functionality into an application”
Register libraries
Create event queue
Create web shell
...

Embedded Web Shell (cont)
Registering components
Register components that aren’t self registering
NS_SetupRegistry();
Registering selfregistering modules
nsComponentManager::Autoregister(…)
Give path to component directory.

Embedded Web Shell (cont)
Creating an event queue
Obtain the EventQueueService
nsServiceManager::GetService(…);
Creating the thread event queue
aEventQueueService->CreateThreadEventQueue(…);

Embedded Web Shell (cont)
Creating a webshell
Creating the webshell instance
nsComponentManager::CreateInstance(…);
Initializing the webshell
mWebShell->Init(native window, x, y, w, h);
mWebShell->Show();
Loading a URL
mWebShell->LoadURL(L”http://…”);

Frankenbrowser
”Easiest way to extend Mozilla”
Unlimited flexibility
Leverage your knowledge of other frameworks
Minimal knowledge of Mozilla interfaces required

How To Get Sample Code
http://www.doczilla.com
Email authors

Further Discussion
Mozilla Organization newsgroups
Email/call authors

Summary

References
Don Box, Essential COM
Erich Gamma et. al., Design Patterns
www.mozilla.org

Thank you!