1

I am writing a simple napapi plugin where I have to print the value passed from javascript function in html page. But I am facing problem while doing it. It works properly on firefox. But I want to do it on qt fancybrowser example. The value printed is always 0 no matter whatever value I pass in javascript code.

The javascript code is as follows :

<html>
.....
<script>
function process_data()
{
    PluginObject = document.getElementById("Object");
    var i =100;
    if(PluginObject){
        ret = PluginObject.process_Data(i); 
    }
}
</script>
....
</html>

The plugin code is as follows :

.....
bool ScriptableObject::process_Data(const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    printf(" process_Data\n");
    printf("\t argCount : %d\n",argCount);

    int tempi =args[0].value.intValue; 
    int tempf =args[0].value.doubleValue; 

        printf("type: %d type: %u\n",args[0].type,args[0].type);
    printf("tempi : %d tempf : %f\n",tempi,tempf);
}
......

The output is as follows :

process_Data
     argCount : 1
type: 4 type: 4
tempi : 0 tempf : 0.000000

Actually it should print 100 which is the value passed in var i from javascript.

Any suggestions/comments are welcome

Thanks in advance

4

2 回答 2

1

当为 NPAPI 方法提供数字参数时,不确定您是否会收到一个Int32Double变体,因此您必须在代码中处理这两种情况。
此外,NPVARIANT_TO_*宏只提取相应的值——它们不进行任何转换。

要从任何数字参数中提取整数,您必须编写自己的代码,例如:

bool convertToInt(const NPVariant& v, int32_t& out) {
  if (NPVARIANT_IS_INT32(v)) {
    out = NPVARIANT_TO_INT32(v);
    return true;
  }

  if (NPVARIANT_IS_DOUBLE(v)) {
    out = NPVARIANT_TO_DOUBLE(v);
    return true;
  }

  // not a numeric variant
  return false;
}
于 2013-02-02T14:09:48.497 回答
-1

从这里http://code.google.com/p/chromium/issues/detail?id=68175和这里https://bugs.webkit.org/show_bug.cgi?id=49036我知道这是 WEB 中的错误套件,所以我在“npruntime.h”中添加下一个:

#define FIX_WEB_KIT_INT32_BUG

#ifdef FIX_WEB_KIT_INT32_BUG
    #define NPVARIANT_IS_INT32(_v)   ((_v).type == NPVariantType_Int32 || (_v).type == NPVariantType_Double)
    #define NPVARIANT_TO_INT32(_v)   ((_v).type == NPVariantType_Double ? (_v).value.doubleValue : (_v).value.intValue)
#else
    #define NPVARIANT_IS_INT32(_v)   ((_v).type == NPVariantType_Int32)
    #define NPVARIANT_TO_INT32(_v)  (_v).value.intValue)
#endif

在网络上(来自 javascript)我对传递给插件的所有 int 值使用 parseInt(myVal,10)。在 Google Chrome 和 Safari 上查看。

于 2012-10-24T16:09:04.640 回答