MozNet Tutorial - Javascript XPCOM Component

Now that we have our component skeleton we can start writing the javascript code that we can call from MozNet. This code will take the screen shot and hand the data back to MozNet where it can be passed on to the calling application.This is probably the point where you're thinking 'Why can't I do this directly in my application or in the MozNet source?'..The answer is that the interface method nsIDOMCanvasRenderingContext2D.drawWindow is not accessible from c#. We need this method to take a snap-shot of the web page and the only way to access it is via Javascript.

Unreachable Interface Methods

Since the only way to get to the nsIDOMCanvasRenderingContext2D.drawWindow method is via javascript we have but one choice and that is to implement it as a XPCOM component. You're probably wondering why script injection wouldn't work here since it's able to return values. The answer is that the injected script would be ran in the context of the page it's injected in. That page doesn't have the right to execute such code hence, it won't work. Our component, on the other hand, has full tust because it's called in the context of our application, MozNet in this case.

Now, lets fill in our skeleton with a little bit of code and even less documentation ;)

That was pretty simple, eh? We're now just a couple steps away from having a working XPCOM component...