Embedding Gecko
Mark Finkle
Why Embed Gecko?
- Quick, robust, and highly standards compliant Web renderer
- Cross platform
- Open-source and royalty-free
How do You Embed Gecko?
- Gecko is part of XULRunner
- Initialization & teardown
- Use the Gecko-provided interfaces
- Implement the required embedder interfaces
Embedding APIs
Problems with Embedding
- Complicated
- Fragile
- Not maintained
- Sparse documentation
- Missing functionality
- Low-level
- Competition
Refactoring Embedding
- Use simple C++ whenever possible
- Create a Gecko isolation layer
- Create framework specific wrappers
- Add functionality
- Minimize the number of "interfaces"
MozApp
class MozApp
{
public:
MozApp(profilePath);
virtual ~MozApp();
nsresult SetCharPref(name, value);
nsresult SetBoolPref(name, value);
nsresult SetIntPref(name, value);
nsresult GetCharPref(name, value);
nsresult GetBoolPref(name, value);
nsresult GetIntPref(name, value);
};
MozView
class MozView
{
public:
MozView();
virtual ~MozView();
nsresult CreateBrowser(nativeWindow, x, y, width, height, chromeFlags);
nsresult SetPositionAndSize(x, y, width, height);
nsresult LoadURI(uri);
nsresult LoadData(baseURL, contentType, data, len);
nsresult Stop();
nsresult Reload();
nsresult GoBack();
nsresult GoForward();
PRBool CanGoBack();
PRBool CanGoForward();
...
};
MozView
class MozView
{
...
nsresult SetFocus(focus);
void Show();
void Hide();
void SetListener(newListener);
MozViewListener* GetListener();
void* GetParentWindow();
void* GetNativeWindow();
void SetParentView(parent);
MozView* GetParentView();
nsresult GetInterfaceRequestor(requestor);
char* EvaluateJavaScript(script);
};
MozViewListener
class MozViewListener
{
public:
MozViewListener();
virtual ~MozViewListener();
void SetMozView(mozView);
virtual void SetTitle(newTitle);
virtual void StatusChanged(newStatus, statusType);
virtual void LocationChanged(newLocation);
virtual PRBool OpenURI(newLocation);
virtual void DocumentLoaded();
virtual MozView* OpenWindow(flags);
virtual void SizeTo(width, height);
virtual void SetVisibility(visible);
virtual void StartModal();
virtual void ExitModal(result);
};
Frameworks Built on the New API
- Win32
- Win32/Qt
- Linux/GTK
- Linux/Qt
- Win32/GTK (contributor)
Roadmap
- Win32/ActiveX component
- Render content to image
- Code snippets section on the MDC
- Access to C++ objects from JS
- Include in nightly SDK builds
- Simplified access to DOM from embedder
- Additional progress events
- Additional platforms support (OS X and Mobile)
Resources
- NewAPI - Details on using the new embedding API
- Gecko embedding basics - Good background document on the core embedding system
- Embedding FAQ - Good answers to common embedding tasks
- #embedding on Mozilla IRC