MozNET Tutorial - Javascript XPCOM Component

EDIT: As of R18, the component created in this tutorial is no longer required for taking screen shots with MozNET but, it still has value in that it will show you how to create a Javascript based XPCom component.

This tutorial will walk you through the steps required to create and register a Javascript based XPCom component to be used with MozNet. Instead of building the normal 'Hello World' introductory tutorial I'm going to show you how to build something that can actually be useful. We're going to build a component that will allow us to take a full page screen shot of a given web site. It's not going to have a bunch of bells or whistles but, it'll be enough to get your hands dirty and at the same time build something usable.

A Good Text Editor

First thing first. We need a decent, light-weight, text editor. While Visual Studio is great for working with code files it's a bit overkill for what we're doing here. A good editor to use would be something such as Programmer's Notepad orNodepad++ or something similar. I use Programmer's Notepad, myself. It's free, light-weight, and has quite a few features. Whenever I'm working with IDL files this is my editor of choice. That being said, I'm sure you have you're own preference for text editors so feel free to use your favorite.
Let's get started...

A Component Skeleton

The second thing we need is a base, something to start building our component from. Below you'll find the skeletal block of code that we'll use as a template for building our XPCOM component.Open your favorite text editor and paste the code below into a new, empty, document. Save it as 'ExampleComponent.js'.

Not a whole lot to it, eh?
We'll, that's about as simplified as it can get actually. Now, let's do something with it.I said we were going to build something useful so let's get started. MozNet lacks a good way of grabbing a full page screen shot of a web site because the interface method provided by XulRunner cannot be used from C# (nor c++). Javascript on the other hand, can easily access the interface method we need. We're going to use this tutorial to build a component that will add the missing feature to MozNet.

Next Page