NPAPI 解析

NPAPI全拼  Netscape-plug-in API Support
load any  Netscape-plug-in API  in process , such as  flash plugin
全称为:Netscape Plugin Application Programming Interface (NPAPI), Netscape Navigator 浏览器早已离我们远去,但Netscape plug-in 却还顽强的活着,并且成为绝大多数浏览器都支持的跨平台插件标准,其中最常见的N插件莫过于 Flash 了,想想满世界的类 “Youtube” 你就知道了。 现在 Qt 4.5 中支持了N插件,最直观的改变就是在 Qt Demo Browser 中原本应该显示 Flash 的位置不会再是一片空白了。
还能做什么? 一个 Youtube 的客户端应该很容易。

NPAPI接口如何在flash plugin 与浏览器之间通信:
When the browser scans its plugin directories and finds a new library, the browser will attempt to see if the library is a plugin. The following things must be able to happen in order for the library to be considered a plugin:

    * The browser must be able to tell the plugin the addresses of the browser-side NAPI functions that the browser implements
    * The plugin must be able to tell the browser the addresses of the plugin-side NAPI functions that the plugin implements
    * The browser must be able to determine what MIME types the plugin handles, along with other metadata about the plugin
    * The browser must be able to determine the plugin's "shutdown" routine

    Caution: The directory where plugins should be installed is both browser and platform specific. It will be up to you (and later, your installer) to determine where the plugin should be installed for your target browsers and platforms.

Once these tasks are completed, the plugin should be registered with the browser. In the case of Firefox or Mozilla, this means that the plugin should appear in the "about:plugins" page. The purpose of this chapter is to show how each of the major platforms tries to accomplish these tasks, so that you can create a plugin with the appropriate entry points for your target platform(s). The next chapter, Registration, will cover registration from a platform-independant point of view.

    Caution: The entry points in this chapter are expected to exported as non-mangled names (i.e., C-exported symbols, not C++). Thus, if you are using C++, you will need to wrap these function declarations (and corresponding definitions) in an extern "C" {} block.

NPAPI在unix下的接口:

Required entry points
     

char*          NP_GetMIMEDescription()
NPError        NP_GetValue(void*, NPPVariable, void* out)
NPError        NP_Initialize(NPNetscapeFuncs*, NPPluginFuncs*)
NPError OSCALL NP_Shutdown()

Browser behavior

    Browser-Side Addresses
    Plugin-Side Addresses
      Browser calls NP_Initialize
  MIME Types & Metadata
        Browser calls NP_GetMIMEDescription for MIME types, and calls NP_GetValue to get the plugin name and description.
  Shutdown
        Browser calls NP_Shutdown

MIME Types & Metadata

The MIME types are returned by the NP_GetMimeDescription as a string of the format `"mime/type:ext,ex2,ex3:Human-Readable Description;mime/type2:ext3:Another description"'. Thus, the MIME types from the Windows example would be represented as follows:
    

"text/html:htm,html:HTML Document;"
"application/x-texinfo:tex,texi,texinfo:TexInfo Document;"
"text/xml:xml:XML File"

The plugin name and description are extracted through the NP_GetValue interfce, which is very similar to the NPP_GetValue interface (FIXME: add cross-reference to the section discussing NPP_GetValue). NP_GetValue is concerned with only two values of NPPVariable: NPPVpluginNameString and NPPVpluginDescriptionString. A typical implementation of NP_GetValue could look like this:
    
//  下边这个函数是获得插件信息,比如插件的名称、插件的描述信息
NPError NP_GetValue(void* reserved, NPPVariable var, void* out)
{
    NPError ret = NPERR_NO_ERROR;
    char**  val;

    if(out == NULL)
        { return NPERR_INVALID_PARAM; }
   
    val = (char**)(out);
   
    switch(var)
    {
        case NPPVpluginNameString:
            *val = "Example Plug-In";
            break;
        case NPPVpluginDescriptionString:
            *val = "A plug-in that demonstrates how NP_GetVal is implemented";
            break;
        default:
            ret = NPERR_INVALID_PARAM;
            break;
    }

    return ret;
}
   

 

原文:http://blog.chinaunix.net/u3/94039/showart_2004756.html


  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值