如何在 Windows 上编写 C++ FireFox 3 插件(不是扩展)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/62977/
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
How to write a C++ FireFox 3 plugin (not extension) on Windows?
提问by Lost Plugin Writer
Could someone write-up a step by step guide to developing a C++ based plugin for FireFox on Windows?
有人可以写一个分步指南来为 Windows 上的 FireFox 开发基于 C++ 的插件吗?
The links and examples on http://www.mozilla.org/projects/plugins/are all old and inaccurate - the "NEW" link was added to the page in 2004.
http://www.mozilla.org/projects/plugins/上的链接和示例都是旧的和不准确的——“新”链接是在 2004 年添加到页面的。
The example could be anything, but I was thinking a plugin that lets JavaScript set the name and then displays "Hello {Name}". To show 2-way communication, it could have a property that returns the full salutation.
这个例子可以是任何东西,但我在想一个插件,让 JavaScript 设置名称,然后显示“Hello {Name}”。为了显示双向通信,它可以具有返回完整称呼的属性。
Though not as important, it would be nice if the plugin would work in Chrome too.
虽然不那么重要,但如果插件也能在 Chrome 中运行就好了。
采纳答案by Nickolay
See also http://developer.mozilla.org/en/Plugins. And yes, NPAPI plugins should work in Google Chrome as well.
另请参阅http://developer.mozilla.org/en/Plugins。是的,NPAPI 插件也应该在 Google Chrome 中工作。
[edit 2015: Chrome removes support for NPAPI soon http://blog.chromium.org/2014/11/the-final-countdown-for-npapi.html]
[编辑 2015:Chrome 很快将取消对 NPAPI 的支持http://blog.chromium.org/2014/11/the-final-countdown-for-npapi.html]
回答by taxilian
If you need something that works cross-browser (firefox and ie), you could look at firebreath: http://www.firebreath.org
如果你需要跨浏览器(firefox 和 ie)的东西,你可以看看 firebreath:http: //www.firebreath.org
For general "how to build a npapi plugin on windows" information, I have a few blog posts on the subject (linked to from some of the above sources as well)
对于一般的“如何在 Windows 上构建 npapi 插件”信息,我有一些关于该主题的博客文章(也链接到上述一些来源)
http://colonelpanic.net/2009/03/building-a-firefox-plugin-part-one/
http://colonelpanic.net/2009/03/building-a-firefox-plugin-part-one/
I really recommend firebreath, however, since we created it exactly for people who don't have time to do the months (literally) of research that it took us to figure out how it all works. If you don't want to use it as a basis for your plugin, though, you can still find a lot of good example code there.
然而,我真的推荐 firebreath,因为我们正是为那些没有时间进行几个月(字面意思)研究的人创建了它,这些研究让我们弄清楚它是如何运作的。但是,如果您不想将其用作插件的基础,您仍然可以在那里找到很多很好的示例代码。
should work on chrome, firefox, and safari on windows too! =]
也应该在 Windows 上的 chrome、firefox 和 safari 上工作!=]
good luck!
祝你好运!
回答by Ben Combee
It's fairly simple to make a plugin using NPAPI. The key header files you'll need from the Gecko distribution are npapi.h and npupp.h. You'll export functions from your plugin DLL or shared library with the names NP_Initialize, NP_Shutdown, NP_GetMIMEDescription, and NP_GetValue, and you'll need to also fill in the symbol table given to you in the NP_Initialize call with handlers for all of the NPP functions.
使用 NPAPI 制作插件相当简单。您需要从 Gecko 发行版获得的关键头文件是 npapi.h 和 npupp.h。您将从您的插件 DLL 或共享库中导出名为 NP_Initialize、NP_Shutdown、NP_GetMIMEDescription 和 NP_GetValue 的函数,并且您还需要填写在 NP_Initialize 调用中提供给您的符号表以及所有 NPP 的处理程序职能。
The key functions to implement from that set are NPP_New and NPP_Destroy. Those define the lifecycle of a plugin instance. If you're going to handle a media file linked from an <object> or <embed>, you'll need to also deal with NPP_NewStream, NPP_WriteReady, NPP_Write, and NPP_DestroyStream as a way for your plugin to get the file's data from the browser. There's plenty more in the Gecko Plugin developer's guide.
从该集合中实现的关键函数是 NPP_New 和 NPP_Destroy。这些定义了插件实例的生命周期。如果您要处理从 <object> 或 <embed> 链接的媒体文件,您还需要处理 NPP_NewStream、NPP_WriteReady、NPP_Write 和 NPP_DestroyStream 作为插件从浏览器。还有很多更在壁虎插件开发人员指南。
回答by Charles Dietrich
Check out Nixysa http://code.google.com/p/nixysa/. I tried to build the samples in the Mozilla SDK but they were hard to build. The Nixysa sample is easy to build. Plus the code is much neater than directly using NPAPI. The only drawback is that as of today Nixysa is not well documented. I have a Nixysa sample that implements callbacks if you want it (I do plan on submitting a patch to Nixysa when I get around to it).
查看 Nixysa http://code.google.com/p/nixysa/。我尝试在 Mozilla SDK 中构建示例,但它们很难构建。Nixysa 示例很容易构建。此外,代码比直接使用 NPAPI 简洁得多。唯一的缺点是,截至今天,Nixysa 还没有得到很好的记录。我有一个 Nixysa 示例,如果您愿意,它可以实现回调(我确实计划在我遇到它时向 Nixysa 提交补丁)。