I'm trying to build an nsIProtocolHandler implementation in Delphi. (I've done an IInternetProtocol before with success, and want to have in FireFox what I've got in Internet Explorer.) Thanks to the d-gecko project, that somehow links the TInterfacedObject magic to the nsISupports magic, I'm able to make a DLL that provides an nsIModule when asked, which provides an nsIFactory when asked, which provides one of my nsIProtocolHandler's when asked, which provides one of my nsIChannel/nsIHttpChannel's when asked.
When debugging using firefox.exe as host process, I can see my library gets loaded, NewURI gets called three times, NewChannel gets called, and I pass an object that implements nsIChannel and nsIHttpChannel.
This is where I'm troubled. I'm not supposed to call OnStartRequest and OnDataAvailable on the nsIStreamListener I get, until I return control from AsyncOpen, but I don't seem to get control back in the thread that AsyncOpen was called in.
I've tried debugging with a self-made wrapper around a default http handler (gotten with CreateInstanceByContractID('@mozilla.org/network/protocol;1?name=http',
...). I also wrapped the listener passed. Oddly enough, I see OnStartRequest and OnDataAvailable get called after my channel wrapper dies, in the same thread. But who's calling? If it's the http-channel I was trying to wrap, how does it survive (in the same thread) and how does it get control to call the listener? I'm baffled. And stuck.
I've tried to contact the main developer of the d-gecko project, but got no response.
(Also, did someone ever notice my blurb at the bottom of the talk page on MDC on nsIProtocolHandler?)
(Oh one more thing, yes I know "life would be simpler" if I would just inherit from nsBaseChannel in C++. But the point is to add a FireFox protocol-handler to an existing Delphi project core.)
Update: I've done some more reading, It's mentioned here as well: "The stream listener's methods are called on the thread that calls asyncOpen [...]" but how that is possible without being called from the 'hosting application' first, isn't clear to me. Is that an XPCOM trick? I guess I'll have to read (a lot) more firefox source before I get it.