Clean up allocation for nsWindowMediator, nsAbout. b=471981 r=neil sr=roc

This commit is contained in:
Josh Aas 2009-01-04 23:22:36 -06:00
Родитель 7785fae4e0
Коммит c96081fc29
5 изменённых файлов: 46 добавлений и 81 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -35,31 +35,24 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsAbout_h__
#define nsAbout_h__
#ifndef nsAbout_h_
#define nsAbout_h_
#include "nsIAboutModule.h"
#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_

Просмотреть файл

@ -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,
}
};

Просмотреть файл

@ -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<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)
@ -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<nsIWindowMediatorListener*>(aElement);
windowData* winData = (windowData*) aData;
WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
listener->OnOpenWindow(winData->mWindow);
return PR_TRUE;
}
@ -803,9 +791,9 @@ 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;
}
@ -814,11 +802,8 @@ 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;
}

Просмотреть файл

@ -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<nsISupportsArray> mListeners;
static PRInt32 gRefCnt;
};
#endif