Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Enumerations | Functions | Variables
ns4xPlugin.cpp File Reference
#include "prtypes.h"
#include "prmem.h"
#include "ns4xPlugin.h"
#include "ns4xPluginInstance.h"
#include "ns4xPluginStreamListener.h"
#include "nsIServiceManager.h"
#include "nsIMemory.h"
#include "nsIPluginStreamListener.h"
#include "nsPluginsDir.h"
#include "nsPluginSafety.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsPluginLogging.h"
#include "nsIPluginInstancePeer2.h"
#include "nsIJSContextStack.h"
#include "nsPIPluginInstancePeer.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMWindow.h"
#include "nsIDocument.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "jscntxt.h"
#include "nsIXPConnect.h"
#include "nsJSNPRuntime.h"

Go to the source code of this file.

Classes

class  ns4xStreamWrapper

Defines

#define TV2FP(f)   (f)
#define FP2TV(f)   (f)

Enumerations

enum  eNPPStreamTypeInternal { eNPPStreamTypeInternal_Get, eNPPStreamTypeInternal_Post }

Functions

static NS_DEFINE_IID (kCPluginManagerCID, NS_PLUGINMANAGER_CID)
static NS_DEFINE_IID (kPluginManagerCID, NS_PLUGINMANAGER_CID)
static NS_DEFINE_IID (kMemoryCID, NS_MEMORY_CID)
static PR_BEGIN_EXTERN_C
NPError NP_EXPORT 
_requestread (NPStream *pstream, NPByteRange *rangeList)
static NPError NP_EXPORT _geturlnotify (NPP npp, const char *relativeURL, const char *target, void *notifyData)
static NPError NP_EXPORT _getvalue (NPP npp, NPNVariable variable, void *r_value)
static NPError NP_EXPORT _setvalue (NPP npp, NPPVariable variable, void *r_value)
static NPError NP_EXPORT _geturl (NPP npp, const char *relativeURL, const char *target)
static NPError NP_EXPORT _posturlnotify (NPP npp, const char *relativeURL, const char *target, uint32 len, const char *buf, NPBool file, void *notifyData)
static NPError NP_EXPORT _posturl (NPP npp, const char *relativeURL, const char *target, uint32 len, const char *buf, NPBool file)
static NPError NP_EXPORT _newstream (NPP npp, NPMIMEType type, const char *window, NPStream **pstream)
static int32 NP_EXPORT _write (NPP npp, NPStream *pstream, int32 len, void *buffer)
static NPError NP_EXPORT _destroystream (NPP npp, NPStream *pstream, NPError reason)
static void NP_EXPORT _status (NPP npp, const char *message)
static void NP_EXPORT _memfree (void *ptr)
static uint32 NP_EXPORT _memflush (uint32 size)
static void NP_EXPORT _reloadplugins (NPBool reloadPages)
static void NP_EXPORT _invalidaterect (NPP npp, NPRect *invalidRect)
static void NP_EXPORT _invalidateregion (NPP npp, NPRegion invalidRegion)
static void NP_EXPORT _forceredraw (NPP npp)
static void NP_EXPORT _pushpopupsenabledstate (NPP npp, NPBool enabled)
static void NP_EXPORT _poppopupsenabledstate (NPP npp)
static const char *NP_EXPORT _useragent (NPP npp)
static void *NP_EXPORT _memalloc (uint32 size)
NPError MakeNew4xStreamInternal (NPP npp, const char *relativeURL, const char *target, eNPPStreamTypeInternal type, PRBool bDoNotify=PR_FALSE, void *notifyData=nsnull, uint32 len=0, const char *buf=nsnull, NPBool file=PR_FALSE)
static JSContextGetJSContextFromNPP (NPP npp)
NPObject *NP_EXPORT _getwindowobject (NPP npp)
NPObject *NP_EXPORT _getpluginelement (NPP npp)
static NPIdentifier doGetIdentifier (JSContext *cx, const NPUTF8 *name)
NPIdentifier NP_EXPORT _getstringidentifier (const NPUTF8 *name)
void NP_EXPORT _getstringidentifiers (const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
NPIdentifier NP_EXPORT _getintidentifier (int32_t intid)
NPUTF8 *NP_EXPORT _utf8fromidentifier (NPIdentifier identifier)
int32_t NP_EXPORT _intfromidentifier (NPIdentifier identifier)
bool NP_EXPORT _identifierisstring (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)
bool NP_EXPORT _tostring (NPObject *npobj, NPVariant *result)
void NP_EXPORT _setexception (NPObject *npobj, const NPUTF8 *message)
const char * PeekException ()
void PopException ()

Variables

static char * gNPPException

Define Documentation

#define FP2TV (   f)    (f)

Definition at line 264 of file ns4xPlugin.cpp.

#define TV2FP (   f)    (f)

Definition at line 263 of file ns4xPlugin.cpp.


Enumeration Type Documentation

Enumerator:
eNPPStreamTypeInternal_Get 
eNPPStreamTypeInternal_Post 

Definition at line 90 of file ns4xPlugin.cpp.


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:

NPError NP_EXPORT _destroystream ( NPP  npp,
NPStream pstream,
NPError  reason 
) [static]

Definition at line 1306 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_DestroyStream: npp=%p, url=%s, reason=%d\n", (void*)npp,
                  pstream->url, (int)reason));

  if (!npp)
    return NPERR_INVALID_INSTANCE_ERROR;

  nsCOMPtr<nsIPluginStreamListener> listener =
    do_QueryInterface((nsISupports *)pstream->ndata);

  // DestroyStream can kill two kinds of streams: NPP derived and NPN derived.
  // check to see if they're trying to kill a NPP stream
  if (listener) {
    // Tell the stream listner that the stream is now gone.
    listener->OnStopBinding(nsnull, NS_BINDING_ABORTED);

    // FIXME: http://bugzilla.mozilla.org/show_bug.cgi?id=240131
    //
    // Is it ok to leave pstream->ndata set here, and who releases it
    // (or is it even properly ref counted)? And who closes the stream
    // etc?
  } else {
    ns4xStreamWrapper* wrapper = (ns4xStreamWrapper *)pstream->ndata;
    NS_ASSERTION(wrapper != NULL, "null wrapper");

    if (wrapper == NULL)
      return NPERR_INVALID_PARAM;

    // This will release the wrapped nsIOutputStream.
    delete wrapper;
    pstream->ndata = nsnull;
  }

  return NPERR_NO_ERROR;
}

