NPClass

  • Revision slug: NPClass
  • Revision title: NPClass
  • Revision id: 172651
  • Created:
  • Creator: Kazssym
  • Is current revision? No
  • Comment Add new fields available in Gecko 1.9.

Revision Content

{{wiki.template('Np-plugin-scripting')}}

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 Gecko 1.8, 2 since Gecko 1.9a1, and 3 since Gecko 1.9b1.
allocate
Returns a pointer to a newly allocated NPObject. Called by NPN_CreateObject() if non-NULL, otherwise the browser calls malloc(). This function is expected to allocate and return enough storage to hold the NPObject that is being created.
deallocate
Called by NPN_ReleaseObject() when an object's reference count reaches zero. If this field is NULL, 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 deallocate function, or free(). 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 given NPObject. Returns true if the method exists, otherwise returns false.
invoke
Called by NPN_Invoke() to invoke a specific method on a given NPObject. Returns true if invocation succeeded or false if an error occurred.
invokeDefault
Called by NPN_InvokeDefault() to invoke the default method (if available) on a given NPObject. Returns true if invocation succeeded or false if an error occurred.
hasProperty
Called by NPN_HasProperty() to check whether a given property exists on a given NPObject. Returns true if the specified property exists, otherwise returns false.
getProperty
Called by NPN_GetProperty() to get the value of the specified property on a given NPObject. Returns true if the value was successfully retrieved, otherwise returns false.
setProperty
Called by NPN_SetProperty() to set the value of the specified property on a given NPObject. Returns true if the value was successfully set, otherwise returns false.
removeProperty
Called by NPN_RemoveProperty() to remove a given property from a specified NPObject. Returns true if the property was successfully removed, otherwise returns false.
enumerate
Called by {{template.Funcref("NPN_Enumerate")}}. This field is available only if structVersion is NP_CLASS_STRUCT_VERSION_ENUM (2) or greater.
construct
Called by {{template.Funcref("NPN_Construct")}}. This field is available only if structVersion is NP_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);

See also

Revision Source

<p>
{{wiki.template('Np-plugin-scripting')}}
</p>
<h3 name="Summary">Summary</h3>
<p><code>NPClass</code> is a structure that holds a set of pointers to functions that make up the behavior of an instance of an <code>NPClass</code> (i.e. an <code><a href="en/NPObject">NPObject</a></code>).
</p>
<h3 name="Syntax">Syntax</h3>
<pre>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;
};
</pre>
<div class="warning"><b>Warning:</b> Don't call these routines directly.  You should instead use the appropriate <a href="en/NPObject#Functions">API functions</a>.</div>
<h3 name="Fields">Fields</h3>
<dl><dt><code>structVersion</code>
</dt><dd>The version number of the structure.  This is set to <code>NP_CLASS_STRUCT_VERSION</code>, which is 1 in Gecko 1.8, 2 since Gecko 1.9a1, and 3 since Gecko 1.9b1.
</dd><dt><code>allocate</code>
</dt><dd>Returns a pointer to a newly allocated <code><a href="en/NPObject">NPObject</a></code>. Called by <code><a href="en/NPN_CreateObject">NPN_CreateObject()</a></code> if non-<code>NULL</code>, otherwise the browser calls <code>malloc()</code>. This function is expected to allocate and return enough storage to hold the <code>NPObject</code> that is being created.
</dd><dt><code>deallocate</code>
</dt><dd>Called by <code><a href="en/NPN_ReleaseObject">NPN_ReleaseObject()</a></code> when an object's reference count reaches zero.  If this field is <code>NULL</code>, <code>free()</code> is called isntead.
</dd><dt><code>invalidate</code>
</dt><dd>Called on live objects that belong to a plugin instance that is being destroyed. This call is always followed by a call to the <code>deallocate</code> function, or <code>free()</code>. Any attempt to use an invalidated object will result in undefined behavior.
</dd><dt><code>hasMethod</code>
</dt><dd>Called by <code><a href="en/NPN_HasMethod">NPN_HasMethod()</a></code> to determine whether or not a specified method exists on a given <code>NPObject</code>.  Returns <code>true</code> if the method exists, otherwise returns <code>false</code>.
</dd><dt><code>invoke</code>
</dt><dd>Called by <code><a href="en/NPN_Invoke">NPN_Invoke()</a></code> to invoke a specific method on a given <code>NPObject</code>.  Returns <code>true</code> if invocation succeeded or <code>false</code> if an error occurred.
</dd><dt><code>invokeDefault</code>
</dt><dd>Called by <code><a href="en/NPN_InvokeDefault">NPN_InvokeDefault()</a></code> to invoke the default method (if available) on a given <code>NPObject</code>. Returns <code>true</code> if invocation succeeded or <code>false</code> if an error occurred.
</dd><dt><code>hasProperty</code>
</dt><dd>Called by <code><a href="en/NPN_HasProperty">NPN_HasProperty()</a></code> to check whether a given property exists on a given <code>NPObject</code>.  Returns <code>true</code> if the specified property exists, otherwise returns <code>false</code>.
</dd><dt><code>getProperty</code>
</dt><dd>Called by <code><a href="en/NPN_GetProperty">NPN_GetProperty()</a></code> to get the value of the specified property on a given <code>NPObject</code>.  Returns <code>true</code> if the value was successfully retrieved, otherwise returns <code>false</code>.
</dd><dt><code>setProperty</code>
</dt><dd>Called by <code><a href="en/NPN_SetProperty">NPN_SetProperty()</a></code> to set the value of the specified property on a given <code>NPObject</code>.  Returns <code>true</code> if the value was successfully set, otherwise returns <code>false</code>.
</dd><dt><code>removeProperty</code>
</dt><dd>Called by <code><a href="en/NPN_RemoveProperty">NPN_RemoveProperty()</a></code> to remove a given property from a specified <code>NPObject</code>.  Returns <code>true</code> if the property was successfully removed, otherwise returns <code>false</code>.
</dd><dt><code>enumerate</code>
</dt><dd>Called by {{template.Funcref("NPN_Enumerate")}}.  This field is available only if <code>structVersion</code> is <code>NP_CLASS_STRUCT_VERSION_ENUM</code> (2) or greater.
</dd><dt><code>construct</code>
</dt><dd>Called by {{template.Funcref("NPN_Construct")}}.  This field is available only if <code>structVersion</code> is <code>NP_CLASS_STRUCT_VERSION_CTOR</code> (3) or greater.
</dd></dl>
<h3 name="Function_pointer_syntax">Function pointer syntax</h3>
<pre>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);
</pre>
<h3 name="See_also">See also</h3>
<ul><li> <code><a href="en/NPObject">NPObject</a></code>
</li></ul>
Revert to this revision