Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
ns4xPlugin.h File Reference
#include "nsIPlugin.h"
#include "nsIPluginInstancePeer.h"
#include "nsIWindowlessPlugInstPeer.h"
#include "prlink.h"
#include "npupp.h"
#include "nsPluginHostImpl.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ns4xPlugin
 A 5.0 wrapper for a 4.x style plugin. More...
class  NPPStack
class  NPPAutoPusher
class  NPPExceptionAutoHolder

Defines

#define NP_EXPORT
#define NS_4XPLUGIN_CALLBACK(_type, _name)   _type (* _name)

Functions

PR_BEGIN_EXTERN_C NPObject
*NP_EXPORT 
_getwindowobject (NPP npp)
NPObject *NP_EXPORT _getpluginelement (NPP npp)
NPIdentifier NP_EXPORT _getstringidentifier (const NPUTF8 *name)
void NP_EXPORT _getstringidentifiers (const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
bool NP_EXPORT _identifierisstring (NPIdentifier identifiers)
NPIdentifier NP_EXPORT _getintidentifier (int32_t intid)
NPUTF8 *NP_EXPORT _utf8fromidentifier (NPIdentifier identifier)
int32_t NP_EXPORT _intfromidentifier (NPIdentifier identifier)
NPObject *NP_EXPORT _createobject (NPP npp, NPClass *aClass)
NPObject *NP_EXPORT _retainobject (NPObject *npobj)
void NP_EXPORT _releaseobject (NPObject *npobj)
bool NP_EXPORT _invoke (NPP npp, NPObject *npobj, NPIdentifier method, const NPVariant *args, uint32_t argCount, NPVariant *result)
bool NP_EXPORT _invokeDefault (NPP npp, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
bool NP_EXPORT _evaluate (NPP npp, NPObject *npobj, NPString *script, NPVariant *result)
bool NP_EXPORT _getproperty (NPP npp, NPObject *npobj, NPIdentifier property, NPVariant *result)
bool NP_EXPORT _setproperty (NPP npp, NPObject *npobj, NPIdentifier property, const NPVariant *value)
bool NP_EXPORT _removeproperty (NPP npp, NPObject *npobj, NPIdentifier property)
bool NP_EXPORT _hasproperty (NPP npp, NPObject *npobj, NPIdentifier propertyName)
bool NP_EXPORT _hasmethod (NPP npp, NPObject *npobj, NPIdentifier methodName)
void NP_EXPORT _releasevariantvalue (NPVariant *variant)
void NP_EXPORT _setexception (NPObject *npobj, const NPUTF8 *message)
PR_END_EXTERN_C const char * PeekException ()
void PopException ()

Define Documentation

Definition at line 60 of file ns4xPlugin.h.

#define NS_4XPLUGIN_CALLBACK (   _type,
  _name 
)    _type (* _name)

Definition at line 68 of file ns4xPlugin.h.


Function Documentation

NPObject* NP_EXPORT _createobject ( NPP  npp,
NPClass aClass 
)

Definition at line 1646 of file ns4xPlugin.cpp.

{
  if (!npp) {
    NS_ERROR("Null npp passed to _createobject()!");

    return nsnull;
  }

  if (!aClass) {
    NS_ERROR("Null class passed to _createobject()!");

    return nsnull;
  }

  NPPAutoPusher nppPusher(npp);

  NPObject *npobj;

  if (aClass->allocate) {
    npobj = aClass->allocate(npp, aClass);
  } else {
    npobj = (NPObject *)PR_Malloc(sizeof(NPObject));
  }

  if (npobj) {
    npobj->_class = aClass;
    npobj->referenceCount = 1;
  }

  return npobj;
}

Here is the caller graph for this function:

bool NP_EXPORT _evaluate ( NPP  npp,
NPObject npobj,
NPString script,
NPVariant result 
)

Definition at line 1732 of file ns4xPlugin.cpp.

{
  if (!npp)
    return false;

  NPPAutoPusher nppPusher(npp);

  JSContext *cx = GetJSContextFromNPP(npp);
  NS_ENSURE_TRUE(cx, false);

  JSObject *obj =
    nsNPObjWrapper::GetNewOrUsed(npp, cx, npobj);

  if (!obj) {
    return false;
  }

  // Root obj and the rval (below).
  jsval vec[] = { OBJECT_TO_JSVAL(obj), JSVAL_NULL };
  JSAutoTempValueRooter tvr(cx, NS_ARRAY_LENGTH(vec), vec);
  jsval *rval = &vec[1];

  if (result) {
    // Initialize the out param to void
    VOID_TO_NPVARIANT(*result);
  }

  if (!script || !script->utf8length || !script->utf8characters) {
    // Nothing to evaluate.

    return true;
  }

  NS_ConvertUTF8toUTF16 utf16script(script->utf8characters,
                                    script->utf8length);

  nsCOMPtr<nsIScriptContext> scx = GetScriptContextFromJSContext(cx);
  NS_ENSURE_TRUE(scx, false);

  nsIPrincipal *principal = nsnull;
  // XXX: Get the principal from the security stack (TBD)

  nsresult rv = scx->EvaluateStringWithValue(utf16script, obj, principal,
                                             nsnull, 0, nsnull, rval, nsnull);

  return NS_SUCCEEDED(rv) &&
         (!result || JSValToNPVariant(npp, cx, *rval, result));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1601 of file ns4xPlugin.cpp.

{
  return (NPIdentifier)INT_TO_JSVAL(intid);
}

Here is the caller graph for this function:

Definition at line 1519 of file ns4xPlugin.cpp.

{
  nsIDOMElement *elementp = nsnull;
  NPError nperr = _getvalue(npp, NPNVDOMElement, &elementp);

  if (nperr != NPERR_NO_ERROR) {
    return nsnull;
  }

  // Pass ownership of elementp to element
  nsCOMPtr<nsIDOMElement> element;
  element.swap(elementp);

  JSContext *cx = GetJSContextFromNPP(npp);
  NS_ENSURE_TRUE(cx, nsnull);

  nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
  NS_ENSURE_TRUE(xpc, nsnull);

  nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
  xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), element,
                  NS_GET_IID(nsIDOMElement),
                  getter_AddRefs(holder));
  NS_ENSURE_TRUE(holder, nsnull);

  JSObject* obj = nsnull;
  holder->GetJSObject(&obj);
  NS_ENSURE_TRUE(obj, nsnull);

  return nsJSObjWrapper::GetNewOrUsed(npp, cx, obj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool NP_EXPORT _getproperty ( NPP  npp,
NPObject npobj,
NPIdentifier  property,
NPVariant result 
)

Definition at line 1782 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->getProperty)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->getProperty(npobj, property, result);
}

