`
my201my
  • 浏览: 9262 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

【Android浏览器插件开发准备工作之NPAPI】使用Visual Studio 2008 运行Firefox浏览器插件实例npruntime

 
阅读更多

【Android浏览器插件开发准备工作之NPAPI】使用Visual Studio 2008 运行Firefox浏览器插件实例npruntime
2011年05月10日
  最近在研究Android上浏览器插件.. 资料比较少.. 基本都是从研究NPAPI开始的.. 那么我也从这开始吧...
  由于这篇文章是边做实验边记录, 加上本身对VS不太了解, 可能有些地方不对, 欢迎大家指正!!
  npruntime 
  参照下述步骤一步一步来: 1.                              Create a new project in Visual Studio for a Win32 GUI library (DLL) (in .NET 2003: Win32 template, then switch to DLL in Application Settings in the following dialog, export symbols too?)(in Visual Studio 2008, it isVisualc++|Win32|Win32 Project, then check DLL in the wizard). 2.                              If a wizard gives you a checkbox to create an empty project, then check it. Otherwise you'll delete files later. 3.                              Again note that the resulting DLL filename must start with "np", so either call your project like this or rename the file later 4.                              Delete the .cpp and .h and ReadMe files from the project and disk (if you did not create an empty project) 5.                              Copy the npruntime sample plugin source code into the dir of the new VS project and add the files to the project using the VS GUI (.cpp files to "Source Files", .h files to "Header Files", .rc file to "Resource Files"). Samples can be obtained from: https://developer.mozilla.org/en/Plugins/Samples_a nd_Test_Cases 6.                              Download the Gecko SDK (aka XULRunner SDK) from mozilla.org release FTP and extract it. You can download it from here: http://developer.mozilla.org/en/docs/Gecko_SDK 7.                              Add the Gecko SDK include path (example : C:\xulrunner-sdk\sdk\include) to Project Properties|(all configurations)|C++|General|Additional Include Directories. Note: If your project is still empty, the C++ tree might not be visible. So, add some files first. 8.                              Add the following preprocessor definitions to Project Properties|(all configurations)|C++|Preprocessor|Preprocessor Definitions:WIN32;_WINDOWS;XP_WIN32;MOZILLA_STRICT_API;XPCOM_G LUE;XP_WIN;_X86_;NPSIMPLE_EXPORTS 9.                              Disable precompiled headers using Project Properties|(all configurations)|C++|Precompiled headers|Create/Use precompiled header. They may be already disabled. 10.                          Define the function exports by adding the .def filename (e.g. nprt.def) to Project Properties|(all configurations)|Linker|Input|Module Definition File. It could be either the full path or the path relative to the project directory. 11.                          Optional: Open the above .def file and change "NPRT" to the filename of your dll as VS sees it (without "np", if you decided to rename later) 12.                          Optional: Edit the .rc file and and the top of npp_gate.cpp for the description, mimetype, file extension etc. to reflect your plugin 13.                          Remove the function NPP_GetJavaClass from npp_gate.cpp 14.                          Build 15.                          Rename the resulting DLL so that the filename starts with "np" and ends with ".dll" (or "32.dll"? 8.3?) and copy it in Mozilla's "plugins" folder 16.                          Start Mozilla and open about:plugins to verify the plugin is detected 17.                          Open the file "test.html" and begin testing. Make sure the mimetypes of your html embed tags match the mimetype specified in your nprt.rc file and the top of your npp_gate.cpp file 第一步:
  
  第二步:
  
  (因为选择的空项目,第三、第四步省略)
  第五步:导入源码
  npruntime 源码结构: 下载地址:  http://mxr.mozilla.org/seamonkey/source/modules/pl ugin/samples/npruntime/ 
  重要:
  调查到最后发现,上面不知道是对应什么版本的。与我下载的SDK 1.9.2 不匹配。所以在下载npruntime源代码的时候,同时注意选择SDK的版本。
  对应Geoc SDK1.9.2 的npruntime源码位置:
  http://mxr.mozilla.org/mozilla1.9.2/source/modules /plugin/sdk/samples/npruntime/
  
  Moliza 1.9.2 版本的npruntime源码结构: (结构是一样的,关键里面代码不一样。郁闷死我了!)
  
  导入后的项目目录结构: 
  
  其中resource.h 和 npxx1.rc 和源码中的可能有点不一样的。
  resource.h是创建npxx1.rc后自动产生的。 第六步& 第七步:
  给项目配置Gecko SDK include path (example : C:\xulrunner-sdk\sdk\include) 。
  配置方法:Project Properties|(all configurations)|C++|General|Additional Include Directories
  注意:如果项目还是空的,那么就无法看到C++这个选项,所以先加几个文件吧。
  
  空项目时的ProjectProperties
  
  追加完Source文件后的ProjectProperties
  
  追加路径的窗口
  第八步:
  添加预处理器定义,把你没有的添加进去即可!
  
  第九步:
  不使用预编译头。
  
  第十步:模块定义文件配置
  Npruntime中有个def文件,之前没有用,现在派上用场了。我把它暂时放在了E盘。使用绝对路径来配置。
  
  第十一步:编辑上面的def文件,重命名DLL.
  
  注意,这边的library名字最好要和resoiurce文件一样! 这边我懒得重新截图了!
  第十二步: 修改.rc文件和npp_gate.cpp 文件 (description, mimetype, file extension) 第十三步:从npp_gate.cpp 文件删除NPP_GetJavaClass 方法 第十四步:编译 第十五步:重命名DLL,一定要以np开头,以.dll结尾 最后附上注意事项,编译时如果有错,也请看下面的介绍: 1.                              If you are using Gecko SDK v1.9 and higher, you'll probably need to add folders \plugin, \nspr, and \java as included directories (as seen above, go to Project Properties|(all configurations)|C++|General|Additional Include Directories). These directories are contained in the Gecko SDK include path that you previously added. 2.                              If VC++ compiler throws you error C2664 on 'DrawText' function call, you may replace it by 'DrawTextA'. In fact, all win32 API functions dealing with character strings can be added an 'A' to the end to avoid unicode cast errors. 3.                              Visual C++ 2008 Express don't support C99 standard about int32_t, uint32_t. You have to add #include "nptypes.h" in top of plugin.h file. For xulrunner 1.9.0.1 SDK, npapi.h file uses int32, uint32 which is different from int32_t, uint32_t defined in nptypes.h, and it may cause problems in link stage. 4.                              For xulrunner 1.9.0.1 SDK, you may not find npfunctions.h in include directories. You have to replace all npfunctions.h by npnpp.h in #include line. 5.                              Feel free to append here your issues fixes if the above guide helped you. 第二条:在SDK1.9.2版本编译时遇到了。
  第三条补充:
  xulrunner 1.9.0.1 SDK以上,nptypes.h 中定义的都是int32_t, uint32_t这样,而不是int32, uint32。  所以npruntime代码中需要相应的修改。
  (如果下载的源码与SDK的版本相对应,应该不存在这个问题)
  第五条补充:
  xulrunner 1.9.0.1 SDK中不存在npfunctions.h,但是在xulrunner 1.9.2 SDK 中又包含了该文件,反而没有npnpp.h。
  总结:(造成打开资源文件时RC1004错误,编译时会造成Error PRJ002等错误,花了我不少时间)
  拷贝npruntime这一步非常重要,我直接Ctrl+c , Ctrl+v来拷贝,最后发现错误一堆。
  所以自己一个一个创建文件吧,然后把代码贴过去。
  另外里面的资源文件nprt.rc 最好要跟你的项目名相同。千万注意这边不是单纯的把这个源文件拷贝过去。
  另外resource.h会由VS2008自动生成,不需要你修改(也不要去拷贝源码中的文件)。 好了,到此所有操作都结束了,运行后会得到一个dll文件。 我这边resource文件名为npxx.rc 在def文件中配置的library名也是npxx, 所以我得到的是 npxx.dll ..  (这两句话感觉好二...)
  把这个dll文件拷贝到Firefox的安装目录下的plugins目录下即可。
  安装完后,在Firefox中可以就可以看到这个插件了。
  
  下面打开测试网页, 就可以看到效果了。
  
  最后附上测试网页代码:   Scriptable Plug-in Test    Sample Scriptable Plug-in   This page contains a testcase which demonstrates the work of scriptable 4.x style Navigator plug-in with Mozilla. The example plug-in occupies the area right below this text, and you should see a frame the plug-in draws around its window. Below the plug-in window there are two buttons. Clicking on the buttons will result in calling native plugin methods from JavaScript. Show Version will instruct the plug-in to retrieve the Mozilla user agent string and display it in the plug-in window, Clear button will call plug-in method to erase the window.
  " + "function bar(" + arg + ") called!" + ""; return 4; } // -->  results go here: 

 
    
          参考文献(Mozila官方文档): https://developer.mozilla.org/en/Gecko_Plugin_API_ Reference/Preface#The Plug-in software development kit 个人博客: NPAPI帮助理解:
分享到:
评论

相关推荐

    让ActiveX在FireFox和Chrome等NPAPI插件接口的浏览器中运行

    让ActiveX在FireFox和Chrome等NPAPI插件接口的浏览器中上运行 这样firefox浏览器就可以正常浏览有ActiveX插件的网页,比如flash 的ActiveX控件: id="Control" TYPE="application/x-itst-activex" WIDTH="300" ...

    浏览器插件开发入门

    使用QT进行浏览器插件开发技术,包括ActiveX控件和NPAPI插件的开发

    Firefox NPAPI插件开发实例

    虽然火狐新版已经不支持npapi技术了,有兴趣研究的同学可以下载参考一下。 其中npruntie实例已经在ff36~ff50版本测试通过

    浏览器插件npapi

    浏览器插件 npapi npruntime 浏览器控件,需要下载相应的SDK 压缩包有注释

    chrome新一代浏览器插件开发SDK

    chrome已经宣布新版本得chrome浏览器不在支持NPAPI,IE也被微软放弃,Edge浏览器除了部分企业版依旧支持ActiveX插件以外也不在支持ActiveX,webkit内核得浏览器对ACtiveX插件得支持并不完善,并且webkit内核对网页得...

    Qt5开发FireFox(NpApi)插件.rar

    使用Qt5+msvc2015编写的npapi浏览器插件 支持firefox52以下浏览器版本 有详细说明文档 有源码和bin文件以及需要的动态库

    NPAPI-Firefox插件示例

    NPAPI-Firefox插件示例,一个基本的框架

    简单的NPAPI插件开发实例

    基于webkit框架的NPAPI插件开发,遵守NPAPI开发准则,实现Browser+plugin+NPAPI完美调用。

    NPAPI firefox插件开发详解

    详细介绍NAAPI开发过程,内有相关的源码下载链接。

    npapi浏览器插件sdk

    NPAPI 原本是由 Netscape 所制定的一组单纯的 C Plugin API,起初是无法支持 Scriptability;于是到了 2004 年底,各家 Browser ( IE , Opera, Mozilla 等) 都同意支持NPRuntime 延伸 API 以支持 Scriptability,...

    PluginOK浏览器插件开发框架

    而PPAPI插件运行在沙箱中,不能访问本地硬件和文件,加载使用又非常困难,导致绝大部分原来的ActiveX控件或NPAPI插件的使用场景无法支持。现在给大家分享一个实现网页前端与本地系统之间可进行双向调用的强兼容、轻...

    Firefox插件开发Demo

    Firefox插件Demo #include "npapi.h" #include "npruntime.h" typedef int int16; class CPlugin { private: NPP m_pNPInstance; #ifdef XP_WIN HWND m_hWnd; #endif NPWindow * m_Window; NPStream *...

    npapi插件浏览器调插件函数Demo

    npapi 插件 js页面调用插件函数Demo

    c++实现跨浏览器插件

    VS2010 编写NPAPI 夸浏览器插件 近日因要使用第三方Activex插件,但是火狐浏览器不支持,故用到了NPAPI封装插件。在此记录一笔,以便日后查阅。

    基于QT的firefox插件

    基于QT的firefox插件

    NPAPI开发入门.doc

    NPAPI全称为:Netscape Plugin Application Programming Interface (NPAPI). NPAPI 是一个很经典的插件方案,用dll进行注入,用协定的API进行通信,用字符串描述插件能力。插件宿主(在这里就是浏览器…)会根据...

    NPAPI 插件获取浏览器地址栏URL

    google chrome扩展和插件开发,使用 NPAPI 插件获取浏览器地址栏URL

    NPAPI and NPRuntime

    NPAPI and NPRuntime

    基于QT的浏览器插件

    基于QT的浏览器插件 使用NPAPI接口 基于QT5.5.1 + VS2010 可以直接运行 实现了简单的计算器功能

    海康威视 摄像头网络摄像头 WEB无插件开发包 Web 3.2控件开发包

    web 3.2无插件 是使用websocket 的相关技术 , web 3.0 插件版是使用了 浏览器的npapi 技术 内容简介 Web 控件 V3.2 基于 ActiveX 和 NPAPI 开发,接口封装于 javascript 脚本,以 javascript 接口形式提供用户 集成...

Global site tag (gtag.js) - Google Analytics