Saphe Implementation - Plugin code

The current Saphe plugin is implemented for Firefox for Windows only (tested on Firefox 1.5 on a Windows XP Professional SP2 machine).

The implementation is based on the aforementioned examples, and the basic files remain unchanged (and their links lead to the mozilla documentation page).

A Mozilla plugin must comply to several requirements, as detailed in the API documentation. Mainly - it must implement several plugin-side functions that can be called by the browser to send and get information. The plugin may call browser-side functions as well (though some of them are not implemented properly by Firefox 1.5…). This enables the browser to communicate with any browser in a generic fashion.

Each plugin is associated with a MIME-type, which is a type of possible data that can be embedded in a web resource. Whenever data of this type is recognized by the browser, a new instance of the plugin is created. The "How plugins work" page provides a good overview of the plugin life-cycle.

The following files were downloaded from the samples given by Mozilla. They provide wrapper code for all the plugin-side and browser-side functions, and also a base class to be inherited from which to implement the actual functionality:

  • npplat.h - various definitions for each of the supported operating-systems (Windows, Unix, Mac)
  • pluginbase.h - a base class for a plugin instance that wraps calls to plugin-side and browser-side functions
  • np_entry.cpp - implementation of several basic functions, and some operating-system dependant code
  • npn_gate.cpp - generic wrapper for plugin-side (NPP) functions
  • npp_gate.cpp - generic wrapper for browser-side (NPN) functions

These are generic files written by Mozilla, and their documentation is therefore synoptical:
In order to implement a plugin based on these files, one should include pluginbase.h and implement a class which publicly inherits from nsPluginInstanceBase. That's it. Now all that's left to do is implement the required plugin-side functions and compile the project (as a DLL, in the Windows case).

A *.def file is used to export functions (all that needs to be changed is the library name).

The *.rc file should be edited to include the relevant MIME-type and other information. Once the DLL is successfully compiled and installed, every time a browser process is started, the plugin is initialized. Each time the browser encounters this MIME-type it automatically creates an instance of the relevant plugin to handle the data.

For Saphe plugin implementation details, see the following files:

Back to implementation documentation page

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License