Commit 77d5e0d0 authored by andersca's avatar andersca

JavaScriptCore:

        Reviewed by Geoff.

        Implement _NPN_Enumerate support.
        
        * JavaScriptCore.exp:
        * bindings/NP_jsobject.cpp:
        (_NPN_Enumerate):
        * bindings/c/c_instance.cpp:
        (KJS::Bindings::CInstance::getPropertyNames):
        * bindings/c/c_instance.h:
        * bindings/npapi.h:
        * bindings/npruntime.h:
        * bindings/npruntime_impl.h:
        * bindings/runtime.h:
        (KJS::Bindings::Instance::getPropertyNames):
        * bindings/runtime_object.cpp:
        (RuntimeObjectImp::getPropertyNames):
        * bindings/runtime_object.h:
        (KJS::RuntimeObjectImp::getInternalInstance):

LayoutTests:

        Reviewed by Geoff.

        Add enumeration test.
        
        * plugins/netscape-enumerate-expected.txt: Added.
        * plugins/netscape-enumerate.html: Added.

WebKit:

        Reviewed by Geoff.

        * Plugins/WebNetscapePluginPackage.m:
        (-[WebNetscapePluginPackage load]):
        Initialize pushpopupsenabledstate, poppopupsenabledstate and enumerate.
        
        * Plugins/npapi.m:
        (NPN_PushPopupsEnabledState):
        (NPN_PopPopupsEnabledState):
        Add stubs for these functions.
        
        * Plugins/npfunctions.h:
        Add new methods to NPNetscapeFuncs.

WebKitTools:

        Reviewed by Geoff.

        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
        Add TestObject.c and TestObject.h
        
        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
        (pluginGetProperty):
        Implement the testObject property.
        
        (pluginInvoke):
        Implement testEnumerate which takes an object and an array and enumerates
        the properties of the object and adds them to the array.
        
        (pluginAllocate):
        Allocate the test object.
        
        (pluginDeallocate):
        Free the test object.
        
        * DumpRenderTree/TestNetscapePlugIn.subproj/TestObject.c: Added.
        * DumpRenderTree/TestNetscapePlugIn.subproj/TestObject.h: Added.
        Add a test object with two enumerable properties.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@20613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1f0bfa23
