Summary
NPClass is a structure that holds a set of pointers to functions that make up the behavior of an instance of an NPClass (i.e. an NPObject).
Syntax
struct NPClass
{
uint32_t structVersion;
NPAllocateFunctionPtr allocate;
NPDeallocateFunctionPtr deallocate;
NPInvalidateFunctionPtr invalidate;
NPHasMethodFunctionPtr hasMethod;
NPInvokeFunctionPtr invoke;
NPInvokeDefaultFunctionPtr invokeDefault;
NPHasPropertyFunctionPtr hasProperty;
NPGetPropertyFunctionPtr getProperty;
NPSetPropertyFunctionPtr setProperty;
NPRemovePropertyFunctionPtr removeProperty;
NPEnumerationFunctionPtr enumerate;
NPConstructFunctionPtr construct;
};
Warning: Don't call these routines directly. You should instead use the appropriate API functions.
Fields
structVersion- The version number of the structure. This is set to
NP_CLASS_STRUCT_VERSION, which is 1 in Mozilla 1.8.*, 2 since Mozilla 1.9a1, and 3 since Firefox 3.0b1. allocate- Returns a pointer to a newly allocated
NPObject. Called byNPN_CreateObject()if non-NULL, otherwise the browser callsmalloc(). This function is expected to allocate and return enough storage to hold theNPObjectthat is being created. deallocate- Called by
NPN_ReleaseObject()when an object's reference count reaches zero. If this field isNULL,free()is called isntead. invalidate- Called on live objects that belong to a plugin instance that is being destroyed. This call is always followed by a call to the
deallocatefunction, orfree(). Any attempt to use an invalidated object will result in undefined behavior. hasMethod- Called by
NPN_HasMethod()to determine whether or not a specified method exists on a givenNPObject. Returnstrueif the method exists, otherwise returnsfalse. invoke- Called by
NPN_Invoke()to invoke a specific method on a givenNPObject. Returnstrueif invocation succeeded orfalseif an error occurred. invokeDefault- Called by
NPN_InvokeDefault()to invoke the default method (if available) on a givenNPObject. Returnstrueif invocation succeeded orfalseif an error occurred. hasProperty- Called by
NPN_HasProperty()to check whether a given property exists on a givenNPObject. Returnstrueif the specified property exists, otherwise returnsfalse. getProperty- Called by
NPN_GetProperty()to get the value of the specified property on a givenNPObject. Returnstrueif the value was successfully retrieved, otherwise returnsfalse. setProperty- Called by
NPN_SetProperty()to set the value of the specified property on a givenNPObject. Returnstrueif the value was successfully set, otherwise returnsfalse. removeProperty- Called by
NPN_RemoveProperty()to remove a given property from a specifiedNPObject. Returnstrueif the property was successfully removed, otherwise returnsfalse. enumerate- Called by
NPN_Enumerate. This field is available only ifstructVersionisNP_CLASS_STRUCT_VERSION_ENUM(2) or greater. construct- Called by
NPN_Construct. This field is available only ifstructVersionisNP_CLASS_STRUCT_VERSION_CTOR(3) or greater.
Function pointer syntax
typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass);
typedef void (*NPDeallocateFunctionPtr)(NPObject *npobj);
typedef void (*NPInvalidateFunctionPtr)(NPObject *npobj);
typedef bool (*NPHasMethodFunctionPtr)(NPObject *npobj, NPIdentifier name);
typedef bool (*NPInvokeFunctionPtr)(NPObject *npobj, NPIdentifier name,
const NPVariant *args, uint32_t argCount,
NPVariant *result);
typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj,
const NPVariant *args,
uint32_t argCount,
NPVariant *result);
typedef bool (*NPHasPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
typedef bool (*NPGetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name,
NPVariant *result);
typedef bool (*NPSetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name,
const NPVariant *value);
typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj,
NPIdentifier name);
typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value,
uint32_t *count);
typedef bool (*NPConstructFunctionPtr)(NPObject *npobj,
const NPVariant *args,
uint32_t argCount,
NPVariant *result);