It's been a while since I've blogged about the status of Mono's MWF WebControl - I kept adding stuff, then I wanted to settle it down on the tree, and then I went on vacation and ran out of net (but not out of fish.. yum!). So now that I'm fed up with fish and my net is back, let's talk about the latest webcontrol milestone.
The code is split up into three components: the WebBrowser and related classes inside MWF (Mono's winforms implementation); Mono.Mozilla, a new class library on the tree that gets called from MWF; and xulbrowser, a c/c++ library that actually does all the talking to mozilla.
Since a picture is worth a thousand words, the image on the right gives an overview of how these components relate to one another. I didn't want to clutter it too much with arrows, so I didn't put arrows upwards, but of course the communication goes both ways.
Mono.Mozilla is essentially a managed wrapper that exposes an interface to MWF so that the WebBrowser* classes can call methods like Navigate, and register for events coming from mozilla. This interface is the only publicly accessible way to talk to the browser windows, so that things are nice and neat and the wrapper can be free to hide those little pesky details that WebBrowser and friends don't really care about.
Although Mono.Mozilla is, well, Mozilla-oriented, it is neatly divided into two namespaces: Mono.WebBrowser, where the public interface resides, and Mono.Mozilla, where the pinvokes to the unmanaged library reside, so you'll never see the Mono.Mozilla namespace called from inside MWF directly. This has the nice side effect of making it easier (or at least doable) to plug in another browser toolkit in the future if need be.
So what's done and working right now on WebControl? Well, the easiest way to implement an API is to have test applications, so I plucked up the UsingTheWebControl sample from msdn and added it to our roster of winforms test apps. From it's description:
This sample contains three tabs. The first tab demonstrates the use of the WebBrowser control in a simple browser application.
The second tab uses the WebBrowser control as a local HTML document viewer.
The third tab demonstrates the use of the WebBrowser.Document HTMLDocument model, together with the WebBrowser.ObjectForScripting prorperty, to implement Form-to-Browser two-way communication. In this scenario, the WebBrowser control is used to load an HTML document template that is populated with data managed by the Form, as a means of supporting custom printing of application data.
The WebBrowser control on Mono is complete enough for the sample to work with the first two tabs, i.e., loading, refreshing, navigation are all there, as well as focus, activation, mouse and key events so that you can actually browse the web (as opposed to, say, just looking at it... which is a fine thing to do in itself, sure, but probably not that useful in the long run). Https support is already in as well.
This sample is particularly nice in that it hits a lot of not-so-used areas, such as manipulating the Document to load custom data. This, btw, is done on the third tab, which isn't working yet.
The sample is available from the /winforms/webbrowser/UsingWebBrowser directory on svn trunk. To get it working, you will need to use the latest mono on svn.
You will also need to get the /mozembed directory from svn, which contains the xulbrowser library. Just build mono, do the usual autogen.sh, make, make install on /mozembed, make the UsingWebBrowser-port directory, and then go to bin and run the application there.