nsCOMPtr<nsIDOMWindow> domWindow (do_GetInterface(contentListener));
nsCOMPtr<nsIDOMWindow> domWindow (do_GetInterface(originalWindowContext));
nsresult nsDocumentOpenInfo::DispatchContent(nsIChannel * aChannel, nsISupports * aCtxt){  nsresult rv;  nsXPIDLCString contentType;  rv = aChannel->GetContentType(getter_Copies(contentType));  if (NS_FAILED(rv)) return rv;   // go to the uri dispatcher and give them our stuff...  NS_WITH_SERVICE(nsIURILoader, pURILoader, kURILoaderCID, &rv);  if (NS_SUCCEEDED(rv))  {    nsCOMPtr<nsIURIContentListener> contentListener;    nsXPIDLCString desiredContentType;    //    // First step:  See if any nsIURIContentListener prefers to handle this    //              content type.    //    PRBool abortDispatch = PR_FALSE;    rv = pURILoader->DispatchContent(contentType, mCommand, m_windowTarget,                                      aChannel, aCtxt,                                      m_contentListener,                                      m_originalContext,                                     getter_Copies(desiredContentType),                                      getter_AddRefs(contentListener),                                     &abortDispatch);    m_originalContext = nsnull; // we don't need this anymore....    // if the uri loader says to abort the dispatch then someone    // else must have stepped in and taken over for us...so stop..    if (abortDispatch) return NS_OK;    //    // Second step:  If no listener prefers this type, see if any stream    //               decoders exist to transform this content type into    //               some other.    //    if (!contentListener) {      nsDocumentOpenInfo* nextLink;      // When applying stream decoders, it is necessary to "insert" an       // intermediate nsDocumentOpenInfo instance to handle the targeting of      // the "final" stream or streams.      //      // For certain content types (ie. multi-part/x-mixed-replace) the input      // stream is split up into multiple destination streams.  This      // intermediate instance is used to target these "decoded" streams...      //      nextLink = Clone();      if (!nextLink) return NS_ERROR_OUT_OF_MEMORY;      NS_ADDREF(nextLink);      // Set up the final destination listener.      nextLink->m_targetStreamListener = nsnull;      // The following call binds this channelListener's mNextListener (typically      // the nsDocumentBindInfo) to the underlying stream converter, and returns      // the underlying stream converter which we then set to be this channelListener's      // mNextListener. This effectively nestles the stream converter down right      // in between the raw stream and the final listener.      // catch the case when some joker server sends back a content type of "*/*"      // because we said we could handle "*/*" in our accept headers      if (nsCRT::strcmp(contentType, "*/*")) {          rv = RetargetOutput(aChannel, contentType, "*/*", nextLink);          NS_RELEASE(nextLink);          if (m_targetStreamListener) {            return NS_OK;          }      } else {        NS_RELEASE(nextLink);      }    }        //    // Step 3:    //    // BIG TIME HACK ALERT!!!!! WE NEED THIS HACK IN PLACE UNTIL OUR NEW UNKNOWN CONTENT    // HANDLER COMES ONLINE!!!     // Until that day, if we couldn't find a handler for the content type, then go back to the listener who    // originated the url request and force them to handle the content....this forces us through the old code    // path for unknown content types which brings up the file save as dialog...    if (!contentListener) {      contentListener = m_contentListener;    }    //    // Good news!  Some content listener can handle this content type.    //    if (contentListener)    {      nsCOMPtr<nsIStreamListener> contentStreamListener;      PRBool bAbortProcess = PR_FALSE;           nsCAutoString contentTypeToUse;      if (desiredContentType)        contentTypeToUse.Assign(desiredContentType);      else        contentTypeToUse.Assign(contentType);      // We need to first figure out if we are retargeting the load to a content listener      // that is different from the one that originated the request....if so, set      // LOAD_RETARGETED_DOCUMENT_URI on the channel.       if (contentListener.get() != m_contentListener.get())      {         // we must be retargeting...so set an appropriate flag on the channel        nsLoadFlags loadAttribs = 0;        aChannel->GetLoadAttributes(&loadAttribs);        loadAttribs |= nsIChannel::LOAD_RETARGETED_DOCUMENT_URI;        aChannel->SetLoadAttributes(loadAttribs);      }      rv = contentListener->DoContent(contentTypeToUse, mCommand, m_windowTarget,                                     aChannel, getter_AddRefs(contentStreamListener),                                    &bAbortProcess);      // the listener is doing all the work from here...we are done!!!      if (bAbortProcess) return rv;      if (NS_FAILED(rv))      {        nsCOMPtr<nsIDOMWindow> domWindow (do_GetInterface(contentListener));        return InvokeUnknownContentHandler(aChannel, contentType, domWindow);      }      // okay, all registered listeners have had a chance to handle this content...      // did one of them give us a stream listener back? if so, let's start reading data      // into it...      rv = RetargetOutput(aChannel, contentType, desiredContentType, contentStreamListener);    }   }  return rv;}