2009-08-05

Building `npruntime` Sample Plugin in Ubuntu

(Small technical note on NPAPI plugins.)

Gecko SDK is provided with example NPAPI plugins. While it is rather easy to get Basic plugin running on Ubuntu, it is not so trivial task with Scriptable plugin.

To start with, I assume that Gecko SDK 1.9.1 is downloaded and installed in `/home/user/xulrunner-sdk`.

Back to Scriptable plugin. I found bundled `Makefile.in` not really usable. I wrote my own `Makefile` based on that for Basic plugin:

CFLAGS = -Wall -DXP_UNIX=1 -DMOZ_X11=1 -fPIC -g
INCLUDE = -I/home/user/xulrunner-sdk/include/plugin

npsimpleplugin : plugin.o
cc $(CFLAGS) -shared -o npsimpleplugin.so \
np_entry.o npn_gate.o npp_gate.o plugin.o \
-lstdc++

plugin.o : plugin.cpp plugin.h
cc -c $(CFLAGS) $(INCLUDE) \
np_entry.cpp npn_gate.cpp npp_gate.cpp plugin.cpp


Then, time for some code hacks. `NPString.UTF8Characters` and `NPString.UTF8Length` members were changed to lowercase, `NPString.utf8characters` and `NPString.utf8length`. All occurrences in `plugin.cpp` should be fixed.

All done, time to test. Create folder for Mozilla plugins if that does not exist:

mkdir ~/.mozilla/plugins


Make and install plugin (yes, I know about `make install`):

make && rm *.o && mv npsimpleplugin.so ~/.mozilla/plugins/


Start Firefox and navigate to test page (also available from Mozilla VCS):

firefox-3.5 test.html


Plugin should be recognized and loaded, all fancy buttons and alerts should be working. Enjoy.

1 comment:

匆匆 said...

I also met with the lower case problem. I don't know why Mozilla changed these functions into lower case...