diff --git a/xpfe/appshell/src/nsAbout.cpp b/xpfe/appshell/src/nsAbout.cpp index 2746e36263ba..2f95e2fa947e 100644 --- a/xpfe/appshell/src/nsAbout.cpp +++ b/xpfe/appshell/src/nsAbout.cpp @@ -82,16 +82,3 @@ nsAbout::GetURIFlags(nsIURI *aURI, PRUint32 *result) *result = nsIAboutModule::ALLOW_SCRIPT; return NS_OK; } - -NS_METHOD -nsAbout::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - nsAbout* about = new nsAbout(); - if (about == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(about); - nsresult rv = about->QueryInterface(aIID, aResult); - NS_RELEASE(about); - return rv; -} - diff --git a/xpfe/appshell/src/nsAbout.h b/xpfe/appshell/src/nsAbout.h index a6e384ef3ba7..ef075a996c94 100644 --- a/xpfe/appshell/src/nsAbout.h +++ b/xpfe/appshell/src/nsAbout.h @@ -35,31 +35,24 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef nsAbout_h__ -#define nsAbout_h__ +#ifndef nsAbout_h_ +#define nsAbout_h_ #include "nsIAboutModule.h" -class nsAbout : public nsIAboutModule +#define NS_ABOUT_CID \ +{ /* {1f1ce501-663a-11d3-b7a0-be426e4e69bc} */ \ +0x1f1ce501, 0x663a, 0x11d3, { 0xb7, 0xa0, 0xbe, 0x42, 0x6e, 0x4e, 0x69, 0xbc } \ +} + +class nsAbout : public nsIAboutModule { public: - NS_DECL_ISUPPORTS - NS_DECL_NSIABOUTMODULE nsAbout() {} virtual ~nsAbout() {} - - static NS_METHOD - Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - -protected: }; -#define NS_ABOUT_CID \ -{ /* {1f1ce501-663a-11d3-b7a0-be426e4e69bc} */ \ -0x1f1ce501, 0x663a, 0x11d3, { 0xb7, 0xa0, 0xbe, 0x42, 0x6e, 0x4e, 0x69, 0xbc } \ -} - -#endif // nsAboutBlank_h__ +#endif // nsAbout_h_ diff --git a/xpfe/appshell/src/nsAppShellFactory.cpp b/xpfe/appshell/src/nsAppShellFactory.cpp index 193cc05ab72f..5bf5fe1c61be 100644 --- a/xpfe/appshell/src/nsAppShellFactory.cpp +++ b/xpfe/appshell/src/nsAppShellFactory.cpp @@ -50,7 +50,8 @@ #include "nsAppShellCID.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShellService) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindowMediator) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAbout) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWindowMediator, Init) static const nsModuleComponentInfo gAppShellModuleInfo[] = { @@ -67,7 +68,7 @@ static const nsModuleComponentInfo gAppShellModuleInfo[] = { "kAboutModuleCID", NS_ABOUT_CID, NS_ABOUT_MODULE_CONTRACTID_PREFIX, - nsAbout::Create, + nsAboutConstructor, } }; diff --git a/xpfe/appshell/src/nsWindowMediator.cpp b/xpfe/appshell/src/nsWindowMediator.cpp index 662b58985cc2..b254220675c2 100644 --- a/xpfe/appshell/src/nsWindowMediator.cpp +++ b/xpfe/appshell/src/nsWindowMediator.cpp @@ -70,43 +70,43 @@ static PRBool notifyCloseWindow(nsISupports *aElement, void* aData); static PRBool notifyWindowTitleChange(nsISupports *aElement, void* aData); // for notifyWindowTitleChange -struct windowData { +struct WindowTitleData { nsIXULWindow* mWindow; const PRUnichar *mTitle; }; nsresult -GetDOMWindow(nsIXULWindow* inWindow, nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow) +GetDOMWindow(nsIXULWindow* inWindow, nsCOMPtr& outDOMWindow) { nsCOMPtr docShell; inWindow->GetDocShell(getter_AddRefs(docShell)); - outDOMWindow = do_GetInterface(docShell); - return outDOMWindow ? NS_OK : NS_ERROR_FAILURE; + outDOMWindow = do_GetInterface(docShell); + return outDOMWindow ? NS_OK : NS_ERROR_FAILURE; } -PRInt32 nsWindowMediator::gRefCnt = 0; - nsWindowMediator::nsWindowMediator() : mEnumeratorList(), mOldestWindow(nsnull), mTopmostWindow(nsnull), mTimeStamp(0), mSortingZOrder(PR_FALSE), mListLock(nsnull) { - // This should really be done in the static constructor fn. - nsresult rv; - rv = Init(); - NS_ASSERTION(NS_SUCCEEDED(rv), "uh oh, couldn't Init() for some reason"); } nsWindowMediator::~nsWindowMediator() { - if (--gRefCnt == 0) { - // Delete data - while (mOldestWindow) - UnregisterWindow(mOldestWindow); + while (mOldestWindow) + UnregisterWindow(mOldestWindow); + + if (mListLock) + PR_DestroyLock(mListLock); +} - if (mListLock) - PR_DestroyLock(mListLock); - } +nsresult nsWindowMediator::Init() +{ + mListLock = PR_NewLock(); + if (!mListLock) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; } NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow) @@ -124,7 +124,7 @@ NS_IMETHODIMP nsWindowMediator::RegisterWindow(nsIXULWindow* inWindow) return NS_ERROR_OUT_OF_MEMORY; if (mListeners) { - windowData winData = { inWindow, nsnull }; + WindowTitleData winData = { inWindow, nsnull }; mListeners->EnumerateForwards(notifyOpenWindow, (void*)&winData); } @@ -156,7 +156,7 @@ nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo) ((nsAppShellWindowEnumerator*)mEnumeratorList[index])->WindowRemoved(inInfo); if (mListeners) { - windowData winData = {inInfo->mWindow.get(), nsnull }; + WindowTitleData winData = {inInfo->mWindow.get(), nsnull }; mListeners->EnumerateForwards(notifyCloseWindow, (void*)&winData); } @@ -263,7 +263,7 @@ nsWindowMediator::GetZOrderDOMWindowEnumerator( else enumerator = new nsASDOMWindowBackToFrontEnumerator(aWindowType, *this); if (enumerator) - return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void**) _retval); + return CallQueryInterface(enumerator, _retval); return NS_ERROR_OUT_OF_MEMORY; } @@ -283,7 +283,7 @@ nsWindowMediator::GetZOrderXULWindowEnumerator( else enumerator = new nsASXULWindowBackToFrontEnumerator(aWindowType, *this); if (enumerator) - return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void**) _retval); + return CallQueryInterface(enumerator, _retval); return NS_ERROR_OUT_OF_MEMORY; } @@ -374,7 +374,7 @@ nsWindowMediator::UpdateWindowTitle(nsIXULWindow* inWindow, { nsAutoLock lock(mListLock); if (mListeners && GetInfoFor(inWindow)) { - windowData winData = { inWindow, inTitle }; + WindowTitleData winData = { inWindow, inTitle }; mListeners->EnumerateForwards(notifyWindowTitleChange, (void *)&winData); } @@ -746,18 +746,6 @@ NS_IMPL_ADDREF(nsWindowMediator) NS_IMPL_QUERY_INTERFACE1(nsWindowMediator, nsIWindowMediator) NS_IMPL_RELEASE(nsWindowMediator) -nsresult -nsWindowMediator::Init() -{ - if (gRefCnt++ == 0) { - mListLock = PR_NewLock(); - if (!mListLock) - return NS_ERROR_OUT_OF_MEMORY; - } - - return NS_OK; -} - NS_IMETHODIMP nsWindowMediator::AddListener(nsIWindowMediatorListener* aListener) { @@ -792,9 +780,9 @@ notifyOpenWindow(nsISupports *aElement, void* aData) { nsIWindowMediatorListener* listener = reinterpret_cast(aElement); - windowData* winData = (windowData*) aData; - + WindowTitleData* winData = static_cast(aData); listener->OnOpenWindow(winData->mWindow); + return PR_TRUE; } @@ -803,9 +791,9 @@ notifyCloseWindow(nsISupports *aElement, void* aData) { nsIWindowMediatorListener* listener = reinterpret_cast(aElement); - windowData* winData = (windowData*) aData; - + WindowTitleData* winData = static_cast(aData); listener->OnCloseWindow(winData->mWindow); + return PR_TRUE; } @@ -814,11 +802,8 @@ notifyWindowTitleChange(nsISupports *aElement, void* aData) { nsIWindowMediatorListener* listener = reinterpret_cast(aElement); - - windowData* titleData = - reinterpret_cast(aData); - listener->OnWindowTitleChange(titleData->mWindow, - titleData->mTitle); + WindowTitleData* titleData = reinterpret_cast(aData); + listener->OnWindowTitleChange(titleData->mWindow, titleData->mTitle); return PR_TRUE; } diff --git a/xpfe/appshell/src/nsWindowMediator.h b/xpfe/appshell/src/nsWindowMediator.h index 109ab72fc817..b02e656142ec 100644 --- a/xpfe/appshell/src/nsWindowMediator.h +++ b/xpfe/appshell/src/nsWindowMediator.h @@ -68,14 +68,15 @@ friend class nsASXULWindowBackToFrontEnumerator; public: nsWindowMediator(); virtual ~nsWindowMediator(); + nsresult Init(); - NS_DECL_NSIWINDOWMEDIATOR NS_DECL_ISUPPORTS + NS_DECL_NSIWINDOWMEDIATOR private: - PRInt32 AddEnumerator( nsAppShellWindowEnumerator* inEnumerator ); - PRInt32 RemoveEnumerator( nsAppShellWindowEnumerator* inEnumerator); + PRInt32 AddEnumerator(nsAppShellWindowEnumerator* inEnumerator); + PRInt32 RemoveEnumerator(nsAppShellWindowEnumerator* inEnumerator); nsWindowInfo *MostRecentWindowInfo(const PRUnichar* inType); nsresult UnregisterWindow(nsWindowInfo *inInfo); @@ -85,15 +86,13 @@ private: void SortZOrderBackToFront(); nsVoidArray mEnumeratorList; - nsWindowInfo *mOldestWindow, - *mTopmostWindow; + nsWindowInfo *mOldestWindow; + nsWindowInfo *mTopmostWindow; PRInt32 mTimeStamp; PRBool mSortingZOrder; PRLock *mListLock; nsCOMPtr mListeners; - - static PRInt32 gRefCnt; }; #endif