MozNet Tutorial - Javascript XPCOM Component

Making It All Accessible

Now that we've done all the javascript and command line work it's time to define the interface that we created - remember our IDL file? We have to redefine our interface in a code file. If you're using the MozNet source code you can define the interface definition in 'interfaces.cs' where most of the other interfaces are defined. If you don't have the MozNet source code you'll have to find a suitable place in your application in which to define the interface.

Once you've chosen a spot to put your interface definition you have to do the hard part of translating it to c# compatible data types. In the case of our example component the translation is pretty simple and direct. In your own components you'll likely run into scenarios that require a bit of thought but, you're a good programmer and can figure it out when the time comes.

For the time being, I'll provide you with a proper definition just to make sure you know what's going on and can't come back saying that it doesn't work ;)

Putting It To Use

Now that we've got everything in place there's just one more thing left to do.. We need to write a method that accesses our interface method and returns a System.Drawing.Image object from the XPCom component. Just for the sake of completeness, I'll provide a working method that you can employ in your own application.

Now we have a working XPCom component. The first time we run our application it will be registered with XulRunner and we'll be able to use it immediately. With the above method we can easily retrieve a full page screen shot of a browser just by passing a GeckoWebBrowser control instance to the method. The javascript component does all the work, passing back a base64 encoded png image which we then convert to a System.Drawing.Image object that we can use in other parts of our application.

This concludes the tutorial. Hopefully you've learned something useful and will continue to build and even share your custom components with other MozNET users. If there's enough interest in the subject, Se7en Soft will create and host a gallery where you can share your custom components with others.

Last Page