JSPluginElementFunctions.cpp [plain text]
#include "config.h"
#include "JSPluginElementFunctions.h"
#include "Bridge.h"
#include "HTMLNames.h"
#include "HTMLPlugInElement.h"
#include "JSHTMLElement.h"
#include "runtime_object.h"
using namespace JSC;
namespace WebCore {
using namespace Bindings;
using namespace HTMLNames;
Instance* pluginInstance(Node* node)
{
if (!node)
return 0;
if (!(node->hasTagName(objectTag) || node->hasTagName(embedTag) || node->hasTagName(appletTag)))
return 0;
HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(node);
Instance* instance = plugInElement->getInstance().get();
if (!instance || !instance->rootObject())
return 0;
return instance;
}
static RuntimeObject* getRuntimeObject(ExecState* exec, Node* node)
{
Instance* instance = pluginInstance(node);
if (!instance)
return 0;
return instance->createRuntimeObject(exec);
}
JSValue runtimeObjectPropertyGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
{
JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(asObject(slotBase));
HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
RuntimeObject* runtimeObject = getRuntimeObject(exec, element);
if (!runtimeObject)
return jsUndefined();
return runtimeObject->get(exec, propertyName);
}
bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, JSHTMLElement* element)
{
RuntimeObject* runtimeObject = getRuntimeObject(exec, element->impl());
if (!runtimeObject)
return false;
if (!runtimeObject->hasProperty(exec, propertyName))
return false;
slot.setCustom(element, runtimeObjectPropertyGetter);
return true;
}
bool runtimeObjectCustomGetOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor, JSHTMLElement* element)
{
RuntimeObject* runtimeObject = getRuntimeObject(exec, element->impl());
if (!runtimeObject)
return false;
if (!runtimeObject->hasProperty(exec, propertyName))
return false;
PropertySlot slot;
slot.setCustom(element, runtimeObjectPropertyGetter);
descriptor.setDescriptor(slot.getValue(exec, propertyName), DontEnum | DontDelete);
return true;
}
bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue value, HTMLElement* element, PutPropertySlot& slot)
{
RuntimeObject* runtimeObject = getRuntimeObject(exec, element);
if (!runtimeObject)
return 0;
if (!runtimeObject->hasProperty(exec, propertyName))
return false;
runtimeObject->put(exec, propertyName, value, slot);
return true;
}
static JSValue JSC_HOST_CALL callPlugin(ExecState* exec, JSObject* function, JSValue, const ArgList& args)
{
Instance* instance = pluginInstance(static_cast<JSHTMLElement*>(function)->impl());
instance->begin();
JSValue result = instance->invokeDefaultMethod(exec, args);
instance->end();
return result;
}
CallType runtimeObjectGetCallData(HTMLElement* element, CallData& callData)
{
Instance* instance = pluginInstance(element);
if (!instance || !instance->supportsInvokeDefaultMethod())
return CallTypeNone;
callData.native.function = callPlugin;
return CallTypeHost;
}
}