bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); IdentifierRep* i = static_cast<IdentifierRep*>(methodName); if (!i->isString()) return false; RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); JSValue func = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); exec->clearException(); return !func.isUndefined(); } if (o->_class->hasMethod) return o->_class->hasMethod(o, methodName); return false; }
bool _NPN_HasProperty(NPP, NPObject* o, NPIdentifier propertyName) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); JSLock lock(SilenceAssertionsOnly); if (i->isString()) { bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string())); exec->clearException(); return result; } bool result = obj->imp->hasProperty(exec, i->number()); exec->clearException(); return result; } if (o->_class->hasProperty) return o->_class->hasProperty(o, propertyName); return false; }
bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); if (i->isString()) { PutPropertySlot slot; obj->imp->put(exec, identifierFromNPIdentifier(i->string()), convertNPVariantToValue(exec, variant, rootObject), slot); } else obj->imp->put(exec, i->number(), convertNPVariantToValue(exec, variant, rootObject)); exec->clearException(); return true; } if (o->_class->setProperty) return o->_class->setProperty(o, propertyName, variant); return false; }
bool _NPN_GetProperty(NPP, NPObject* o, NPIdentifier propertyName, NPVariant* variant) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); JSLock lock(SilenceAssertionsOnly); JSValue result; if (i->isString()) result = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); else result = obj->imp->get(exec, i->number()); convertValueToNPVariant(exec, result, variant); exec->clearException(); return true; } if (o->_class->hasProperty && o->_class->getProperty) { if (o->_class->hasProperty(o, propertyName)) return o->_class->getProperty(o, propertyName, variant); return false; } VOID_TO_NPVARIANT(*variant); return false; }
bool _NPN_Enumerate(NPP, NPObject* o, NPIdentifier** identifier, uint32_t* count) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); PropertyNameArray propertyNames(exec); obj->imp->getPropertyNames(exec, propertyNames); unsigned size = static_cast<unsigned>(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; exec->clearException(); return true; } if (NP_CLASS_STRUCT_VERSION_HAS_ENUM(o->_class) && o->_class->enumerate) return o->_class->enumerate(o, identifier, count); return false; }
bool _NPN_Construct(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(SilenceAssertionsOnly); // Call the constructor object. JSValue constructor = obj->imp; ConstructData constructData; ConstructType constructType = constructor.getConstructData(constructData); if (constructType == ConstructTypeNone) return false; MarkedArgumentBuffer argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValue resultV = JSC::construct(exec, constructor, constructType, constructData, argList); globalObject->globalData()->timeoutChecker.stop(); // 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; }
bool _NPN_InvokeDefault(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 function object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(SilenceAssertionsOnly); // Call the function object. JSValue function = obj->imp; CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) return false; MarkedArgumentBuffer argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); globalObject->globalData()->timeoutChecker.start(); JSValue resultV = JSC::call(exec, function, callType, callData, function, argList); globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); exec->clearException(); return true; } if (o->_class->invokeDefault) return o->_class->invokeDefault(o, args, argCount, result); VOID_TO_NPVARIANT(*result); return true; }
bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); IdentifierRep* i = static_cast<IdentifierRep*>(methodName); if (!i->isString()) return false; // Special case the "eval" method. if (methodName == _NPN_GetStringIdentifier("eval")) { if (argCount != 1) return false; if (args[0].type != NPVariantType_String) return false; return _NPN_Evaluate(npp, o, const_cast<NPString*>(&args[0].value.stringValue), result); } // Look up the function object. RootObject* rootObject = obj->rootObject; if (!rootObject || !rootObject->isValid()) return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLockHolder lock(exec); JSValue function = obj->imp->get(exec, identifierFromNPIdentifier(exec, i->string())); CallData callData; CallType callType = getCallData(function, callData); if (callType == CallTypeNone) return false; // Call the function object. MarkedArgumentBuffer argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); JSValue resultV = JSC::call(exec, function, callType, callData, obj->imp, argList); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); exec->clearException(); return true; } if (o->_class->invoke) return o->_class->invoke(o, methodName, args, argCount, result); VOID_TO_NPVARIANT(*result); return true; }
void WebMediaPlayerProxy::invokeMethod(const String& methodName) { Frame* frame = element()->document()->frame(); RootObject *root = frame->script()->bindingRootObject(); if (!root) return; ExecState *exec = root->globalObject()->globalExec(); Instance* instance = pluginInstance().get(); if (!instance) return; instance->begin(); Class *aClass = instance->getClass(); Identifier iden(exec, methodName); MethodList methodList = aClass->methodsNamed(iden, instance); ArgList args; instance->invokeMethod(exec, methodList , args); instance->end(); }