Here is the caller graph for this function:

Definition at line 1566 of file ns4xPlugin.cpp.

{
  nsCOMPtr<nsIThreadJSContextStack> stack =
    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
  if (!stack)
    return NULL;

  JSContext *cx = nsnull;
  stack->GetSafeJSContext(&cx);
  if (!cx)
    return NULL;

  return doGetIdentifier(cx, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NP_EXPORT _getstringidentifiers ( const NPUTF8 **  names,
int32_t  nameCount,
NPIdentifier identifiers 
)

Definition at line 1582 of file ns4xPlugin.cpp.

{
  nsCOMPtr<nsIThreadJSContextStack> stack =
    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
  if (!stack)
    return;

  JSContext *cx = nsnull;
  stack->GetSafeJSContext(&cx);
  if (!cx)
    return;

  for (int32_t i = 0; i < nameCount; ++i) {
    identifiers[i] = doGetIdentifier(cx, names[i]);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1507 of file ns4xPlugin.cpp.

{
  JSContext *cx = GetJSContextFromNPP(npp);
  NS_ENSURE_TRUE(cx, nsnull);

  // Using ::JS_GetGlobalObject(cx) is ok here since the window we
  // want to return here is the outer window, *not* the inner (since
  // we don't know what the plugin will do with it).
  return nsJSObjWrapper::GetNewOrUsed(npp, cx, ::JS_GetGlobalObject(cx));
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool NP_EXPORT _hasmethod ( NPP  npp,
NPObject npobj,
NPIdentifier  methodName 
)

Definition at line 1832 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->hasMethod)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->hasProperty(npobj, methodName);
}

Here is the caller graph for this function:

bool NP_EXPORT _hasproperty ( NPP  npp,
NPObject npobj,
NPIdentifier  propertyName 
)

Definition at line 1820 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->hasProperty)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->hasProperty(npobj, propertyName);
}

Here is the caller graph for this function:

Definition at line 1638 of file ns4xPlugin.cpp.

{
  jsval v = (jsval)identifier;

  return JSVAL_IS_STRING(v);
}

Here is the caller graph for this function:

Definition at line 1626 of file ns4xPlugin.cpp.

{
  jsval v = (jsval)identifier;

  if (!JSVAL_IS_INT(v)) {
    return PR_INT32_MIN;
  }

  return JSVAL_TO_INT(v);
}

Here is the caller graph for this function:

bool NP_EXPORT _invoke ( NPP  npp,
NPObject npobj,
NPIdentifier  method,
const NPVariant args,
uint32_t  argCount,
NPVariant result 
)

Definition at line 1706 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->invoke)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->invoke(npobj, method, args, argCount, result);
}

