Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1652077
  • 博文数量: 245
  • 博客积分: 10378
  • 博客等级: 上将
  • 技术积分: 2571
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-27 08:19
文章分类

全部博文(245)

文章存档

2013年(4)

2012年(8)

2011年(13)

2010年(68)

2009年(152)

分类: LINUX

2009-07-23 15:37:14

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;
}
  

  
阅读(4436) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~