NS_IMETHODIMP nsMsgProgress::OnProgress(nsIRequest *request, nsISupports* ctxt,
                                        PRUint64 aProgress, PRUint64 aProgressMax)
{
  // XXX: What should the nsIWebProgress be?
  // XXX: This truncates 64-bit to 32-bit
  return OnProgressChange(nsnull, request, nsUint64(aProgress), nsUint64(aProgressMax),
                          nsUint64(aProgress) /* current total progress */, nsUint64(aProgressMax) /* max total progress */);
}
NS_IMETHODIMP
nsWyciwygChannel::OnDataAvailable(nsIRequest *request, nsISupports *ctx,
                                  nsIInputStream *input,
                                  PRUint32 offset, PRUint32 count)
{
  LOG(("nsWyciwygChannel::OnDataAvailable [this=%x request=%x offset=%u count=%u]\n",
      this, request, offset, count));

  nsresult rv;
  
  rv = mListener->OnDataAvailable(this, mListenerContext, input, offset, count);

  // XXX handle 64-bit stuff for real
  if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
    mProgressSink->OnProgress(this, nsnull, nsUint64(offset + count),
                              nsUint64(mContentLength));

  return rv; // let the pump cancel on failure
}
Exemple #3
0
NS_IMETHODIMP
nsXPInstallManager::OnProgress(nsIRequest* request, nsISupports *ctxt, PRUint64 aProgress, PRUint64 aProgressMax)
{
    nsresult rv = NS_OK;

    if (mDlg && !mCancelled)
    {
        if (mContentLength < 1) {
            nsCOMPtr<nsIChannel> channel = do_QueryInterface(request,&rv);
            NS_ASSERTION(channel, "should have a channel");
            if (NS_FAILED(rv)) return rv;
            rv = channel->GetContentLength(&mContentLength);
            if (NS_FAILED(rv)) return rv;
        }
        // XXX once channels support that, use 64-bit contentlength
        rv = mDlg->OnProgress( mNextItem-1, aProgress, nsUint64(mContentLength) );
    }

    return rv;
}
NS_IMETHODIMP
nsDownload::OnProgressChange64(nsIWebProgress *aWebProgress,
                               nsIRequest *aRequest,
                               PRInt64 aCurSelfProgress,
                               PRInt64 aMaxSelfProgress,
                               PRInt64 aCurTotalProgress,
                               PRInt64 aMaxTotalProgress)
{
    if (!mRequest)
        mRequest = aRequest; // used for pause/resume

    // Filter notifications since they come in so frequently, but we want to
    // process the last notification.
    PRTime now = PR_Now();
    nsInt64 delta = now - mLastUpdate;
    if (delta < gInterval && aCurTotalProgress != aMaxTotalProgress)
        return NS_OK;

    mLastUpdate = now;

    if (mDownloadState == NOTSTARTED) {
        nsCAutoString path;
        nsresult rv = GetFilePathUTF8(mTarget, path);
        if (NS_FAILED(rv)) return rv;

        mDownloadState = DOWNLOADING;
        mDownloadManager->DownloadStarted(path);
    }

    // Calculate the speed using the elapsed delta time and bytes downloaded
    // during that time for more accuracy.
    double elapsedSecs = double(delta) / PR_USEC_PER_SEC;
    if (elapsedSecs > 0) {
        nsUint64 curTotalProgress = (PRUint64)aCurTotalProgress;
        nsUint64 diffBytes = curTotalProgress - nsUint64(mCurrBytes);
        double speed = double(diffBytes) / elapsedSecs;
        if (LL_IS_ZERO(mCurrBytes))
            mSpeed = speed;
        else {
            // Calculate 'smoothed average' of 10 readings.
            mSpeed = mSpeed * 0.9 + speed * 0.1;
        }
    }

    if (aMaxTotalProgress > 0)
        mPercentComplete = aCurTotalProgress * 100 / aMaxTotalProgress;
    else
        mPercentComplete = -1;

    mCurrBytes = aCurTotalProgress;
    mMaxBytes = aMaxTotalProgress;

    if (mDownloadManager->MustUpdateUI()) {
        nsCOMPtr<nsIDownloadProgressListener> internalListener;
        mDownloadManager->GetInternalListener(getter_AddRefs(internalListener));
        if (internalListener) {
            internalListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
                                               aCurTotalProgress, aMaxTotalProgress, this);
        }
    }

    if (mDialogListener) {
        mDialogListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress,
                                          aCurTotalProgress, aMaxTotalProgress, this);
    }

    return NS_OK;
}
PRInt32 nsMailboxProtocol::ReadMessageResponse(nsIInputStream * inputStream, PRUint32 sourceOffset, PRUint32 length)
{
  char *line = nsnull;
  PRUint32 status = 0;
  nsresult rv = NS_OK;
  mCurrentProgress += length;
  
  // if we are doing a move or a copy, forward the data onto the copy handler...
  // if we want to display the message then parse the incoming data...
  
  if (m_channelListener)
  {
    // just forward the data we read in to the listener...
    rv = m_channelListener->OnDataAvailable(this, m_channelContext, inputStream, sourceOffset, length);
  }
  else
  {
    PRBool pauseForMoreData = PR_FALSE;
    PRBool canonicalLineEnding = PR_FALSE;
    nsCOMPtr<nsIMsgMessageUrl> msgurl = do_QueryInterface(m_runningUrl);
    
    if (msgurl)
      msgurl->GetCanonicalLineEnding(&canonicalLineEnding);
    do
    {
      char *saveLine;
      saveLine = line = m_lineStreamBuffer->ReadNextLine(inputStream, status, pauseForMoreData);
      
      if (!line || (line[0] == '.' && line[1] == 0))
      {
        // we reached the end of the message!
        ClearFlag(MAILBOX_PAUSE_FOR_READ);
      } // otherwise process the line
      else
      {
        if (line[0] == '.')
          line++; // skip over the '.'
        
        /* When we're sending this line to a converter (ie,
        it's a message/rfc822) use the local line termination
        convention, not CRLF.  This makes text articles get
        saved with the local line terminators.  Since SMTP
        and NNTP mandate the use of CRLF, it is expected that
        the local system will convert that to the local line
        terminator as it is read.
        */
        // mscott - the firstline hack is aimed at making sure we don't write
        // out the dummy header when we are trying to display the message.
        // The dummy header is the From line with the date tag on it.
        if (m_msgFileOutputStream && TestFlag(MAILBOX_MSG_PARSE_FIRST_LINE))
        {
          PRUint32 count = 0;
          if (line)
            rv = m_msgFileOutputStream->Write(line, PL_strlen(line),
            &count);
          if (NS_FAILED(rv)) break;
          
          if (canonicalLineEnding)
            rv = m_msgFileOutputStream->Write(CRLF, 2, &count);
          else
            rv = m_msgFileOutputStream->Write(MSG_LINEBREAK,
            MSG_LINEBREAK_LEN, &count);
          
          if (NS_FAILED(rv)) break;
        }
        else
          SetFlag(MAILBOX_MSG_PARSE_FIRST_LINE);
      } 
      PR_Free(saveLine);
    }
    while (line && !pauseForMoreData);
  }
  
  SetFlag(MAILBOX_PAUSE_FOR_READ); // wait for more data to become available...
  if (mProgressEventSink)
  {
    PRInt32 contentLength = 0;
    GetContentLength(&contentLength);
    // XXX 64-bit
    mProgressEventSink->OnProgress(this, m_channelContext,
                                   nsUint64(mCurrentProgress),
                                   nsUint64(contentLength));
  }
  
  if (NS_FAILED(rv)) return -1;
  
  return 0;
}