Commit cd8b895e authored by andersca@apple.com's avatar andersca@apple.com

2009-01-26 Anders Carlsson <andersca@apple.com>

        Reviewed by Sam Weinig.

        Implement using plug-in objects as constructors, and setting and getting properties from a plug-in object.
        
        * Plugins/Hosted/NetscapePluginHostProxy.mm:
        (WKPCBooleanAndDataReply):
        * Plugins/Hosted/NetscapePluginInstanceProxy.h:
        (WebKit::NetscapePluginInstanceProxy::Reply::):
        (WebKit::NetscapePluginInstanceProxy::BooleanAndDataReply::BooleanAndDataReply):
        Rename NPObjectInvokeReply to BooleanAndDataReply.
        
        * Plugins/Hosted/NetscapePluginInstanceProxy.mm:
        (WebKit::NetscapePluginInstanceProxy::addValueToArray):
        Fix a cut and paste error.
        
        (WebKit::NetscapePluginInstanceProxy::demarshalValueFromArray):
        Handle NPObjects.
        
        * Plugins/Hosted/ProxyInstance.h:
        * Plugins/Hosted/ProxyInstance.mm:
        (WebKit::ProxyField::valueFromInstance):
        (WebKit::ProxyField::setValueToInstance):
        Call the ProxyInstance method.
        
        (WebKit::ProxyInstance::~ProxyInstance):
        Release the NPObject.
        
        (WebKit::ProxyInstance::supportsConstruct):
        Ask the plug-in host if an instance supports construct.
        
        (WebKit::ProxyInstance::fieldValue):
        (WebKit::ProxyInstance::setFieldValue):
        Call the plug-in host methods.
        
        * Plugins/Hosted/WebKitPluginHostTypes.h:
        Rename ObjectValueType to JSObjectValueType, and add NPObjectValueType.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@40263 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0038c003
