C++ 如何编写浏览器插件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2649056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 00:13:13  来源:igfitidea点击:

How to write a browser plugin?

c++npapibrowser-plugin

提问by Nathan Osman

I'm curious as to the procedure for writing browser plugins for browsers like Chrome, Safari, and Opera. I'm thinking specifically of Windows here and would prefer working with C++.

我很好奇为 Chrome、Safari 和 Opera 等浏览器编写浏览器插件的过程。我在这里专门考虑 Windows,并且更喜欢使用 C++。

Are there any tools or tutorials that detail the process?

是否有任何工具或教程详细说明了该过程?

Note: I am not referring to extensions or 'addons'. I'm referring to a plugin similar to how Flash and Adobe Reader have plugins to handle specific content-types.

注意:我不是指扩展或“插件”。我指的是一个插件,类似于 Flash 和 Adob​​e Reader 的插件来处理特定的内容类型。

回答by Georg Fritzsche

As others point out, plugins for those browser are written using the NPAPI.

正如其他人指出的那样,这些浏览器的插件是使用NPAPI编写的。

Note: Both Firefox and Chrome will default most plugins to click-to-play soon, with Chrome planning to phase out NPAPI entirely. NPAPI for new projects is discouraged at this point.

注意:Firefox 和 Chrome很快会将大多数插件默认为点击播放,Chrome 计划完全淘汰 NPAPI。此时不鼓励为新项目使用 NPAPI。

Resources for getting started with NPAPI:

开始使用 NPAPI 的资源:

The NPAPI itself is however relatively low-level, but there are tools and frameworks that can help you with it:

然而,NPAPI 本身是相对低级的,但有一些工具和框架可以帮助您:

  • FireBreath- cross-browser, cross-platform frame-work for plugins
  • Nixysa- generate glue-code for NPAPI plugins
  • JUCE- application framework also providing support for plugins
  • QtBrowserPlugin- Qt based browser plugin framework
  • FireBreath- 跨浏览器、跨平台的插件框架
  • Nixysa- 为 NPAPI 插件生成胶水代码
  • JUCE- 应用程序框架也提供插件支持
  • QtBrowserPlugin- 基于 Qt 的浏览器插件框架

回答by Tyler Long

I investigated some frameworks listed by Georg, here is what I get:

我调查了 Georg 列出的一些框架,这是我得到的:

  1. FireBreath. I think it is almost the best one available. You can create a cross platform browser plugin with FireBreath in a few days. I did find some cons: It does not support utf-8 characters on Windows. For example: if there are Chinese characters in a file name, you cannot read the content of that file. I believe that boost/locale can resolve this issue. But FireBreath does not contain boost/locale. Yes you can use external boost, but I spent several days configuring and tweaking and still cannot get it compiling on Windows. The author uses cmake to orgnize code and sub-projects. And he created a lot of bat or shell scripts and cmake macros, it is very hard to understand and configure. In short, if you want something that FireBreath currently does not provide, you will have a bad luck, it is very hard to add new features.

  2. Nixysa. I don't think that it is being actively developed. Documentation is poor. And from the comments of the wiki page: https://code.google.com/p/nixysa/wiki/HelloWorldWalkThruWe can know that users could not get help at all and were having trouble get it running on Windows

  3. JUCE. It is not specially for creating browser plugins. It does NOT support Linux. The author thinks that NPAPI is going to die so he has no plan to support Linux or add new features.

  4. QtBrowserPlugin. You can not find it in documentation later than QT 4.5. In another word, it is not maintained(and removed from Qt 5.0)

  1. 火息。我认为它几乎是最好的一种。您可以在几天内使用 FireBreath 创建一个跨平台浏览器插件。我确实发现了一些缺点:它在 Windows 上不支持 utf-8 字符。例如:如果文件名中有汉字,则无法读取该文件的内容。我相信 boost/locale 可以解决这个问题。但是 FireBreath 不包含 boost/locale。是的,您可以使用外部增强,但我花了几天的时间进行配置和调整,但仍然无法在 Windows 上进行编译。作者使用cmake来组织代码和子项目。而且他创建了很多bat或shell脚本和cmake宏,很难理解和配置。总之,如果你想要一些 FireBreath 目前没有提供的东西,你会很倒霉,很难添加新的功能。

  2. 尼克莎。我不认为它正在被积极开发。文档很差。从 wiki 页面的评论:https: //code.google.com/p/nixysa/wiki/HelloWorldWalkThru我们可以知道用户根本无法获得帮助并且无法在 Windows 上运行

  3. 果汁。它不是专门用于创建浏览器插件的。它不支持 Linux。作者认为 NPAPI 即将消亡,因此他没有计划支持 Linux 或添加新功能。

  4. Qt浏览器插件。您无法在 QT 4.5 之后的文档中找到它。换句话说,它没有被维护(并从 Qt 5.0 中删除)

I will update this answer once I find more.

一旦我找到更多,我会更新这个答案。

Update: Chrome dropped NPAPIsupport. I think in the future it becomes harder and harder to write plugins in C++ because lacks of support from browsers.

更新:Chrome 放弃了NPAPI支持。我认为在未来,由于缺乏浏览器的支持,用 C++ 编写插件会变得越来越难。

回答by Ming-Tang

Browsers like Netscape-based browsers, Chrome, Safari and Opera uses NPAPI plugin system, you can learn how to write NPAPI plugins in https://developer.mozilla.org/en/Pluginsand http://code.google.com/chrome/extensions/npapi.html

基于 Netscape 的浏览器、Chrome、Safari 和 Opera 等浏览器使用 NPAPI 插件系统,您可以在https://developer.mozilla.org/en/Pluginshttp://code.google.com/学习如何编写 NPAPI 插件铬/扩展/npapi.html

回答by Henrik Hansen

If you know Qt then they have got some classes that makes it easier to implement browser plug-ins

如果您了解 Qt,那么他们有一些类可以更轻松地实现浏览器插件