How to find Contract ID by interface name?

170 views Asked by At

Example: I want to use the interface of nsILocalFile in Javascript, how to find the corresponding Contract ID("@mozilla.org/file/local;1")? Is there a map in the source code?

1

There are 1 answers

0
nmaier On BEST ANSWER

You don't. This isn't a one-to-one relationship between contracts and interfaces but a many-to-many one:

  • A single component as accessible by a contract can implement multiple interfaces.
  • A single interface can have multiple components implementing it and therefore multiple contracts.

But, often it is a one-to-one relationship in practice. E.g. if I wanted to find out about what components implement nsILocalFile, I'd search it in the sources, for instance:

Other times, the contract ids are even specified in the idl itself, e.g. in nsITimer.idl (at the bottom).

The most commonly used interfaces usually are also present on MDN incl. contracts, e.g. nsILocalFile.