We have a number of interfaces, including lots of embedding-
related ones, that implement nsIInterfaceRequestor, and expect
clients to use GetInterface to get ahold of interfaces that they
want.
The problem with GetInterface is that the implementation has to
eagerly instantiate whatever it is under the hood that supports that
interface (often an implementation class that is owned). If this
instantiation has side-effects, then GetInterface can end up being a
much more expensive call than the caller intended.
For example, say you can get to an nsIWebBrowserFind using GI from
nsIWebBrowser. Under the hood, the implementation of nsIWebBrowser
has to do a CreateInstance of an implemenation of nsIWebBrowserFind,
and hand that back to the caller.
Now, imagine that an embedder needs to test for the presence of a
Find string to enable the Find menu item. What they really want to
know is "is there a find implementation, and, if so, does it have a
zero length string". However, there is no way to test, currently,
whether nsIWebBrowser already has an implementation of
nsIWebBrowserFind that it can give back at zero cost.
I've run into similar issues with editor embedding, where I had to
jump through hoops to ensure that doing
nsIWebBrowser->GetInterface(NS_GET_IID(nsIEditingSession) didn't
suddenly try to make your document editable under you.
I guess what I'm looking for a method on nsIInterfaceRequestor that
is something like "IsInterfaceInstantiated" or
"IsInterfaceCheaplyAvailable".
Thoughts?
Simon
--
Simon Fraser Entomologist
[EMAIL PROTECTED] http://people.netscape.com/sfraser/