if (contentListener != m_contentListener)
if (contentListener.get() != m_contentListener.get())
nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports * aCtxt){  nsresult rv;  nsCAutoString 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(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;    // Check whether the data should be forced to be handled    // externally.  This could happen because the Content-Disposition    // header is set so, or, in the future, because the user has    // specified external handling for the MIME type.    PRBool forceExternalHandling = PR_FALSE;    nsCAutoString disposition;    nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));    if (httpChannel)    {      rv = httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"),                                          disposition);    }    else    {      nsCOMPtr<nsIMultiPartChannel> multipartChannel(do_QueryInterface(request));      if (multipartChannel)      {        rv = multipartChannel->GetContentDisposition(disposition);      }    }    if (NS_SUCCEEDED(rv) && !disposition.IsEmpty())    {      nsCAutoString::const_iterator start, end;      disposition.BeginReading(start);      disposition.EndReading(end);      // skip leading whitespace      while (start != end && nsCRT::IsAsciiSpace(*start))      {        ++start;      }      nsCAutoString::const_iterator iter = start;      // walk forward till we hit the next whitespace or semicolon      while (iter != end && *iter != ';' && !nsCRT::IsAsciiSpace(*iter))      {        ++iter;      }      if (start != iter &&          Substring(start, iter).Equals(NS_LITERAL_CSTRING("attachment"),                                        nsCaseInsensitiveCStringComparator()))      {        // We have a content-disposition of "attachment"        forceExternalHandling = PR_TRUE;      }    }        if (!forceExternalHandling)    {    //    // First step:  See if any nsIURIContentListener prefers to handle this    //              content type.    //    PRBool abortDispatch = PR_FALSE;    rv = uriLoader->DispatchContent(contentType.get(),                                    mIsContentPreferred,                                     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.    //    // We always want to do this, since even content being forced to    // be handled externally may need decoding (eg via the unknown    // content decoder)    if (!contentListener)     {      rv = RetargetOutput(request, contentType.get(), "*/*", 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)    {      if (!forceExternalHandling)      {      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 != m_contentListener)      {          // 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.get(),                                      mIsContentPreferred,                                      request,                                      getter_AddRefs(contentStreamListener),                                      &bAbortProcess);      // Do not continue loading if nsIURIContentListener::DoContent(...)      // fails - It means that an unexpected error occurred...      //      // If bAbortProcess is TRUE then the listener is doing all the work from      // here...we are done!!!      if (NS_FAILED(rv) || bAbortProcess) {        return rv;      }      }      // try to detect if there is a helper application we an use...      if (!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.get(), uri, m_originalContext, &abortProcess, getter_AddRefs(contentStreamListener));            if (NS_SUCCEEDED(rv) && contentStreamListener)              return RetargetOutput(request, contentType.get(), contentType.get(), 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.get(), desiredContentType, contentStreamListener);      // Reinitialize the content listener in case this is a multipart stream.      m_contentListener = do_GetInterface(m_originalContext);    }   }  return rv;}