4.11.2008

Setting the Mozilla Plugin development environment

Before the fight with the Inferno specific issues I must have a right and clean Mozilla Plugin development environment, that is: the structure of source code files and include files from the Mozilla source tree in order to link the code of my plugin to those files.

In order to have a clean environment I decided to use the Gecko SDK 1.8 for linux, download the tar.b2z file and decompress & expand it on a directory of your election, "~/IPMF/gecko-sdk" seems to be ok.

When you will write the Makefile of the plugin you must have in mind to include "gecko-sdk/include" in order to be used for the plugin. You can move the "gecko-sdk/include" folder to another location within your plugin's tree in order to be more clear.

A Mozilla Plugin must implement three types of functions, NPN functions, NPP functions and NP functions.

NPN functions are the functions that the plugin can call from the browser (NPN is NPNetscape), you can find documentation about NPN functions in the Browser-Side Plugin API.
NPP functions are the functions that the browser will call from the plugin (NPP is NPPlugin), and you can find documentation about the NPP functions in the Plugin-Side Plugin API.

Mozilla uses two function tables (NPNetscapeFuncs and NPPluginFuncs) in order to let Netscape to know the pointers to the NPP functions that the plugin implements, and the same thing for the plugin. These two tables must be filled before the plugin instance is created (in the initialization).

So NP functions are the main plugin entry points, these functions are:

- NP_Initialize: fills the NPN and NPP function tables and calls to plugin initialization specific functions.
- NP_Shutdown
-NP_GetMimedDescription: returns MIME Types description before the plugin instance is created (to the about:plugins page for instance).
- NP_GetValue: to get the plugin version, and many other.

In the mozilla source tree there are several locations where you can find plugin examples, for instance, "mozilla/modules/tools/sdk/samples/", I get the entire "common" folder and copied it to the directory of my plugin. The common folder contains three files, np_entry.cpp, npp_gate.cpp and npn_gate.cpp. NPN_gate.cpp contains stubs functions of the NPN functions, the same with NPP for the plugins functions, and NP_entry.cpp contains the main entry points for the plugins, the NP functions.

These stubs calls to specific functions of the plugin's code named NS_function's, i.e., the plugin will implement a function named NS_PluginInitialize or NS_NewPluginInstance but Firefox won't call straight these functions but it will call the NPP_New function (it's in the NPPluginFunctions table), and the stub of NPP_New (in NPP_gate) will finally call NS_New, and you have to write the NS_New function.

To sum up, a right and clean Mozilla Plugin Development Environment will consist in:

- All the include files of mozilla gecko-sdk
- The common folder with the stub files (npp_gate, npn_gate, np_entry)
- The source files of the plugin itself
- A well done Makefile in order to compile the plugin source files (including the gecko-sdk includes)

-IPMF - common - npp_gate.cpp
npn_gate.cpp
np_entry.cpp
include - pluginbase.h
... (gecko-sdk include files)
Makefile
plugin.cpp
plugin.h
...

And then it's time for Inferno issues...