Here is the call graph for this function:

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:

void NP_EXPORT _forceredraw ( NPP  npp) [static]

Definition at line 1456 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_ForceDraw: npp=%p\n", (void*)npp));

  if (!npp || !npp->ndata) {
    NS_WARNING("_forceredraw: npp or npp->ndata == 0");
    return;
  }

  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;

  nsCOMPtr<nsIPluginInstancePeer> peer;
  if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) && peer) {
    nsCOMPtr<nsIWindowlessPluginInstancePeer> wpeer(do_QueryInterface(peer));
    if (wpeer) {
      wpeer->ForceRedraw();
    }
  }
}

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:

NPError NP_EXPORT _geturl ( NPP  npp,
const char *  relativeURL,
const char *  target 
) [static]

Definition at line 1117 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
  ("NPN_GetURL: npp=%p, target=%s, url=%s\n", (void *)npp, target,
   relativeURL));

  // Block Adobe Acrobat from loading URLs that are not http:, https:,
  // or ftp: URLs if the given target is null.
  if (target == nsnull && relativeURL &&
      (strncmp(relativeURL, "http:", 5) != 0) &&
      (strncmp(relativeURL, "https:", 6) != 0) &&
      (strncmp(relativeURL, "ftp:", 4) != 0)) {
    ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;

    const char *name = nsPluginHostImpl::GetPluginName(inst);

    if (name && strstr(name, "Adobe") && strstr(name, "Acrobat")) {
      return NPERR_NO_ERROR;
    }
  }

  return MakeNew4xStreamInternal (npp, relativeURL, target,
                                  eNPPStreamTypeInternal_Get);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NPError NP_EXPORT _geturlnotify ( NPP  npp,
const char *  relativeURL,
const char *  target,
void notifyData 
) [static]

