Commit c48986ae authored by jst%mozilla.jstenback.com's avatar jst%mozilla.jstenback.com
Browse files

Landing fix for bug 296159. Adding support for NPObject enumeration to...

Landing fix for bug 296159. Adding support for NPObject enumeration to npruntime. Patch by alfred.peng@sun.com, r=mrbkap@gmail.com, sr=jst@mozilla.org
parent 20eba215
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@


/*
 *  npapi.h $Revision: 3.41 $
 *  npapi.h $Revision: 3.42 $
 *  Netscape client plug-in API spec
 */

@@ -125,7 +125,7 @@
/*----------------------------------------------------------------------*/

#define NP_VERSION_MAJOR 0
#define NP_VERSION_MINOR 16
#define NP_VERSION_MINOR 17


/* The OS/2 version of Netscape uses RC_DATA to define the
+15 −1
Original line number Diff line number Diff line
@@ -292,6 +292,8 @@ 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);

/*
    NPObjects returned by create, retain, invoke, and getProperty pass
@@ -310,6 +312,11 @@ typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj,
    will typically return immediately, with 0 or NULL, from an attempt
    to dispatch to a NPObject, but this behavior should not be
    depended upon.)

    The NPEnumerationFunctionPtr function may pass an array of
    NPIdentifiers back to the caller. The callee allocs the memory of
    the array using NPN_MemAlloc(), and it's the caller's responsibility
    to release it using NPN_MemFree().
*/
struct NPClass
{
@@ -324,9 +331,14 @@ struct NPClass
    NPGetPropertyFunctionPtr getProperty;
    NPSetPropertyFunctionPtr setProperty;
    NPRemovePropertyFunctionPtr removeProperty;
    NPEnumerationFunctionPtr enumerate;
};

#define NP_CLASS_STRUCT_VERSION 1
#define NP_CLASS_STRUCT_VERSION      2
#define NP_CLASS_STRUCT_VERSION_ENUM 2

#define NP_CLASS_STRUCT_VERSION_HAS_ENUM(npclass)   \
        ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM)

struct NPObject {
    NPClass *_class;
@@ -381,6 +393,8 @@ bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
bool NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
bool NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
bool NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName);
bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
                   uint32_t *count);

/*
    NPN_SetException may be called to trigger a script exception upon
+31 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@


/*
 *  npupp.h $Revision: 3.20 $
 *  npupp.h $Revision: 3.21 $
 *  function call mecahnics needed by platform specific glue code.
 */

@@ -1638,6 +1638,35 @@ typedef bool (* NP_LOADDS NPN_PopPopupsEnabledStateUPP)(NPP npp);

#endif

/* NPN_Enumerate */

#if _NPUPP_USE_UPP_

typedef UniversalProcPtr NPN_EnumerateUPP;
enum {
	uppNPN_EnumerateProcInfo = kThinkCStackBased
		| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP)))
		| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPObject*)))
		| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPIdentifier**)))
		| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32_t*)))
		| RESULT_SIZE(SIZE_CODE(sizeof(bool)))
};

#define NewNPN_EnumerateProc(FUNC)		\
		(NPN_EnumerateUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_EnumerateProcInfo, GetCurrentArchitecture())
#define CallNPN_EnumerateProc(FUNC, ARG1, ARG2, ARG3, ARG4)		\
		(jref)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_EnumerateProcInfo, (ARG1), (ARG2), (ARG3), (ARG4))

#else

typedef bool (* NP_LOADDS NPN_EnumerateUPP)(NPP npp, NPObject *obj, NPIdentifier **identifier, uint32_t *count);
#define NewNPN_EnumerateProc(FUNC)		\
		((NPN_EnumerateUPP) (FUNC))
#define CallNPN_EnumerateProc(FUNC, ARG1, ARG2, ARG3, ARG4)		\
		(*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4))

#endif



/******************************************************************************************
@@ -1714,6 +1743,7 @@ typedef struct _NPNetscapeFuncs {
    NPN_SetExceptionUPP setexception;
    NPN_PushPopupsEnabledStateUPP pushpopupsenabledstate;
    NPN_PopPopupsEnabledStateUPP poppopupsenabledstate;
    NPN_EnumerateUPP enumerate;
} NPNetscapeFuncs;

#ifdef XP_MAC
+23 −0
Original line number Diff line number Diff line
@@ -396,6 +396,9 @@ ns4xPlugin::CheckClassInitialized(void)
  CALLBACKS.hasmethod =
    NewNPN_HasMethodProc(FP2TV(_hasmethod));

  CALLBACKS.enumerate =
    NewNPN_EnumerateProc(FP2TV(_enumerate));

  CALLBACKS.releasevariantvalue =
    NewNPN_ReleaseVariantValueProc(FP2TV(_releasevariantvalue));

@@ -1828,6 +1831,26 @@ _hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName)
  return npobj->_class->hasProperty(npobj, methodName);
}

bool NP_EXPORT
_enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
           uint32_t *count)
{
  if (!npp || !npobj || !npobj->_class)
    return false;

  if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(npobj->_class) ||
      !npobj->_class->enumerate) {
    *identifier = 0;
    *count = 0;
    return true;
  }

  NPPExceptionAutoHolder nppExceptionHolder;
  NPPAutoPusher nppPusher(npp);

  return npobj->_class->enumerate(npobj, identifier, count);
}

void NP_EXPORT
_releasevariantvalue(NPVariant* variant)
{
+4 −0
Original line number Diff line number Diff line
@@ -241,6 +241,10 @@ _hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName);
bool NP_EXPORT
_hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName);

bool NP_EXPORT
_enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
           uint32_t *count);

void NP_EXPORT
_releasevariantvalue(NPVariant *variant);

Loading