热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

最近在研究Android上浏览器插件..资料比较少..基本都是从研究NPAPI开始的..那么我也从这开始吧由于这篇文章是边做实验边记录,加上本身对VS不太了解,可能有些地方不对,

 


最近在研究Android上浏览器插件.. 资料比较少.. 基本都是从研究NPAPI开始的.. 那么我也从这开始吧...

 

由于这篇文章是边做实验边记录, 加上本身对VS不太了解, 可能有些地方不对, 欢迎大家指正!!

 

 


 

npruntime 

参照下述步骤一步一步来:

Build

1.  Create a new project in VisualStudio for a Win32 GUI library (DLL) (in .NET 2003: Win32 template, then switch to DLL in Application Settings in the following dialog, exportsymbols too?)(in Visual Studio 2008, it isVisualc++|Win32|Win32 Project, thencheck DLL in the wizard).

2.  If a wizard gives you acheckbox to create an empty project, thencheck it. Otherwise you'll delete files later.

3.  Again note that the resultingDLL 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 (ifyou did not create an empty project)

5. Copy the npruntime sampleplugin source code into the dir of the new VS project and add the files to theproject 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_and_Test_Cases

6. Download the GeckoSDK (akaXULRunner SDK) from mozilla.org release FTP and extract it. You can download itfrom here: http://developer.mozilla.org/en/docs/Gecko_SDK

7. Add the GeckoSDK include path (example :C:/xulrunner-sdk/sdk/include) to Project Properties|(allconfigurations)|C++|General|Additional Include Directories. Note:If your project is still empty, the C++ tree might not be visible. So, addsome files first.

8. Add the following preprocessordefinitions to Project Properties|(allconfigurations)|C++|Preprocessor|Preprocessor Definitions:WIN32;_WINDOWS;XP_WIN32;MOZILLA_STRICT_API;XPCOM_GLUE;XP_WIN;_X86_;NPSIMPLE_EXPORTS

9.Disable precompiled headersusing Project Properties|(allconfigurations)|C++|Precompiled headers|Create/Use precompiled header.They may be already disabled.

10. Define the function exports byadding the .def filename (e.g. nprt.def) to ProjectProperties|(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" tothe filename of your dll as VS sees it (without "np", if you decidedto rename later)

12. Optional: Edit the .rc file and and the top of npp_gate.cpp for the description, mimetype, fileextension etc. to reflect your plugin

13. Remove the function NPP_GetJavaClass from npp_gate.cpp

14. Build

15. Rename the resulting DLL sothat the filename starts with "np"and ends with ".dll" (or "32.dll"? 8.3?) and copy it inMozilla'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 htmlembed 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/plugin/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后自动产生的。

 

第六步 & 第七步:

给项目配置GeckoSDK include path (example :C:/xulrunner-sdk/sdk/include) 

配置方法: Project Properties|(allconfigurations)|C++|General|Additional Include Directories

注意: 如果项目还是空的,那么就无法看到C++这个选项,所以先加几个文件吧。

 

空项目时的 Project Properties:

 

追加完Source文件后的Project Properties:

 

追加路径的窗口:

 

 

第八步:

添加预处理器定义, 把你没有的添加进去即可!


 

第九步:

不使用预编译头。 (一般默认就是不使用了)

 

第十步:模块定义文件配置

Npruntime中有个def文件,之前没有用,现在派上用场了。 我把它暂时放在了E盘。 使用绝对路径来配置。


 

第十一步: 编辑上面的def文件, 重命名DLL.

 

注意,这边的library名字最好要和resoiurce文件一样! 这边我懒得重新截图了!

 

第十二步: 修改.rc文件和npp_gate.cpp 文件(description,mimetype, file extension)

第十三步: npp_gate.cpp 文件删除 NPP_GetJavaClass
方法

第十四步: 编译

第十五步:重命名DLL,一定要以np开头,以.dll结尾

 

 

最后附上注意事项,编译时如果有错,也请看下面的介绍:

VersionIssues

1. If youare 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|(allconfigurations)|C++|General|Additional Include Directories). These directories are contained in the Gecko SDKinclude 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 stringscan be added an 'A' to the end to avoid unicode cast errors.

3. VisualC++ 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 freeto 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错误,编译时会造成ErrorPRJ002等错误,花了我不少时间)

拷贝npruntime这一步非常重要,我直接Ctrl+c Ctrl+v来拷贝,最后发现错误一堆。

所以自己一个一个创建文件吧,然后把代码贴过去。


另外里面的资源文件nprt.rc 最好要跟你的项目名相同。千万注意这边不是单纯的把这个源文件拷贝过去。

另外resource.h会由VS2008自动生成,不需要你修改(也不要去拷贝源码中的文件)。

 

 


 

好了,到此所有操作都结束了,运行后会得到一个dll文件。 我这边resource文件名为npxx.rc 在def文件中配置的library名也是npxx, 所以我得到的是 npxx.dll ..  (这两句话感觉好二...)

 