2007-03-30 Anders Carlsson <andersca@apple.com>
Reviewed by Geoff.
Implement _NPN_Enumerate support.
* JavaScriptCore.exp:
* bindings/NP_jsobject.cpp:
(_NPN_Enumerate):
* bindings/c/c_instance.cpp:
(KJS::Bindings::CInstance::getPropertyNames):
* bindings/c/c_instance.h:
* bindings/npapi.h:
* bindings/npruntime.h:
* bindings/npruntime_impl.h:
* bindings/runtime.h:
(KJS::Bindings::Instance::getPropertyNames):
* bindings/runtime_object.cpp:
(RuntimeObjectImp::getPropertyNames):
* bindings/runtime_object.h:
(KJS::RuntimeObjectImp::getInternalInstance):
2007-03-28 Jeff Walden <jwalden+code@mit.edu>
Reviewed by Darin.
......
......@@ -84,6 +84,7 @@ _WTFReportError
_WTFReportFatalError
__NPN_CreateObject
__NPN_DeallocateObject
__NPN_Enumerate
__NPN_Evaluate
__NPN_GetIntIdentifier
__NPN_GetProperty
......
......@@ -30,6 +30,7 @@
#include "npruntime_impl.h"
#include "npruntime_priv.h"
#include "object.h"
#include "PropertyNameArray.h"
#include "runtime_root.h"
using namespace KJS;
......@@ -64,8 +65,8 @@ static void jsDeallocate(NPObject* npObj)
free(obj);
}
static NPClass javascriptClass = { 1, jsAllocate, jsDeallocate, 0, 0, 0, 0, 0, 0, 0, 0 };
static NPClass noScriptClass = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static NPClass javascriptClass = { 1, jsAllocate, jsDeallocate, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static NPClass noScriptClass = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
NPClass* NPScriptObjectClass = &javascriptClass;
static NPClass* NPNoScriptObjectClass = &noScriptClass;
......@@ -392,3 +393,38 @@ void _NPN_SetException(NPObject* o, const NPUTF8* message)
throwError(exec, GeneralError, message);
}
}
bool _NPN_Enumerate(NPP npp, NPObject *o, NPIdentifier **identifier, uint32_t *count)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject* obj = (JavaScriptObject*)o;
if (!_isSafeScript(obj))
return false;
RootObject* rootObject = obj->rootObject;
if (!rootObject || !rootObject->isValid())
return false;
ExecState* exec = rootObject->interpreter()->globalExec();
JSLock lock;
PropertyNameArray propertyNames;
obj->imp->getPropertyNames(exec, propertyNames);
unsigned size = propertyNames.size();
// FIXME: This should really call NPN_MemAlloc but that's in WebKit
NPIdentifier *identifiers = static_cast<NPIdentifier*>(malloc(sizeof(NPIdentifier) * size));
for (unsigned i = 0; i < size; i++)
identifiers[i] = _NPN_GetStringIdentifier(propertyNames[i].ustring().UTF8String().c_str());
*identifier = identifiers;
*count = size;
return true;
}
if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(o->_class) && o->_class->enumerate)
return o->_class->enumerate(o, identifier, count);
return false;
}
......@@ -31,6 +31,7 @@
#include "c_utility.h"
#include "list.h"
#include "npruntime_impl.h"
#include "PropertyNameArray.h"
#include "runtime_root.h"
#include <wtf/StringExtras.h>
#include <wtf/Vector.h>
......@@ -173,5 +174,33 @@ JSValue* CInstance::valueOf() const
return stringValue();
}
void CInstance::getPropertyNames(ExecState*, PropertyNameArray& nameArray)
{
if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(_object->_class) ||
!_object->_class->enumerate)
return;
unsigned count;
NPIdentifier* identifiers;
{
JSLock::DropAllLocks dropAllLocks;
if (!_object->_class->enumerate(_object, &identifiers, &count))
return;
}
for (unsigned i = 0; i < count; i++) {
PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(identifiers[i]);
if (identifier->isString)
nameArray.add(identifierFromNPIdentifier(identifier->value.string));
else
nameArray.add(Identifier::from(identifier->value.number));
}
// FIXME: This should really call NPN_MemFree but that's in WebKit
free(identifiers);
}
}
}
......@@ -54,6 +54,7 @@ public:
virtual JSValue *invokeMethod (ExecState *exec, const MethodList &method, const List &args);
virtual JSValue *invokeDefaultMethod (ExecState *exec, const List &args);
virtual void getPropertyNames(ExecState*, PropertyNameArray&);
JSValue *stringValue() const;
JSValue *numberValue() const;
......
......@@ -104,7 +104,7 @@
/*----------------------------------------------------------------------*/
#define NP_VERSION_MAJOR 0
#define NP_VERSION_MINOR 14
#define NP_VERSION_MINOR 17
......@@ -677,6 +677,8 @@ NPError NPN_SetValue(NPP instance, NPPVariable variable,
void NPN_InvalidateRect(NPP instance, NPRect *invalidRect);
void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion);
void NPN_ForceRedraw(NPP instance);
void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled);
void NPN_PopPopupsEnabledState(NPP instance);
#ifdef __cplusplus
} /* end extern "C" */
......
......@@ -246,6 +246,7 @@ typedef bool (*NPHasPropertyFunctionPtr)(NPObject *obj, 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);
typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value, uint32_t *count);
/*
NPObjects returned by create have a reference count of one. It is the caller's responsibility
......@@ -262,6 +263,11 @@ typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, NPIdentifier name);
native code is still retaining those NPObject instances.
(The runtime 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
{
......@@ -276,9 +282,13 @@ 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;
......@@ -325,6 +335,7 @@ bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, const
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 return
......
......@@ -52,6 +52,7 @@ extern bool _NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyN
extern bool _NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName);
extern bool _NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName);
extern void _NPN_SetException(NPObject *obj, const NPUTF8 *message);
extern bool _NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count);
#ifdef __cplusplus
} /* end extern "C" */
......
......@@ -35,6 +35,7 @@ namespace KJS {
class Identifier;
class List;
class PropertyNameArray;
namespace Bindings {
......@@ -170,6 +171,8 @@ public:
virtual JSValue* invokeMethod(ExecState*, const MethodList&, const List& args) = 0;
virtual JSValue* invokeDefaultMethod(ExecState*, const List&) { return jsUndefined(); }
virtual void getPropertyNames(ExecState*, PropertyNameArray&) { }
virtual JSValue* defaultValue(JSType hint) const = 0;
virtual JSValue* valueOf() const { return jsString(getClass()->name()); }
......
......@@ -194,3 +194,10 @@ JSValue *RuntimeObjectImp::callAsFunction(ExecState* exec, JSObject*, const List
return aValue;
}
void RuntimeObjectImp::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
{
instance->begin();
instance->getPropertyNames(exec, propertyNames);
instance->end();
}
......@@ -44,9 +44,10 @@ public:
virtual JSValue *defaultValue(ExecState *exec, JSType hint) const;
virtual bool implementsCall() const;
virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
Bindings::Instance *getInternalInstance() const { return instance.get(); }
virtual void getPropertyNames(ExecState*, PropertyNameArray&);
Bindings::Instance *getInternalInstance() const { return instance.get(); }
static const ClassInfo info;
private:
......
2007-03-30 Anders Carlsson <andersca@apple.com>
Reviewed by Geoff.
Add enumeration test.
* plugins/netscape-enumerate-expected.txt: Added.
* plugins/netscape-enumerate.html: Added.
2007-03-29 Geoffrey Garen <ggaren@apple.com>
Layout test for <rdar://problem/5061807>. (This one's for you, Boyscout!)
This tests that a plugin can enumerate an object's properties using NPN_Enumerate. It also tests that JavaScript can enumerate a plugin object's properties. If this test is successful the text "SUCCESS" will be show below.
SUCCESS
<html>
<script>
function runTest()
{
if (window.layoutTestController)
layoutTestController.dumpAsText();
var plugin = document.getElementById("testPlugin");
var result = document.getElementById('result');
// First test NPN_Enumerate from the plugin's side
var testObject = { "one" : 1, "two" : 2, "three" : 3, 4 : 4 }
var outArray = [];
plugin.testEnumerate(testObject, outArray);
if (outArray.toString() != 'one,two,three,4') {
result.innerHTML = 'FAILURE: Array returned from plugin was ' + outArray.toString();
return;
}
// Now try enumerating a plugin object's properties
var propNames = [];
for (var v in plugin.testObject) {
propNames.push(v);
}
if (propNames.toString() != 'foo,bar') {
result.innerHTML = 'FAILURE: Plugin object properties was ' + propNames.toString();
return;
}
result.innerHTML = 'SUCCESS';
}
</script>
<body onload="runTest();">
<embed id="testPlugin" type="application/x-webkit-test-netscape" width="200" height="200"></embed>
This tests that a plugin can enumerate an object's properties using NPN_Enumerate. It also tests that JavaScript can enumerate a plugin object's properties. If this test is successful the text "SUCCESS" will be show below.
<div id="result">FAILURE</div>
</body>
</html>
2007-03-30 Anders Carlsson <andersca@apple.com>
Reviewed by Geoff.
* Plugins/WebNetscapePluginPackage.m:
(-[WebNetscapePluginPackage load]):
Initialize pushpopupsenabledstate, poppopupsenabledstate and enumerate.
* Plugins/npapi.m:
(NPN_PushPopupsEnabledState):
(NPN_PopPopupsEnabledState):
Add stubs for these functions.
* Plugins/npfunctions.h:
Add new methods to NPNetscapeFuncs.
2007-03-29 Geoffrey Garen <ggaren@apple.com>
Reviewed by Beth Dakin, reviewed by Maciej Stachowiak.
......
......@@ -377,7 +377,9 @@ - (BOOL)load
browserFuncs.forceredraw = (NPN_ForceRedrawProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_ForceRedraw);
browserFuncs.getJavaEnv = (NPN_GetJavaEnvProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_GetJavaEnv);
browserFuncs.getJavaPeer = (NPN_GetJavaPeerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_GetJavaPeer);
browserFuncs.pushpopupsenabledstate = (NPN_PushPopupsEnabledStateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_PushPopupsEnabledState);
browserFuncs.poppopupsenabledstate = (NPN_PopPopupsEnabledStateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_PopPopupsEnabledState);
browserFuncs.releasevariantvalue = (NPN_ReleaseVariantValueProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_ReleaseVariantValue);
browserFuncs.getstringidentifier = (NPN_GetStringIdentifierProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_GetStringIdentifier);
browserFuncs.getstringidentifiers = (NPN_GetStringIdentifiersProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_GetStringIdentifiers);
......@@ -394,7 +396,8 @@ - (BOOL)load
browserFuncs.setproperty = (NPN_SetPropertyProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_SetProperty);
browserFuncs.removeproperty = (NPN_RemovePropertyProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_RemoveProperty);
browserFuncs.setexception = (NPN_SetExceptionProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_SetException);
browserFuncs.enumerate = (NPN_EnumerateProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_Enumerate);
#if !LOG_DISABLED
CFAbsoluteTime mainStart = CFAbsoluteTimeGetCurrent();
#endif
......@@ -470,7 +473,9 @@ - (BOOL)load
browserFuncs.forceredraw = NPN_ForceRedraw;
browserFuncs.getJavaEnv = NPN_GetJavaEnv;
browserFuncs.getJavaPeer = NPN_GetJavaPeer;
browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
browserFuncs.getstringidentifiers = _NPN_GetStringIdentifiers;
......@@ -487,6 +492,7 @@ - (BOOL)load
browserFuncs.setproperty = _NPN_SetProperty;
browserFuncs.removeproperty = _NPN_RemoveProperty;
browserFuncs.setexception = _NPN_SetException;
browserFuncs.enumerate = _NPN_Enumerate;
#if !LOG_DISABLED
CFAbsoluteTime initializeStart = CFAbsoluteTimeGetCurrent();
......
......@@ -158,3 +158,13 @@ NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
LOG(Plugins, "NPN_GetJavaPeer");
return NULL;
}
void
NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
{
}
void
NPN_PopPopupsEnabledState(NPP instance)
{
}
......@@ -29,6 +29,9 @@ typedef NPError (*NPN_GetURLProcPtr)(NPP instance, const char* URL, const char*
typedef NPError (*NPN_PostURLProcPtr)(NPP instance, const char* URL, const char* window, uint32 len, const char* buf, NPBool file);
typedef void* (*NPN_GetJavaEnvProcPtr)(void);
typedef void* (*NPN_GetJavaPeerProcPtr)(NPP instance);
typedef void (*NPN_PushPopupsEnabledStateProcPtr)(NPP instance, NPBool enabled);
typedef void (*NPN_PopPopupsEnabledStateProcPtr)(NPP instance);
typedef void (*NPN_ReleaseVariantValueProcPtr) (NPVariant *variant);
......@@ -51,6 +54,7 @@ typedef bool (*NPN_HasPropertyProcPtr) (NPP, NPObject *npobj, NPIdentifier prope
typedef bool (*NPN_HasMethodProcPtr) (NPP npp, NPObject *npobj, NPIdentifier methodName);
typedef bool (*NPN_RemovePropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName);
typedef void (*NPN_SetExceptionProcPtr) (NPObject *obj, const NPUTF8 *message);
typedef bool (*NPN_EnumerateProcPtr) (NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count);
typedef NPError (*NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
typedef NPError (*NPP_DestroyProcPtr)(NPP instance, NPSavedData** save);
......@@ -115,6 +119,9 @@ typedef struct _NPNetscapeFuncs {
NPN_HasMethodProcPtr hasmethod;
NPN_ReleaseVariantValueProcPtr releasevariantvalue;
NPN_SetExceptionProcPtr setexception;
NPN_PushPopupsEnabledStateProcPtr pushpopupsenabledstate;
NPN_PopPopupsEnabledStateProcPtr poppopupsenabledstate;
NPN_EnumerateProcPtr enumerate;
} NPNetscapeFuncs;
typedef struct _NPPluginFuncs {
......
2007-03-30 Anders Carlsson <andersca@apple.com>
Reviewed by Geoff.
* DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
Add TestObject.c and TestObject.h
* DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.c:
(pluginGetProperty):
Implement the testObject property.
(pluginInvoke):
Implement testEnumerate which takes an object and an array and enumerates
the properties of the object and adds them to the array.
(pluginAllocate):
Allocate the test object.
(pluginDeallocate):
Free the test object.
* DumpRenderTree/TestNetscapePlugIn.subproj/TestObject.c: Added.
* DumpRenderTree/TestNetscapePlugIn.subproj/TestObject.h: Added.
Add a test object with two enumerable properties.
2007-03-29 Geoffrey Garen <ggaren@apple.com>
Reviewed by Beth Dakin.
......
......@@ -39,6 +39,8 @@
14A6FB8A0971CAE5008B014F /* NavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 14A6FB880971CAE5008B014F /* NavigationController.h */; };
14A6FB8B0971CAE5008B014F /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 14A6FB890971CAE5008B014F /* NavigationController.m */; };
1A6CA8DE0B7122D100A24B62 /* ResourceLoadDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A6CA8640B7120CF00A24B62 /* ResourceLoadDelegate.m */; };
1A8F02E70BB9B4EC008CFA34 /* TestObject.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A8F024D0BB9B056008CFA34 /* TestObject.c */; };
1A8F02E80BB9B4EC008CFA34 /* TestObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A8F024C0BB9B056008CFA34 /* TestObject.h */; };
22181BD109DC8C4B008342E8 /* ObjCPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 22181BCD09DC8C4B008342E8 /* ObjCPlugin.h */; };
22181BD209DC8C4B008342E8 /* ObjCPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 22181BCE09DC8C4B008342E8 /* ObjCPlugin.m */; };
22181BD309DC8C4B008342E8 /* ObjCPluginFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 22181BCF09DC8C4B008342E8 /* ObjCPluginFunction.h */; };
......@@ -105,6 +107,8 @@
14A6FB890971CAE5008B014F /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = "<group>"; };
1A6CA8630B7120CF00A24B62 /* ResourceLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadDelegate.h; sourceTree = "<group>"; };
1A6CA8640B7120CF00A24B62 /* ResourceLoadDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ResourceLoadDelegate.m; sourceTree = "<group>"; };
1A8F024C0BB9B056008CFA34 /* TestObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestObject.h; sourceTree = "<group>"; };
1A8F024D0BB9B056008CFA34 /* TestObject.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = TestObject.c; sourceTree = "<group>"; };
22181BCD09DC8C4B008342E8 /* ObjCPlugin.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ObjCPlugin.h; sourceTree = "<group>"; };
22181BCE09DC8C4B008342E8 /* ObjCPlugin.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = ObjCPlugin.m; sourceTree = "<group>"; };
22181BCF09DC8C4B008342E8 /* ObjCPluginFunction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ObjCPluginFunction.h; sourceTree = "<group>"; };
......@@ -198,6 +202,8 @@
141BF445096A45C800E0753C /* main.c */,
141BF446096A45C800E0753C /* PluginObject.c */,
141BF447096A45C800E0753C /* PluginObject.h */,
1A8F024D0BB9B056008CFA34 /* TestObject.c */,
1A8F024C0BB9B056008CFA34 /* TestObject.h */,
141BF448096A45C800E0753C /* Info.plist */,
);
path = TestNetscapePlugIn.subproj;
......@@ -264,6 +270,7 @@
buildActionMask = 2147483647;
files = (
141BF453096A45EB00E0753C /* PluginObject.h in Headers */,
1A8F02E80BB9B4EC008CFA34 /* TestObject.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -355,13 +362,11 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C29C308902C6D008A9EFC /* Build configuration list for PBXProject "DumpRenderTree" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* DumpRenderTree */;
productRefGroup = 9340995508540CAF007F3BC8 /* Products */;
projectDirPath = "";
projectRoot = "";
shouldCheckCompatibility = 1;
targets = (
A84F608D08B1370600E9745F /* All */,
9340994A08540CAE007F3BC8 /* DumpRenderTree */,
......@@ -389,6 +394,7 @@
files = (
141BF44A096A45C800E0753C /* main.c in Sources */,
141BF44B096A45C800E0753C /* PluginObject.c in Sources */,
1A8F02E70BB9B4EC008CFA34 /* TestObject.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -31,7 +31,10 @@
OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "PluginObject.h"
#include "PluginObject.h"
#include "TestObject.h"
#include <assert.h>
static void pluginInvalidate(NPObject *obj);
static bool pluginHasProperty(NPObject *obj, NPIdentifier name);
......@@ -68,13 +71,15 @@ static bool identifiersInitialized = false;
#define ID_PROPERTY_PROPERTY 0
#define ID_PROPERTY_EVENT_LOGGING 1
#define ID_PROPERTY_HAS_STREAM 2
#define NUM_PROPERTY_IDENTIFIERS 3
#define ID_PROPERTY_TEST_OBJECT 3
#define NUM_PROPERTY_IDENTIFIERS 4
static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
"property",
"eventLoggingEnabled",
"hasStream"
"hasStream",
"testObject"
};
#define ID_TEST_CALLBACK_METHOD 0
......@@ -84,7 +89,8 @@ static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
#define ID_TEST_GET_URL_NOTIFY 4
#define ID_TEST_INVOKE_DEFAULT 5
#define ID_DESTROY_STREAM 6
#define NUM_METHOD_IDENTIFIERS 7
#define ID_TEST_ENUMERATE 7
#define NUM_METHOD_IDENTIFIERS 8
static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
......@@ -94,13 +100,14 @@ static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
"testDOMAccess",
"getURLNotify",
"testInvokeDefault",
"destroyStream"
"destroyStream",
"testEnumerate"
};
static NPUTF8* createCStringFromNPVariant(const NPVariant *variant)
{
size_t length = NPVARIANT_TO_STRING(*variant).UTF8Length;
NPUTF8* result = malloc(length + 1);
NPUTF8* result = (NPUTF8*)malloc(length + 1);
memcpy(result, NPVARIANT_TO_STRING(*variant).UTF8Characters, length);
result[length] = '\0';
return result;
......@@ -139,6 +146,11 @@ static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *varia
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_HAS_STREAM]) {
BOOLEAN_TO_NPVARIANT(((PluginObject *)obj)->stream != 0, *variant);
return true;
} else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT]) {
NPObject *testObject = ((PluginObject *)obj)->testObject;
browser->retainobject(testObject);
OBJECT_TO_NPVARIANT(testObject, *variant);
return true;
}
return false;
}
......@@ -180,7 +192,7 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
// call whatever method name we're given
if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
NPObject *windowScriptObject;
browser->getvalue(obj->npp, NPPVpluginScriptableNPObject, &windowScriptObject);
browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
NPUTF8* callbackString = createCStringFromNPVariant(&args[0]);
NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
......@@ -248,14 +260,41 @@ static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *a
browser->releasevariantvalue(&browserResult);
BOOLEAN_TO_NPVARIANT(retval, *result);
return true;
return true;
} else if (name == pluginMethodIdentifiers[ID_TEST_ENUMERATE]) {
if (argCount == 2 && NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_OBJECT(args[1])) {
uint32_t count;
NPIdentifier* identifiers;
if (browser->enumerate(obj->npp, NPVARIANT_TO_OBJECT(args[0]), &identifiers, &count)) {
NPObject* outArray = NPVARIANT_TO_OBJECT(args[1]);
NPIdentifier pushIdentifier = browser->getstringidentifier("push");
for (uint32_t i = 0; i < count; i++) {
NPUTF8* string = browser->utf8fromidentifier(identifiers[i]);
if (!string)
continue;
NPVariant args[1];
STRINGZ_TO_NPVARIANT(string, args[0]);
NPVariant browserResult;
browser->invoke(obj->npp, outArray, pushIdentifier, args, 1, &browserResult);
browser->releasevariantvalue(&browserResult);
}
browser->memfree(identifiers);
}
VOID_TO_NPVARIANT(*result);
return true;
}
} else if (name == pluginMethodIdentifiers[ID_DESTROY_STREAM]) {
assert(obj->stream);
NPError npError = browser->destroystream(obj->npp, obj->stream, NPRES_USER_BREAK);
INT32_TO_NPVARIANT(npError, *result);
return true;
}
return false;
}
......@@ -271,7 +310,7 @@ static void pluginInvalidate(NPObject *obj)
static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
{
PluginObject *newInstance = malloc(sizeof(PluginObject));
PluginObject *newInstance = (PluginObject*)malloc(sizeof(PluginObject));
if (!identifiersInitialized) {
identifiersInitialized = true;
......@@ -279,15 +318,20 @@ static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
}
newInstance->npp = npp;
newInstance->testObject = browser->createobject(npp, getTestClass());
newInstance->eventLogging = FALSE;
newInstance->stream = 0;
return (NPObject *)newInstance;
}
static void pluginDeallocate(NPObject *obj)
static void pluginDeallocate(NPObject *header)
{
free(obj);
PluginObject* obj = (PluginObject*)header;
browser->releaseobject(obj->testObject);
free(header);
}
void handleCallback(PluginObject* object, const char *url, NPReason reason, void *notifyData)
......@@ -297,7 +341,7 @@ void handleCallback(PluginObject* object, const char *url, NPReason reason, void
NPVariant args[1];