简体   繁体   English

从Javascript访问NPAPI插件的属性

[英]Accessing property of NPAPI plugin from Javascript

Have a problem when try to get a value of a property via Javascript using a NPAPI plugin; 尝试使用NPAPI插件通过Javascript获取属性值时遇到问题; During the debugging I see that all the chain of functions (HasProperty, HasMethod, and GetProperty) are called. 在调试期间,我看到所有函数链(HasProperty,HasMethod和GetProperty)都已调用。 More over I see that during calling GetProperty I set the new values into the result parameter. 而且,我看到在调用GetProperty时,我将新值设置为result参数。 But after leaving GetProperty I get an exception and can't understand what the reason of it. 但是离开GetProperty后,我得到一个异常,无法理解其原因。

May FireFox call some additional functions which I forgot to initialize? FireFox可以调用一些我忘记初始化的附加功能吗?

Thanks in advance 提前致谢

My code is: 我的代码是:

// static function which calls Get_Property for the instance of CScriptableNPObject
bool CScriptableNPObject::NP_GetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
{
    m_Logs.WriteLogs(10, _T("Enter the CScriptableNPObject::NP_GetProperty()"));

    return ((CScriptableNPObject *)npobj)->GetProperty(name, result);
}

// just converter name from NPIdentifier to char *
bool CScriptableNPObject::GetProperty(NPIdentifier name, NPVariant *result)
{
    NPUTF8 *pszProperty = m_pNPNFuncs->utf8fromidentifier(name);

    return GetProperty(pszProperty, result);
}

// checking the dictionary of properties, if property exists put its value into the result
bool CScriptableNPObject::GetProperty(NPUTF8 *pszProperty, NPVariant *result)
{
    VOID_TO_NPVARIANT(*result);

    JSPropertiesMap::iterator it = m_JSProperties.find(pszProperty);

    if (it == m_JSProperties.end())
        return false;

    NPUTF8 *pszNewPropertyValue = new NPUTF8[it->second->value.stringValue.UTF8Length + 1];
    sprintf(pszNewPropertyValue, it->second->value.stringValue.UTF8Characters);

    STRINGZ_TO_NPVARIANT(pszNewPropertyValue, *result);

    return true;
}

您需要使用NPN_MemAlloc()

NPUTF8* newValue = NPN_MemAlloc(length + 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM