Clean up allocation for nsWindowMediator, nsAbout.
b=471981 r=neil sr=roc
--- a/xpfe/appshell/src/nsAbout.cpp
+++ b/xpfe/appshell/src/nsAbout.cpp
@@ -77,21 +77,8 @@ nsAbout::NewChannel(nsIURI *aURI, nsICha
}
NS_IMETHODIMP
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;
-}
-
--- a/xpfe/appshell/src/nsAbout.h
+++ b/xpfe/appshell/src/nsAbout.h
@@ -30,36 +30,29 @@
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** 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_
--- a/xpfe/appshell/src/nsAppShellFactory.cpp
+++ b/xpfe/appshell/src/nsAppShellFactory.cpp
@@ -45,34 +45,35 @@
#include "nsIAppShellService.h"
#include "nsAppShellService.h"
#include "nsWindowMediator.h"
#include "nsChromeTreeOwner.h"
#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[] =
{
{ "AppShell Service",
NS_APPSHELLSERVICE_CID,
NS_APPSHELLSERVICE_CONTRACTID,
nsAppShellServiceConstructor,
},
{ "Window Mediator",
NS_WINDOWMEDIATOR_CID,
NS_WINDOWMEDIATOR_CONTRACTID,
nsWindowMediatorConstructor,
},
{ "kAboutModuleCID",
NS_ABOUT_CID,
NS_ABOUT_MODULE_CONTRACTID_PREFIX,
- nsAbout::Create,
+ nsAboutConstructor,
}
};
static nsresult
nsAppShellModuleConstructor(nsIModule *aModule)
{
return nsChromeTreeOwner::InitGlobals();
}
--- a/xpfe/appshell/src/nsWindowMediator.cpp
+++ b/xpfe/appshell/src/nsWindowMediator.cpp
@@ -65,53 +65,53 @@
static nsresult GetDOMWindow(nsIXULWindow* inWindow,
nsCOMPtr< nsIDOMWindowInternal>& outDOMWindow);
static PRBool notifyOpenWindow(nsISupports *aElement, void* aData);
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<nsIDOMWindowInternal>& outDOMWindow)
{
nsCOMPtr<nsIDocShell> 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)
{
if (GetInfoFor(inWindow)) {
NS_ERROR("multiple window registration");
return NS_ERROR_FAILURE;
}
@@ -119,17 +119,17 @@ NS_IMETHODIMP nsWindowMediator::Register
mTimeStamp++;
// Create window info struct and add to list of windows
nsWindowInfo* windowInfo = new nsWindowInfo (inWindow, mTimeStamp);
if (!windowInfo)
return NS_ERROR_OUT_OF_MEMORY;
if (mListeners) {
- windowData winData = { inWindow, nsnull };
+ WindowTitleData winData = { inWindow, nsnull };
mListeners->EnumerateForwards(notifyOpenWindow, (void*)&winData);
}
nsAutoLock lock(mListLock);
if (mOldestWindow)
windowInfo->InsertAfter(mOldestWindow->mOlder, nsnull);
else
mOldestWindow = windowInfo;
@@ -151,17 +151,17 @@ nsresult
nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo)
{
// Inform the iterators
PRInt32 index = -1;
while (++index < mEnumeratorList.Count())
((nsAppShellWindowEnumerator*)mEnumeratorList[index])->WindowRemoved(inInfo);
if (mListeners) {
- windowData winData = {inInfo->mWindow.get(), nsnull };
+ WindowTitleData winData = {inInfo->mWindow.get(), nsnull };
mListeners->EnumerateForwards(notifyCloseWindow, (void*)&winData);
}
// Remove from the lists and free up
if (inInfo == mOldestWindow)
mOldestWindow = inInfo->mYounger;
if (inInfo == mTopmostWindow)
mTopmostWindow = inInfo->mLower;
@@ -258,17 +258,17 @@ nsWindowMediator::GetZOrderDOMWindowEnum
nsAutoLock lock(mListLock);
nsAppShellWindowEnumerator *enumerator;
if (aFrontToBack)
enumerator = new nsASDOMWindowFrontToBackEnumerator(aWindowType, *this);
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;
}
NS_IMETHODIMP
nsWindowMediator::GetZOrderXULWindowEnumerator(
const PRUnichar *aWindowType, PRBool aFrontToBack,
nsISimpleEnumerator **_retval)
@@ -278,17 +278,17 @@ nsWindowMediator::GetZOrderXULWindowEnum
nsAutoLock lock(mListLock);
nsAppShellWindowEnumerator *enumerator;
if (aFrontToBack)
enumerator = new nsASXULWindowFrontToBackEnumerator(aWindowType, *this);
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;
}
PRInt32
nsWindowMediator::AddEnumerator(nsAppShellWindowEnumerator * inEnumerator)
{
return mEnumeratorList.AppendElement(inEnumerator);
@@ -369,17 +369,17 @@ nsWindowMediator::UpdateWindowTimeStamp(
}
NS_IMETHODIMP
nsWindowMediator::UpdateWindowTitle(nsIXULWindow* inWindow,
const PRUnichar* inTitle)
{
nsAutoLock lock(mListLock);
if (mListeners && GetInfoFor(inWindow)) {
- windowData winData = { inWindow, inTitle };
+ WindowTitleData winData = { inWindow, inTitle };
mListeners->EnumerateForwards(notifyWindowTitleChange, (void *)&winData);
}
return NS_OK;
}
/* This method's plan is to intervene only when absolutely necessary.
We will get requests to place our windows behind unknown windows.
@@ -741,28 +741,16 @@ nsWindowMediator::SortZOrderBackToFront(
mSortingZOrder = PR_FALSE;
}
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)
{
NS_ENSURE_ARG_POINTER(aListener);
nsresult rv;
if (!mListeners) {
rv = NS_NewISupportsArray(getter_AddRefs(mListeners));
@@ -787,38 +775,35 @@ nsWindowMediator::RemoveListener(nsIWind
return NS_OK;
}
PRBool
notifyOpenWindow(nsISupports *aElement, void* aData)
{
nsIWindowMediatorListener* listener =
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
- windowData* winData = (windowData*) aData;
+ WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
+ listener->OnOpenWindow(winData->mWindow);
- listener->OnOpenWindow(winData->mWindow);
return PR_TRUE;
}
PRBool
notifyCloseWindow(nsISupports *aElement, void* aData)
{
nsIWindowMediatorListener* listener =
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
- windowData* winData = (windowData*) aData;
-
+ WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
listener->OnCloseWindow(winData->mWindow);
+
return PR_TRUE;
}
PRBool
notifyWindowTitleChange(nsISupports *aElement, void* aData)
{
nsIWindowMediatorListener* listener =
reinterpret_cast<nsIWindowMediatorListener*>(aElement);
-
- windowData* titleData =
- reinterpret_cast<windowData*>(aData);
- listener->OnWindowTitleChange(titleData->mWindow,
- titleData->mTitle);
+ WindowTitleData* titleData = reinterpret_cast<WindowTitleData*>(aData);
+ listener->OnWindowTitleChange(titleData->mWindow, titleData->mTitle);
return PR_TRUE;
}
--- a/xpfe/appshell/src/nsWindowMediator.h
+++ b/xpfe/appshell/src/nsWindowMediator.h
@@ -63,37 +63,36 @@ friend class nsASDOMWindowEarlyToLateEnu
friend class nsASDOMWindowFrontToBackEnumerator;
friend class nsASXULWindowFrontToBackEnumerator;
friend class nsASDOMWindowBackToFrontEnumerator;
friend class nsASXULWindowBackToFrontEnumerator;
public:
nsWindowMediator();
virtual ~nsWindowMediator();
+
nsresult Init();
+ NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWMEDIATOR
- NS_DECL_ISUPPORTS
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);
nsWindowInfo *GetInfoFor(nsIXULWindow *aWindow);
nsWindowInfo *GetInfoFor(nsIWidget *aWindow);
void SortZOrderFrontToBack();
void SortZOrderBackToFront();
nsVoidArray mEnumeratorList;
- nsWindowInfo *mOldestWindow,
- *mTopmostWindow;
+ nsWindowInfo *mOldestWindow;
+ nsWindowInfo *mTopmostWindow;
PRInt32 mTimeStamp;
PRBool mSortingZOrder;
PRLock *mListLock;
nsCOMPtr<nsISupportsArray> mListeners;
-
- static PRInt32 gRefCnt;
};
#endif