bool GnashPluginScriptObject::Invoke(NPObject */* npobj */, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { // log_debug(__PRETTY_FUNCTION__); #if 1 if (NPN_IdentifierIsString(name)) { log_debug("Invoking Method \"%s\"...", NPN_UTF8FromIdentifier(name)); } else { log_debug("Invoking Method: \"%d\"...", NPN_IntFromIdentifier(name)); } // log_debug("SCRIPT OBJECT invoke %s: %x", NPN_UTF8FromIdentifier(name), // (void *)npobj); #endif std::map<NPIdentifier, NPInvokeFunctionPtr>::iterator it; it = _methods.find(name); if (it != _methods.end()) { // log_debug("FOUND Method \"%s\"!", NPN_UTF8FromIdentifier(name)); NPInvokeFunctionPtr func = it->second; return func(this, name, args, argCount, result); } else { log_error("Couldn't find Method \"%s\"", NPN_UTF8FromIdentifier(name)); } return false; // return NPN_Invoke(nppinstance, this, name, args, argCount, result); }
bool JsObjectWrapper::getInfo(NPIdentifier name, TypeMemberInfo& info) { if(!getTypeInfo()) return false; if(NPN_IdentifierIsString(name)) { NPUTF8* id = NPN_UTF8FromIdentifier(name); MembersByName_t::const_iterator it = m_byName.find(id); NPN_MemFree(id); if(it == m_byName.end()) return false; info = it->second; return true; } else if(m_indexerLength >= 0) { uint32_t index = NPN_IntFromIdentifier(name); if(index < m_indexerLength) { info.dispatchType = DT_PropertyGet | DT_PropertySet; //info.memberId = index; return true; } } return false; }
static bool HasProperty(NPObject *obj, NPIdentifier propertyName) { printf("*** HasProperty(%p)\n", propertyName); if (NPN_IdentifierIsString(propertyName)) { printf("*** is a string\n"); char *name = NPN_UTF8FromIdentifier(propertyName); printf("*** HasProperty(string %s)\n", name); } else { int i = NPN_IntFromIdentifier(propertyName); printf("*** HasProperty(int %d)\n", i); } return false; }
const char* debugName(NPIdentifier name) { static char buf[1024]; if(NPN_IdentifierIsString(name)) { NPUTF8* strName = NPN_UTF8FromIdentifier(name); sprintf_s(buf, sizeof(buf), "'%s'", strName); NPN_MemFree(strName); } else { int intName = NPN_IntFromIdentifier(name); sprintf_s(buf, sizeof(buf), "%d", intName); } return buf; }
bool GnashPluginScriptObject::HasMethod(NPIdentifier name) { #if 0 log_debug("Checking for Method \""); if (NPN_IdentifierIsString(name)) { log_debug("%s\"...", NPN_UTF8FromIdentifier(name)); } else { log_debug("%d\"...", NPN_IntFromIdentifier(name)); } #endif return _methods.find(name) != _methods.end(); }
bool GnashPluginScriptObject::InvokeDefault(const NPVariant */* args */, uint32_t /* argCount */, NPVariant */* result */) { log_debug(__PRETTY_FUNCTION__); #if 0 log_debug("Invoking Default Method \""); if (NPN_IdentifierIsString(name)) { log_debug("%s\"...", NPN_UTF8FromIdentifier(name)); } else { log_debug("%d\"...", NPN_IntFromIdentifier(name)); } #endif return false; }
DispatchIdentifier CreateDispatchIdentifier(NPIdentifier name) { static char buf[1024]; DispatchIdentifier ret; if(NPN_IdentifierIsString(name)) { NPUTF8* strName = NPN_UTF8FromIdentifier(name); ret.tag = IT_String; ret.name = strName; NPN_MemFree(strName); } else { int id = NPN_IntFromIdentifier(name); ret.tag = IT_Int; ret.id = id; } return ret; }
bool GnashPluginScriptObject::AddMethod(NPIdentifier name, NPInvokeFunctionPtr func) { // log_debug(__PRETTY_FUNCTION__); #if 0 if (NPN_IdentifierIsString(name)) { log_debug("Adding Method \"%s\"...", NPN_UTF8FromIdentifier(name)); } else { log_debug("Adding Method \"%d\"...", NPN_IntFromIdentifier(name)); } #endif _methods[name] = func; return true; }
bool GnashPluginScriptObject::marshalHasMethod (NPObject *npobj, NPIdentifier name) { // log_debug(__PRETTY_FUNCTION__); GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj; #if 0 log_debug("Checking for Method: "); if (NPN_IdentifierIsString(name)) { log_debug("%s", NPN_UTF8FromIdentifier(name)); } else { log_debug("%d", NPN_IntFromIdentifier(name)); } #endif return gpso->HasMethod(name); }
bool GnashPluginScriptObject::GetProperty(NPIdentifier name, NPVariant *result) { if (NPN_IdentifierIsString(name)) { log_debug("Getting Property \"%s\"...", NPN_UTF8FromIdentifier(name)); } else { log_debug("Getting Property \"%d\"...", NPN_IntFromIdentifier(name)); } std::map<NPIdentifier, GnashNPVariant>::const_iterator it; it = _properties.find(name); if (it == _properties.end()) { return false; } const GnashNPVariant& val = it->second; val.copy(*result); return true; };
// Sends something like this: // <invoke name="TestASMethod" returntype="xml"> // <arguments> // <number>123</number> // </arguments> // </invoke> // // Receives: // An XML response of one of the standard types like Number or String. bool remoteCallback (NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { // log_debug(__PRETTY_FUNCTION__); GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj; std::string method; #if 1 if (NPN_IdentifierIsString(name)) { log_debug("Invoking remote Method \"%s\"...", NPN_UTF8FromIdentifier(name)); method = NPN_UTF8FromIdentifier(name); } else { log_debug("Invoking remote Method: \"%d\"...", NPN_IntFromIdentifier(name)); } #endif // Build the argument array std::vector<std::string> fnargs; for (uint32_t i=0; i<argCount; ++i) { std::string xml = plugin::ExternalInterface::convertNPVariant(&args[i]); fnargs.push_back(xml); } std::string str = plugin::ExternalInterface::makeInvoke(method, fnargs); // Write the message to the Control FD. size_t ret = gpso->writePlayer(str); // Unless we wrote the same amount of data as the message contained, // something went wrong. if (ret != str.size()) { log_error("Couldn't invoke %s, network problems.", method); return false; } // Have the read function allocate the memory std::string data = gpso->readPlayer(); if (data.empty()) { log_error("Couldn't read a response for invoke, network problems."); NULL_TO_NPVARIANT(*result); return false; } std::string answer; GnashNPVariant parsed = plugin::ExternalInterface::parseXML(data); if (!NPVARIANT_IS_NULL(parsed.get())) { answer = NPStringToString(NPVARIANT_TO_STRING(parsed.get())); } if (answer == "Error") { NULL_TO_NPVARIANT(*result); } else if (answer == "SecurityError") { NULL_TO_NPVARIANT(*result); } else { parsed.copy(*result); } // printNPVariant(&parsed.get()); // Returning false makes Javascript stop executing the script. return true; }