+2004-08-12 Richard Williamson <rjw@apple.com>
+
+ Bring npruntime.h and friends closer to compliance with
+ latest spec.
+
+ Reviewed by Maciej.
+
+ * JavaScriptCore.pbproj/project.pbxproj:
+ * bindings/NP_jsobject.cpp:
+ (jsAllocate):
+ (_NPN_CreateScriptObject):
+ (NPN_Call):
+ (NPN_Evaluate):
+ (NPN_GetProperty):
+ (NPN_SetProperty):
+ (NPN_RemoveProperty):
+ * bindings/NP_jsobject.h:
+ * bindings/c/c_instance.cpp:
+ (CInstance::invokeMethod):
+ * bindings/c/c_utility.cpp:
+ (convertNPVariantToValue):
+ * bindings/npruntime.cpp:
+ (NPN_IdentifierIsString):
+ (NPN_VariantIsVoid):
+ (NPN_VariantIsNull):
+ (NPN_VariantIsUndefined):
+ (NPN_VariantIsBool):
+ (NPN_VariantIsInt32):
+ (NPN_VariantIsDouble):
+ (NPN_VariantIsString):
+ (NPN_VariantIsObject):
+ (NPN_VariantToBool):
+ (NPN_VariantToString):
+ (NPN_VariantToInt32):
+ (NPN_VariantToDouble):
+ (NPN_VariantToObject):
+ (NPN_InitializeVariantAsVoid):
+ (NPN_InitializeVariantAsNull):
+ (NPN_InitializeVariantAsUndefined):
+ (NPN_InitializeVariantWithBool):
+ (NPN_InitializeVariantWithInt32):
+ (NPN_InitializeVariantWithDouble):
+ (NPN_InitializeVariantWithString):
+ (NPN_InitializeVariantWithStringCopy):
+ (NPN_InitializeVariantWithObject):
+ (NPN_InitializeVariantWithVariant):
+ (NPN_ReleaseVariantValue):
+ (NPN_CreateObject):
+ * bindings/npruntime.h:
+ (_NPString::):
+ (_NPString::_NPVariant::):
+ * bindings/npruntime_priv.h: Added.
+
2004-08-12 Darin Adler <darin@apple.com>
Reviewed by Adele.
650B68DB0639033F009D42DE,
51863F70065420E800E9E8DD,
700DA118065984CE00747C0B,
+ 51CA3B5006CC2166005600E3,
+ 51DFF2CA06CC36F6006F1ECC,
);
isa = PBXHeadersBuildPhase;
runOnlyForDeploymentPostprocessing = 0;
700DA117065984CE00747C0B,
51863F6F065420E800E9E8DD,
51863FC406542D3100E9E8DD,
+ 51CA3B4F06CC2166005600E3,
5199B265061BB1300070C006,
5199B1BD061B65BC0070C006,
5199B1BE061B65BC0070C006,
+ 51DFF2C906CC36F6006F1ECC,
5182A53A06012C3000CBD2F2,
5182A53B06012C3000CBD2F2,
5182A45605FFCF4B00CBD2F2,
settings = {
};
};
+ 51CA3B4F06CC2166005600E3 = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ name = npapi.h;
+ path = bindings/npapi.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 51CA3B5006CC2166005600E3 = {
+ fileRef = 51CA3B4F06CC2166005600E3;
+ isa = PBXBuildFile;
+ settings = {
+ ATTRIBUTES = (
+ Private,
+ );
+ };
+ };
+ 51DFF2C906CC36F6006F1ECC = {
+ fileEncoding = 30;
+ isa = PBXFileReference;
+ lastKnownFileType = sourcecode.c.h;
+ name = npruntime_priv.h;
+ path = bindings/npruntime_priv.h;
+ refType = 4;
+ sourceTree = "<group>";
+ };
+ 51DFF2CA06CC36F6006F1ECC = {
+ fileRef = 51DFF2C906CC36F6006F1ECC;
+ isa = PBXBuildFile;
+ settings = {
+ };
+ };
51F0EB0005C85A6300E6DF1B = {
fileEncoding = 30;
isa = PBXFileReference;
#include <JavaScriptCore/npruntime.h>
#include <JavaScriptCore/c_utility.h>
-
+#include <JavaScriptCore/npruntime_priv.h>
using namespace KJS;
using namespace KJS::Bindings;
return aList;
}
-static NPObject *jsAllocate()
+static NPObject *jsAllocate(NPP npp)
{
return (NPObject *)malloc(sizeof(JavaScriptObject));
}
0,
0,
0,
+ 0
};
static NPClass *javascriptClass = &_javascriptClass;
return identifier;
}
-NPObject *_NPN_CreateScriptObject (KJS::ObjectImp *imp, KJS::Bindings::RootObject *root)
+NPObject *_NPN_CreateScriptObject (NPP npp, KJS::ObjectImp *imp, KJS::Bindings::RootObject *root)
{
- JavaScriptObject *obj = (JavaScriptObject *)NPN_CreateObject(NPScriptObjectClass);
+ JavaScriptObject *obj = (JavaScriptObject *)NPN_CreateObject(npp, NPScriptObjectClass);
obj->imp = imp;
obj->root = root;
return (NPObject *)obj;
}
-NPBool NPN_Call (NPObject *o, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result)
+bool NPN_Call (NPP npp, NPObject *o, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject *obj = (JavaScriptObject *)o;
return true;
}
-NPBool NPN_Evaluate (NPObject *o, NPString *s, NPVariant *variant)
+bool NPN_Evaluate (NPP npp, NPObject *o, NPString *s, NPVariant *variant)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject *obj = (JavaScriptObject *)o;
return false;
}
-NPBool NPN_GetProperty (NPObject *o, NPIdentifier propertyName, NPVariant *variant)
+bool NPN_GetProperty (NPP npp, NPObject *o, NPIdentifier propertyName, NPVariant *variant)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject *obj = (JavaScriptObject *)o;
return false;
}
-NPBool NPN_SetProperty (NPObject *o, NPIdentifier propertyName, const NPVariant *variant)
+bool NPN_SetProperty (NPP npp, NPObject *o, NPIdentifier propertyName, const NPVariant *variant)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject *obj = (JavaScriptObject *)o;
return false;
}
-NPBool NPN_RemoveProperty (NPObject *o, NPIdentifier propertyName)
+bool NPN_RemoveProperty (NPP npp, NPObject *o, NPIdentifier propertyName)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject *obj = (JavaScriptObject *)o;
KJS::Bindings::RootObject *root;
} JavaScriptObject;
-NPObject *_NPN_CreateScriptObject (KJS::ObjectImp *imp, KJS::Bindings::RootObject *root);
+NPObject *_NPN_CreateScriptObject (NPP npp, KJS::ObjectImp *imp, KJS::Bindings::RootObject *root);
#ifdef __cplusplus
}
#include <c_runtime.h>
#include <c_utility.h>
+#include <npruntime_priv.h>
+
#ifdef NDEBUG
#define C_LOG(formatAndArgs...) ((void)0)
#else
NPN_ReleaseVariantValue (&cArgs[i]);
}
- if (resultVariant.type != NPVariantVoidType) {
+ if (!NPVARIANT_IS_VOID(resultVariant)) {
resultValue = convertNPVariantToValue (exec, &resultVariant);
if (cArgs != localBuffer)
#include <c_instance.h>
#include <c_utility.h>
#include <internal.h>
+#include <npruntime_priv.h>
#include <runtime.h>
#include <runtime_object.h>
#include <runtime_root.h>
{
NPVariantType type = variant->type;
- if (type == NPVariantBoolType) {
+ if (type == NPVariantType_Bool) {
NPBool aBool;
if (NPN_VariantToBool (variant, &aBool))
return KJS::Boolean (aBool);
return KJS::Boolean (false);
}
- else if (type == NPVariantNullType) {
+ else if (type == NPVariantType_Null) {
return Null();
}
- else if (type == NPVariantUndefinedType) {
+ else if (type == NPVariantType_Void) {
return Undefined();
}
- else if (type == NPVariantInt32Type) {
+ else if (type == NPVariantType_Int32) {
int32_t anInt;
if (NPN_VariantToInt32 (variant, &anInt))
return Number (anInt);
return Number (0);
}
- else if (type == NPVariantDoubleType) {
+ else if (type == NPVariantType_Double) {
double aDouble;
if (NPN_VariantToDouble (variant, &aDouble))
return Number (aDouble);
return Number (0);
}
- else if (type == NPVariantStringType) {
+ else if (type == NPVariantType_String) {
NPUTF16 *stringValue;
unsigned int UTF16Length;
convertNPStringToUTF16 (&variant->value.stringValue, &stringValue, &UTF16Length); // requires free() of returned memory.
free (stringValue);
return resultString;
}
- else if (type == NPVariantObjectType) {
+ else if (type == NPVariantType_Object) {
NPObject *obj = variant->value.objectValue;
if (obj->_class == NPScriptObjectClass) {
return (NPIdentifier)identifier;
}
-NPBool NPN_IdentifierIsString(NPIdentifier identifier)
+bool NPN_IdentifierIsString(NPIdentifier identifier)
{
PrivateIdentifier *i = (PrivateIdentifier *)identifier;
return i->isString;
NPBool NPN_VariantIsVoid (const NPVariant *variant)
{
- return variant->type == NPVariantVoidType;
+ return variant->type == NPVariantType_Void;
}
NPBool NPN_VariantIsNull (const NPVariant *variant)
{
- return variant->type == NPVariantNullType;
+ return variant->type == NPVariantType_Null;
}
NPBool NPN_VariantIsUndefined (const NPVariant *variant)
{
- return variant->type == NPVariantUndefinedType;
+ return variant->type == NPVariantType_Void;
}
NPBool NPN_VariantIsBool (const NPVariant *variant)
{
- return variant->type == NPVariantBoolType;
+ return variant->type == NPVariantType_Bool;
}
NPBool NPN_VariantIsInt32 (const NPVariant *variant)
{
- return variant->type == NPVariantInt32Type;
+ return variant->type == NPVariantType_Int32;
}
NPBool NPN_VariantIsDouble (const NPVariant *variant)
{
- return variant->type == NPVariantDoubleType;
+ return variant->type == NPVariantType_Double;
}
NPBool NPN_VariantIsString (const NPVariant *variant)
{
- return variant->type == NPVariantStringType;
+ return variant->type == NPVariantType_String;
}
NPBool NPN_VariantIsObject (const NPVariant *variant)
{
- return variant->type == NPVariantObjectType;
+ return variant->type == NPVariantType_Object;
}
NPBool NPN_VariantToBool (const NPVariant *variant, NPBool *result)
{
- if (variant->type != NPVariantBoolType)
+ if (variant->type != NPVariantType_Bool)
return false;
*result = variant->value.boolValue;
NPString NPN_VariantToString (const NPVariant *variant)
{
- if (variant->type != NPVariantStringType) {
+ if (variant->type != NPVariantType_String) {
NPString emptyString = { 0, 0 };
return emptyString;
}
NPBool NPN_VariantToInt32 (const NPVariant *variant, int32_t *result)
{
- if (variant->type == NPVariantInt32Type)
+ if (variant->type == NPVariantType_Int32)
*result = variant->value.intValue;
- else if (variant->type == NPVariantDoubleType)
+ else if (variant->type == NPVariantType_Double)
*result = (int32_t)variant->value.doubleValue;
else
return false;
NPBool NPN_VariantToDouble (const NPVariant *variant, double *result)
{
- if (variant->type == NPVariantInt32Type)
+ if (variant->type == NPVariantType_Int32)
*result = (double)variant->value.intValue;
- else if (variant->type == NPVariantDoubleType)
+ else if (variant->type == NPVariantType_Double)
*result = variant->value.doubleValue;
else
return false;
NPBool NPN_VariantToObject (const NPVariant *variant, NPObject **result)
{
- if (variant->type != NPVariantObjectType)
+ if (variant->type != NPVariantType_Object)
return false;
*result = variant->value.objectValue;
void NPN_InitializeVariantAsVoid (NPVariant *variant)
{
- variant->type = NPVariantVoidType;
+ variant->type = NPVariantType_Void;
}
void NPN_InitializeVariantAsNull (NPVariant *variant)
{
- variant->type = NPVariantNullType;
+ variant->type = NPVariantType_Null;
}
void NPN_InitializeVariantAsUndefined (NPVariant *variant)
{
- variant->type = NPVariantUndefinedType;
+ variant->type = NPVariantType_Void;
}
void NPN_InitializeVariantWithBool (NPVariant *variant, NPBool value)
{
- variant->type = NPVariantBoolType;
+ variant->type = NPVariantType_Bool;
variant->value.boolValue = value;
}
void NPN_InitializeVariantWithInt32 (NPVariant *variant, int32_t value)
{
- variant->type = NPVariantInt32Type;
+ variant->type = NPVariantType_Int32;
variant->value.intValue = value;
}
void NPN_InitializeVariantWithDouble (NPVariant *variant, double value)
{
- variant->type = NPVariantDoubleType;
+ variant->type = NPVariantType_Double;
variant->value.doubleValue = value;
}
void NPN_InitializeVariantWithString (NPVariant *variant, const NPString *value)
{
- variant->type = NPVariantStringType;
+ variant->type = NPVariantType_String;
variant->value.stringValue = *value;
}
void NPN_InitializeVariantWithStringCopy (NPVariant *variant, const NPString *value)
{
- variant->type = NPVariantStringType;
+ variant->type = NPVariantType_String;
variant->value.stringValue.UTF8Length = value->UTF8Length;
variant->value.stringValue.UTF8Characters = (NPUTF8 *)malloc(sizeof(NPUTF8) * value->UTF8Length);
memcpy ((void *)variant->value.stringValue.UTF8Characters, value->UTF8Characters, sizeof(NPUTF8) * value->UTF8Length);
void NPN_InitializeVariantWithObject (NPVariant *variant, NPObject *value)
{
- variant->type = NPVariantObjectType;
+ variant->type = NPVariantType_Object;
variant->value.objectValue = NPN_RetainObject (value);
}
void NPN_InitializeVariantWithVariant (NPVariant *destination, const NPVariant *source)
{
switch (source->type){
- case NPVariantVoidType: {
+ case NPVariantType_Void: {
NPN_InitializeVariantAsVoid (destination);
break;
}
- case NPVariantNullType: {
+ case NPVariantType_Null: {
NPN_InitializeVariantAsNull (destination);
break;
}
- case NPVariantUndefinedType: {
- NPN_InitializeVariantAsUndefined (destination);
- break;
- }
- case NPVariantBoolType: {
+ case NPVariantType_Bool: {
NPN_InitializeVariantWithBool (destination, source->value.boolValue);
break;
}
- case NPVariantInt32Type: {
+ case NPVariantType_Int32: {
NPN_InitializeVariantWithInt32 (destination, source->value.intValue);
break;
}
- case NPVariantDoubleType: {
+ case NPVariantType_Double: {
NPN_InitializeVariantWithDouble (destination, source->value.doubleValue);
break;
}
- case NPVariantStringType: {
+ case NPVariantType_String: {
NPN_InitializeVariantWithStringCopy (destination, &source->value.stringValue);
break;
}
- case NPVariantObjectType: {
+ case NPVariantType_Object: {
NPN_InitializeVariantWithObject (destination, source->value.objectValue);
break;
}
{
assert (variant);
- if (variant->type == NPVariantObjectType) {
+ if (variant->type == NPVariantType_Object) {
NPN_ReleaseObject (variant->value.objectValue);
variant->value.objectValue = 0;
}
- else if (variant->type == NPVariantStringType) {
+ else if (variant->type == NPVariantType_String) {
free ((void *)variant->value.stringValue.UTF8Characters);
variant->value.stringValue.UTF8Characters = 0;
variant->value.stringValue.UTF8Length = 0;
}
- variant->type = NPVariantUndefinedType;
+ variant->type = NPVariantType_Void;
}
-NPObject *NPN_CreateObject (NPClass *aClass)
+NPObject *NPN_CreateObject (NPP npp, NPClass *aClass)
{
assert (aClass);
NPObject *obj;
if (aClass->allocate != NULL)
- obj = aClass->allocate ();
+ obj = aClass->allocate (npp);
else
obj = (NPObject *)malloc (sizeof(NPObject));
/*
- * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright © 2004, Apple Computer, Inc. and The Mozilla Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla
+ * Foundation ("Mozilla") nor the names of their contributors may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE, MOZILLA OR
+ * THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Revision 1 (March 4, 2004):
* Initial proposal.
* NPIdentifier becomes a void*, was int32_t
* Remove NP_IsValidIdentifier, renamed NP_IdentifierFromUTF8 to NP_GetIdentifier
* Added NPVariant and modified functions to use this new type.
+ *
+ * Revision 8 (July 9, 2004):
+ * Updated to joint Apple-Mozilla license.
+ *
+ * Revision 9 (August 12, 2004):
+ * Changed NPVariantType enum values to form PVariantType_XXX
+ * Added NPP arguments to NPObject functions.
+ * Replaced NPVariant functions with macros.
*/
#ifndef _NP_RUNTIME_H_
#define _NP_RUNTIME_H_
extern "C" {
#endif
+#include "npapi.h"
+
/*
This API is used to facilitate binding code written in C to script
objects. The API in this header does not assume the presence of a
- user agent. That is, it can be used to bind C code to scripting environments
- outside of the context of a user agent.
+ user agent. That is, it can be used to bind C code to scripting
+ environments outside of the context of a user agent.
- However, the normal use of the this API is in the context of a scripting
- environment running in a browser or other user agent. In particular it is used
- to support the extended Netscape script-ability API for plugins (NP-SAP).
- NP-SAP is an extension of the Netscape plugin API. As such we have adopted the
- use of the "NP" prefix for this API.
-*/
+ However, the normal use of the this API is in the context of a
+ scripting environment running in a browser or other user agent.
+ In particular it is used to support the extended Netscape
+ script-ability API for plugins (NP-SAP). NP-SAP is an extension
+ of the Netscape plugin API. As such we have adopted the use of
+ the "NP" prefix for this API.
+
+ The following NP{N|P}Variables were added to the Netscape plugin
+ API (in npapi.h):
+
+ NPNVWindowNPObject
+ NPNVPluginElementNPObject
+ NPPVpluginScriptableNPObject
+
+ These variables are exposed through NPN_GetValue() and
+ NPP_GetValue() (respectively) and are used to establish the
+ initial binding between the user agent and native code. The DOM
+ objects in the user agent can be examined and manipulated using
+ the NPN_ functions that operate on NPObjects described in this
+ header.
+
+ To the extent possible the assumptions about the scripting
+ language used by the scripting environment have been minimized.*/
/*
- Data passed between 'C' and script is always wrapped in an NPObject.
- The 'interface' of an NPObject is described by an NPClass.
+ Objects (non-primitive data) passed between 'C' and script is
+ always wrapped in an NPObject. The 'interface' of an NPObject is
+ described by an NPClass.
*/
typedef struct NPObject NPObject;
typedef struct NPClass NPClass;
const NPUTF8 *UTF8Characters;
uint32_t UTF8Length;
} NPString;
-
-#ifndef _NPAPI_H_
-// Ack! Temporary hack to get build working.
-typedef unsigned char NPBool;
-#endif
typedef enum {
- NPVariantVoidType,
- NPVariantNullType,
- NPVariantUndefinedType,
- NPVariantBoolType,
- NPVariantInt32Type,
- NPVariantDoubleType,
- NPVariantStringType,
- NPVariantObjectType
+ NPVariantType_Void,
+ NPVariantType_Null,
+ NPVariantType_Bool,
+ NPVariantType_Int32,
+ NPVariantType_Double,
+ NPVariantType_String,
+ NPVariantType_Object
} NPVariantType;
typedef struct _NPVariant {
NPVariantType type;
union {
- NPBool boolValue;
+ bool boolValue;
int32_t intValue;
double doubleValue;
NPString stringValue;
*/
void NPN_ReleaseVariantValue (NPVariant *variant);
-NPBool NPN_VariantIsVoid (const NPVariant *variant);
-NPBool NPN_VariantIsNull (const NPVariant *variant);
-NPBool NPN_VariantIsUndefined (const NPVariant *variant);
-NPBool NPN_VariantIsBool (const NPVariant *variant);
-NPBool NPN_VariantIsInt32 (const NPVariant *variant);
-NPBool NPN_VariantIsDouble (const NPVariant *variant);
-NPBool NPN_VariantIsString (const NPVariant *variant);
-NPBool NPN_VariantIsObject (const NPVariant *variant);
-NPBool NPN_VariantToBool (const NPVariant *variant, NPBool *result);
-NPBool NPN_VariantToInt32 (const NPVariant *variant, int32_t *result);
-NPBool NPN_VariantToDouble (const NPVariant *variant, double *result);
-NPString NPN_VariantToString (const NPVariant *variant);
-NPString NPN_VariantToStringCopy (const NPVariant *variant);
-NPBool NPN_VariantToObject (const NPVariant *variant, NPObject **result);
+#define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void)
+#define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null)
+#define NPVARIANT_IS_BOOLEAN(_v) ((_v).type == NPVariantType_Bool)
+#define NPVARIANT_IS_INT32(_v) ((_v).type == NPVariantType_Int32)
+#define NPVARIANT_IS_DOUBLE(_v) ((_v).type == NPVariantType_Double)
+#define NPVARIANT_IS_STRING(_v) ((_v).type == NPVariantType_String)
+#define NPVARIANT_IS_OBJECT(_v) ((_v).type == NPVariantType_Object)
+
+#define NPVARIANT_TO_BOOLEAN(_v) ((_v).value.boolValue)
+#define NPVARIANT_TO_INT32(_v) ((_v).value.intValue)
+#define NPVARIANT_TO_DOUBLE(_v) ((_v).value.doubleValue)
+#define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue)
+#define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue)
+
+#define NP_BEGIN_MACRO do {
+#define NP_END_MACRO } while (0)
+
+#define VOID_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Void; (_v).value.objectValue = NULL; NP_END_MACRO
+#define NULL_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Null; (_v).value.objectValue = NULL; NP_END_MACRO
+#define BOOLEAN_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Bool; (_v).value.boolValue = !!(_val); NP_END_MACRO
+#define INT32_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Int32; (_v).value.intValue = _val; NP_END_MACRO
+#define DOUBLE_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Double; (_v).value.doubleValue = _val; NP_END_MACRO
+#define STRINGZ_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str = { _val, strlen(_val) }; (_v).value.stringValue = str; NP_END_MACRO
+#define STRINGN_TO_NPVARIANT(_val, _len, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str = { _val, _len }; (_v).value.stringValue = str; NP_END_MACRO
+#define OBJECT_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Object; (_v).value.objectValue = _val; NP_END_MACRO
/*
- NPVariants initialized with the NPN_InitializeVariantXXX() functions
- must be released using the NPN_ReleaseVariantValue() function.
-*/
-void NPN_InitializeVariantAsVoid (NPVariant *variant);
-void NPN_InitializeVariantAsNull (NPVariant *variant);
-void NPN_InitializeVariantAsUndefined (NPVariant *variant);
-void NPN_InitializeVariantWithBool (NPVariant *variant, NPBool value);
-void NPN_InitializeVariantWithInt32 (NPVariant *variant, int32_t value);
-void NPN_InitializeVariantWithDouble (NPVariant *variant, double value);
-
-/*
- NPN_InitializeVariantWithString() does not copy string data. However
- the string data will be deallocated by calls to NPReleaseVariantValue().
-*/
-void NPN_InitializeVariantWithString (NPVariant *variant, const NPString *value);
-
-/*
- NPN_InitializeVariantWithStringCopy() will copy string data. The string data
- will be deallocated by calls to NPReleaseVariantValue().
-*/
-void NPN_InitializeVariantWithStringCopy (NPVariant *variant, const NPString *value);
-
-/*
- NPN_InitializeVariantWithObject() retains the NPObject. The object will be released
- by calls to NPReleaseVariantValue();
-*/
-void NPN_InitializeVariantWithObject (NPVariant *variant, NPObject *value);
-
-void NPN_InitializeVariantWithVariant (NPVariant *destination, const NPVariant *source);
-
-/*
- Type mappings (JavaScript types have been used for illustration
+ Type mappings (JavaScript types have been used for illustration
purposes):
- script to C
- Boolean NPVariant (with type NPVariantBoolType)
- Number NPVariant (with type NPVariantDoubleType)
- String NPVariant (with type NPVariantStringType)
- Undefined NPVariant (with type NPVariantUndefinedType)
- Null NPVariant (with type NPVariantNullType)
- Object (including Array) NPVariant (with type NPVariantObjectType, objectValue will be a NPObject)
- Object (NPObject wrapper) NPVariant (with type NPVariantObjectType)
-
-
- C to script
- NPVariant (with type NPVariantBoolType) Boolean
- NPVariant (with type NPVariantInt32Type) Number
- NPVariant (with type NPVariantDoubleType) Number
- NPVariant (with type NPVariantStringType) String
- NPVariant (with type NPVariantUndefinedType) Undefined
- NPVariant (with type NPVariantNullType) Null
- NPArray Array (restricted)
- NPObject Object or (NPObject wrapper)
-
+ JavaScript to C (NPVariant with type:)
+ undefined NPVariantType_Void
+ null NPVariantType_Null
+ Boolean NPVariantType_Bool
+ Number NPVariantType_Double or NPVariantType_Int32
+ String NPVariantType_String
+ Object NPVariantType_Object
+
+ C (NPVariant with type:) to JavaScript
+ NPVariantType_Void undefined
+ NPVariantType_Null null
+ NPVariantType_Bool Boolean
+ NPVariantType_Int32 Number
+ NPVariantType_Double Number
+ NPVariantType_String String
+ NPVariantType_Object Object
*/
typedef void *NPIdentifier;
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name);
void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers);
NPIdentifier NPN_GetIntIdentifier(int32_t intid);
-NPBool NPN_IdentifierIsString(NPIdentifier identifier);
-NPUTF8 *NPN_UTF8FromIdentifier (NPIdentifier identifier);
+bool NPN_IdentifierIsString(NPIdentifier identifier);
/*
- NPObject behavior is implemented using the following set of callback functions.
-
- The NPVariant *result parameter of NPInvokeFunctionPtr and NPGetPropertyFunctionPtr functions
- should be initialized using one of the NPN_InitializeVariantXXX functions. The variant result
- of the two functions will be released using NPN_ReleaseVariantValue().
+ The NPUTF8 returned from NPN_UTF8FromIdentifier SHOULD be freed.
*/
-typedef NPObject *(*NPAllocateFunctionPtr)();
+NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier);
+
+/*
+ Get the integer represented by identifier. If identifier is not an
+ integer identifier, the behaviour is undefined.
+*/
+int32_t NPN_IntFromIdentifier(NPIdentifier identifier);
+
+/*
+ NPObject behavior is implemented using the following set of
+ callback functions.
+
+ The NPVariant *result argument of these functions (where
+ applicable) should be released using NPN_ReleaseVariantValue().
+*/
+typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp);
typedef void (*NPDeallocateFunctionPtr)(NPObject *obj);
typedef void (*NPInvalidateFunctionPtr)(NPObject *obj);
-typedef NPBool (*NPHasMethodFunctionPtr)(NPClass *theClass, NPIdentifier name);
-typedef NPBool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, unsigned argCount, NPVariant *result);
-typedef NPBool (*NPHasPropertyFunctionPtr)(NPClass *theClass, NPIdentifier name);
-typedef NPBool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
-typedef NPBool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
+typedef bool (*NPHasMethodFunctionPtr)(NPClass *theClass, NPIdentifier name);
+typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPHasPropertyFunctionPtr)(NPClass *theClass, NPIdentifier name);
+typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
+typedef bool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
+typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
/*
NPObjects returned by create have a reference count of one. It is the caller's responsibility
NPHasPropertyFunctionPtr hasProperty;
NPGetPropertyFunctionPtr getProperty;
NPSetPropertyFunctionPtr setProperty;
+ NPRemovePropertyFunctionPtr removeProperty;
};
-#define kNPClassStructVersion1 1
-#define kNPClassStructVersionCurrent kNPClassStructVersion1
+#define NP_CLASS_STRUCT_VERSION 1
struct NPObject {
NPClass *_class;
function it is the responsibility of that implementation to set the initial retain
count to 1.
*/
-NPObject *NPN_CreateObject (NPClass *aClass);
+NPObject *NPN_CreateObject(NPP npp, NPClass *aClass);
/*
Increment the NPObject's reference count.
/*
Functions to access script objects represented by NPObject.
+
+ Calls to script objects are synchronous. If a function returns a
+ value, it will be supplied via the result NPVariant
+ argument. Successful calls will return true, false will be
+ returned in case of an error.
- Calls to script objects are asynchronous. If a function returns a value, it
- will be supplied via the NPScriptResultFunctionPtr callback.
-
- Calls made from plugin code to script may be made from any thread.
-
- Calls made from script to the plugin will always be made on the main
- user agent thread, this include calls to NPScriptResultFunctionPtr callbacks.
+ Calls made from plugin code to script must be made from the thread
+ on which the plugin was initialized.
*/
-NPBool NPN_Call (NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
-NPBool NPN_Evaluate (NPObject *obj, NPString *script, NPVariant *result);
-NPBool NPN_GetProperty (NPObject *obj, NPIdentifier propertyName, NPVariant *result);
-NPBool NPN_SetProperty (NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
-NPBool NPN_RemoveProperty (NPObject *obj, NPIdentifier propertyName);
+bool NPN_Call(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, NPVariant *result);
+bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result);
+bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value);
+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);
/*
NPN_SetException may be called to trigger a script exception upon return
--- /dev/null
+/*
+ * Copyright (C) 2003 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _NP_RUNTIME_PRIV_H_
+#define _NP_RUNTIME_PRIV_H_
+
+NPBool NPN_VariantIsVoid (const NPVariant *variant);
+NPBool NPN_VariantIsNull (const NPVariant *variant);
+NPBool NPN_VariantIsUndefined (const NPVariant *variant);
+NPBool NPN_VariantIsBool (const NPVariant *variant);
+NPBool NPN_VariantIsInt32 (const NPVariant *variant);
+NPBool NPN_VariantIsDouble (const NPVariant *variant);
+NPBool NPN_VariantIsString (const NPVariant *variant);
+NPBool NPN_VariantIsObject (const NPVariant *variant);
+NPBool NPN_VariantToBool (const NPVariant *variant, NPBool *result);
+NPBool NPN_VariantToInt32 (const NPVariant *variant, int32_t *result);
+NPBool NPN_VariantToDouble (const NPVariant *variant, double *result);
+NPString NPN_VariantToString (const NPVariant *variant);
+NPString NPN_VariantToStringCopy (const NPVariant *variant);
+NPBool NPN_VariantToObject (const NPVariant *variant, NPObject **result);
+
+/*
+ NPVariants initialized with the NPN_InitializeVariantXXX() functions
+ must be released using the NPN_ReleaseVariantValue() function.
+*/
+void NPN_InitializeVariantAsVoid (NPVariant *variant);
+void NPN_InitializeVariantAsNull (NPVariant *variant);
+void NPN_InitializeVariantAsUndefined (NPVariant *variant);
+void NPN_InitializeVariantWithBool (NPVariant *variant, NPBool value);
+void NPN_InitializeVariantWithInt32 (NPVariant *variant, int32_t value);
+void NPN_InitializeVariantWithDouble (NPVariant *variant, double value);
+
+/*
+ NPN_InitializeVariantWithString() does not copy string data. However
+ the string data will be deallocated by calls to NPReleaseVariantValue().
+*/
+void NPN_InitializeVariantWithString (NPVariant *variant, const NPString *value);
+
+/*
+ NPN_InitializeVariantWithStringCopy() will copy string data. The string data
+ will be deallocated by calls to NPReleaseVariantValue().
+*/
+void NPN_InitializeVariantWithStringCopy (NPVariant *variant, const NPString *value);
+
+/*
+ NPN_InitializeVariantWithObject() retains the NPObject. The object will be released
+ by calls to NPReleaseVariantValue();
+*/
+void NPN_InitializeVariantWithObject (NPVariant *variant, NPObject *value);
+
+void NPN_InitializeVariantWithVariant (NPVariant *destination, const NPVariant *source);
+
+#endif
+2004-08-12 Richard Williamson <rjw@apple.com>
+
+ Bring npruntime.h and friends closer to compliance with
+ latest spec.
+
+ Reviewed by Maciej.
+
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::windowScriptNPObject):
+
2004-08-12 Maciej Stachowiak <mjs@apple.com>
Reviewed by Richard.
{
if (!_windowScriptNPObject) {
KJS::ObjectImp *win = static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(this));
- _windowScriptNPObject = _NPN_CreateScriptObject (win, bindingRootObject());
+ _windowScriptNPObject = _NPN_CreateScriptObject (0, win, bindingRootObject());
}
return _windowScriptNPObject;
+2004-08-12 Richard Williamson <rjw@apple.com>
+
+ Bring npruntime.h and friends closer to compliance with
+ latest spec.
+
+ Reviewed by Maciej.
+
+ * Plugins.subproj/npapi.h:
+ * Plugins.subproj/npfunctions.h:
+ * Plugins.subproj/npruntime.h:
+ (_NPString::):
+ (_NPString::_NPVariant::):
+ * copy-webcore-files-to-webkit:
+
2004-08-12 Chris Blumenberg <cblu@apple.com>
Fixed: <rdar://problem/3761097> should be able to option-drag selection so HTML can be copied within a page
#endif
#ifdef XP_MACOSX
+ #include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
#endif
#define NULL (0L)
#endif
-#ifndef _NP_RUNTIME_H_
+//#ifndef _NP_RUNTIME_H_
// Ack! Temporary hack to get build working.
typedef unsigned char NPBool;
-#endif
+//#endif
typedef int16 NPError;
typedef int16 NPReason;
typedef char* NPMIMEType;
typedef NPIdentifier (*NPN_GetStringIdentifierProcPtr) (const NPUTF8 *name);
typedef void (*NPN_GetStringIdentifiersProcPtr) (const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers);
typedef NPIdentifier (*NPN_GetIntIdentifierProcPtr) (int32_t intid);
-typedef NPBool (*NPN_IdentifierIsStringProcPtr) (NPIdentifier identifier);
+typedef bool (*NPN_IdentifierIsStringProcPtr) (NPIdentifier identifier);
typedef NPUTF8 *(*NPN_UTF8FromIdentifierProcPtr) (NPIdentifier identifier);
-typedef NPObject* (*NPN_CreateObjectProcPtr) (NPClass *aClass);
+typedef NPObject* (*NPN_CreateObjectProcPtr) (NPP, NPClass *aClass);
typedef NPObject* (*NPN_RetainObjectProcPtr) (NPObject *obj);
typedef void (*NPN_ReleaseObjectProcPtr) (NPObject *obj);
-typedef NPBool (*NPN_CallProcPtr) (NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
-typedef NPBool (*NPN_EvaluateProcPtr) (NPObject *obj, NPString *script, NPVariant *result);
-typedef NPBool (*NPN_GetPropertyProcPtr) (NPObject *obj, NPIdentifier propertyName, NPVariant *result);
-typedef NPBool (*NPN_SetPropertyProcPtr) (NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
-typedef NPBool (*NPN_RemovePropertyProcPtr) (NPObject *obj, NPIdentifier propertyName);
+typedef bool (*NPN_CallProcPtr) (NPP npp, NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPN_EvaluateProcPtr) (NPP npp, NPObject *obj, NPString *script, NPVariant *result);
+typedef bool (*NPN_GetPropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result);
+typedef bool (*NPN_SetPropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
+typedef bool (*NPN_RemovePropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName);
typedef void (*NPN_SetExceptionProcPtr) (NPObject *obj, NPString *message);
typedef NPError (*NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
/*
- * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright © 2004, Apple Computer, Inc. and The Mozilla Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla
+ * Foundation ("Mozilla") nor the names of their contributors may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE, MOZILLA OR
+ * THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Revision 1 (March 4, 2004):
* Initial proposal.
* NPIdentifier becomes a void*, was int32_t
* Remove NP_IsValidIdentifier, renamed NP_IdentifierFromUTF8 to NP_GetIdentifier
* Added NPVariant and modified functions to use this new type.
+ *
+ * Revision 8 (July 9, 2004):
+ * Updated to joint Apple-Mozilla license.
+ *
+ * Revision 9 (August 12, 2004):
+ * Changed NPVariantType enum values to form PVariantType_XXX
+ * Added NPP arguments to NPObject functions.
+ * Replaced NPVariant functions with macros.
*/
#ifndef _NP_RUNTIME_H_
#define _NP_RUNTIME_H_
extern "C" {
#endif
+#include "npapi.h"
+
/*
This API is used to facilitate binding code written in C to script
objects. The API in this header does not assume the presence of a
- user agent. That is, it can be used to bind C code to scripting environments
- outside of the context of a user agent.
+ user agent. That is, it can be used to bind C code to scripting
+ environments outside of the context of a user agent.
- However, the normal use of the this API is in the context of a scripting
- environment running in a browser or other user agent. In particular it is used
- to support the extended Netscape script-ability API for plugins (NP-SAP).
- NP-SAP is an extension of the Netscape plugin API. As such we have adopted the
- use of the "NP" prefix for this API.
-*/
+ However, the normal use of the this API is in the context of a
+ scripting environment running in a browser or other user agent.
+ In particular it is used to support the extended Netscape
+ script-ability API for plugins (NP-SAP). NP-SAP is an extension
+ of the Netscape plugin API. As such we have adopted the use of
+ the "NP" prefix for this API.
+
+ The following NP{N|P}Variables were added to the Netscape plugin
+ API (in npapi.h):
+
+ NPNVWindowNPObject
+ NPNVPluginElementNPObject
+ NPPVpluginScriptableNPObject
+
+ These variables are exposed through NPN_GetValue() and
+ NPP_GetValue() (respectively) and are used to establish the
+ initial binding between the user agent and native code. The DOM
+ objects in the user agent can be examined and manipulated using
+ the NPN_ functions that operate on NPObjects described in this
+ header.
+
+ To the extent possible the assumptions about the scripting
+ language used by the scripting environment have been minimized.*/
/*
- Data passed between 'C' and script is always wrapped in an NPObject.
- The 'interface' of an NPObject is described by an NPClass.
+ Objects (non-primitive data) passed between 'C' and script is
+ always wrapped in an NPObject. The 'interface' of an NPObject is
+ described by an NPClass.
*/
typedef struct NPObject NPObject;
typedef struct NPClass NPClass;
const NPUTF8 *UTF8Characters;
uint32_t UTF8Length;
} NPString;
-
-#ifndef _NPAPI_H_
-// Ack! Temporary hack to get build working.
-typedef unsigned char NPBool;
-#endif
typedef enum {
- NPVariantVoidType,
- NPVariantNullType,
- NPVariantUndefinedType,
- NPVariantBoolType,
- NPVariantInt32Type,
- NPVariantDoubleType,
- NPVariantStringType,
- NPVariantObjectType
+ NPVariantType_Void,
+ NPVariantType_Null,
+ NPVariantType_Bool,
+ NPVariantType_Int32,
+ NPVariantType_Double,
+ NPVariantType_String,
+ NPVariantType_Object
} NPVariantType;
typedef struct _NPVariant {
NPVariantType type;
union {
- NPBool boolValue;
+ bool boolValue;
int32_t intValue;
double doubleValue;
NPString stringValue;
*/
void NPN_ReleaseVariantValue (NPVariant *variant);
-NPBool NPN_VariantIsVoid (const NPVariant *variant);
-NPBool NPN_VariantIsNull (const NPVariant *variant);
-NPBool NPN_VariantIsUndefined (const NPVariant *variant);
-NPBool NPN_VariantIsBool (const NPVariant *variant);
-NPBool NPN_VariantIsInt32 (const NPVariant *variant);
-NPBool NPN_VariantIsDouble (const NPVariant *variant);
-NPBool NPN_VariantIsString (const NPVariant *variant);
-NPBool NPN_VariantIsObject (const NPVariant *variant);
-NPBool NPN_VariantToBool (const NPVariant *variant, NPBool *result);
-NPBool NPN_VariantToInt32 (const NPVariant *variant, int32_t *result);
-NPBool NPN_VariantToDouble (const NPVariant *variant, double *result);
-NPString NPN_VariantToString (const NPVariant *variant);
-NPString NPN_VariantToStringCopy (const NPVariant *variant);
-NPBool NPN_VariantToObject (const NPVariant *variant, NPObject **result);
+#define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void)
+#define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null)
+#define NPVARIANT_IS_BOOLEAN(_v) ((_v).type == NPVariantType_Bool)
+#define NPVARIANT_IS_INT32(_v) ((_v).type == NPVariantType_Int32)
+#define NPVARIANT_IS_DOUBLE(_v) ((_v).type == NPVariantType_Double)
+#define NPVARIANT_IS_STRING(_v) ((_v).type == NPVariantType_String)
+#define NPVARIANT_IS_OBJECT(_v) ((_v).type == NPVariantType_Object)
+
+#define NPVARIANT_TO_BOOLEAN(_v) ((_v).value.boolValue)
+#define NPVARIANT_TO_INT32(_v) ((_v).value.intValue)
+#define NPVARIANT_TO_DOUBLE(_v) ((_v).value.doubleValue)
+#define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue)
+#define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue)
+
+#define NP_BEGIN_MACRO do {
+#define NP_END_MACRO } while (0)
+
+#define VOID_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Void; (_v).value.objectValue = NULL; NP_END_MACRO
+#define NULL_TO_NPVARIANT(_v) NP_BEGIN_MACRO (_v).type = NPVariantType_Null; (_v).value.objectValue = NULL; NP_END_MACRO
+#define BOOLEAN_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Bool; (_v).value.boolValue = !!(_val); NP_END_MACRO
+#define INT32_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Int32; (_v).value.intValue = _val; NP_END_MACRO
+#define DOUBLE_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Double; (_v).value.doubleValue = _val; NP_END_MACRO
+#define STRINGZ_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str = { _val, strlen(_val) }; (_v).value.stringValue = str; NP_END_MACRO
+#define STRINGN_TO_NPVARIANT(_val, _len, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_String; NPString str = { _val, _len }; (_v).value.stringValue = str; NP_END_MACRO
+#define OBJECT_TO_NPVARIANT(_val, _v) NP_BEGIN_MACRO (_v).type = NPVariantType_Object; (_v).value.objectValue = _val; NP_END_MACRO
/*
- NPVariants initialized with the NPN_InitializeVariantXXX() functions
- must be released using the NPN_ReleaseVariantValue() function.
-*/
-void NPN_InitializeVariantAsVoid (NPVariant *variant);
-void NPN_InitializeVariantAsNull (NPVariant *variant);
-void NPN_InitializeVariantAsUndefined (NPVariant *variant);
-void NPN_InitializeVariantWithBool (NPVariant *variant, NPBool value);
-void NPN_InitializeVariantWithInt32 (NPVariant *variant, int32_t value);
-void NPN_InitializeVariantWithDouble (NPVariant *variant, double value);
-
-/*
- NPN_InitializeVariantWithString() does not copy string data. However
- the string data will be deallocated by calls to NPReleaseVariantValue().
-*/
-void NPN_InitializeVariantWithString (NPVariant *variant, const NPString *value);
-
-/*
- NPN_InitializeVariantWithStringCopy() will copy string data. The string data
- will be deallocated by calls to NPReleaseVariantValue().
-*/
-void NPN_InitializeVariantWithStringCopy (NPVariant *variant, const NPString *value);
-
-/*
- NPN_InitializeVariantWithObject() retains the NPObject. The object will be released
- by calls to NPReleaseVariantValue();
-*/
-void NPN_InitializeVariantWithObject (NPVariant *variant, NPObject *value);
-
-void NPN_InitializeVariantWithVariant (NPVariant *destination, const NPVariant *source);
-
-/*
- Type mappings (JavaScript types have been used for illustration
+ Type mappings (JavaScript types have been used for illustration
purposes):
- script to C
- Boolean NPVariant (with type NPVariantBoolType)
- Number NPVariant (with type NPVariantDoubleType)
- String NPVariant (with type NPVariantStringType)
- Undefined NPVariant (with type NPVariantUndefinedType)
- Null NPVariant (with type NPVariantNullType)
- Object (including Array) NPVariant (with type NPVariantObjectType, objectValue will be a NPObject)
- Object (NPObject wrapper) NPVariant (with type NPVariantObjectType)
-
-
- C to script
- NPVariant (with type NPVariantBoolType) Boolean
- NPVariant (with type NPVariantInt32Type) Number
- NPVariant (with type NPVariantDoubleType) Number
- NPVariant (with type NPVariantStringType) String
- NPVariant (with type NPVariantUndefinedType) Undefined
- NPVariant (with type NPVariantNullType) Null
- NPArray Array (restricted)
- NPObject Object or (NPObject wrapper)
-
+ JavaScript to C (NPVariant with type:)
+ undefined NPVariantType_Void
+ null NPVariantType_Null
+ Boolean NPVariantType_Bool
+ Number NPVariantType_Double or NPVariantType_Int32
+ String NPVariantType_String
+ Object NPVariantType_Object
+
+ C (NPVariant with type:) to JavaScript
+ NPVariantType_Void undefined
+ NPVariantType_Null null
+ NPVariantType_Bool Boolean
+ NPVariantType_Int32 Number
+ NPVariantType_Double Number
+ NPVariantType_String String
+ NPVariantType_Object Object
*/
typedef void *NPIdentifier;
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name);
void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers);
NPIdentifier NPN_GetIntIdentifier(int32_t intid);
-NPBool NPN_IdentifierIsString(NPIdentifier identifier);
-NPUTF8 *NPN_UTF8FromIdentifier (NPIdentifier identifier);
+bool NPN_IdentifierIsString(NPIdentifier identifier);
/*
- NPObject behavior is implemented using the following set of callback functions.
-
- The NPVariant *result parameter of NPInvokeFunctionPtr and NPGetPropertyFunctionPtr functions
- should be initialized using one of the NPN_InitializeVariantXXX functions. The variant result
- of the two functions will be released using NPN_ReleaseVariantValue().
+ The NPUTF8 returned from NPN_UTF8FromIdentifier SHOULD be freed.
*/
-typedef NPObject *(*NPAllocateFunctionPtr)();
+NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier);
+
+/*
+ Get the integer represented by identifier. If identifier is not an
+ integer identifier, the behaviour is undefined.
+*/
+int32_t NPN_IntFromIdentifier(NPIdentifier identifier);
+
+/*
+ NPObject behavior is implemented using the following set of
+ callback functions.
+
+ The NPVariant *result argument of these functions (where
+ applicable) should be released using NPN_ReleaseVariantValue().
+*/
+typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp);
typedef void (*NPDeallocateFunctionPtr)(NPObject *obj);
typedef void (*NPInvalidateFunctionPtr)(NPObject *obj);
-typedef NPBool (*NPHasMethodFunctionPtr)(NPClass *theClass, NPIdentifier name);
-typedef NPBool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, unsigned argCount, NPVariant *result);
-typedef NPBool (*NPHasPropertyFunctionPtr)(NPClass *theClass, NPIdentifier name);
-typedef NPBool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
-typedef NPBool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
+typedef bool (*NPHasMethodFunctionPtr)(NPClass *theClass, NPIdentifier name);
+typedef bool (*NPInvokeFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *args, unsigned argCount, NPVariant *result);
+typedef bool (*NPHasPropertyFunctionPtr)(NPClass *theClass, NPIdentifier name);
+typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVariant *result);
+typedef bool (*NPSetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, const NPVariant *value);
+typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
/*
NPObjects returned by create have a reference count of one. It is the caller's responsibility
NPHasPropertyFunctionPtr hasProperty;
NPGetPropertyFunctionPtr getProperty;
NPSetPropertyFunctionPtr setProperty;
+ NPRemovePropertyFunctionPtr removeProperty;
};
-#define kNPClassStructVersion1 1
-#define kNPClassStructVersionCurrent kNPClassStructVersion1
+#define NP_CLASS_STRUCT_VERSION 1
struct NPObject {
NPClass *_class;
function it is the responsibility of that implementation to set the initial retain
count to 1.
*/
-NPObject *NPN_CreateObject (NPClass *aClass);
+NPObject *NPN_CreateObject(NPP npp, NPClass *aClass);
/*
Increment the NPObject's reference count.
/*
Functions to access script objects represented by NPObject.
+
+ Calls to script objects are synchronous. If a function returns a
+ value, it will be supplied via the result NPVariant
+ argument. Successful calls will return true, false will be
+ returned in case of an error.
- Calls to script objects are asynchronous. If a function returns a value, it
- will be supplied via the NPScriptResultFunctionPtr callback.
-
- Calls made from plugin code to script may be made from any thread.
-
- Calls made from script to the plugin will always be made on the main
- user agent thread, this include calls to NPScriptResultFunctionPtr callbacks.
+ Calls made from plugin code to script must be made from the thread
+ on which the plugin was initialized.
*/
-NPBool NPN_Call (NPObject *obj, NPIdentifier methodName, const NPVariant *args, unsigned argCount, NPVariant *result);
-NPBool NPN_Evaluate (NPObject *obj, NPString *script, NPVariant *result);
-NPBool NPN_GetProperty (NPObject *obj, NPIdentifier propertyName, NPVariant *result);
-NPBool NPN_SetProperty (NPObject *obj, NPIdentifier propertyName, const NPVariant *value);
-NPBool NPN_RemoveProperty (NPObject *obj, NPIdentifier propertyName);
+bool NPN_Call(NPP npp, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result);
+bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, NPVariant *result);
+bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, NPVariant *result);
+bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value);
+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);
/*
NPN_SetException may be called to trigger a script exception upon return
my %JavaScriptCoreFiles = (
'bindings/npruntime.h' => 'Plugins.subproj/npruntime.h',
+ 'bindings/npapi.h' => 'Plugins.subproj/npapi.h',
'bindings/npsap.h' => 'Plugins.subproj/npsap.h',
'bindings/objc/WebScriptObject.h' => 'Plugins.subproj/WebScriptObject.h',
);