【问题标题】:NPAPI functions Called by Javascript由 Javascript 调用的 NPAPI 函数
【发布时间】:2013-04-04 15:15:05
【问题描述】:

我正在尝试编写一个 NPAPI 插件的 hello world 示例。我实现了所有需要的基本函数,并添加了一个返回 hello world 字符串的 Get_String() 函数。

构建后,浏览器可以检测到插件和所有相关信息,但我无法从 JavaScript 调用我的 Get_String() 函数! 这里有一些代码: 插件.c

#define PLUGIN_NAME        "Name Plugin"
#define PLUGIN_DESCRIPTION " Plugin Description"
#define PLUGIN_VERSION     "1.0"

static NPNetscapeFuncs* sBrowserFuncs = NULL;

NP_EXPORT(NPError)
NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs)
{
  sBrowserFuncs = bFuncs;

  if (pFuncs->size < (offsetof(NPPluginFuncs, setvalue) + sizeof(void*)))
    return NPERR_INVALID_FUNCTABLE_ERROR; 

  pFuncs->newp = NPP_New;
  pFuncs->destroy = NPP_Destroy;

  return NPERR_NO_ERROR;
}


NP_EXPORT(char*)
NP_GetPluginVersion()
{
  return PLUGIN_VERSION;
}


NP_EXPORT(const char*)
NP_GetMIMEDescription()
{
  return "application/my-plugin::";
}


NP_EXPORT(NPError)
NP_GetValue(void* future, NPPVariable aVariable, void* aValue) {
  switch (aVariable) {
    case NPPVpluginNameString:
      *((char**)aValue) = PLUGIN_NAME;
      break;
    case NPPVpluginDescriptionString:
      *((char**)aValue) = PLUGIN_DESCRIPTION;
      break;
    default:
      return NPERR_INVALID_PARAM;
      break;
  }
  return NPERR_NO_ERROR;
}


NP_EXPORT(NPError)
NP_Shutdown()
{
  return NPERR_NO_ERROR; 
}


NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
{

  return NPERR_NO_ERROR;
}


NPError NPP_Destroy(NPP instance, NPSavedData** save)
{

  return NPERR_NO_ERROR;
}

char* Get_String()
{
    return "hello world from Get function" ;
}

void Set(NPObject object){}

test.html

<doctype html>
<html>
<head>
<script>
  var plugin = document.getElementById("plugin");
  console.log(plugin.Get_String());
</script>
</head>
<embed id="plugin" type="application/typemine-plugin"> 
<body>
</body>
</html>

【问题讨论】:

  • 你读过NPAPI tutorialdocumentation吗?你知道像Firebreath 这样更简单的选择吗?
  • 是的,我看过它和其他的。但就我而言,我不需要它。我想用艰难的方式做到这一点。
  • 那么,您是否阅读了教程和/或文档?听起来您缺少可编写脚本的方法所需的所有设置,并期望只能从 JS 访问纯 C 函数。
  • 我没有向你展示我开发的所有代码,只是一个我想从 javascript 调用的函数作为示例。 NPAPI 的所有必要功能都已实现。
  • 如果 NPAPI 的所有必要功能都已实现,那么它将起作用。您没有包含任何我们需要查看的代码以了解问题所在。它甚至被实例化了吗?您是否尝试过设置断点或添加日志语句来找出答案?你没有给我们任何可以在这里工作的东西。

标签: c google-chrome-extension npapi browser-plugin


【解决方案1】:

您需要从NPP_GetValue() 提供浏览器with a custom scriptable object。浏览器需要它来找出插件具有哪些方法和属性、调用它们等。

您可以在part 3 of taxilians tutorial 中找到实现脚本的基本概述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    相关资源
    最近更新 更多