if (bAbortProcess) return rv;
if (NS_FAILED(rv) || bAbortProcess) { return rv; }
nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * aCtxt){  nsresult rv;  nsXPIDLCString contentType;  nsCOMPtr<nsISupports> originalWindowContext = m_originalContext; // local variable to keep track of this.  nsCOMPtr<nsIStreamListener> contentStreamListener;  nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);  if (!aChannel) {      return NS_ERROR_FAILURE;  }  rv = aChannel->GetContentType(getter_Copies(contentType));  if (NS_FAILED(rv)) return rv;   // go to the uri dispatcher and give them our stuff...  nsCOMPtr<nsIURILoader> uriLoader;  uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID, &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 = uriLoader->DispatchContent(contentType, mCommand,                                     request, aCtxt,                                     m_contentListener,                                     m_originalContext,                                    getter_Copies(desiredContentType),                                     getter_AddRefs(contentListener),                                    &abortDispatch);      // 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)     {      rv = RetargetOutput(request, contentType, "*/*", nsnull);      if (m_targetStreamListener)        return NS_OK;    }        //    // 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)    {      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 loadFlags = 0;        aChannel->GetLoadFlags(&loadFlags);        loadFlags |= nsIChannel::LOAD_RETARGETED_DOCUMENT_URI;        aChannel->SetLoadFlags(loadFlags);      }      rv = contentListener->DoContent(contentTypeToUse, mCommand,                                     request, getter_AddRefs(contentStreamListener),                                    &bAbortProcess);      // the listener is doing all the work from here...we are done!!!      if (bAbortProcess) return rv;      // try to detect if there is a helper application we an use...      if (/* mCommand == nsIURILoader::viewUserClick && */ !contentStreamListener)      {        nsCOMPtr<nsIURI> uri;        PRBool abortProcess = PR_FALSE;        aChannel->GetURI(getter_AddRefs(uri));        nsCOMPtr<nsIExternalHelperAppService> helperAppService (do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID));        if (helperAppService)        {            rv = helperAppService->DoContent(contentType, uri, m_originalContext, &abortProcess, getter_AddRefs(contentStreamListener));            if (NS_SUCCEEDED(rv) && contentStreamListener)              return RetargetOutput(request, contentType, contentType, contentStreamListener);        }        rv = NS_ERROR_FAILURE; // this will cause us to bring up the unknown content handler dialog.      }      // 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(request, contentType, desiredContentType, contentStreamListener);      m_originalContext = nsnull; // we don't need this anymore....    }   }  return rv;}