implement GetContentLength for mailbox protocol. Report progress

via the progress listener event sink associated with the load
This commit is contained in:
mscott%netscape.com 2000-05-03 21:19:22 +00:00
Родитель c77c2ff1b5
Коммит 04a20c671b
2 изменённых файлов: 46 добавлений и 9 удалений

Просмотреть файл

@ -75,6 +75,29 @@ nsMailboxProtocol::~nsMailboxProtocol()
delete m_lineStreamBuffer;
}
NS_IMETHODIMP nsMailboxProtocol::GetContentLength(PRInt32 * aContentLength)
{
*aContentLength = -1;
if (m_mailboxAction == nsIMailboxUrl::ActionParseMailbox)
{
// our file transport knows the entire length of the berkley mail folder
// so get it from there.
if (m_channel)
return m_channel->GetContentLength(aContentLength);
else
return NS_OK;
}
else if (m_runningUrl)
{
PRUint32 msgSize = 0;
m_runningUrl->GetMessageSize(&msgSize);
*aContentLength = (PRInt32) msgSize;
}
return NS_OK;
}
void nsMailboxProtocol::Initialize(nsIURI * aURL)
{
NS_PRECONDITION(aURL, "invalid URL passed into MAILBOX Protocol");
@ -112,6 +135,7 @@ void nsMailboxProtocol::Initialize(nsIURI * aURL)
m_nextState = MAILBOX_READ_FOLDER;
m_initialState = MAILBOX_READ_FOLDER;
mCurrentProgress = 0;
NS_NewFileSpecWithSpec(m_tempMsgFileSpec, getter_AddRefs(m_tempMessageFile));
}
@ -248,7 +272,7 @@ nsresult nsMailboxProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
// ohhh, display message already writes a msg to disk (as part of a hack)
// so we can piggy back off of that!! We just need to change m_tempMessageFile
// to be the name of our save message to disk file. Since save message to disk
// urls are run without a webshell to display the msg into, we won't be trying
// urls are run without a docshell to display the msg into, we won't be trying
// to display the message after we write it to disk...
{
nsCOMPtr<nsIMsgMessageUrl> msgUri = do_QueryInterface(m_runningUrl);
@ -304,11 +328,18 @@ PRInt32 nsMailboxProtocol::ReadFolderResponse(nsIInputStream * inputStream, PRUi
// folder parser object!!!
nsresult rv = NS_OK;
mCurrentProgress += length;
if (m_mailboxParser)
{
nsCOMPtr <nsIURI> url = do_QueryInterface(m_runningUrl);
rv = m_mailboxParser->OnDataAvailable(nsnull, url, inputStream, sourceOffset, length); // let the parser deal with it...
if (mProgressEventSink)
{
PRInt32 contentLength = 0;
GetContentLength(&contentLength);
mProgressEventSink->OnProgress(this, url, mCurrentProgress, contentLength);
}
}
if (NS_FAILED(rv))
@ -332,7 +363,8 @@ PRInt32 nsMailboxProtocol::ReadMessageResponse(nsIInputStream * inputStream, PRU
{
char *line = nsnull;
PRUint32 status = 0;
nsresult rv = NS_OK;
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...
@ -399,8 +431,14 @@ PRInt32 nsMailboxProtocol::ReadMessageResponse(nsIInputStream * inputStream, PRU
}
SetFlag(MAILBOX_PAUSE_FOR_READ); // wait for more data to become available...
if (mProgressEventSink)
{
PRInt32 contentLength = 0;
GetContentLength(&contentLength);
mProgressEventSink->OnProgress(this, m_channelContext, mCurrentProgress, contentLength);
}
if (NS_FAILED(rv)) return -1;
if (NS_FAILED(rv)) return -1;
return 0;
}

Просмотреть файл

@ -27,12 +27,9 @@
#include "nsCOMPtr.h"
#include "nsIFileSpec.h"
#include "nsIChannel.h"
#include "nsIOutputStream.h"
#include "nsIMailboxUrl.h"
#include "nsIWebShell.h" // mscott - this dependency should only be temporary!
// State Flags (Note, I use the word state in terms of storing
// state information about the connection (authentication, have we sent
// commands, etc. I do not intend it to refer to protocol state)
@ -72,7 +69,7 @@ public:
nsMailboxProtocol(nsIURI * aURL);
virtual ~nsMailboxProtocol();
// the consumer of the url might be something like an nsIWebShell....
// the consumer of the url might be something like an nsIDocShell....
virtual nsresult LoadUrl(nsIURI * aURL, nsISupports * aConsumer);
////////////////////////////////////////////////////////////////////////////////////////
@ -81,6 +78,7 @@ public:
NS_IMETHOD OnStartRequest(nsIChannel * aChannel, nsISupports *ctxt);
NS_IMETHOD OnStopRequest(nsIChannel * aChannel, nsISupports *ctxt, nsresult aStatus, const PRUnichar *aMsg);
NS_IMETHOD GetContentLength(PRInt32 * aContentLength);
private:
nsCOMPtr<nsIMailboxUrl> m_runningUrl; // the nsIMailboxURL that is currently running
@ -96,8 +94,9 @@ private:
// Generic state information -- What state are we in? What state do we want to go to
// after the next response? What was the last response code? etc.
MailboxStatesEnum m_nextState;
MailboxStatesEnum m_initialState;
MailboxStatesEnum m_initialState;
PRInt32 mCurrentProgress;
PRUint32 m_messageID;
nsCOMPtr<nsIFileSpec> m_tempMessageFile;