Commit 4348c6a8 authored by andersca@apple.com's avatar andersca@apple.com
Browse files

WebCore:

2008-10-24  Anders Carlsson  <andersca@apple.com>

        Reviewed by Sam Weinig.

        <rdar://problem/5440917> Support NPN_Construct
                
        * WebCore.NPAPI.exp:
        Export _NPN_Construct.
        
        * bridge/NP_jsobject.cpp:
        (_NPN_Construct):
        Implement this.
        
        * bridge/c/c_instance.cpp:
        (JSC::Bindings::CInstance::supportsConstruct):
        (JSC::Bindings::CInstance::invokeConstruct):
        Have this call the appropriate NPClass method.
        
        * bridge/npruntime.h:
        Add NPN_Construct.

        * bridge/npruntime_impl.h:
        Add _NPN_Construct.
        
        * bridge/runtime.h:
        (JSC::Bindings::Instance::supportsConstruct):
        (JSC::Bindings::Instance::invokeConstruct):
        New methods.
        
        * bridge/runtime_object.cpp:
        (JSC::callRuntimeConstructor):
        Call the native instance.
        
        (JSC::RuntimeObjectImp::getConstructData):
        Implement this.
        
        * bridge/runtime_object.h:
        Add new method declarations.
        
        * plugins/gtk/PluginPackageGtk.cpp:
        (WebCore::PluginPackage::load):
        * plugins/qt/PluginPackageQt.cpp:
        (WebCore::PluginPackage::load):
        * plugins/win/PluginPackageWin.cpp:
        (WebCore::PluginPackage::load):
        Initialize m_pluginFuncs.construct.

WebKit/mac:

2008-10-24  Anders Carlsson  <andersca@apple.com>

        Reviewed by Sam Weinig.

        <rdar://problem/5440917> Support NPN_Construct
        
        Set construct.
        
        * Plugins/WebNetscapePluginPackage.m:
        (-[WebNetscapePluginPackage load]):

WebKitTools:

2008-10-24  Anders Carlsson  <andersca@apple.com>

        Reviewed by Sam Weinig.
        
        <rdar://problem/5440917> Support NPN_Construct
        
        * DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.cpp:
        (testCallback):
        Fix a memory leak.
        
        (testConstruct):
        New test method that treats it first argument as a constructor and invokes it with the rest of the arguments.
        
        (pluginInvoke):
        Handle testConstruct.
        
        * DumpRenderTree/TestNetscapePlugIn.subproj/TestObject.cpp:
        (testGetProperty):
        Add objectPointer property.
        
        (testEnumerate):
        Only enumerate the two first properties.
        
        (testConstruct):
        Add a simple construct implementation that just returns the test object.

LayoutTests:

2008-10-24  Anders Carlsson  <andersca@apple.com>

        Reviewed by Sam Weinig.

        <rdar://problem/5440917> Support NPN_Construct
        
        Add testcase.
        
        * plugins/netscape-construct-expected.txt: Added.
        * plugins/netscape-construct.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37869 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4bf03f02
2008-10-24 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
<rdar://problem/5440917> Support NPN_Construct
Add testcase.
* plugins/netscape-construct-expected.txt: Added.
* plugins/netscape-construct.html: Added.
2008-10-24 Greg Bolsinga <bolsinga@apple.com>
Reviewed by Sam Weinig.
......
This tests that NPN_Construct works correctly, and that it is possible to use "new" with NPObjects that implement construct.
SUCCESS
<html>
<script>
function runTest()
{
if (window.layoutTestController)
layoutTestController.dumpAsText();
var successCount = 0;
var plugin = document.getElementById("testPlugin");
var array = plugin.testConstruct(Array, 1, 2, 3, 4);
if (array instanceof Array) {
successCount++
if (array.length == 4)
successCount++
}
var n = new plugin.testObject();
if (n.objectPointer == plugin.testObject.objectPointer)
successCount++;
if (successCount == 3)
document.getElementById('result').innerHTML = 'SUCCESS'
}
</script>
<body onload="runTest();">
This tests that NPN_Construct works correctly, and that it is possible to use "new" with NPObjects that implement construct.
<div id="result">FAILURE</div>
<embed id="testPlugin" type="application/x-webkit-test-netscape" width="200" height="200"></embed>
</body>
</html>
2008-10-24 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
<rdar://problem/5440917> Support NPN_Construct
* WebCore.NPAPI.exp:
Export _NPN_Construct.
* bridge/NP_jsobject.cpp:
(_NPN_Construct):
Implement this.
* bridge/c/c_instance.cpp:
(JSC::Bindings::CInstance::supportsConstruct):
(JSC::Bindings::CInstance::invokeConstruct):
Have this call the appropriate NPClass method.
* bridge/npruntime.h:
Add NPN_Construct.
* bridge/npruntime_impl.h:
Add _NPN_Construct.
* bridge/runtime.h:
(JSC::Bindings::Instance::supportsConstruct):
(JSC::Bindings::Instance::invokeConstruct):
New methods.
* bridge/runtime_object.cpp:
(JSC::callRuntimeConstructor):
Call the native instance.
(JSC::RuntimeObjectImp::getConstructData):
Implement this.
* bridge/runtime_object.h:
Add new method declarations.
* plugins/gtk/PluginPackageGtk.cpp:
(WebCore::PluginPackage::load):
* plugins/qt/PluginPackageQt.cpp:
(WebCore::PluginPackage::load):
* plugins/win/PluginPackageWin.cpp:
(WebCore::PluginPackage::load):
Initialize m_pluginFuncs.construct.
2008-10-24 Adele Peterson <adele@apple.com>
 