Definition at line 1145 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
    ("NPN_GetURLNotify: npp=%p, target=%s, notify=%p, url=%s\n", (void*)npp,
     target, notifyData, relativeURL));

  return MakeNew4xStreamInternal (npp, relativeURL, target,
                                  eNPPStreamTypeInternal_Get, PR_TRUE,
                                  notifyData);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NPError NP_EXPORT _getvalue ( NPP  npp,
NPNVariable  variable,
void r_value 
) [static]

Definition at line 1933 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_GetValue: npp=%p, var=%d\n",
                                     (void*)npp, (int)variable));

  nsresult res;

  switch(variable) {
#if defined(XP_UNIX) && !defined(XP_MACOSX)
  case NPNVxDisplay : {
#ifdef MOZ_WIDGET_GTK2
    if (npp) {
      ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;
      NPBool rtv = PR_FALSE;
      inst->GetValue((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &rtv);
      if (rtv) {
        (*(Display **)result) = GDK_DISPLAY();
        return NPERR_NO_ERROR;
      }
    }
#endif
#if defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_GTK2)
    // adobe nppdf calls XtGetApplicationNameAndClass(display,
    // &instance, &class) we have to init Xt toolkit before get
    // XtDisplay just call gtk_xtbin_new(w,0) once
    static GtkWidget *gtkXtBinHolder = 0;
    if (!gtkXtBinHolder) {
      gtkXtBinHolder = gtk_xtbin_new(GDK_ROOT_PARENT(),0);
      // it crashes on destroy, let it leak
      // gtk_widget_destroy(gtkXtBinHolder);
    }
    (*(Display **)result) =  GTK_XTBIN(gtkXtBinHolder)->xtdisplay;
    return NPERR_NO_ERROR;
#endif
    return NPERR_GENERIC_ERROR;
  }

  case NPNVxtAppContext:
    return NPERR_GENERIC_ERROR;
#endif

#if defined(XP_WIN) || defined(XP_OS2)
  case NPNVnetscapeWindow: {
    if (!npp || !npp->ndata)
      return NPERR_INVALID_INSTANCE_ERROR;

    ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;

    nsCOMPtr<nsIPluginInstancePeer> peer;
    if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) &&
        peer &&
        NS_SUCCEEDED(peer->GetValue(nsPluginInstancePeerVariable_NetscapeWindow,
                                    result))) {
      return NPERR_NO_ERROR;
    }
    return NPERR_GENERIC_ERROR;
  }
