Open Bug 463332 Opened 16 years ago Updated 2 years ago

No way for modules to register with xpcom category manager

Categories

(Core :: XPConnect, defect)

1.9.0 Branch
defect

Tracking

()

People

(Reporter: hello, Unassigned)

Details

XPCOM components have the ability to register with the category manager to get e.g. app-startup.  JS modules can't do this and need to rely on a component to call them.

I wrote such a component for my own use, and I was thinking about generalizing it to work with other modules.  But any options I can think of to generalize it feel clunky (since the component needs to know what resource URL to import and what object to send the observer notification to).

So, this feels like something that should be built into the platform.  I'm thinking of some sort of lightweight module registration with category manager support.
I don't think this is true. Can't they do this in their registration methods?

For instance, nsBrowserContentHandler.js does this.
nsBrowserContentHandler.js is a component, not a module, and thus does have the ability to register with the category manager to get startup notifications.  This bug is about giving modules that same capability.
How would you give a module this ability? The category manager just manages a persistent set of category/key/value string maps... these maps often store component contractIDs. Since modules are shared code and not components, they don't have contractIDs.
Here are a few thoughts:

* via the manifest file. it's piling more crap into that file, but at the same time that's where the resource url is defined (which is later used to import modules).  So you could have a couple of lines like:

resource foo modules/
register-category "app-startup" resource://foo/blah.js MyObject

* via prefs.  the component I wrote for my own use has hardcoded in it a Cu.import() for my module and runs a function in an object I export.  Everything else is 100% boilerplate.

A component could read prefs to determine what modules to import and what object to deliver the notification to.  For example:

modules.catreg.foo.categories = "app-startup, foobar"
modules.catreg.foo.resource = resource://foo/blah.js
modules.catreg.foo.object = MyObject

caveat here: I'm not sure when prefs are loaded, it might make it impossible for modules to register for early events like app-startup.

* via some other file.  okay, this is the grossest way.  but I'm pretty sure a component could walk the list of bundles and check whether they have some file in them (say, modulereg.json),  which could contain the necessary information to set things up.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.