A little browser sample

on Friday, November 07, 2008
By popular demand, here is the sample that I used at the ENEI presentation - a browser in 12 lines of code.


Anonymous said...

Nice! Would it be much harder if using System.Windows.Forms?

Unknown said...

It would be different, as winforms doesn't have a gtk main loop which the webkit widget can use. There is an experimental webkit backend for the webbrowser control on winforms which takes care of this little problem, it's on http://anonsvn.mono-project.com/source/trunk/mono-webbrowser

You can see how it's doing it by looking at mono-webkit/EmbedWidget.cs and mono-webkit/WebBrowser.cs (the Load and InitializeWindow are the methods that make it go).

The EmbedWidget class basically wraps a winforms control inside a gtk window, and WebBrowser runs the gtk main loop on a separate thread and creates the EmbedWidget, adding a WebView to it. This allows both winforms and gtk loops to run side by side without interfering with each other.