rv = listener->OnStartRequest(this, ctxt);
rv = PostLoadEvent(this, HandleStartLoadEvent); if (NS_FAILED(rv)) { if (mLoadGroup) { PR_LOG(gLog, PR_LOG_DEBUG, ("nsCachedChromeChannel[%p]: removing self from load group %p", this, mLoadGroup.get()));
nsCachedChromeChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount, nsISupports *ctxt, nsIStreamListener *listener){    if (listener) {        nsresult rv;        if (mLoadGroup) {            PR_LOG(gLog, PR_LOG_DEBUG,                   ("nsCachedChromeChannel[%p]: adding self to load group %p",                    this, mLoadGroup.get()));            rv = mLoadGroup->AddChannel(this, nsnull);            if (NS_FAILED(rv)) return rv;        }        // Fire the OnStartRequest(), which will cause the XUL        // document to get embedded.        PR_LOG(gLog, PR_LOG_DEBUG,               ("nsCachedChromeChannel[%p]: firing OnStartRequest for %p",                this, listener));        rv = listener->OnStartRequest(this, ctxt);        // Queue an event to ourselves to let the stack unwind before        // calling OnStopRequest(). This allows embedding to occur        // before we fire OnStopRequest().        if (NS_SUCCEEDED(rv)) {            nsCOMPtr<nsIEventQueueService> svc = do_GetService(kEventQueueServiceCID, &rv);            if (svc) {                nsCOMPtr<nsIEventQueue> queue;                rv = svc->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue));                if (NS_SUCCEEDED(rv) && queue) {                    rv = NS_ERROR_OUT_OF_MEMORY;                    StopLoadEvent* event = new StopLoadEvent;                    if (event) {                        PL_InitEvent(NS_REINTERPRET_CAST(PLEvent*, event),                                     nsnull,                                     HandleStopLoadEvent,                                     DestroyStopLoadEvent);                        event->mChannel = this;                        NS_ADDREF(event->mChannel);                        rv = queue->EnterMonitor();                        if (NS_SUCCEEDED(rv)) {                            mContext  = ctxt;                            mListener = listener;                            (void) queue->PostEvent(NS_REINTERPRET_CAST(PLEvent*, event));                            (void) queue->ExitMonitor();                            return NS_OK;                        }                        // If we get here, something bad happened. Clean up.                        NS_RELEASE(event->mChannel);                        delete event;                    }                }            }        }        // Uh oh, something went wrong. Fire a balancing        // OnStopRequest() and indicate an error occurred.        PR_LOG(gLog, PR_LOG_DEBUG,               ("nsCachedChromeChannel[%p]: error 0x%x! firing on OnStopRequest for %p",                this, rv, mListener.get()));        (void) listener->OnStopRequest(this, ctxt, rv, nsnull);        if (mLoadGroup) {            PR_LOG(gLog, PR_LOG_DEBUG,                   ("nsCachedChromeChannel[%p]: removing self from load group %p",                    this, mLoadGroup.get()));            (void) mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);        }    }    return NS_OK;}