#endif

  case NPNVjavascriptEnabledBool: {
    *(NPBool*)result = PR_FALSE;
    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
    if (prefs) {
      PRBool js = PR_FALSE;;
      res = prefs->GetBoolPref("javascript.enabled", &js);
      if (NS_SUCCEEDED(res))
        *(NPBool*)result = js;
    }
    return NPERR_NO_ERROR;
  }

  case NPNVasdEnabledBool:
    *(NPBool*)result = FALSE;
    return NPERR_NO_ERROR;

  case NPNVisOfflineBool: {
    PRBool offline = PR_FALSE;
    nsCOMPtr<nsIIOService> ioservice =
      do_GetService(NS_IOSERVICE_CONTRACTID, &res);
    if (NS_SUCCEEDED(res))
      res = ioservice->GetOffline(&offline);
    if (NS_FAILED(res))
      return NPERR_GENERIC_ERROR;

    *(NPBool*)result = offline;
    return NPERR_NO_ERROR;
  }

  case NPNVserviceManager: {
    nsIServiceManager * sm;
    res = NS_GetServiceManager(&sm);
    if (NS_SUCCEEDED(res)) {
      *(nsIServiceManager**)result = sm;
      return NPERR_NO_ERROR;
    } else
      return NPERR_GENERIC_ERROR;
  }

  case NPNVDOMElement: {
    ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;
    NS_ENSURE_TRUE(inst, NPERR_GENERIC_ERROR);

    nsCOMPtr<nsIPluginInstancePeer> pip;
    inst->GetPeer(getter_AddRefs(pip));
    nsCOMPtr<nsIPluginTagInfo2> pti2 (do_QueryInterface(pip));
    if (pti2) {
      nsCOMPtr<nsIDOMElement> e;
      pti2->GetDOMElement(getter_AddRefs(e));
      if (e) {
        NS_ADDREF(*(nsIDOMElement**)result = e.get());
        return NPERR_NO_ERROR;
      }
    }
    return NPERR_GENERIC_ERROR;
  }

  case NPNVDOMWindow: {
    ns4xPluginInstance *inst = (ns4xPluginInstance *)npp->ndata;
    NS_ENSURE_TRUE(inst, NPERR_GENERIC_ERROR);

    nsIDOMWindow *domWindow = inst->GetDOMWindow().get();

    if (domWindow) {
      // Pass over ownership of domWindow to the caller.
      (*(nsIDOMWindow**)result) = domWindow;

      return NPERR_NO_ERROR;
    }
    return NPERR_GENERIC_ERROR;
  }

  case NPNVToolkit: {
#ifdef MOZ_WIDGET_GTK
    *((NPNToolkitType*)result) = NPNVGtk12;
#endif

#ifdef MOZ_WIDGET_GTK2
    *((NPNToolkitType*)result) = NPNVGtk2;
#endif

    if (result)
        return NPERR_NO_ERROR;

    return NPERR_GENERIC_ERROR;
  }

  case NPNVSupportsXEmbedBool: {
#ifdef MOZ_WIDGET_GTK2
    *(NPBool*)result = PR_TRUE;
#else
    *(NPBool*)result = PR_FALSE;
#endif
    return NPERR_NO_ERROR;
  }

  case NPNVWindowNPObject: {
    *(NPObject **)result = _getwindowobject(npp);

    return NPERR_NO_ERROR;
  }

  case NPNVPluginElementNPObject: {
    *(NPObject **)result = _getpluginelement(npp);

    return NPERR_NO_ERROR;
  }

  default : return NPERR_GENERIC_ERROR;
  }
}

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:

void NP_EXPORT _invalidaterect ( NPP  npp,
NPRect invalidRect 
) [static]

Definition at line 1403 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_InvalidateRect: npp=%p, top=%d, left=%d, bottom=%d, "
                  "right=%d\n", (void *)npp, invalidRect->top,
                  invalidRect->left, invalidRect->bottom, invalidRect->right));

  if (!npp || !npp->ndata) {
    NS_WARNING("_invalidaterect: npp or npp->ndata == 0");
    return;
  }

  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;

  nsCOMPtr<nsIPluginInstancePeer> peer;
  if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) && peer) {
    nsCOMPtr<nsIWindowlessPluginInstancePeer> wpeer(do_QueryInterface(peer));
    if (wpeer) {
      // XXX nsRect & NPRect are structurally equivalent
      wpeer->InvalidateRect((nsPluginRect *)invalidRect);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NP_EXPORT _invalidateregion ( NPP  npp,
NPRegion  invalidRegion 
) [static]

Definition at line 1430 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_InvalidateRegion: npp=%p, region=%p\n", (void*)npp,
                  (void*)invalidRegion));

  if (!npp || !npp->ndata) {
    NS_WARNING("_invalidateregion: npp or npp->ndata == 0");
    return;
  }

  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;

  nsCOMPtr<nsIPluginInstancePeer> peer;
  if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) && peer) {
    nsCOMPtr<nsIWindowlessPluginInstancePeer> wpeer(do_QueryInterface(peer));
    if (wpeer) {
      // XXX nsRegion & NPRegion are typedef'd to the same thing
      wpeer->InvalidateRegion((nsPluginRegion)invalidRegion);
    }
  }
}

Here is the call graph for this function:

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:

void *NP_EXPORT _memalloc ( uint32  size) [static]

Definition at line 2242 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPN_MemAlloc: size=%d\n", size));
  return nsMemory::Alloc(size);
}