把这个dll文件拷贝到Firefox的安装目录下的plugins目录下即可。

 

安装完后,在Firefox的地址栏中输入: about:plugins , 就可以看到这个插件了。

 

 

下面打开测试网页, 就可以看到效果了。

 

 

最后附上测试网页代码:

 

 

 

 

参考文献(Mozila官方文档)

http://code.google.com/chrome/extensions/npapi.html

https://developer.mozilla.org/en/Plugins

https://developer.mozilla.org/en/Gecko_Plugin_API_Reference

https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Preface#ThePlug-in software development kit

 

个人博客:

http://blog.csdn.net/qyqzj/archive/2010/06/14/5670816.aspx

http://blog.csdn.net/qyqzj/archive/2010/07/04/5712151.aspx

http://www.blogjava.net/anymobile/articles/328592.html?opt=admin

http://blog.csdn.net/qyqzj/archive/2010/05/30/5634532.aspx

http://blog.csdn.net/qyqzj/archive/2010/08/03/5786313.aspx

http://blog.sina.com.cn/s/blog_6d1656130100ml5t.html

 

NPAPI帮助理解:

http://blog.csdn.net/hanyuxinting/archive/2010/10/28/5972428.aspx

http://blog.csdn.net/hanyuxinting/archive/2010/10/29/5973630.aspx

http://blog.csdn.net/hanyuxinting/archive/2010/12/10/6068384.aspx

http://blog.csdn.net/vinilarain/archive/2010/03/03/5343170.aspx

 


推荐阅读
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • 全面介绍Windows内存管理机制及C++内存分配实例(四):内存映射文件
    本文旨在全面介绍Windows内存管理机制及C++内存分配实例中的内存映射文件。通过对内存映射文件的使用场合和与虚拟内存的区别进行解析,帮助读者更好地理解操作系统的内存管理机制。同时,本文还提供了相关章节的链接,方便读者深入学习Windows内存管理及C++内存分配实例的其他内容。 ... [详细]
  • 本文详细介绍了Android中的坐标系以及与View相关的方法。首先介绍了Android坐标系和视图坐标系的概念,并通过图示进行了解释。接着提到了View的大小可以超过手机屏幕,并且只有在手机屏幕内才能看到。最后,作者表示将在后续文章中继续探讨与View相关的内容。 ... [详细]
  • 本文介绍了在Ubuntu 11.10 x64环境下安装Android开发环境的步骤,并提供了解决常见问题的方法。其中包括安装Eclipse的ADT插件、解决缺少GEF插件的问题以及解决无法找到'userdata.img'文件的问题。此外,还提供了相关插件和系统镜像的下载链接。 ... [详细]
  • 在加载一个第三方厂商的dll文件时,提示“找不到指定模块,加载失败”。由于缺乏必要的技术支持,百思不得期间。后来发现一个有用的工具 ... [详细]
  • Mono为何能跨平台
    概念JIT编译(JITcompilation),运行时需要代码时,将Microsoft中间语言(MSIL)转换为机器码的编译。CLR(CommonLa ... [详细]
  • 本文介绍了如何使用PHP向系统日历中添加事件的方法,通过使用PHP技术可以实现自动添加事件的功能,从而实现全局通知系统和迅速记录工具的自动化。同时还提到了系统exchange自带的日历具有同步感的特点,以及使用web技术实现自动添加事件的优势。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 不同优化算法的比较分析及实验验证
    本文介绍了神经网络优化中常用的优化方法,包括学习率调整和梯度估计修正,并通过实验验证了不同优化算法的效果。实验结果表明,Adam算法在综合考虑学习率调整和梯度估计修正方面表现较好。该研究对于优化神经网络的训练过程具有指导意义。 ... [详细]
  • 有没有一种方法可以在不继承UIAlertController的子类或不涉及UIAlertActions的情况下 ... [详细]
  • 核心代码第一种声音[DllImport(Kernel32.dll)]引入命名空间usingSystem.Runtime.InteropServices;publicstat ... [详细]
  • 本篇文章笔者在上海吃饭的时候突然想到的这段时间就有想写几篇关于返回系统的笔记,所以回家到之后就奋笔疾书的写出来发布了事先在网上找了很多方法,发现有 ... [详细]
  • ExcelApp#启动excel程序ExcelAppCreateOleObject(“Excel.Application”);#加载文件但不显示文件内容(true表 ... [详细]
  • 转载:MFC 获得各类指针、句柄的方法
    2019独角兽企业重金招聘Python工程师标准转载:最近有些人在问MFC编程一些要点,有一些句柄的获取、指针的获取是 ... [详细]
  • unitUnit1;interfaceusesWinapi.Windows,Winapi.Messages,System.SysUtils,System.Variants,Syst ... [详细]
author-avatar
哒Dayling玲
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有