Lets talk about plugins

Ok, let’s talk about plugins,

Firefox plugins are written using the NPAPI (Gecko Plugin API: http://developer.mozilla.org/en/docs/Gecko_Plugin_API_Reference), Mozilla provides an SDK and API in order to let programmers who want to build plugins build it without needing of the entire mozilla source code tree, you can get it here (http://developer.mozilla.org/en/docs/Gecko_SDK). there are a lot of documentation right there, however most of these docs are incomplete. You can find examples and tests of using the npapi (http://developer.mozilla.org/en/docs/Plugins:_Samples_and_Test_Cases).

If I have to be honest, I couldn’t even compile these examples without errors, I don’t know if I’m a little bit clumsy… Then, what did I do? Well, the npapi is in C++ with O.O. and I want C pure, then I get the SDK and I write my own NPAPI interface, I write a C version of the needed files, based on the Gecko Plugin API Reference.

I wrote two files, “npn_gate.c” and “npp_gate.c”, these files come from the Plugin Side Plugin API, and from the Browser Side Plugin API respectively.

When you have a Plugin you need two things, first your plugin has to provide a minimal set of functions in order to let Firefox talk with him, these functions are defined in the file “npp_gate.c”, and in the other hand your plugin has to define the interface to communicate with netscape functions, in the file “npn_gate.c” there are wrapper function for the Browser Side API, and there is the function that fills the Plugin and Browser Side functions table. These two files include the npapi.h (from the NPAPI SDK) where you can find all the functions that must be implemented.

If your plugin code includes these two files Mozilla will recognise it as a valid plugin.