Here is the call graph for this function:

Here is the caller graph for this function:

uint32 NP_EXPORT _memflush ( uint32  size) [static]

Definition at line 1379 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPN_MemFlush: size=%d\n", size));

  nsMemory::HeapMinimize(PR_TRUE);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NP_EXPORT _memfree ( void ptr) [static]

Definition at line 1368 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NOISY, ("NPN_MemFree: ptr=%p\n", ptr));

  if (ptr)
    nsMemory::Free(ptr);
}

Here is the caller graph for this function:

NPError NP_EXPORT _newstream ( NPP  npp,
NPMIMEType  type,
const char *  window,
NPStream **  pstream 
) [static]

Definition at line 1242 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
  ("NPN_NewStream: npp=%p, type=%s, target=%s\n", (void*)npp,
   (const char *)type, target));

  NPError err = NPERR_INVALID_INSTANCE_ERROR;
  if (npp && npp->ndata) {
    nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;
    nsCOMPtr<nsIOutputStream> stream;
    nsCOMPtr<nsIPluginInstancePeer> peer;
    if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) &&
      peer &&
      NS_SUCCEEDED(peer->NewStream((const char*) type, target,
                                   getter_AddRefs(stream)))) {
      ns4xStreamWrapper* wrapper = new ns4xStreamWrapper(stream);
      if (wrapper) {
        (*result) = wrapper->GetNPStream();
        err = NPERR_NO_ERROR;
      } else {
        err = NPERR_OUT_OF_MEMORY_ERROR;
      }
    } else {
      err = NPERR_GENERIC_ERROR;
    }
  }
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2270 of file ns4xPlugin.cpp.

{
  ns4xPluginInstance *inst = (ns4xPluginInstance *)npp->ndata;
  if (!inst)
    return;

  inst->PopPopupsEnabledState();
}

Here is the call graph for this function:

Here is the caller graph for this function:

NPError NP_EXPORT _posturl ( NPP  npp,
const char *  relativeURL,
const char *  target,
uint32  len,
const char *  buf,
NPBool  file 
) [static]

Definition at line 1177 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_PostURL: npp=%p, target=%s, file=%d, len=%d, url=%s, "
                  "buf=%s\n",
                  (void*)npp, target, file, len, relativeURL, buf));

 return MakeNew4xStreamInternal(npp, relativeURL, target,
                                eNPPStreamTypeInternal_Post, PR_FALSE, nsnull,
                                len, buf, file);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NPError NP_EXPORT _posturlnotify ( NPP  npp,
const char *  relativeURL,
const char *  target,
uint32  len,
const char *  buf,
NPBool  file,
void notifyData 
) [static]

Definition at line 1160 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_PostURLNotify: npp=%p, target=%s, len=%d, file=%d, "
                  "notify=%p, url=%s, buf=%s\n",
                  (void*)npp, target, len, file, notifyData, relativeURL,
                  buf));

  return MakeNew4xStreamInternal(npp, relativeURL, target,
                                 eNPPStreamTypeInternal_Post, PR_TRUE,
                                 notifyData, len, buf, file);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NP_EXPORT _pushpopupsenabledstate ( NPP  npp,
NPBool  enabled 
) [static]

Definition at line 2260 of file ns4xPlugin.cpp.

{
  ns4xPluginInstance *inst = (ns4xPluginInstance *)npp->ndata;
  if (!inst)
    return;

  inst->PushPopupsEnabledState(enabled);
}

Here is the call graph for this function:

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:

void NP_EXPORT _reloadplugins ( NPBool  reloadPages) [static]

Definition at line 1390 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_ReloadPlugins: reloadPages=%d\n", reloadPages));

  nsCOMPtr<nsIPluginManager> pm(do_GetService(kPluginManagerCID));

  pm->ReloadPlugins(reloadPages);
}

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:

NPError NP_EXPORT _requestread ( NPStream pstream,
NPByteRange rangeList 
) [static]

Definition at line 2181 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_RequestRead: stream=%p\n",
                                     (void*)pstream));

