You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
4.0 KiB
Plaintext
67 lines
4.0 KiB
Plaintext
How to build a Scripting Plugins in Mozilla. (cross-browser NPAPI extensions )
|
|
|
|
1. Background.
|
|
A> plugin file type: Mozilla type browsers load plug-in from DLL (IE loads it as an ActiveX control).
|
|
B> HTML tag: both IE and Firefox(later version) support <object> tag, but IE use 'classid' to find ActiveX
|
|
and Mozilla type browser use MIMETYPE 'type' attribute
|
|
NOTE: you cnanot put a classid attribute there when load plugin in mozilla browser, otherwise plugin
|
|
won't be loaded.
|
|
C> Mozilla requires plugins to be put into sub-folder "plugins" under its program installed folder
|
|
D> Mozilla requires plugins' file has to be format of "NPxxxx.dll"
|
|
E> Mozilla plugin cannot be automatically downloaded by browser like IE when you specified a "codebase" attribute,
|
|
but you can build a xpi package and put it to mozilla web site to ask them to publish your plugin, in this
|
|
case, firefox can download your plugin and install it. but the most better idea is to create your own installation
|
|
program to install your plugin for both IE and firefox. in this case, you put your plugin under firefox
|
|
folder and register it, so that it can loaded by both browsers, otherwise, when installed by IE, it puts plugin
|
|
under its folder,then mozilla cannot loaded it. or installed by mozilla, it will not register plugin, so IE cannot load
|
|
it.
|
|
F> here is how plugin works in mozilla type browser:
|
|
> browser loads plugins info by obtaining plugin's functions throught dll's entry point.
|
|
> mozilla type browser first create a window that will be used to hold plugin
|
|
> browser then calls plugin's function to load plugin
|
|
G> our plugin support both IE and firefox by same code base and same dll by creating same Activex. but for firefix,
|
|
create a Activex is not really neccessary, you can just subclass your control or just work on the HWND mozilla
|
|
create for you. please see source code for more detail.
|
|
|
|
2. How to build ( following instruction is used to build a MFC activex project that support both IE and mozilla browsers )
|
|
***** sample project was built by VC++ 6.0
|
|
A> build a MFC ActiveX project ( or if you already have a activex project )
|
|
B> put all files in 'moz' under our sample projects into new this project folder
|
|
C> There two files need to be modified:
|
|
npp_gete.cpp: put your plugin information in lines that marked as "TODO"
|
|
mplugin.c: modify it so that plugin can load your window. your window will be created here.
|
|
D> add following files into your project:
|
|
mplugin.h, mplugin.cpp,np_entry.cpp, npn_gate.cpp,npp_gate.cpp
|
|
E> add 'XP_WIN' to your project setting / C++ / general / Preprocessor definitions
|
|
F> change dll name to NPxxx.dll ( or you can change it when you copy it to mozilla program folder )
|
|
G> modify project resource file ( .rc file ) by adding a MIME type (following 3 lines ):
|
|
VALUE "MIMEType", "application/x-your-type\0"
|
|
VALUE "FileExtents", "*\0"
|
|
VALUE "FileOpenName", "your-type\0"
|
|
|
|
********* important ****************************************
|
|
change block header from "BLOCK "040904b0" to "BLOCK 040904e4"
|
|
********* important ***************************************
|
|
|
|
H> export mozilla functions in your dll by adding following definitions to xxxx.def file:
|
|
NP_GetEntryPoints @5
|
|
NP_Initialize @6
|
|
NP_Shutdown @7
|
|
|
|
I> now build your project, you get a dll no matter its extension is .ocx or .dll, change its name
|
|
to NPxxx.dll and copy it to mozilla plugins folder.
|
|
(e.g: c:\program files\mozilla.org\mozilla\plugins\)
|
|
|
|
NOTE: this dll is still an activex component dll, you can register it and load it by IE.
|
|
|
|
J> now everything is done, you can run mozilla firefox, in address bar, type "about:plugins",
|
|
your plugin will display there
|
|
|
|
K> in sample project folder, their are testforff.html and testforie.html which load this plugin.
|
|
|
|
L> you can register MIME type for activex so that you can load activex by MIME type from IE.
|
|
|
|
Tips:
|
|
because container is diffirent between IE and mozilla, so plugin will behave diffirently in
|
|
diffirent type browsers, like keyboard etc.
|