You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



OJI Plugin Requirements

Author: Ed Burns

 

Note: This is a first draft of this document.

This document covers the following topics:

Document Purpose
Implementation Requirements

Shared-Library Functions
OJI and Plugin Interfaces

Sample Implementation Framework

 

Document Purpose

This document specifies the requirements for a Mozilla OJI plugin. It is assumed (1) you know what OJI is; (2) you want to start writing an OJI plugin.

Implementation Requirements

To write an OJI plugin, you must:

Shared Library Functions

An OJI plugin is a Mozilla plugin that also implements the required OJI interfaces. Like all Mozilla plugins, the entry points from Mozilla to your plugin must be in a shared library with a filename starting with np, as in npoji.dll. This shared library must be in the plugins directory, which is currently mozilla/dist/[WIN32*/]bin/plugins. Your OJI shared library should implement and export the following four functions (which are Mozilla's component auto-registration functions):

 

extern "C" nsresult NSGetFactory(nsISupports *pProvider, 
                                 const nsCID &clsid, 
                                 const char *aClassName, 
                                 const char *aProgID, 
                                 nsIFactory **ppFactory);
 

nsISupports *pProvider

This points to the current nsIServiceManager.

  const nsCID %clsid

This is kPluginCID from static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID);

  const char *aClass

This value ends up being null when Mozilla calls NSGetFactory for your OJI plugin.

  const char *progID

This value ends up being null when Mozilla calls NSGetFactory for your OJI plugin.

  nsIFactory **ppFactory

This is where you store the return value, which must be an instance of nsIPlugin.

Note: The above function gets called when LiveConnect is started. It is your opportunity to return an instance of nsIPlugin. You may find it convenient to have this instance also implement nsIJVMPlugin.

 

extern "C" nsresult NSRegisterSelf(nsISupports* serviceMgr, 
                                   const char *path);
  nsISupports *serviceMgr

This points to the current nsIServiceManager.

  const char *path

This is the absolute qualified path to the dll being loaded

Note: The above function is not called by the Mozilla plugin system.

extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* serviceMgr, 
                                               const char *path);
  nsISupports *serviceMgr

This points to the current nsIServiceManager.

  const char *path

This is the absolute qualified path to the dll being loaded.

Note: The above function is not called by the Mozilla plugin system. If this were an XPCOM component that was auto-registering, this function would be called to allow the component to register itself with the serviceManager.

 

extern "C" PRBool NSCanUnload(nsISupports* serviceMgr);
  nsISupports *serviceMgr

This points to the current nsIServiceManager.

Note: The above function is not called by the Mozilla plugin system, but if it were, its purpose would be to determine if it were safe to unload the plugin.

 

OJI and Plugin Interfaces

This section lists all interfaces that an OJI plugin must implement, and it provides links to the header files via LXR. Listed for each interface are the interfaces to which it must respond when called by QueryInterface or AggregatedQueryInterface (this is in addition to the mandatory nsISupports).

 

OJI Interfaces
mozilla\modules\oji\public\nsIJVMConsole.h: nsIJVMConsole
AggregatedQueryInterface: NS_IJVMCONSOLE_IID
mozilla\modules\oji\public\nsIJVMPlugin.h: nsIJVMPlugin
QueryInterface: NS_IJVMPLUGIN_IID, NS_IJVMCONSOLE_IID
mozilla\modules\oji\public\nsIJVMPluginInstance.h: nsIJVMPluginInstance
QueryInterface: NS_IPLUGININSTANCE_IID, NS_IJVMPLUGININSTANCE_IID
mozilla\modules\oji\public\nsIJVMPrefsWindow.h: nsIJVMPrefsWindow
AggregatedQueryInterface: NS_IJVMPREFSWINDOW_IID
mozilla\modules\oji\public\nsISecureEnv.h: nsISecureEnv
AggregatedQueryInterface: NS_ISECUREENV_IID
Plugin Interfaces
mozilla\modules\plugin\public\nsIPlugin.h: nsIPlugin
AggregatedQueryInterface: NS_IPLUGIN_IID
mozilla\modules\plugin\public\nsIPluginInstance.h: nsIPluginInstance
QueryInterface: NS_IPLUGININSTANCE_IID
mozilla\modules\plugin\public\nsIPluginInstancePeer.h: nsIPluginInstancePeer
QueryInterface: NS_IPLUGININSTANCEPEER_IID

PENDING (Ed Burns): Unsure why the plugin needs to implement this.
mozilla\modules\plugin\public\nsIPluginManager.h: nsIPluginManager
QueryInterface: NS_IPLUGINMANAGER_IID

PENDING (Ed Burns): Unsure why the plugin needs to implement this.
mozilla\modules\plugin\public\nsIPluginStreamInfo.h: nsIPluginStreamInfo
QueryInterface: NS_IPLUGINSTREAMINFO_IID
mozilla\modules\plugin\public\nsIPluginStreamListener.h: nsIPluginStreamListener
QueryInterface: NS_IPLUGINSTREAMLISTENER_IID

mozilla\modules\plugin\public\nsIPluginTagInfo.h: nsIPluginTagInfo
QueryInterface: NS_IPLUGINTAGINFO_IID
PENDING (Ed Burns): Unsure why the plugin needs to implement this.

 

Sample Implementation Framework

This section lists sample class definitions and the appropriate Mozilla inheritences for each class. You must implement these interfaces, in addition to the above-mentioned NS* functions, in order to implement a Java Plugin.

 

/**

 * Responsible for creating an instance of the Java Plugin.

 */

class JavaPluginFactory : public nsIJVMPlugin, public nsIPlugin
{
};
	

/**

 * The actual java plugin instance.  

 */

class JavaPlugin : public nsIJVMPluginInstance, public nsIPluginInstance 
{
};
	

/**

 * Instances of this class come from the nsIJVMPlugin instance.  
 * This class provides a secure version of the JNIEnv class from 
 * Sun's JNI.  There is a 1:1 mapping of methods in this class to
 * methods in JNI.

 */

class SecureJNIEnv : public nsISecureEnv
{
};
	

/**

 * Allows Mozilla to pop up or hide a console that displays the console
 * output from the java plugin.

 */

class JavaConsole : public nsIJVMConsole
{
};
	

/**

 * Allows Mozilla to pop up or hide a window that allows the user to
 * control settings of the Java plugin.

 */

class JavaPrefsWindow : public nsIJVMPrefsWindow
{
};
	

/**

 * 
PENDING (Ed Burns): Unsure why the plugin needs to implement this. */ class PluginInstancePeer : public nsIPluginInstancePeer, public nsIPluginTagInfo { };

/**

 * 
PENDING (Ed Burns): Unsure why the plugin needs to implement this. */ class PluginManager : public nsIPluginManager { };

/**

 * Allows Mozilla to gain information about streams for this plugin.
 * 
PENDING (Ed Burns): Unsure why the plugin needs to implement this. */ class PluginStreamInfo : public nsIPluginStreamInfo { };

/**

 * Methods that get called by Mozilla for various stream events.

 */
class PluginStreamListener : public nsIPluginStreamListener 
{
};