if (mContentType.IsEmpty()) { LOG_SCOPE(gImgLog, "imgRequest::OnDataAvailable |sniffing of mimetype failed|");  nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));  nsresult rv = NS_ERROR_FAILURE; if (chan) { rv = chan->GetContentType(mContentType); }  if (NS_FAILED(rv)) { PR_LOG(gImgLog, PR_LOG_ERROR, ("[this=%p] imgRequest::OnDataAvailable -- Content type unavailable from the channel\n", this));  this->Cancel(NS_IMAGELIB_ERROR_FAILURE);  return NS_BINDING_ABORTED; }  LOG_MSG(gImgLog, "imgRequest::OnDataAvailable", "Got content type from the channel"); }  LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable", "content type", mContentType.get());  nsCAutoString conid(NS_LITERAL_CSTRING("@mozilla.org/image/decoder;2?type=") + mContentType);  mDecoder = do_CreateInstance(conid.get());  if (!mDecoder) { PR_LOG(gImgLog, PR_LOG_WARNING, ("[this=%p] imgRequest::OnDataAvailable -- Decoder not available\n", this));   this->Cancel(NS_IMAGELIB_ERROR_NO_DECODER);  return NS_IMAGELIB_ERROR_NO_DECODER; }  nsresult rv = mDecoder->Init(NS_STATIC_CAST(imgILoad*, this)); if (NS_FAILED(rv)) { PR_LOG(gImgLog, PR_LOG_WARNING, ("[this=%p] imgRequest::OnDataAvailable -- mDecoder->Init failed\n", this));  this->Cancel(NS_IMAGELIB_ERROR_FAILURE);  return NS_BINDING_ABORTED; }
if (!mDestListener) {  PRUint32 _retval; inStr->ReadSegments(dispose_of_data, nsnull, count, &_retval); return NS_OK;
NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctxt, nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count){  LOG_SCOPE_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable", "count", count);  NS_ASSERTION(aRequest, "imgRequest::OnDataAvailable -- no request!");  if (!mProcessing) {    LOG_SCOPE(gImgLog, "imgRequest::OnDataAvailable |First time through... finding mimetype|");    /* set our processing flag to true if this is the first OnDataAvailable() */    mProcessing = PR_TRUE;    /* look at the first few bytes and see if we can tell what the data is from that     * since servers tend to lie. :(     */    PRUint32 out;    inStr->ReadSegments(sniff_mimetype_callback, this, count, &out);#ifdef NS_DEBUG    /* NS_WARNING if the content type from the channel isn't the same if the sniffing */#endif    if (mContentType.IsEmpty()) {      LOG_SCOPE(gImgLog, "imgRequest::OnDataAvailable |sniffing of mimetype failed|");      nsCOMPtr<nsIChannel> chan(do_QueryInterface(aRequest));      nsresult rv = NS_ERROR_FAILURE;      if (chan) {        rv = chan->GetContentType(mContentType);      }      if (NS_FAILED(rv)) {        PR_LOG(gImgLog, PR_LOG_ERROR,               ("[this=%p] imgRequest::OnDataAvailable -- Content type unavailable from the channel\n",                this));        this->Cancel(NS_IMAGELIB_ERROR_FAILURE);        return NS_BINDING_ABORTED;      }      LOG_MSG(gImgLog, "imgRequest::OnDataAvailable", "Got content type from the channel");    }    LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable", "content type", mContentType.get());    nsCAutoString conid(NS_LITERAL_CSTRING("@mozilla.org/image/decoder;2?type=") + mContentType);    mDecoder = do_CreateInstance(conid.get());    if (!mDecoder) {      PR_LOG(gImgLog, PR_LOG_WARNING,             ("[this=%p] imgRequest::OnDataAvailable -- Decoder not available\n", this));      // no image decoder for this mimetype :(      this->Cancel(NS_IMAGELIB_ERROR_NO_DECODER);      return NS_IMAGELIB_ERROR_NO_DECODER;    }    nsresult rv = mDecoder->Init(NS_STATIC_CAST(imgILoad*, this));    if (NS_FAILED(rv)) {      PR_LOG(gImgLog, PR_LOG_WARNING,             ("[this=%p] imgRequest::OnDataAvailable -- mDecoder->Init failed\n", this));      this->Cancel(NS_IMAGELIB_ERROR_FAILURE);      return NS_BINDING_ABORTED;    }  }  if (!mDecoder) {    PR_LOG(gImgLog, PR_LOG_WARNING,           ("[this=%p] imgRequest::OnDataAvailable -- no decoder\n", this));    this->Cancel(NS_IMAGELIB_ERROR_NO_DECODER);    return NS_BINDING_ABORTED;  }  PRUint32 wrote;  nsresult rv = mDecoder->WriteFrom(inStr, count, &wrote);  if (NS_FAILED(rv)) {    PR_LOG(gImgLog, PR_LOG_WARNING,           ("[this=%p] imgRequest::OnDataAvailable -- mDecoder->WriteFrom failed\n", this));    this->Cancel(NS_IMAGELIB_ERROR_FAILURE);    return NS_BINDING_ABORTED;  }  return NS_OK;}