views:

6997

answers:

5

Could someone write-up a step by step guide to developing a C++ based plugin for FireFox on Windows?

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.

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.

Though not as important, it would be nice if the plugin would work in Chrome too...

Thanks in advance.

A: 

Anything more specific about the "problems with latest Gecko (1.9)"?

Lost Plugin Writer
+2  A: 

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.

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.

Ben Combee
+1  A: 

See also http://developer.mozilla.org/en/Plugins . And yes, NPAPI plugins should work in Google Chrome as well.

Nickolay
+2  A: 

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).

Charles
Have you tried it as an extension? I have yet to find a *single one* NPAPI Visual Studio solution that would build! If you still have it, I would like to see the code you have, and instructions how to get it build... nixysa has solution file for example "complex" but it does not compile either. Using the scons the examples do compile but compiled dll is broken, it is missing stuff (?) and Chrome does not find the methods of the plugin. Thanks.
Ciantic
+3  A: 

If you need something that works cross-browser (firefox and ie), you could look at firebreath: http://firebreath.googlecode.com

It's nearing a 1.0 release, but is currently windows only.

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)

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.

should work on chrome, firefox, and safari on windows too! =]

good luck!

Taxilian
Wow, buddy, you just saved my bacon, thanks for an incredible api and all-round heroic contribution.
Gearoid Murphy