step-by-step guide for developing the "HelloWorld" plugin of firefox.
下载这个链接http://p.blog.csdn.net/images/p_blog_csdn_net/wuzh1230/EntryImages/20091014/helloworld.zip.png (链接另存为, 因为这不是一个图片,这是一个以PNG为后缀的ZIP压缩包),在本地将这个PNG文件重命名为ZIP,解压以后可以得到完整的项目。
在编译项目前,你需要gecko-sdk(这是旧的名字,现在1.9以后,叫做xulrunner-sdk ),地址在http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.9.1.3/sdk/xulrunner-1.9.1.3.en-US.win32.sdk.zip
如果你习惯Makefile,那么启动VC命令行进行NMake,不过注意修改Makefile中SDK路径(最顶上)。
如果你喜欢IDE那么,请使用VS2008打开npnull.sln,同样的,请修改项目里面的额外包含路径。
拷贝你得到的npnull.dll 到firefox安装目录下的plugins子目录,在firefox地址栏里面输入about:plugins可以看到你npnull已经启用了。
调试,项目里面包含一个test.htm页面,可以用来测试这个插件。 具体怎么调试DLL,就不赘述了。
4.1 导出的3个接口
(1) NP_GetEntryPoints
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs) { if(pFuncs == NULL) return NPERR_INVALID_FUNCTABLE_ERROR; if(pFuncs->size < sizeof(NPPluginFuncs)) return NPERR_INVALID_FUNCTABLE_ERROR; pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; pFuncs->newp = NPP_New; pFuncs->destroy = NPP_Destroy; pFuncs->setwindow = NPP_SetWindow; pFuncs->newstream = NPP_NewStream; pFuncs->destroystream = NPP_DestroyStream; pFuncs->asfile = NPP_StreamAsFile; pFuncs->writeready = NPP_WriteReady; pFuncs->write = NPP_Write; pFuncs->print = NPP_Print; pFuncs->event = NPP_HandleEvent; pFuncs->urlnotify = NPP_URLNotify; pFuncs->getvalue = NPP_GetValue; pFuncs->setvalue = NPP_SetValue; pFuncs->javaClass = NULL; return NPERR_NO_ERROR; }
(3) NP_Shutdown()
还可以导出NP_GetMIMEDescription等辅助接口
4.2 各个函数的意义
(1) NPP_SetWindow 创建GUI窗口
(2) NPP_GetValue 通过参数 “NPPVpluginScriptableNPObject” 可以获取一个和脚本交互的对象指针
总的来讲,这个mozilla给的那个原始SAMPLE里面BUG还是非常多的(不过,你这里下载的这个修改版,应该是可以一下子编译通过的,只要路径设置好了)。所以,你一定要耐心的修改。
https://developer.mozilla.org/en/Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio
http://www.codeproject.com/KB/openGL/FirefoxOpenGL.aspx
https://developer.mozilla.org/en/Gecko_Plugin_API_Reference
https://developer.mozilla.org/en/Plugins
ie插件和js交互的文章