Exposing Extension Functionality to Web-Page Javascript
From jstritar: I looked up how we expose an object to the javascript in web pages [in ForecastFox] - its actually really cool. The ffIWeb component provides an API for installing icon packs:
ffIWeb.idl: http://www.ensolis.com/cvs/forecastfox/src/components/ffWeb.idl?rev=1.2&content-type=text/vnd.viewcvs-markup
ffIWeb.js: http://www.ensolis.com/cvs/forecastfox/src/components/ffWeb.js?rev=1.5&content-type=text/vnd.viewcvs-markup
The key part is in the registerSelf function of gModule:
var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
catMgr.addCategoryEntry("JavaScript global property", "forecastfox", CONTRACT_ID, true, true);
After doing that, the ffIWeb XPCOM object is the "forecastfox" property of the window in client javascript. The name seems to imply its a property of everything... but it doesn't seem to be. Prehaps it only applies to global objects and/or window objects. If you look at the javascript at the top of http://forecastfox.mozdev.org/packs/ source you can see how it works on that side.
ffIWeb.idl: http://www.ensolis.com/cvs/forecastfox/src/components/ffWeb.idl?rev=1.2&content-type=text/vnd.viewcvs-markup
ffIWeb.js: http://www.ensolis.com/cvs/forecastfox/src/components/ffWeb.js?rev=1.5&content-type=text/vnd.viewcvs-markup
The key part is in the registerSelf function of gModule:
var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
catMgr.addCategoryEntry("JavaScript global property", "forecastfox", CONTRACT_ID, true, true);
After doing that, the ffIWeb XPCOM object is the "forecastfox" property of the window in client javascript. The name seems to imply its a property of everything... but it doesn't seem to be. Prehaps it only applies to global objects and/or window objects. If you look at the javascript at the top of http://forecastfox.mozdev.org/packs/ source you can see how it works on that side.