XPCOM - Getting Started
Links
Sample
The sample code for this project is in my repository: http://toybox/hg/sample/file/tip/mozilla/xpcom/xpcom-test/
Setup
Following the above blog:
Download and install Visual C++ Express Edition.
Download
xulrunner-1.9.1.3.en-US.win32.sdk.zipfrom http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.9.1.3/sdk/Extract to a folder. I extracted to:
C:\src\xulrunner-1.9.1.3\
Download
wintools.zipfrom http://ftp.mozilla.org/pub/mozilla.org/mozilla/source/Open
wintools.zipand copy:buildtools/windows/bin/x86/glib-1.2.dllbuildtools/windows/bin/x86/libIDL-0.6.dll
…to the
sdk/bin/folder of yourxulrunnerproject e.g:C:\src\xulrunner-1.9.1.3\sdk\bin\
Download
xpcom-test.zipfrom http://starkravingfinkle.org/blog/wp-content/uploads/2006/10/Extract
xpcom-test.zipinto yourxulrunnerproject folder e.g:C:\development\sample\mozilla\xpcom\xpcom-test\
Build
We need to regenerate the
comp.handcomp.xptfiles in the root of thexpcom-testproject:Change into the
xpcom-testproject folder:cd C:\development\sample\mozilla\xpcom\xpcom-test\
Edit the
xpidl-build.batfile and update thesdkpaths:C:\src\xulrunner-1.9.1.3\sdk\bin\xpidl.exe -m header -IC:\src\xulrunner-1.9.1.3\sdk\idl %1 C:\src\xulrunner-1.9.1.3\sdk\bin\xpidl.exe -m typelib -IC:\src\xulrunner-1.9.1.3\sdk\idl %1
Regenerate the
comp.handcomp.xptfiles:xpidl-build.bat comp.idl
Start Visual C++ Express Edition and open the solution file:
C:\development\sample\mozilla\xpcom\xpcom-test\test.sln
Edit the project properties changing the location of the header and library files from
..\gecko-sdk\to..\\sdk\.C:\src\xulrunner-1.9.1.3\sdk\include C:\src\xulrunner-1.9.1.3\sdk\lib
Build the project. The build will create a
dllfile:C:\development\sample\mozilla\xpcom\xpcom-test\Debug\test.dll
Deploy
Note: You might need to open a command prompt with Administrator permissions before performing the next few steps.
Create a Firefox development profile, Profile…
Create a folder inside your Firefox profile for your component. I created the
component__xpcom-testfolder:C:\Users\Patrick\AppData\Roaming\Mozilla\Firefox\Profiles\h33vgw96.dev-xpcom-test\component__xpcom-test\
Copy the
comp.xptandDebug/test.dllfiles to your component folder:cd c:\development\sample\mozilla\xpcom\xpcom-test\ copy comp.xpt C:\Users\Patrick\AppData\Roaming\Mozilla\Firefox\Profiles\h33vgw96.dev-xpcom-test\component__xpcom-test\ copy Debug\test.dll C:\Users\Patrick\AppData\Roaming\Mozilla\Firefox\Profiles\h33vgw96.dev-xpcom-test\component__xpcom-test\
To register the component, run
regxpcom:cd C:\src\xulrunner-1.9.1.3\bin\ ..\sdk\bin\regxpcom.exe -x "C:\Users\Patrick\AppData\Roaming\Mozilla\Firefox\Profiles\h33vgw96.dev-xpcom-test\component__xpcom-test\"
Note: It is important to run
regxpcom.exe** from the ``binfolder (notsdk/bin) because the command needs some of thedllfiles in thebinfolder.
Test
Re-start Firefox:
"%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -P dev-xpcom-test
Download this test page: http://wanderingstan.com/files/xpcom/xpcom-test.html. A copy of this page is in the root of the sample project: xpcom-test.html
Note: Copy this page to your workstation before opening it. If you don’t, Firefox will throw an exception:
``Error: A script from "http://toybox" was denied UniversalXPConnect privileges``.
Load the test page in Firefox and click the test button. With any luck, you’ll see that 3+4=7.
You can now start modifying the component.
Be sure to go back and read the pages from Alex Sirota and Mark Finkle for more details.