diff --git a/xpcom/ds/nsObserverService.cpp b/xpcom/ds/nsObserverService.cpp index dac9adf977e7..013e82460b0c 100644 --- a/xpcom/ds/nsObserverService.cpp +++ b/xpcom/ds/nsObserverService.cpp @@ -45,6 +45,9 @@ #include "nsObserverService.h" #include "nsObserverList.h" #include "nsHashtable.h" +#include "nsIWeakReference.h" + +#define NS_WEAK_OBSERVERS static NS_DEFINE_CID(kObserverServiceCID, NS_OBSERVERSERVICE_CID); @@ -211,6 +214,17 @@ NS_IMETHODIMP nsObserverService::NotifyObservers( nsISupports *aSubject, nsCOMPtr observer = do_QueryInterface(observerRef); if ( observer ) observer->Observe( aSubject, aTopic, someData ); +#ifdef NS_WEAK_OBSERVERS + else + { // check for weak reference. + nsCOMPtr weakRef = do_QueryInterface(observerRef); + if ( weakRef ) + weakRef->QueryReferent(NS_GET_IID(nsIObserver), getter_AddRefs(observer)); + + if ( observer ) + observer->Observe( aSubject, aTopic, someData ); + } +#endif } return NS_OK; }