How to write C++ XPCOM components
I've been playing around with XPCOM to extend the functionality of Firefox. "Creating XPCOM components" is the best step by step introduction I have found so far. It details how to develop a C++ XPCOM component using windows and Visual Studio (2003).
Here's the summary of the steps:
- Download the Gecko SDK. It allows you to write XPCOM components without building Mozilla itself (which I still didn't manage to do :-[ ).
- Start an empty Win32 project in Visual Studio, selecting the "Dynamic Linked Library (DLL)" option.
- Create and IDL file describing the interface of your component.
- Run xpidl twice on the IDL file, with "xpidl -I <geckosdk/idl path> -m header <yourIDL file>" and "xpidl -I <geckosdk/idl path> -m typelib <yourIDL file>".
- Create a cpp file that includes the generated header file (which includes a a handy template for your class).
- Implement the main entry point (NSGetModule) and the XPCOM module and factory, as well as your own component (matching the signature in the generated header file). The tutorial provides a sample file which you can re-use (but there are some little code mistakes, see errata section).
- Configure Visual Studio to search headers in the Gecko SDK/include directory (with the "Additional Include Directories" setting in the "C/C++"->"General" tab). Do the same thing to include the Gecko SDK/lib directory (using the "Additional Library Directories" setting in the "Linker"->"General" tab).
- Build your component.
- Add a post-build event in Visual Studio to copy the XPCOM dll to Firefox's components directory with "copy $(OutDir)\<yourXPCOM>.dll <FirefoxDir>\components".
- Copy the xpt file (typelib) generated by xpidl to the Firefox components directory.
- Run regxpcom with "regxpcom -x <GeckoSDK>\bin <FireFoxDir>\components\<yourXPCOM>.dll".
- You can optionally configure Visual Studio to run and debug regxpcom to troubleshoot the previous step (thru the "Command", "Command Arguments" and "Working Directory" in the "Debugging" tab). It'll allow you to verify your dll gets loaded. The NSGetModule method makes for a good first breakpoint.
- Build a simple unittest html file, using "netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");" to get access to XPConnect/XPCOM. Use the Components object to create an instance of your component.
- Attach to the running Firefox.exe process to debug the component.
Java, Perl and Python can interoperate with XPCOM (see Blackwood for Java, PyXPCOM for Python and PlXPCOM for Perl). I wonder how difficult it would be to support .Net? You would be able to call XPCOM from .Net and implement XPCOM components using in .Net.
Sorry, it don't work with me.
I have an exception when I run my javascipt ("classe has no property")
Erm so where's the errata section?Posted by: Blurhead (February 15, 2005 11:59 PM) ______________________________________
I can't seem to find the errata anymore. It may have been integrated into an updated version of the main body?Posted by: Julien Couvreur (February 17, 2005 10:20 AM) ______________________________________ Craig (February 19, 2005 04:23 PM) ______________________________________
same as sim.
it doesn't work.
javasript throw an exception "classe has no property"
i want know how to change functionality of fireox
using xpcom in linux any one can tell me which step i should follow to create my own components....
thanx in advance.....
Can anyone help me in integrating flash player in XPCOM.Posted by: Amol (July 26, 2006 05:14 AM) ______________________________________
Abv details about xpcom in c++ is very clear and good......
PLZ give details abt " How to write XPCOM component in JAVA"