#ifdef PLUGIN_LOGGING
  for(NPByteRange * range = rangeList; range != nsnull; range = range->next)
    PR_LOG(nsPluginLogging::gNPNLog,PLUGIN_LOG_NOISY,
    ("%i-%i", range->offset, range->offset + range->length - 1));

  PR_LOG(nsPluginLogging::gNPNLog,PLUGIN_LOG_NOISY, ("\n\n"));
  PR_LogFlush();
#endif

  if (!pstream || !rangeList || !pstream->ndata)
    return NPERR_INVALID_PARAM;

  ns4xPluginStreamListener * streamlistener =
    (ns4xPluginStreamListener *)pstream->ndata;

  nsPluginStreamType streamtype = nsPluginStreamType_Normal;

  streamlistener->GetStreamType(&streamtype);

  if (streamtype != nsPluginStreamType_Seek)
    return NPERR_STREAM_NOT_SEEKABLE;

  if (streamlistener->mStreamInfo)
    streamlistener->mStreamInfo->RequestRead((nsByteRange *)rangeList);

  return NS_OK;
}

Here is the call graph for this function:

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:

NPError NP_EXPORT _setvalue ( NPP  npp,
NPPVariable  variable,
void r_value 
) [static]

Definition at line 2107 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_SetValue: npp=%p, var=%d\n",
                                     (void*)npp, (int)variable));

  if (!npp)
    return NPERR_INVALID_INSTANCE_ERROR;

  ns4xPluginInstance *inst = (ns4xPluginInstance *) npp->ndata;

  NS_ASSERTION(inst != NULL, "null instance");

  if (inst == NULL)
    return NPERR_INVALID_INSTANCE_ERROR;

  switch (variable) {

    // we should keep backward compatibility with 4x where the
    // actual pointer value is checked rather than its content
    // wnen passing booleans
    case NPPVpluginWindowBool: {
      NPBool bWindowless = (result == nsnull);
      return inst->SetWindowless(bWindowless);
    }

    case NPPVpluginTransparentBool: {
      NPBool bTransparent = (result != nsnull);
      return inst->SetTransparent(bTransparent);
    }

    case NPPVjavascriptPushCallerBool:
      {
        nsresult rv;
        nsCOMPtr<nsIJSContextStack> contextStack =
          do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
        if (NS_SUCCEEDED(rv)) {
          NPBool bPushCaller = (result != nsnull);

          if (bPushCaller) {
            rv = NS_ERROR_FAILURE;

            nsCOMPtr<nsIPluginInstancePeer> peer;
            if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) && peer) {
              nsCOMPtr<nsIPluginInstancePeer2> peer2 =
                do_QueryInterface(peer);

              if (peer2) {
                JSContext *cx;
                rv = peer2->GetJSContext(&cx);

                if (NS_SUCCEEDED(rv))
                  rv = contextStack->Push(cx);
              }
            }
          } else {
            rv = contextStack->Pop(nsnull);
          }
        }
        return NS_SUCCEEDED(rv) ? NPERR_NO_ERROR : NPERR_GENERIC_ERROR;
      }
      break;

    case NPPVpluginKeepLibraryInMemory: {
      NPBool bCached = (result != nsnull);
      return inst->SetCached(bCached);
    }

    default:
      return NPERR_NO_ERROR;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NP_EXPORT _status ( NPP  npp,
const char *  message 
) [static]

Definition at line 1347 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_Status: npp=%p, message=%s\n",
                                     (void*)npp, message));

  if (!npp || !npp->ndata) {
    NS_WARNING("_status: npp or npp->ndata == 0");
    return;
  }

  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;

  nsCOMPtr<nsIPluginInstancePeer> peer;
  if (NS_SUCCEEDED(inst->GetPeer(getter_AddRefs(peer))) && peer) {
    peer->ShowStatus(message);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool NP_EXPORT _tostring ( NPObject npobj,
NPVariant result 
)

Definition at line 1879 of file ns4xPlugin.cpp.

{
  NS_ERROR("Write me!");

  return PR_FALSE;
}
const char *NP_EXPORT _useragent ( NPP  npp) [static]

Definition at line 2226 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("NPN_UserAgent: npp=%p\n", (void*)npp));

  char *retstr;

  nsCOMPtr<nsIPluginManager> pm(do_GetService(kPluginManagerCID));

  pm->UserAgent((const char **)&retstr);

  return retstr;
}