2009-01-26 Anders Carlsson <andersca@apple.com>
Reviewed by Sam Weinig.
Implement using plug-in objects as constructors, and setting and getting properties from a plug-in object.
* Plugins/Hosted/NetscapePluginHostProxy.mm:
(WKPCBooleanAndDataReply):
* Plugins/Hosted/NetscapePluginInstanceProxy.h:
(WebKit::NetscapePluginInstanceProxy::Reply::):
(WebKit::NetscapePluginInstanceProxy::BooleanAndDataReply::BooleanAndDataReply):
Rename NPObjectInvokeReply to BooleanAndDataReply.
* Plugins/Hosted/NetscapePluginInstanceProxy.mm:
(WebKit::NetscapePluginInstanceProxy::addValueToArray):
Fix a cut and paste error.
(WebKit::NetscapePluginInstanceProxy::demarshalValueFromArray):
Handle NPObjects.
* Plugins/Hosted/ProxyInstance.h:
* Plugins/Hosted/ProxyInstance.mm:
(WebKit::ProxyField::valueFromInstance):
(WebKit::ProxyField::setValueToInstance):
Call the ProxyInstance method.
(WebKit::ProxyInstance::~ProxyInstance):
Release the NPObject.
(WebKit::ProxyInstance::supportsConstruct):
Ask the plug-in host if an instance supports construct.
(WebKit::ProxyInstance::fieldValue):
(WebKit::ProxyInstance::setFieldValue):
Call the plug-in host methods.
* Plugins/Hosted/WebKitPluginHostTypes.h:
Rename ObjectValueType to JSObjectValueType, and add NPObjectValueType.
2009-01-26 Mark Rowe <mrowe@apple.com>
Fix the build.
......
......@@ -254,7 +254,7 @@ kern_return_t WKPCBooleanReply(mach_port_t clientPort, uint32_t pluginID, boolea
return KERN_SUCCESS;
}
kern_return_t WKPCNPObjectInvokeReply(mach_port_t clientPort, uint32_t pluginID, boolean_t returnValue, data_t resultData, mach_msg_type_number_t resultLength)
kern_return_t WKPCBooleanAndDataReply(mach_port_t clientPort, uint32_t pluginID, boolean_t returnValue, data_t resultData, mach_msg_type_number_t resultLength)
{
NetscapePluginHostProxy* hostProxy = pluginProxyMap().get(clientPort);
if (!hostProxy)
......@@ -265,7 +265,7 @@ kern_return_t WKPCNPObjectInvokeReply(mach_port_t clientPort, uint32_t pluginID,
return KERN_FAILURE;
RetainPtr<CFDataRef> result = CFDataCreate(0, reinterpret_cast<UInt8*>(resultData), resultLength);
instanceProxy->setCurrentReply(new NetscapePluginInstanceProxy::NPObjectInvokeReply(returnValue, result));
instanceProxy->setCurrentReply(new NetscapePluginInstanceProxy::BooleanAndDataReply(returnValue, result));
return KERN_SUCCESS;
}
......
......@@ -113,6 +113,7 @@ public:
PassRefPtr<JSC::Bindings::Instance> createBindingsInstance(PassRefPtr<JSC::Bindings::RootObject>);
RetainPtr<NSData *> marshalValues(JSC::ExecState*, const JSC::ArgList& args);
void marshalValue(JSC::ExecState*, JSC::JSValuePtr value, data_t& resultData, mach_msg_type_number_t& resultLength);
JSC::JSValuePtr demarshalValue(JSC::ExecState*, const char* valueData, mach_msg_type_number_t valueLength);
// Reply structs
......@@ -120,7 +121,7 @@ public:
enum Type {
InstantiatePlugin,
GetScriptableNPObject,
NPObjectInvoke,
BooleanAndData,
Boolean
};
......@@ -170,10 +171,10 @@ public:
boolean_t m_result;
};
struct NPObjectInvokeReply : public Reply {
static const Reply::Type ReplyType = NPObjectInvoke;
struct BooleanAndDataReply : public Reply {
static const Reply::Type ReplyType = BooleanAndData;
NPObjectInvokeReply(boolean_t returnValue, RetainPtr<CFDataRef> result)
BooleanAndDataReply(boolean_t returnValue, RetainPtr<CFDataRef> result)
: Reply(ReplyType)
, m_returnValue(returnValue)
, m_result(result)
......@@ -237,7 +238,6 @@ private:
// NPRuntime
uint32_t idForObject(JSC::JSObject*);
void marshalValue(JSC::ExecState*, JSC::JSValuePtr value, data_t& resultData, mach_msg_type_number_t& resultLength);
void addValueToArray(NSMutableArray *, JSC::ExecState* exec, JSC::JSValuePtr value);
bool demarshalValueFromArray(JSC::ExecState*, NSArray *array, NSUInteger& index, JSC::JSValuePtr& result);
......
......@@ -797,7 +797,7 @@ void NetscapePluginInstanceProxy::addValueToArray(NSMutableArray *array, ExecSta
[array addObject:[NSNumber numberWithDouble:value.toNumber(exec)]];
} else if (value.isBoolean()) {
[array addObject:[NSNumber numberWithInt:BoolValueType]];
[array addObject:[NSNumber numberWithDouble:value.toBoolean(exec)]];
[array addObject:[NSNumber numberWithBool:value.toBoolean(exec)]];
} else if (value.isNull())
[array addObject:[NSNumber numberWithInt:NullValueType]];
else if (value.isObject()) {
......@@ -806,7 +806,7 @@ void NetscapePluginInstanceProxy::addValueToArray(NSMutableArray *array, ExecSta
// FIXME: Handle ProxyInstance objects.
ASSERT_NOT_REACHED();
} else {
[array addObject:[NSNumber numberWithInt:ObjectValueType]];
[array addObject:[NSNumber numberWithInt:JSObjectValueType]];
[array addObject:[NSNumber numberWithInt:idForObject(object)]];
}
} else
......@@ -866,14 +866,32 @@ bool NetscapePluginInstanceProxy::demarshalValueFromArray(ExecState* exec, NSArr
result = jsString(exec, String(string));
return true;
}
case ObjectValueType: {
case JSObjectValueType: {
uint32_t objectID = [[array objectAtIndex:index++] intValue];
result = m_objects.get(objectID);
ASSERT(result);
return true;
}
case NPObjectValueType: {
uint32_t objectID = [[array objectAtIndex:index++] intValue];
Frame* frame = core([m_pluginView webFrame]);
if (!frame)
return false;
if (!frame->script()->isEnabled())
return false;
RefPtr<RootObject> rootObject = frame->script()->createRootObject(m_pluginView);
if (!rootObject)
return false;
result = ProxyInstance::create(rootObject.release(), this, objectID)->createRuntimeObject(exec);
return true;
}
default:
ASSERT_NOT_REACHED();
return false;
}
}
......
......@@ -49,15 +49,22 @@ public:
JSC::Bindings::MethodList methodsNamed(const JSC::Identifier&);
JSC::Bindings::Field* fieldNamed(const JSC::Identifier&);
JSC::JSValuePtr fieldValue(JSC::ExecState*, const JSC::Bindings::Field*) const;
void setFieldValue(JSC::ExecState*, const JSC::Bindings::Field*, JSC::JSValuePtr) const;
private:
ProxyInstance(PassRefPtr<JSC::Bindings::RootObject>, NetscapePluginInstanceProxy*, uint32_t objectID);
virtual JSC::Bindings::Class *getClass() const;
virtual JSC::JSValuePtr invokeMethod(JSC::ExecState*, const JSC::Bindings::MethodList&, const JSC::ArgList& args);
virtual bool supportsInvokeDefaultMethod() const;
virtual JSC::JSValuePtr invokeDefaultMethod(JSC::ExecState*, const JSC::ArgList&);
virtual bool supportsConstruct() const;
virtual JSC::JSValuePtr invokeConstruct(JSC::ExecState*, const JSC::ArgList&);
virtual JSC::JSValuePtr defaultValue(JSC::ExecState*, JSC::PreferredPrimitiveType) const;
virtual JSC::JSValuePtr valueOf(JSC::ExecState*) const;
......@@ -65,7 +72,7 @@ private:
JSC::JSValuePtr numberValue(JSC::ExecState*) const;
JSC::JSValuePtr booleanValue() const;
virtual JSC::JSValuePtr invoke(JSC::ExecState*, InvokeType, uint64_t identifier, const JSC::ArgList& args);
JSC::JSValuePtr invoke(JSC::ExecState*, InvokeType, uint64_t identifier, const JSC::ArgList& args);
NetscapePluginInstanceProxy* m_instanceProxy;
uint32_t m_objectID;
......
......@@ -70,6 +70,8 @@ public:
{
}
uint64_t serverIdentifier() const { return m_serverIdentifier; }
private:
virtual JSValuePtr valueFromInstance(ExecState*, const Instance*) const;
virtual void setValueToInstance(ExecState*, const Instance*, JSValuePtr) const;
......@@ -77,15 +79,14 @@ private:
uint64_t m_serverIdentifier;
};
JSValuePtr ProxyField::valueFromInstance(ExecState*, const Instance*) const
JSValuePtr ProxyField::valueFromInstance(ExecState* exec, const Instance* instance) const
{
ASSERT_NOT_REACHED();
return JSValuePtr();
return static_cast<const ProxyInstance*>(instance)->fieldValue(exec, this);
}
void ProxyField::setValueToInstance(ExecState*, const Instance*, JSValuePtr) const
void ProxyField::setValueToInstance(ExecState* exec, const Instance* instance, JSValuePtr value) const
{
ASSERT_NOT_REACHED();
static_cast<const ProxyInstance*>(instance)->setFieldValue(exec, this, value);
}
class ProxyMethod : public JSC::Bindings::Method {
......@@ -115,7 +116,8 @@ ProxyInstance::~ProxyInstance()
deleteAllValues(m_fields);
deleteAllValues(m_methods);
// FIXME: Tell the host that we're no longer interested in this object.
_WKPHNPObjectRelease(m_instanceProxy->hostProxy()->port(),
m_instanceProxy->pluginID(), m_objectID);
}
JSC::Bindings::Class *ProxyInstance::getClass() const
......@@ -131,7 +133,7 @@ JSValuePtr ProxyInstance::invoke(JSC::ExecState* exec, InvokeType type, uint64_t
type, identifier, (char*)[arguments.get() bytes], [arguments.get() length]) != KERN_SUCCESS)
return jsUndefined();
auto_ptr<NetscapePluginInstanceProxy::NPObjectInvokeReply> reply = m_instanceProxy->waitForReply<NetscapePluginInstanceProxy::NPObjectInvokeReply>();
auto_ptr<NetscapePluginInstanceProxy::BooleanAndDataReply> reply = m_instanceProxy->waitForReply<NetscapePluginInstanceProxy::BooleanAndDataReply>();
if (!reply.get() || !reply->m_returnValue)
return jsUndefined();
......@@ -166,6 +168,25 @@ JSValuePtr ProxyInstance::invokeDefaultMethod(ExecState* exec, const ArgList& ar
return invoke(exec, InvokeDefault, 0, args);
}
bool ProxyInstance::supportsConstruct() const
{
if (_WKPHNPObjectHasConstructMethod(m_instanceProxy->hostProxy()->port(),
m_instanceProxy->pluginID(),
m_objectID) != KERN_SUCCESS)
return false;
auto_ptr<NetscapePluginInstanceProxy::BooleanReply> reply = m_instanceProxy->waitForReply<NetscapePluginInstanceProxy::BooleanReply>();
if (reply.get() && reply->m_result)
return true;
return false;
}
JSValuePtr ProxyInstance::invokeConstruct(ExecState* exec, const ArgList& args)
{
return invoke(exec, Construct, 0, args);
}
JSValuePtr ProxyInstance::defaultValue(ExecState* exec, PreferredPrimitiveType hint) const
{
if (hint == PreferString)
......@@ -249,6 +270,40 @@ Field* ProxyInstance::fieldNamed(const Identifier& identifier)
return 0;
}
JSC::JSValuePtr ProxyInstance::fieldValue(ExecState* exec, const Field* field) const
{
uint64_t serverIdentifier = static_cast<const ProxyField*>(field)->serverIdentifier();
if (_WKPHNPObjectGetProperty(m_instanceProxy->hostProxy()->port(),
m_instanceProxy->pluginID(),
m_objectID, serverIdentifier) != KERN_SUCCESS)
return jsUndefined();
auto_ptr<NetscapePluginInstanceProxy::BooleanAndDataReply> reply = m_instanceProxy->waitForReply<NetscapePluginInstanceProxy::BooleanAndDataReply>();
if (!reply.get() || !reply->m_returnValue)
return jsUndefined();
return m_instanceProxy->demarshalValue(exec, (char*)CFDataGetBytePtr(reply->m_result.get()), CFDataGetLength(reply->m_result.get()));
}
void ProxyInstance::setFieldValue(ExecState* exec, const Field* field, JSValuePtr value) const
{
uint64_t serverIdentifier = static_cast<const ProxyField*>(field)->serverIdentifier();
data_t valueData;
mach_msg_type_number_t valueLength;
m_instanceProxy->marshalValue(exec, value, valueData, valueLength);
kern_return_t kr = _WKPHNPObjectSetProperty(m_instanceProxy->hostProxy()->port(),
m_instanceProxy->pluginID(),
m_objectID, serverIdentifier, valueData, valueLength);
mig_deallocate(reinterpret_cast<vm_address_t>(valueData), valueLength);
if (kr != KERN_SUCCESS)
return;
auto_ptr<NetscapePluginInstanceProxy::BooleanReply> reply = m_instanceProxy->waitForReply<NetscapePluginInstanceProxy::BooleanReply>();
}
} // namespace WebKit
#endif // USE(PLUGIN_HOST_PROCESS)
......
......@@ -152,7 +152,7 @@ simpleroutine BooleanReply(clientPort :mach_port_t;
pluginID :uint32_t;
result :boolean_t);
simpleroutine NPObjectInvokeReply(clientPort :mach_port_t;
simpleroutine BooleanAndDataReply(clientPort :mach_port_t;
pluginID :uint32_t;
returnValue :boolean_t;
result :data_t);
......
......@@ -149,6 +149,21 @@ simpleroutine NPObjectHasConstructMethod(pluginHostPort :mach_port_t;
pluginID :uint32_t;
objectID :uint32_t);
simpleroutine NPObjectGetProperty(pluginHostPort :mach_port_t;
pluginID :uint32_t;
objectID :uint32_t;
propertyName :uint64_t);
simpleroutine NPObjectSetProperty(pluginHostPort :mach_port_t;
pluginID :uint32_t;
objectID :uint32_t;
propertyName :uint64_t;
value :data_t);
simpleroutine NPObjectRelease(pluginHostPort :mach_port_t;
pluginID :uint32_t;
objectID :uint32_t);
// Replies
simpleroutine EvaluateReply(pluginHostPort :mach_port_t;
......
......@@ -54,7 +54,8 @@ enum ValueType {
BoolValueType,
DoubleValueType,
StringValueType,
ObjectValueType
JSObjectValueType,
NPObjectValueType
};
#endif // WebKitPluginHostTypes_h
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