diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 6f3e54ae685e..6018ce8fc39e 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -252,7 +252,7 @@ using mozilla::TimeStamp; using mozilla::TimeDuration; nsIDOMStorageList *nsGlobalWindow::sGlobalStorageList = nsnull; -nsGlobalWindow::WindowByIdTable *nsGlobalWindow::sOuterWindowsById = nsnull; +nsGlobalWindow::WindowByIdTable *nsGlobalWindow::sWindowsById = nsnull; static nsIEntropyCollector *gEntropyCollector = nsnull; static PRInt32 gRefCnt = 0; @@ -887,18 +887,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow) mObserver = nsnull; SetIsProxy(); - - if (!sOuterWindowsById) { - sOuterWindowsById = new WindowByIdTable(); - if (!sOuterWindowsById->Init()) { - delete sOuterWindowsById; - sOuterWindowsById = nsnull; - } - } - - if (sOuterWindowsById) { - sOuterWindowsById->Put(mWindowID, this); - } } // We could have failed the first time through trying @@ -952,17 +940,35 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow) PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG, ("DOMWINDOW %p created outer=%p", this, aOuterWindow)); #endif + + // TODO: could be moved to a ::Init() method, see bug 667183. + if (!sWindowsById) { + sWindowsById = new WindowByIdTable(); + if (!sWindowsById->Init()) { + delete sWindowsById; + sWindowsById = nsnull; + NS_ERROR("sWindowsById initialization failed!"); + } + } + + if (sWindowsById) { + NS_ASSERTION(!sWindowsById->Get(mWindowID), + "This window shouldn't be in the hash table yet!"); + sWindowsById->Put(mWindowID, this); + } } nsGlobalWindow::~nsGlobalWindow() { - if (sOuterWindowsById) { - sOuterWindowsById->Remove(mWindowID); + // We have to check if sWindowsById isn't null because ::Shutdown might have + // been called. + if (sWindowsById) { + NS_ASSERTION(sWindowsById->Get(mWindowID), + "This window should be in the hash table"); + sWindowsById->Remove(mWindowID); } if (!--gRefCnt) { NS_IF_RELEASE(gEntropyCollector); - delete sOuterWindowsById; - sOuterWindowsById = nsnull; } #ifdef DEBUG nsCAutoString url; @@ -1038,6 +1044,9 @@ nsGlobalWindow::ShutDown() fclose(gDumpFile); } gDumpFile = nsnull; + + delete sWindowsById; + sWindowsById = nsnull; } // static diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 974eae44bcfc..7514b41d331f 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -531,7 +531,8 @@ public: } static nsGlobalWindow* GetOuterWindowWithId(PRUint64 aWindowID) { - return sOuterWindowsById ? sOuterWindowsById->Get(aWindowID) : nsnull; + nsGlobalWindow* outerWindow = sWindowsById->Get(aWindowID); + return outerWindow && !outerWindow->IsInnerWindow() ? outerWindow : nsnull; } static bool HasIndexedDBSupport(); @@ -960,7 +961,7 @@ protected: static nsIDOMStorageList* sGlobalStorageList; typedef nsDataHashtable WindowByIdTable; - static WindowByIdTable* sOuterWindowsById; + static WindowByIdTable* sWindowsById; }; /*