From db5cd594e2da0fea92ad0da47743df98990bcff3 Mon Sep 17 00:00:00 2001 From: "scc%netscape.com" Date: Tue, 7 Dec 1999 14:06:36 +0000 Subject: [PATCH] Make observers support weak references. Bug #18682; r=dp. --- content/xml/document/src/nsXMLContentSink.cpp | 22 ++++---- content/xml/document/src/nsXMLContentSink.h | 2 + .../pics/public/nsPICSElementObserver.h | 7 ++- extensions/pics/src/nsPICSElementObserver.cpp | 52 +++++++------------ extensions/wallet/src/nsWalletService.cpp | 42 ++++++--------- extensions/wallet/src/nsWalletService.h | 4 +- extensions/xmlterm/base/mozXMLTerminal.cpp | 45 +++++----------- extensions/xmlterm/base/mozXMLTerminal.h | 4 +- intl/chardet/src/nsMetaCharsetObserver.cpp | 44 ++++------------ intl/chardet/src/nsXMLEncodingObserver.cpp | 44 ++++------------ layout/xml/document/src/nsXMLContentSink.cpp | 22 ++++---- layout/xml/document/src/nsXMLContentSink.h | 2 + mailnews/base/src/nsMsgAccountManager.cpp | 2 +- mailnews/base/src/nsMsgAccountManager.h | 6 ++- mailnews/base/src/nsMsgBiffManager.cpp | 2 +- mailnews/base/src/nsMsgBiffManager.h | 7 ++- mailnews/base/src/nsMsgRDFDataSource.cpp | 32 +++--------- mailnews/base/src/nsMsgRDFDataSource.h | 2 + .../protocol/ftp/src/nsFtpProtocolHandler.cpp | 11 +++- .../protocol/ftp/src/nsFtpProtocolHandler.h | 4 +- xpcom/tests/TestObserverService.cpp | 5 +- xpfe/appshell/src/nsAppShellService.cpp | 14 ++++- xpfe/browser/src/nsBrowserInstance.cpp | 30 +++++++---- xpfe/browser/src/nsBrowserInstance.h | 4 +- 24 files changed, 182 insertions(+), 227 deletions(-) diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index db0b78d9ab90..60d5a80624d5 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -240,22 +240,26 @@ nsXMLContentSink::Init(nsIDocument* aDoc, #ifndef XSL -NS_IMPL_ISUPPORTS3(nsXMLContentSink, - nsIXMLContentSink, - nsIContentSink, - nsIUnicharStreamLoaderObserver) +NS_IMPL_ADDREF(nsXMLContentSink) +NS_IMPL_RELEASE(nsXMLContentSink) #else NS_IMPL_THREADSAFE_ADDREF(nsXMLContentSink) NS_IMPL_THREADSAFE_RELEASE(nsXMLContentSink) -NS_IMPL_QUERY_INTERFACE4(nsXMLContentSink, - nsIXMLContentSink, - nsIContentSink, - nsIObserver, - nsIUnicharStreamLoaderObserver) + #endif +NS_INTERFACE_MAP_BEGIN(nsXMLContentSink) + NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink) +#ifdef XSL + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) +#endif + NS_INTERFACE_MAP_ENTRY(nsIUnicharStreamLoaderObserver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink) +NS_INTERFACE_MAP_END + // nsIContentSink NS_IMETHODIMP nsXMLContentSink::WillBuildModel(void) diff --git a/content/xml/document/src/nsXMLContentSink.h b/content/xml/document/src/nsXMLContentSink.h index 6bf34aa5f4b9..35052ee2e6fe 100644 --- a/content/xml/document/src/nsXMLContentSink.h +++ b/content/xml/document/src/nsXMLContentSink.h @@ -28,6 +28,7 @@ #include "nsIScrollableView.h" #ifdef XSL #include "nsIObserver.h" +#include "nsWeakReference.h" #include "nsITransformMediator.h" #endif #include "nsIUnicharInputStream.h" @@ -56,6 +57,7 @@ typedef enum { class nsXMLContentSink : public nsIXMLContentSink, #ifdef XSL public nsIObserver, + public nsSupportsWeakReference, #endif public nsIUnicharStreamLoaderObserver { diff --git a/extensions/pics/public/nsPICSElementObserver.h b/extensions/pics/public/nsPICSElementObserver.h index 05ed6d937083..2027ac31fcd6 100644 --- a/extensions/pics/public/nsPICSElementObserver.h +++ b/extensions/pics/public/nsPICSElementObserver.h @@ -26,6 +26,7 @@ #include "nsIFactory.h" #include "nsIElementObserver.h" #include "nsIObserver.h" +#include "nsWeakReference.h" // {E12F6997-F28F-11d2-8ACE-00105A1B8860} @@ -34,7 +35,11 @@ -class nsPICSElementObserver : public nsIElementObserver, public nsIObserver { +class nsPICSElementObserver + : public nsIElementObserver, + public nsIObserver, + public nsSupportsWeakReference +{ public: nsPICSElementObserver(); diff --git a/extensions/pics/src/nsPICSElementObserver.cpp b/extensions/pics/src/nsPICSElementObserver.cpp index 8fdbf9889a76..b86075dbac13 100644 --- a/extensions/pics/src/nsPICSElementObserver.cpp +++ b/extensions/pics/src/nsPICSElementObserver.cpp @@ -57,7 +57,25 @@ static NS_DEFINE_IID(kPICSCID, NS_PICS_CID); NS_IMPL_ADDREF(nsPICSElementObserver) \ -NS_IMPL_RELEASE(nsPICSElementObserver) +NS_IMPL_RELEASE(nsPICSElementObserver) + + +NS_INTERFACE_MAP_BEGIN(nsPICSElementObserver) + /* + Slight problem here: there is no |class nsIPICSElementObserver|, + so, this is a slightly un-orthodox entry, which will have to be + fixed before we could switch over to the table-driven mechanism. + */ + if ( aIID.Equals(kIPICSElementObserverIID) ) + foundInterface = NS_STATIC_CAST(nsIElementObserver*, this); + else + + NS_INTERFACE_MAP_ENTRY(nsIElementObserver) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIElementObserver) +NS_INTERFACE_MAP_END + NS_PICS nsresult NS_NewPICSElementObserver(nsIObserver** anObserver) { @@ -85,38 +103,6 @@ nsPICSElementObserver::~nsPICSElementObserver(void) } -NS_IMETHODIMP nsPICSElementObserver::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - - if( NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - *aInstancePtr = NULL; - - if( aIID.Equals ( kIPICSElementObserverIID )) { - *aInstancePtr = (void*) ((nsIElementObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - if( aIID.Equals ( kIElementObserverIID )) { - *aInstancePtr = (void*) ((nsIElementObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - if( aIID.Equals ( kIObserverIID )) { - *aInstancePtr = (void*) ((nsIObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - - if( aIID.Equals ( kISupportsIID )) { - *aInstancePtr = (void*) (this); - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - const char* nsPICSElementObserver::GetTagNameAt(PRUint32 aTagIndex) { if (aTagIndex == 0) { diff --git a/extensions/wallet/src/nsWalletService.cpp b/extensions/wallet/src/nsWalletService.cpp index 4806686cdf77..14ec043bb3af 100644 --- a/extensions/wallet/src/nsWalletService.cpp +++ b/extensions/wallet/src/nsWalletService.cpp @@ -55,35 +55,27 @@ nsWalletlibService::~nsWalletlibService() { } -NS_IMETHODIMP -nsWalletlibService::QueryInterface(REFNSIID iid, void** result) -{ - if (! result) { - return NS_ERROR_NULL_POINTER; - } - *result = nsnull; - - if (iid.Equals(NS_GET_IID(nsISupports)) || iid.Equals(kIWalletServiceIID)) { - *result = NS_STATIC_CAST(nsIWalletService*, this); - AddRef(); - return NS_OK; - } - if (iid.Equals(kIFormSubmitObserverIID)) { - *result = NS_STATIC_CAST(nsIFormSubmitObserver*, this); - AddRef(); - return NS_OK; - } - if (iid.Equals(nsIDocumentLoaderObserver::GetIID())) { - *result = (void*) ((nsIDocumentLoaderObserver*)this); - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} NS_IMPL_ADDREF(nsWalletlibService); NS_IMPL_RELEASE(nsWalletlibService); +NS_INTERFACE_MAP_BEGIN(nsWalletlibService) + NS_INTERFACE_MAP_ENTRY(nsIWalletService) + + /* + Note: although this class always inherited from |nsIObserver|, + |QueryInterface| didn't previously respond to this request. + Now it does. + */ + NS_INTERFACE_MAP_ENTRY(nsIObserver) + + NS_INTERFACE_MAP_ENTRY(nsIFormSubmitObserver) + NS_INTERFACE_MAP_ENTRY(nsIDocumentLoaderObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWalletService) +NS_INTERFACE_MAP_END + + NS_IMETHODIMP nsWalletlibService::WALLET_PreEdit(nsAutoString& walletList) { ::WLLT_PreEdit(walletList); return NS_OK; diff --git a/extensions/wallet/src/nsWalletService.h b/extensions/wallet/src/nsWalletService.h index 972d628b5cdd..4e5eccb60571 100644 --- a/extensions/wallet/src/nsWalletService.h +++ b/extensions/wallet/src/nsWalletService.h @@ -27,11 +27,13 @@ #include "nsIObserver.h" #include "nsIFormSubmitObserver.h" #include "nsIDocumentLoaderObserver.h" +#include "nsWeakReference.h" class nsWalletlibService : public nsIWalletService, public nsIObserver, public nsIFormSubmitObserver, - public nsIDocumentLoaderObserver { + public nsIDocumentLoaderObserver, + public nsSupportsWeakReference { public: NS_DECL_ISUPPORTS diff --git a/extensions/xmlterm/base/mozXMLTerminal.cpp b/extensions/xmlterm/base/mozXMLTerminal.cpp index 5fc8b7b68124..4f861a820eae 100644 --- a/extensions/xmlterm/base/mozXMLTerminal.cpp +++ b/extensions/xmlterm/base/mozXMLTerminal.cpp @@ -125,39 +125,18 @@ NS_IMPL_ADDREF(mozXMLTerminal) NS_IMPL_RELEASE(mozXMLTerminal) -NS_IMETHODIMP -mozXMLTerminal::QueryInterface(REFNSIID aIID,void** aInstancePtr) -{ - if (aInstancePtr == NULL) { - return NS_ERROR_NULL_POINTER; - } - - // Always NULL result, in case of failure - *aInstancePtr = NULL; - - if ( aIID.Equals(kISupportsIID)) { - *aInstancePtr = NS_STATIC_CAST(nsISupports*, - NS_STATIC_CAST(mozIXMLTerminal*,this)); - - } else if ( aIID.Equals(mozIXMLTerminal::GetIID()) ) { - *aInstancePtr = NS_STATIC_CAST(mozIXMLTerminal*,this); - - } else if (aIID.Equals(nsIDocumentLoaderObserver::GetIID())) { - *aInstancePtr = NS_STATIC_CAST(nsIDocumentLoaderObserver*,this); - - } else if (aIID.Equals(nsIObserver::GetIID())) { - *aInstancePtr = NS_STATIC_CAST(nsIObserver*,this); - - } else { - return NS_ERROR_NO_INTERFACE; - } - - NS_ADDREF_THIS(); - - XMLT_LOG(mozXMLTerminal::QueryInterface,20,("mRefCnt = %d\n", mRefCnt)); - - return NS_OK; -} +NS_INTERFACE_MAP_BEGIN(mozXMLTerminal) + /* + I maintained the order from the original, however, + the original called |XMLT_LOG| and in the interface-map form + it no longer does. Is this an issue? + */ + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozIXMLTerminal) + NS_INTERFACE_MAP_ENTRY(mozIXMLTerminal) + NS_INTERFACE_MAP_ENTRY(nsIDocumentLoaderObserver) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) +NS_INTERFACE_MAP_END NS_IMETHODIMP mozXMLTerminal::GetCurrentEntryNumber(PRInt32 *aNumber) diff --git a/extensions/xmlterm/base/mozXMLTerminal.h b/extensions/xmlterm/base/mozXMLTerminal.h index bf7f424b3519..9f2e6adb2d58 100644 --- a/extensions/xmlterm/base/mozXMLTerminal.h +++ b/extensions/xmlterm/base/mozXMLTerminal.h @@ -25,6 +25,7 @@ #include "nscore.h" #include "nspr.h" #include "nsCOMPtr.h" +#include "nsWeakReference.h" #include "nsString.h" #include "mozXMLT.h" @@ -38,7 +39,8 @@ class mozXMLTerminal : public mozIXMLTerminal, public nsIDocumentLoaderObserver, - public nsIObserver + public nsIObserver, + public nsSupportsWeakReference { public: diff --git a/intl/chardet/src/nsMetaCharsetObserver.cpp b/intl/chardet/src/nsMetaCharsetObserver.cpp index 390d16ad30c2..3cea4e099689 100644 --- a/intl/chardet/src/nsMetaCharsetObserver.cpp +++ b/intl/chardet/src/nsMetaCharsetObserver.cpp @@ -32,6 +32,7 @@ #include "nsCharDetDll.h" #include "nsIServiceManager.h" #include "nsObserverBase.h" +#include "nsWeakReference.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -43,7 +44,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); class nsMetaCharsetObserver: public nsIElementObserver, public nsIObserver, public nsObserverBase, - public nsIMetaCharsetService { + public nsIMetaCharsetService, + public nsSupportsWeakReference { NS_DECL_ISUPPORTS @@ -110,39 +112,13 @@ nsMetaCharsetObserver::~nsMetaCharsetObserver() NS_IMPL_ADDREF ( nsMetaCharsetObserver ); NS_IMPL_RELEASE ( nsMetaCharsetObserver ); -//------------------------------------------------------------------------- -NS_IMETHODIMP nsMetaCharsetObserver::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - - if( NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - *aInstancePtr = NULL; - - if( aIID.Equals ( nsIElementObserver::GetIID() )) { - *aInstancePtr = (void*) ((nsIElementObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - if( aIID.Equals ( nsIObserver::GetIID() )) { - *aInstancePtr = (void*) ((nsIObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - - if( aIID.Equals ( nsIMetaCharsetService::GetIID() )) { - *aInstancePtr = (void*) ((nsIMetaCharsetService*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - - if( aIID.Equals ( kISupportsIID )) { - *aInstancePtr = (void*) ( this ); - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} +NS_INTERFACE_MAP_BEGIN(nsMetaCharsetObserver) + NS_INTERFACE_MAP_ENTRY(nsIElementObserver) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsIMetaCharsetService) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIElementObserver) +NS_INTERFACE_MAP_END //------------------------------------------------------------------------- NS_IMETHODIMP_(const char*) nsMetaCharsetObserver::GetTagNameAt(PRUint32 aTagIndex) diff --git a/intl/chardet/src/nsXMLEncodingObserver.cpp b/intl/chardet/src/nsXMLEncodingObserver.cpp index 13cf59516ef9..14f750cc5645 100644 --- a/intl/chardet/src/nsXMLEncodingObserver.cpp +++ b/intl/chardet/src/nsXMLEncodingObserver.cpp @@ -32,6 +32,7 @@ #include "nsCharDetDll.h" #include "nsIServiceManager.h" #include "nsObserverBase.h" +#include "nsWeakReference.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -43,7 +44,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); class nsXMLEncodingObserver: public nsIElementObserver, public nsIObserver, public nsObserverBase, - public nsIXMLEncodingService { + public nsIXMLEncodingService, + public nsSupportsWeakReference { NS_DECL_ISUPPORTS @@ -100,39 +102,13 @@ nsXMLEncodingObserver::~nsXMLEncodingObserver() NS_IMPL_ADDREF ( nsXMLEncodingObserver ); NS_IMPL_RELEASE ( nsXMLEncodingObserver ); -//------------------------------------------------------------------------- -NS_IMETHODIMP nsXMLEncodingObserver::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - - if( NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - *aInstancePtr = NULL; - - if( aIID.Equals ( nsIElementObserver::GetIID() )) { - *aInstancePtr = (void*) ((nsIElementObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - if( aIID.Equals ( nsIObserver::GetIID() )) { - *aInstancePtr = (void*) ((nsIObserver*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - - if( aIID.Equals ( nsIXMLEncodingService::GetIID() )) { - *aInstancePtr = (void*) ((nsIXMLEncodingService*) this); - NS_ADDREF_THIS(); - return NS_OK; - } - - if( aIID.Equals ( kISupportsIID )) { - *aInstancePtr = (void*) ( this ); - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} +NS_INTERFACE_MAP_BEGIN(nsXMLEncodingObserver) + NS_INTERFACE_MAP_ENTRY(nsIElementObserver) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsIXMLEncodingService) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIElementObserver) +NS_INTERFACE_MAP_END //------------------------------------------------------------------------- NS_IMETHODIMP_(const char*) nsXMLEncodingObserver::GetTagNameAt(PRUint32 aTagIndex) diff --git a/layout/xml/document/src/nsXMLContentSink.cpp b/layout/xml/document/src/nsXMLContentSink.cpp index db0b78d9ab90..60d5a80624d5 100644 --- a/layout/xml/document/src/nsXMLContentSink.cpp +++ b/layout/xml/document/src/nsXMLContentSink.cpp @@ -240,22 +240,26 @@ nsXMLContentSink::Init(nsIDocument* aDoc, #ifndef XSL -NS_IMPL_ISUPPORTS3(nsXMLContentSink, - nsIXMLContentSink, - nsIContentSink, - nsIUnicharStreamLoaderObserver) +NS_IMPL_ADDREF(nsXMLContentSink) +NS_IMPL_RELEASE(nsXMLContentSink) #else NS_IMPL_THREADSAFE_ADDREF(nsXMLContentSink) NS_IMPL_THREADSAFE_RELEASE(nsXMLContentSink) -NS_IMPL_QUERY_INTERFACE4(nsXMLContentSink, - nsIXMLContentSink, - nsIContentSink, - nsIObserver, - nsIUnicharStreamLoaderObserver) + #endif +NS_INTERFACE_MAP_BEGIN(nsXMLContentSink) + NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink) +#ifdef XSL + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) +#endif + NS_INTERFACE_MAP_ENTRY(nsIUnicharStreamLoaderObserver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink) +NS_INTERFACE_MAP_END + // nsIContentSink NS_IMETHODIMP nsXMLContentSink::WillBuildModel(void) diff --git a/layout/xml/document/src/nsXMLContentSink.h b/layout/xml/document/src/nsXMLContentSink.h index 6bf34aa5f4b9..35052ee2e6fe 100644 --- a/layout/xml/document/src/nsXMLContentSink.h +++ b/layout/xml/document/src/nsXMLContentSink.h @@ -28,6 +28,7 @@ #include "nsIScrollableView.h" #ifdef XSL #include "nsIObserver.h" +#include "nsWeakReference.h" #include "nsITransformMediator.h" #endif #include "nsIUnicharInputStream.h" @@ -56,6 +57,7 @@ typedef enum { class nsXMLContentSink : public nsIXMLContentSink, #ifdef XSL public nsIObserver, + public nsSupportsWeakReference, #endif public nsIUnicharStreamLoaderObserver { diff --git a/mailnews/base/src/nsMsgAccountManager.cpp b/mailnews/base/src/nsMsgAccountManager.cpp index 34630c03c173..a0902595ba0d 100644 --- a/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mailnews/base/src/nsMsgAccountManager.cpp @@ -341,7 +341,7 @@ typedef struct _findAccountByKeyEntry { -NS_IMPL_ISUPPORTS2(nsMsgAccountManager, nsIMsgAccountManager, nsIObserver) +NS_IMPL_ISUPPORTS3(nsMsgAccountManager, nsIMsgAccountManager, nsIObserver, nsISupportsWeakReference) nsMsgAccountManager::nsMsgAccountManager() : m_accountsLoaded(PR_FALSE), diff --git a/mailnews/base/src/nsMsgAccountManager.h b/mailnews/base/src/nsMsgAccountManager.h index 3b8078233aaf..0f997ece0e52 100644 --- a/mailnews/base/src/nsMsgAccountManager.h +++ b/mailnews/base/src/nsMsgAccountManager.h @@ -28,6 +28,7 @@ #include "nsIPref.h" #include "nsIMsgFolderCache.h" #include "nsIObserver.h" +#include "nsWeakReference.h" /* * some platforms (like Windows and Mac) use a map file, because of @@ -61,7 +62,10 @@ #define HAVE_MOVEMAIL 1 #endif /* HAVE_MOVEMAIL */ -class nsMsgAccountManager : public nsIMsgAccountManager, public nsIObserver +class nsMsgAccountManager + : public nsIMsgAccountManager, + public nsIObserver, + public nsSupportsWeakReference { public: diff --git a/mailnews/base/src/nsMsgBiffManager.cpp b/mailnews/base/src/nsMsgBiffManager.cpp index e2e83534c342..a067ce80380d 100644 --- a/mailnews/base/src/nsMsgBiffManager.cpp +++ b/mailnews/base/src/nsMsgBiffManager.cpp @@ -28,7 +28,7 @@ static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID); -NS_IMPL_ISUPPORTS3(nsMsgBiffManager, nsIMsgBiffManager, nsIIncomingServerListener, nsIObserver) +NS_IMPL_ISUPPORTS4(nsMsgBiffManager, nsIMsgBiffManager, nsIIncomingServerListener, nsIObserver, nsISupportsWeakReference) void OnBiffTimer(nsITimer *timer, void *aBiffManager) { diff --git a/mailnews/base/src/nsMsgBiffManager.h b/mailnews/base/src/nsMsgBiffManager.h index eeaab247ded9..84c25e10dc68 100644 --- a/mailnews/base/src/nsMsgBiffManager.h +++ b/mailnews/base/src/nsMsgBiffManager.h @@ -32,6 +32,7 @@ #include "nsCOMPtr.h" #include "nsIIncomingServerListener.h" #include "nsIObserver.h" +#include "nsWeakReference.h" typedef struct { nsCOMPtr server; @@ -39,7 +40,11 @@ typedef struct { } nsBiffEntry; -class nsMsgBiffManager: public nsIMsgBiffManager, public nsIIncomingServerListener, public nsIObserver +class nsMsgBiffManager + : public nsIMsgBiffManager, + public nsIIncomingServerListener, + public nsIObserver, + public nsSupportsWeakReference { public: nsMsgBiffManager(); diff --git a/mailnews/base/src/nsMsgRDFDataSource.cpp b/mailnews/base/src/nsMsgRDFDataSource.cpp index 1dce3e728212..13b44b989d75 100644 --- a/mailnews/base/src/nsMsgRDFDataSource.cpp +++ b/mailnews/base/src/nsMsgRDFDataSource.cpp @@ -77,32 +77,14 @@ void nsMsgRDFDataSource::Close() NS_IMPL_ADDREF(nsMsgRDFDataSource) NS_IMPL_RELEASE(nsMsgRDFDataSource) - -nsresult -nsMsgRDFDataSource::QueryInterface(const nsIID& iid, void **result) -{ - nsresult rv = NS_NOINTERFACE; - if (! result) - return NS_ERROR_NULL_POINTER; - void *res=nsnull; - - if (iid.Equals(nsCOMTypeInfo::GetIID()) || - iid.Equals(nsCOMTypeInfo::GetIID())) - res = NS_STATIC_CAST(nsIRDFDataSource*, this); - else if(iid.Equals(nsCOMTypeInfo::GetIID())) - res = NS_STATIC_CAST(nsIObserver*, this); - else if(iid.Equals(nsCOMTypeInfo::GetIID())) - res = NS_STATIC_CAST(nsIMsgRDFDataSource*, this); - - if (res) { - NS_ADDREF(this); - *result = res; - rv = NS_OK; - } - - return rv; -} +NS_INTERFACE_MAP_BEGIN(nsMsgRDFDataSource) + NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsIMsgRDFDataSource) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRDFDataSource) +NS_INTERFACE_MAP_END /* readonly attribute string URI; */ diff --git a/mailnews/base/src/nsMsgRDFDataSource.h b/mailnews/base/src/nsMsgRDFDataSource.h index 14e56c4491c3..3f95ff2edffe 100644 --- a/mailnews/base/src/nsMsgRDFDataSource.h +++ b/mailnews/base/src/nsMsgRDFDataSource.h @@ -33,9 +33,11 @@ #include "nsITransactionManager.h" #include "nsIMsgWindow.h" #include "nsIMsgRDFDataSource.h" +#include "nsWeakReference.h" class nsMsgRDFDataSource : public nsIRDFDataSource, public nsIObserver, + public nsSupportsWeakReference, public nsIMsgRDFDataSource { public: diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index b50e5d55548a..accae4261606 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -58,7 +58,16 @@ nsFtpProtocolHandler::~nsFtpProtocolHandler() { PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("~nsFtpProtocolHandler() called")); } -NS_IMPL_ISUPPORTS3(nsFtpProtocolHandler, nsIProtocolHandler, nsIConnectionCache, nsIObserver); +NS_IMPL_ADDREF(nsFtpProtocolHandler) +NS_IMPL_RELEASE(nsFtpProtocolHandler) + +NS_INTERFACE_MAP_BEGIN(nsFtpProtocolHandler) + NS_INTERFACE_MAP_ENTRY(nsIProtocolHandler) + NS_INTERFACE_MAP_ENTRY(nsIConnectionCache) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIProtocolHandler) +NS_INTERFACE_MAP_END NS_METHOD nsFtpProtocolHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h index 2a2efbf08994..d3eccd16f091 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h @@ -32,6 +32,7 @@ #include "nsIThreadPool.h" #include "nsIObserverService.h" #include "nsIObserver.h" +#include "nsWeakReference.h" // {25029490-F132-11d2-9588-00805F369F95} #define NS_FTPPROTOCOLHANDLER_CID \ @@ -39,7 +40,8 @@ class nsFtpProtocolHandler : public nsIProtocolHandler, public nsIConnectionCache, - public nsIObserver + public nsIObserver, + public nsSupportsWeakReference { public: NS_DECL_ISUPPORTS diff --git a/xpcom/tests/TestObserverService.cpp b/xpcom/tests/TestObserverService.cpp index e11b064b1485..f19adb4e3583 100644 --- a/xpcom/tests/TestObserverService.cpp +++ b/xpcom/tests/TestObserverService.cpp @@ -29,6 +29,7 @@ #include "nsString.h" #include "prprf.h" #include +#include "nsWeakReference.h" static nsIObserverService *anObserverService = NULL; @@ -48,7 +49,7 @@ extern ostream &operator<<( ostream &s, nsString &str ) { return s; } -class TestObserver : public nsIObserver { +class TestObserver : public nsIObserver, public nsSupportsWeakReference { public: TestObserver( const nsString &name = "unknown" ) : mName( name ) { @@ -60,7 +61,7 @@ public: nsString mName; }; -NS_IMPL_ISUPPORTS( TestObserver, NS_GET_IID(nsIObserver) ); +NS_IMPL_ISUPPORTS2( TestObserver, nsIObserver, nsISupportsWeakReference ); NS_IMETHODIMP TestObserver::Observe( nsISupports *aSubject, diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index 0b4e9003c8f9..c6ce0631cf64 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -30,6 +30,7 @@ #include "nsIEventQueueService.h" #include "nsIObserverService.h" #include "nsIObserver.h" +#include "nsWeakReference.h" #include "nsXPComFactory.h" /* template implementation of a XPCOM factory */ #include "nsITimer.h" @@ -103,7 +104,8 @@ static char *gEQActivatedNotification = "nsIEventQueueActivated"; static char *gEQDestroyedNotification = "nsIEventQueueDestroyed"; class nsAppShellService : public nsIAppShellService, - public nsIObserver + public nsIObserver, + public nsSupportsWeakReference { public: nsAppShellService(void); @@ -173,7 +175,15 @@ nsAppShellService::~nsAppShellService() /* * Implement the nsISupports methods... */ -NS_IMPL_ISUPPORTS2(nsAppShellService, nsIAppShellService, nsIObserver); +NS_IMPL_ADDREF(nsAppShellService) +NS_IMPL_RELEASE(nsAppShellService) + +NS_INTERFACE_MAP_BEGIN(nsAppShellService) + NS_INTERFACE_MAP_ENTRY(nsIAppShellService) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAppShellService) +NS_INTERFACE_MAP_END NS_IMETHODIMP diff --git a/xpfe/browser/src/nsBrowserInstance.cpp b/xpfe/browser/src/nsBrowserInstance.cpp index 4b59db3cbeda..5643006f3de4 100644 --- a/xpfe/browser/src/nsBrowserInstance.cpp +++ b/xpfe/browser/src/nsBrowserInstance.cpp @@ -165,16 +165,17 @@ nsBrowserAppCore::~nsBrowserAppCore() NS_IF_RELEASE(mSHistory); } -NS_IMPL_ADDREF(nsBrowserAppCore) -NS_IMPL_RELEASE(nsBrowserAppCore) +NS_IMPL_ADDREF(nsBrowserInstance) +NS_IMPL_RELEASE(nsBrowserInstance) - -NS_IMPL_QUERY_HEAD(nsBrowserAppCore) - NS_IMPL_QUERY_BODY(nsIBrowserInstance) - NS_IMPL_QUERY_BODY(nsIDocumentLoaderObserver) - NS_IMPL_QUERY_BODY(nsIObserver) - NS_IMPL_QUERY_BODY(nsIURIContentListener) -NS_IMPL_QUERY_TAIL(nsIBrowserInstance) +NS_INTERFACE_MAP_BEGIN(nsBrowserInstance) + NS_INTERFACE_MAP_ENTRY(nsIBrowserInstance) + NS_INTERFACE_MAP_ENTRY(nsIDocumentLoaderObserver) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsIURIContentListener) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener) +NS_INTERFACE_MAP_END static @@ -948,7 +949,7 @@ nsBrowserAppCore::LoadUrl(const PRUnichar *aUrl) #ifdef DEBUG #include "nsProxyObjectManager.h" -class PageCycler : public nsIObserver { +class PageCycler : public nsIObserver, public nsSupportsWeakReference { public: NS_DECL_ISUPPORTS @@ -1059,7 +1060,14 @@ protected: nsAutoString mLastRequest; }; -NS_IMPL_ISUPPORTS1(PageCycler, nsIObserver); +NS_IMPL_ADDREF(PageCycler) +NS_IMPL_RELEASE(PageCycler) + +NS_INTERFACE_MAP_BEGIN(PageCycler) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver) +NS_INTERFACE_MAP_END #endif diff --git a/xpfe/browser/src/nsBrowserInstance.h b/xpfe/browser/src/nsBrowserInstance.h index f38c49273465..2f9a7156b66e 100644 --- a/xpfe/browser/src/nsBrowserInstance.h +++ b/xpfe/browser/src/nsBrowserInstance.h @@ -28,6 +28,7 @@ #include "nscore.h" #include "nsCOMPtr.h" +#include "nsWeakReference.h" #include "nsString.h" #include "nsISupports.h" @@ -60,7 +61,8 @@ class nsBrowserInstance : public nsIBrowserInstance, public nsIDocumentLoaderObserver, public nsIObserver, public nsISessionHistory, - public nsIURIContentListener { + public nsIURIContentListener, + public nsSupportsWeakReference { public: nsBrowserInstance();