Gecko# wraps GtkMozEmbed, which is a C GTK widget, hiding Mozilla’s native C++. Understandably this widget isn’t bloated by wrapping the Mozilla DOM or other internals: it claims to exposes enough functionality for “about 80% of uses”. Essentially this means a basic web browser.
However, to do anything interesting I need to interact with Gecko# from my C# code, and vice versa. There are two obvious ways to approach this:
So, assuming I choose the second for speed and ease of development, how do I go about implementing it? This time, I have four choices:
- Abusing Gecko#
- Mono-XPCOM bridge
- Yes, there is one, and it would be the most elegant solution… unfortunately it’s not nearly complete enough to begin using for a project like this just now, and I’m not familiar enough with XPCOM to fix it up myself. I can see switching to this when it becomes stable enough.
- Web server
- This would cause the editor to effectively become an “AJAX” application. Ouch. A horrible hack, and a horribly-named technology. On the upside, this would be relatively quick and easy.
- C++ wrapper and P/Invoke
- Similar to the Gecko# abuse, but strangely, more elegant, despite the additional dependecies and build steps this method entails. The handle from Gecko# can be passed to a C/C++ wrapper via Platform Invoke. The wrapper function then uses GtkMozEmbed’s “gtk_moz_embed_get_nsIWebBrowser” function to access Gecko’s internals, does interesting thisgs to it with XPCOM, and optionally even returns values.
Well, I initially tried the fourth method, until I realised how much easier the first would be, and cursed XPCOM and the days it had taken from my life.
Fate has twisted sense of humour. Two days into the initial implementation of the editor’s high-level architecture, as I began to flesh out the message passing system, I discovered the fickleness of Gecko#’s streams, and had to revert to XPCOM and P/Invoke.
More on this story later, once I have something working.