简体   繁体   English

如何在 Windows 上编写 C++ FireFox 3 插件(非扩展)?

[英]How to write a C++ FireFox 3 plugin (not extension) on Windows?

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}".这个例子可以是任何东西,但我在想一个插件,让 JavaScript 设置名称,然后显示“Hello {Name}”。 To show 2-way communication, it could have a property that returns the full salutation.为了显示双向通信,它可以具有返回完整称呼的属性。

Though not as important, it would be nice if the plugin would work in Chrome too.虽然不那么重要,但如果该插件也可以在 Chrome 中运行,那就太好了。

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.然而,我真的推荐 firebreath,因为我们正是为那些没有时间进行数月(字面意思)研究的人创建的,我们花了几个月的时间才弄清楚它是如何工作的。 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.但是,如果您不想将它用作插件的基础,您仍然可以在那里找到很多很好的示例代码。

should work on chrome, firefox, and safari on windows too!也可以在 windows 上使用 chrome、firefox 和 safari! =] =]

good luck!祝你好运!

See also http://developer.mozilla.org/en/Plugins .另请参阅http://developer.mozilla.org/en/Plugins And yes, NPAPI plugins should work in Google Chrome as well.是的,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 ]

It's fairly simple to make a plugin using NPAPI.使用 NPAPI 制作插件相当简单。 The key header files you'll need from the Gecko distribution are npapi.h and npupp.h.您需要的 Gecko 发行版中的关键 header 文件是 npapi.h 和 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.您将从插件 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.从该集合中实现的关键函数是 NPP_New 和 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.如果您要处理从 <object> 或 <embed> 链接的媒体文件,您还需要处理 NPP_NewStream、NPP_WriteReady、NPP_Write 和 NPP_DestroyStream 作为插件从浏览器。 There's plenty more in the Gecko Plugin developer's guide . Gecko 插件开发者指南中还有更多内容。

Check out Nixysa http://code.google.com/p/nixysa/ .查看 Nixysa http://code.google.com/p/nixysa/ I tried to build the samples in the Mozilla SDK but they were hard to build.我尝试在 Mozilla SDK 中构建示例,但它们很难构建。 The Nixysa sample is easy to build. Nixysa 示例很容易构建。 Plus the code is much neater than directly using NPAPI.加上代码比直接使用 NPAPI 更简洁。 The only drawback is that as of today Nixysa is not well documented.唯一的缺点是截至今天 Nixysa 没有很好的文档记录。 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 示例,可以根据需要实现回调(我确实计划在处理它时向 Nixysa 提交补丁)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM