Add url listener manager support to mailbox urls.

This commit is contained in:
mscott%netscape.com 1999-03-03 01:14:45 +00:00
parent f236b51fd2
commit f81fb8eafa
2 changed files with 74 additions and 7 deletions

View File

@ -36,6 +36,7 @@
// that doesn't allow you to call ::nsISupports::IID() inside of a class
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID);
nsMailboxUrl::nsMailboxUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
{
@ -62,12 +63,18 @@ nsMailboxUrl::nsMailboxUrl(nsISupports* aContainer, nsIURLGroup* aGroup)
m_runningUrl = PR_FALSE;
m_urlListeners = nsnull;
nsServiceManager::GetService(kUrlListenerManagerCID, nsIUrlListenerManager::IID(),
(nsISupports **)&m_urlListeners);
m_container = aContainer;
NS_IF_ADDREF(m_container);
}
nsMailboxUrl::~nsMailboxUrl()
{
NS_IF_RELEASE(m_urlListeners);
NS_IF_RELEASE(m_container);
PR_FREEIF(m_errorMessage);
@ -91,26 +98,35 @@ NS_IMPL_THREADSAFE_RELEASE(nsMailboxUrl);
nsresult nsMailboxUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
if (NULL == aInstancePtr)
{
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsIMailboxUrl::IID()) ||
aIID.Equals(kISupportsIID)) {
if (aIID.Equals(nsIMailboxUrl::IID()) || aIID.Equals(kISupportsIID))
{
*aInstancePtr = (void*) ((nsIMailboxUrl*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIURL::IID())) {
if (aIID.Equals(nsIURL::IID()))
{
*aInstancePtr = (void*) ((nsIURL*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsINetlibURL::IID())) {
if (aIID.Equals(nsINetlibURL::IID()))
{
*aInstancePtr = (void*) ((nsINetlibURL*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMsgMailNewsUrl::IID()))
{
*aInstancePtr = (void *) ((nsIMsgMailNewsUrl *) this);
NS_ADDREF_THIS();
return NS_OK;
}
#if defined(NS_DEBUG)
/*
@ -198,6 +214,45 @@ nsresult nsMailboxUrl::GetErrorMessage (char ** errorMessage) const
return NS_OK;
}
// url listener registration details...
nsresult nsMailboxUrl::RegisterListener (nsIUrlListener * aUrlListener)
{
nsresult rv = NS_OK;
if (m_urlListeners)
rv = m_urlListeners->RegisterListener(aUrlListener);
return rv;
}
nsresult nsMailboxUrl::UnRegisterListener (nsIUrlListener * aUrlListener)
{
nsresult rv = NS_OK;
if (m_urlListeners)
rv = m_urlListeners->UnRegisterListener(aUrlListener);
return rv;
}
nsresult nsMailboxUrl::GetUrlState(PRBool * aRunningUrl)
{
if (aRunningUrl)
*aRunningUrl = m_runningUrl;
return NS_OK;
}
nsresult nsMailboxUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode)
{
m_runningUrl = aRunningUrl;
if (m_urlListeners)
{
if (m_runningUrl)
m_urlListeners->OnStartRunningUrl(this);
else
m_urlListeners->OnStopRunningUrl(this, aExitCode);
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// End nsIMailboxUrl specific support
@ -213,7 +268,12 @@ NS_METHOD nsMailboxUrl::SetURLInfo(URL_Struct *URL_s)
/* Hook us up with the world. */
m_URL_s = URL_s;
// NET_HoldURLStruct(URL_s);
if (m_mailboxAction == nsMailboxActionDisplayMessage)
{
// set the byte field range for the url struct...
}
return result;
}

View File

@ -20,6 +20,7 @@
#define nsMailboxUrl_h__
#include "nsIMailboxUrl.h"
#include "nsIUrlListenerManager.h"
#include "nsINetlibURL.h" /* this should be temporary until Network N2 project lands */
#include "nsFileSpec.h"
@ -71,11 +72,14 @@ public:
NS_IMPL_CLASS_GETSET(MailboxAction, nsMailboxAction, m_mailboxAction);
// from nsIMsgMailNewsUrl:
NS_IMPL_CLASS_GETSET(RunningUrlFlag, PRBool, m_runningUrl);
NS_IMETHOD SetUrlState(PRBool aRunningUrl, nsresult aExitCode);
NS_IMETHOD GetUrlState(PRBool * aRunningUrl);
NS_IMETHOD SetErrorMessage (char * errorMessage);
// caller must free using PR_FREE
NS_IMETHOD GetErrorMessage (char ** errorMessage) const;
NS_IMETHOD RegisterListener (nsIUrlListener * aUrlListener);
NS_IMETHOD UnRegisterListener (nsIUrlListener * aUrlListener);
// nsMailboxUrl
@ -92,6 +96,9 @@ protected:
// mailboxurl specific state
nsIStreamListener *m_mailboxParser;
// manager of all of current url listeners....
nsIUrlListenerManager * m_urlListeners;
/* Here's our link to the old netlib world.... */
URL_Struct *m_URL_s;