Build fix.
......
__NPN_Construct
__NPN_CreateObject
__NPN_Enumerate
__NPN_Evaluate
......
......@@ -72,8 +72,8 @@ static void jsDeallocate(NPObject* npObj)
free(obj);
}
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 };
static NPClass javascriptClass = { 1, jsAllocate, jsDeallocate, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static NPClass noScriptClass = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
NPClass* NPScriptObjectClass = &javascriptClass;
static NPClass* NPNoScriptObjectClass = &noScriptClass;
......@@ -414,4 +414,44 @@ bool _NPN_Enumerate(NPP, NPObject* o, NPIdentifier** identifier, uint32_t* count
return false;
}
bool _NPN_Construct(NPP npp, NPObject* o, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
if (o->_class == NPScriptObjectClass) {
JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o);
VOID_TO_NPVARIANT(*result);
// Lookup the constructor object.
RootObject* rootObject = obj->rootObject;
if (!rootObject || !rootObject->isValid())
return false;
ExecState* exec = rootObject->globalObject()->globalExec();
JSLock lock(false);
// Call the constructor object.
JSValue* constructor = obj->imp;
ConstructData constructData;
ConstructType constructType = constructor->getConstructData(constructData);
if (constructType == ConstructTypeNone)
return false;
ArgList argList;
getListFromVariantArgs(exec, args, argCount, rootObject, argList);
rootObject->globalObject()->startTimeoutCheck();
JSValue* resultV = construct(exec, constructor, constructType, constructData, argList);
rootObject->globalObject()->stopTimeoutCheck();
// Convert and return the result.
convertValueToNPVariant(exec, resultV, result);
exec->clearException();
return true;
}
if (NP_CLASS_STRUCT_VERSION_HAS_CTOR(o->_class) && o->_class->construct)
return o->_class->construct(o, args, argCount, result);
return false;
}
#endif // ENABLE(NETSCAPE_PLUGIN_API)
......@@ -83,7 +83,7 @@ JSValue* CInstance::invokeMethod(ExecState* exec, const MethodList& methodList,
return jsUndefined();
unsigned count = args.size();
Vector<NPVariant, 128> cArgs(count);
Vector<NPVariant, 8> cArgs(count);
unsigned i;
for (i = 0; i < count; i++)
......@@ -113,7 +113,7 @@ JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const ArgList& args)
return jsUndefined();
unsigned count = args.size();
Vector<NPVariant, 128> cArgs(count);
Vector<NPVariant, 8> cArgs(count);
unsigned i;
for (i = 0; i < count; i++)
......@@ -135,6 +135,38 @@ JSValue* CInstance::invokeDefaultMethod(ExecState* exec, const ArgList& args)
return resultValue;
}
bool CInstance::supportsConstruct() const
{
return _object->_class->construct;
}
JSValue* CInstance::invokeConstruct(ExecState* exec, const ArgList& args)
{
if (!_object->_class->construct)
return jsUndefined();
unsigned count = args.size();
Vector<NPVariant, 8> cArgs(count);
unsigned i;
for (i = 0; i < count; i++)
convertValueToNPVariant(exec, args.at(exec, i), &cArgs[i]);
// Invoke the 'C' method.
NPVariant resultVariant;
VOID_TO_NPVARIANT(resultVariant);
{
JSLock::DropAllLocks dropAllLocks(false);
_object->_class->construct(_object, cArgs.data(), count, &resultVariant);
}
for (i = 0; i < count; i++)
_NPN_ReleaseVariantValue(&cArgs[i]);
JSValue* resultValue = convertNPVariantToValue(exec, &resultVariant, _rootObject.get());
_NPN_ReleaseVariantValue(&resultVariant);
return resultValue;
}
JSValue* CInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const
{
......
......@@ -56,6 +56,10 @@ public:
virtual JSValue* invokeMethod(ExecState*, const MethodList&, const ArgList&);
virtual bool supportsInvokeDefaultMethod() const;
virtual JSValue* invokeDefaultMethod(ExecState*, const ArgList&);
virtual bool supportsConstruct() const;
virtual JSValue* invokeConstruct(ExecState*, const ArgList&);
virtual void getPropertyNames(ExecState*, PropertyNameArray&);
JSValue* stringValue(ExecState*) const;
......
......@@ -247,6 +247,7 @@ typedef bool (*NPGetPropertyFunctionPtr)(NPObject *obj, NPIdentifier name, NPVar
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);
typedef bool (*NPConstructFunctionPtr)(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result);
/*
NPObjects returned by create have a reference count of one. It is the caller's responsibility
......@@ -283,12 +284,17 @@ struct NPClass
NPSetPropertyFunctionPtr setProperty;
NPRemovePropertyFunctionPtr removeProperty;
NPEnumerationFunctionPtr enumerate;
NPConstructFunctionPtr construct;
};
#define NP_CLASS_STRUCT_VERSION 2
#define NP_CLASS_STRUCT_VERSION_ENUM 2
#define NP_CLASS_STRUCT_VERSION 3
#define NP_CLASS_STRUCT_VERSION_ENUM 2
#define NP_CLASS_STRUCT_VERSION_CTOR 3
#define NP_CLASS_STRUCT_VERSION_HAS_ENUM(npclass) \
((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM)
#define NP_CLASS_STRUCT_VERSION_HAS_CTOR(npclass) \
((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_CTOR)
struct NPObject {
NPClass *_class;
......
......@@ -55,6 +55,7 @@ extern bool _NPN_HasProperty(NPP, NPObject*, NPIdentifier);
extern bool _NPN_HasMethod(NPP, NPObject*, NPIdentifier);
extern void _NPN_SetException(NPObject*, const NPUTF8*);
extern bool _NPN_Enumerate(NPP, NPObject*, NPIdentifier**, uint32_t* count);
extern bool _NPN_Construct(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant *result);
#ifdef __cplusplus
} /* end extern "C" */
......
......@@ -118,6 +118,9 @@ public:
virtual bool supportsInvokeDefaultMethod() const { return false; }
virtual JSValue* invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); }
virtual bool supportsConstruct() const { return false; }
virtual JSValue* invokeConstruct(ExecState*, const ArgList&) { return 0; }
virtual void getPropertyNames(ExecState*, PropertyNameArray&) { }
virtual JSValue* defaultValue(ExecState*, PreferredPrimitiveType) const = 0;
......
......@@ -221,6 +221,25 @@ CallType RuntimeObjectImp::getCallData(CallData& callData)
return CallTypeHost;
}
JSObject* callRuntimeConstructor(ExecState* exec, JSObject* constructor, const ArgList& args)
{
RefPtr<Instance> instance(static_cast<RuntimeObjectImp*>(constructor)->getInternalInstance());
instance->begin();
JSValue* result = instance->invokeConstruct(exec, args);
instance->end();
ASSERT(result);
return result->isObject() ? static_cast<JSObject*>(result) : constructor;
}
ConstructType RuntimeObjectImp::getConstructData(ConstructData& constructData)
{
if (!instance || !instance->supportsConstruct())
return ConstructTypeNone;
constructData.native.function = callRuntimeConstructor;
return ConstructTypeHost;
}
void RuntimeObjectImp::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
{
if (!instance) {
......
......@@ -40,6 +40,8 @@ public:
virtual bool deleteProperty(ExecState* , const Identifier& propertyName);
virtual JSValue* defaultValue(ExecState*, PreferredPrimitiveType) const;
virtual CallType getCallData(CallData&);
virtual ConstructType getConstructData(ConstructData&);
virtual void getPropertyNames(ExecState*, PropertyNameArray&);
virtual void invalidate();
......
......@@ -239,6 +239,7 @@ bool PluginPackage::load()
m_browserFuncs.hasmethod = _NPN_HasProperty;
m_browserFuncs.setexception = _NPN_SetException;
m_browserFuncs.enumerate = _NPN_Enumerate;
m_browserFuncs.construct = _NPN_Construct;
#if defined(XP_UNIX)
npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
......
......@@ -175,6 +175,7 @@ bool PluginPackage::load()
m_browserFuncs.hasmethod = _NPN_HasProperty;
m_browserFuncs.setexception = _NPN_SetException;
m_browserFuncs.enumerate = _NPN_Enumerate;
m_browserFuncs.construct = _NPN_Construct;
#if defined(XP_UNIX)
npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
......
......@@ -324,6 +324,7 @@ bool PluginPackage::load()
m_browserFuncs.hasmethod = _NPN_HasMethod;
m_browserFuncs.setexception = _NPN_SetException;
m_browserFuncs.enumerate = _NPN_Enumerate;
m_browserFuncs.construct = _NPN_Construct;
npErr = NP_Initialize(&m_browserFuncs);
LOG_NPERROR(npErr);
......
2008-10-24 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
<rdar://problem/5440917> Support NPN_Construct
Set construct.
* Plugins/WebNetscapePluginPackage.m:
(-[WebNetscapePluginPackage load]):
2008-10-24 Mark Rowe <mrowe@apple.com>
Rubber-stamped by Tim Hatcher.
......
......@@ -447,6 +447,7 @@ - (BOOL)load
browserFuncs.removeproperty = (NPN_RemovePropertyProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_RemoveProperty);
browserFuncs.setexception = (NPN_SetExceptionProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_SetException);
browserFuncs.enumerate = (NPN_EnumerateProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_Enumerate);
browserFuncs.construct = (NPN_ConstructProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_Construct);
[self _applyDjVuWorkaround];
......@@ -553,7 +554,8 @@ - (BOOL)load
browserFuncs.removeproperty = _NPN_RemoveProperty;
browserFuncs.setexception = _NPN_SetException;
browserFuncs.enumerate = _NPN_Enumerate;
browserFuncs.construct = _NPN_Construct;
[self _applyDjVuWorkaround];
#if !LOG_DISABLED
......
2008-10-24 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
<rdar://problem/5440917> Support NPN_Construct
* DumpRenderTree/TestNetscapePlugIn.subproj/PluginObject.cpp:
(testCallback):
Fix a memory leak.
(testConstruct):
New test method that treats it first argument as a constructor and invokes it with the rest of the arguments.
(pluginInvoke):
Handle testConstruct.
* DumpRenderTree/TestNetscapePlugIn.subproj/TestObject.cpp:
(testGetProperty):
Add objectPointer property.
(testEnumerate):
Only enumerate the two first properties.
(testConstruct):
Add a simple construct implementation that just returns the test object.
2008-10-24 David Kilzer <ddkilzer@apple.com>
 
Bug 21850: svn-apply and svn-unapply should preserve patch line endings
......
......@@ -94,7 +94,8 @@ static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
#define ID_TEST_IDENTIFIER_TO_STRING 12
#define ID_TEST_IDENTIFIER_TO_INT 13
#define ID_TEST_POSTURL_FILE 14
#define NUM_METHOD_IDENTIFIERS 15
#define ID_TEST_CONSTRUCT 15
#define NUM_METHOD_IDENTIFIERS 16
static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
......@@ -113,6 +114,7 @@ static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
"testIdentifierToString",
"testIdentifierToInt",
"testPostURLFile",
"testConstruct",
};
static NPUTF8* createCStringFromNPVariant(const NPVariant* variant)
......@@ -291,6 +293,8 @@ static bool testCallback(PluginObject* obj, const NPVariant* args, uint32_t argC
browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, 0, 0, &browserResult);
browser->releasevariantvalue(&browserResult);
browser->releaseobject(windowScriptObject);
VOID_TO_NPVARIANT(*result);
return true;
}
......@@ -523,6 +527,14 @@ static bool testPostURLFile(PluginObject* obj, const NPVariant* args, uint32_t a
return true;
}
static bool testConstruct(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
if (!argCount || !NPVARIANT_IS_OBJECT(args[0]))
return false;
return browser->construct(obj->npp, NPVARIANT_TO_OBJECT(args[0]), args + 1, argCount - 1, result);
}
static bool pluginInvoke(NPObject* header, NPIdentifier name, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
PluginObject* plugin = reinterpret_cast<PluginObject*>(header);
......@@ -556,7 +568,9 @@ static bool pluginInvoke(NPObject* header, NPIdentifier name, const NPVariant* a
return testIdentifierToInt(plugin, args, argCount, result);
else if (name == pluginMethodIdentifiers[ID_TEST_POSTURL_FILE])
return testPostURLFile(plugin, args, argCount, result);
else if (name == pluginMethodIdentifiers[ID_TEST_CONSTRUCT])
return testConstruct(plugin, args, argCount, result);
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment