if (channelURI) { channelURI->GetSpec(spec);
if (channel) { nsCOMPtr<nsIURI> uri; channel->GetURI(getter_AddRefs(uri)); if (uri) uri->GetSpec(spec);
SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,                                nsISupports* aContext,                                nsresult aStatus,                                nsIUnicharInputStream* aDataStream){  LOG(("SheetLoadData::OnStreamComplete"));  NS_ASSERTION(!mLoader->mSyncCallback, "Synchronous callback from necko");  if (mIsCancelled) {    // Just return.  Don't call SheetComplete -- it's already been    // called and calling it again will lead to an extra NS_RELEASE on    // this data and a likely crash.    return NS_OK;  }    if (!mLoader->mDocument && !mIsAgent) {    // Sorry, we don't care about this load anymore    LOG_WARN(("  No document and not agent sheet; dropping load"));    mLoader->SheetComplete(this, PR_FALSE);    return NS_OK;  }    nsCOMPtr<nsIChannel> channel;  nsresult result = aLoader->GetChannel(getter_AddRefs(channel));  if (NS_FAILED(result))    channel = nsnull;    nsCOMPtr<nsIURI> channelURI;  if (channel) {    channel->GetURI(getter_AddRefs(channelURI));  }  #ifdef MOZ_TIMELINE  NS_TIMELINE_OUTDENT();  NS_TIMELINE_MARK_CHANNEL("SheetLoadData::OnStreamComplete(%s)", channel);#endif // MOZ_TIMELINE    // If it's an HTTP channel, we want to make sure this is not an  // error document we got.  nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));  if (httpChannel) {    PRBool requestSucceeded;    result = httpChannel->GetRequestSucceeded(&requestSucceeded);    if (NS_SUCCEEDED(result) && !requestSucceeded) {      LOG(("  Load returned an error page"));      mLoader->SheetComplete(this, PR_FALSE);      return NS_OK;    }  }  if (aDataStream) {    nsCAutoString contentType;    if (channel) {      channel->GetContentType(contentType);    }        PRBool validType = contentType.Equals(NS_LITERAL_CSTRING("text/css")) ||      contentType.Equals(NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE)) ||      contentType.IsEmpty();                                              if (mLoader->mCompatMode == eCompatibility_NavQuirks || validType) {      if (!validType) {        nsCAutoString spec;        if (channelURI) {          channelURI->GetSpec(spec);        }        const nsAFlatString& specUCS2 = NS_ConvertUTF8toUCS2(spec);        const nsAFlatString& ctypeUCS2 = NS_ConvertASCIItoUCS2(contentType);        const PRUnichar *strings[] = { specUCS2.get(), ctypeUCS2.get() };        ReportToConsole(NS_LITERAL_STRING("MimeNotCssWarn").get(), strings, 2,                        nsIScriptError::warningFlag);      }    } else {      // Drop the data stream so that we do not load it      aDataStream = nsnull;            nsCAutoString spec;      if (channelURI) {        channelURI->GetSpec(spec);      }      const nsAFlatString& specUCS2 = NS_ConvertUTF8toUCS2(spec);      const nsAFlatString& ctypeUCS2 = NS_ConvertASCIItoUCS2(contentType);      const PRUnichar *strings[] = { specUCS2.get(), ctypeUCS2.get() };      ReportToConsole(NS_LITERAL_STRING("MimeNotCss").get(), strings, 2,                      nsIScriptError::errorFlag);    }  }    if (NS_FAILED(aStatus) || !aDataStream) {    LOG_WARN(("  Load failed: status %u, data stream %p",              aStatus, aDataStream));    mLoader->SheetComplete(this, PR_FALSE);    return NS_OK;  }  if (channelURI) {    // Enough to set the URI on mSheet, since any sibling datas we have share    // the same mInner as mSheet and will thus get the same URI.    mSheet->SetURL(channelURI);  }    PRBool completed;  return mLoader->ParseSheet(aDataStream, this, completed);}