Here is the call graph for this function:

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:

int32 NP_EXPORT _write ( NPP  npp,
NPStream pstream,
int32  len,
void buffer 
) [static]

Definition at line 1274 of file ns4xPlugin.cpp.

{
  NPN_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
                 ("NPN_Write: npp=%p, url=%s, len=%d, buffer=%s\n", (void*)npp,
                  pstream->url, len, (char*)buffer));

  // negative return indicates failure to the plugin
  if (!npp)
    return -1;

  ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
  NS_ASSERTION(wrapper != NULL, "null stream");

  if (wrapper == NULL)
    return -1;

  nsIOutputStream* stream;
  wrapper->GetStream(stream);

  PRUint32 count = 0;
  nsresult rv = stream->Write((char *)buffer, len, &count);
  NS_RELEASE(stream);

  if (rv != NS_OK)
    return -1;

  return (int32)count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NPIdentifier doGetIdentifier ( JSContext cx,
const NPUTF8 name 
) [static]

Definition at line 1552 of file ns4xPlugin.cpp.

{
  NS_ConvertUTF8toUTF16 utf16name(name);

  JSString *str = ::JS_InternUCStringN(cx, (jschar *)utf16name.get(),
                                       utf16name.Length());

  if (!str)
    return nsnull;

  return (NPIdentifier)STRING_TO_JSVAL(str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static JSContext* GetJSContextFromNPP ( NPP  npp) [static]

Definition at line 1477 of file ns4xPlugin.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

NPError MakeNew4xStreamInternal ( NPP  npp,
const char *  relativeURL,
const char *  target,
eNPPStreamTypeInternal  type,
PRBool  bDoNotify = PR_FALSE,
void notifyData = nsnull,
uint32  len = 0,
const char *  buf = nsnull,
NPBool  file = PR_FALSE 
)

Definition at line 1066 of file ns4xPlugin.cpp.

{
  if (!npp)
    return NPERR_INVALID_INSTANCE_ERROR;

  nsIPluginInstance *inst = (nsIPluginInstance *) npp->ndata;

  NS_ASSERTION(inst != NULL, "null instance");
  if (inst == NULL)
    return NPERR_INVALID_INSTANCE_ERROR;

  nsCOMPtr<nsIPluginManager> pm = do_GetService(kPluginManagerCID);
  NS_ASSERTION(pm, "failed to get plugin manager");
  if (!pm) return NPERR_GENERIC_ERROR;

  nsIPluginStreamListener* listener = nsnull;
  if (target == nsnull)
    ((ns4xPluginInstance*)inst)->NewNotifyStream(&listener, notifyData,
                                                 bDoNotify, relativeURL);

  switch (type) {
  case eNPPStreamTypeInternal_Get:
    {
      if (NS_FAILED(pm->GetURL(inst, relativeURL, target, listener)))
        return NPERR_GENERIC_ERROR;
      break;
    }
  case eNPPStreamTypeInternal_Post:
    {
      if (NS_FAILED(pm->PostURL(inst, relativeURL, len, buf, file, target,
                                listener)))
        return NPERR_GENERIC_ERROR;
      break;
    }
  default:
    NS_ASSERTION(0, "how'd I get here");
  }

  return NPERR_NO_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_IID ( kCPluginManagerCID  ,
NS_PLUGINMANAGER_CID   
) [static]
static NS_DEFINE_IID ( kPluginManagerCID  ,
NS_PLUGINMANAGER_CID   
) [static]
static NS_DEFINE_IID ( kMemoryCID  ,
NS_MEMORY_CID   
) [static]
const char* PeekException ( )

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:


Variable Documentation

char* gNPPException [static]

Definition at line 1886 of file ns4xPlugin.cpp.