Here is the caller graph for this function:

bool NP_EXPORT _invokeDefault ( NPP  npp,
NPObject npobj,
const NPVariant args,
uint32_t  argCount,
NPVariant result 
)

Definition at line 1719 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->invokeDefault)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->invokeDefault(npobj, args, argCount, result);
}

Here is the caller graph for this function:

Definition at line 1689 of file ns4xPlugin.cpp.

{
  if (!npobj)
    return;

  int32_t refCnt = PR_AtomicDecrement((PRInt32*)&npobj->referenceCount);

  if (refCnt == 0) {
    if (npobj->_class && npobj->_class->deallocate) {
      npobj->_class->deallocate(npobj);
    } else {
      PR_Free(npobj);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1844 of file ns4xPlugin.cpp.

{
  switch (variant->type) {
  case NPVariantType_Void :
  case NPVariantType_Null :
  case NPVariantType_Bool :
  case NPVariantType_Int32 :
  case NPVariantType_Double :
    break;
  case NPVariantType_String :
    {
      const NPString *s = &NPVARIANT_TO_STRING(*variant);

      if (s->utf8characters)
        PR_Free((void *)s->utf8characters);

      break;
    }
  case NPVariantType_Object:
    {
      NPObject *npobj = NPVARIANT_TO_OBJECT(*variant);

      if (npobj)
        _releaseobject(npobj);

      break;
    }
  default:
    NS_ERROR("Unknown NPVariant type!");
  }

  VOID_TO_NPVARIANT(*variant);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool NP_EXPORT _removeproperty ( NPP  npp,
NPObject npobj,
NPIdentifier  property 
)

Definition at line 1808 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->removeProperty)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->removeProperty(npobj, property);
}

Here is the caller graph for this function:

Definition at line 1679 of file ns4xPlugin.cpp.

{
  if (npobj) {
    PR_AtomicIncrement((PRInt32*)&npobj->referenceCount);
  }

  return npobj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NP_EXPORT _setexception ( NPObject npobj,
const NPUTF8 message 
)

Definition at line 1889 of file ns4xPlugin.cpp.

{
  if (gNPPException) {
    // If a plugin throws multiple exceptions, we'll only report the
    // last one for now.
    free(gNPPException);
  }

  gNPPException = strdup(message);
}

Here is the caller graph for this function:

bool NP_EXPORT _setproperty ( NPP  npp,
NPObject npobj,
NPIdentifier  property,
const NPVariant value 
)

Definition at line 1795 of file ns4xPlugin.cpp.

{
  if (!npp || !npobj || !npobj->_class || !npobj->_class->setProperty)
    return false;

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->setProperty(npobj, property, value);
}

Here is the caller graph for this function:

Definition at line 1607 of file ns4xPlugin.cpp.

{
  if (!identifier)
    return NULL;

  jsval v = (jsval)identifier;

  if (!JSVAL_IS_STRING(v)) {
    return nsnull;
  }

  JSString *str = JSVAL_TO_STRING(v);

  return
    ToNewUTF8String(nsDependentString((PRUnichar *)::JS_GetStringChars(str),
                                      ::JS_GetStringLength(str)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1901 of file ns4xPlugin.cpp.

{
  return gNPPException;
}

Here is the caller graph for this function:

Definition at line 1907 of file ns4xPlugin.cpp.

{
  NS_ASSERTION(!gNPPException, "Uh, no NPP exception to pop!");

  if (gNPPException) {
    free(gNPPException);

    gNPPException = nsnull;
  }
}

Here is the caller graph for this function: