diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 48165ce31758..dc642a903526 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -3551,9 +3551,8 @@ nsGlobalWindow::DetachFromDocShell() inner->FreeInnerObjects(); } - if (auto* reporter = nsWindowMemoryReporter::Get()) { - reporter->ObserveDOMWindowDetached(this); - } + // Don't report that we were detached to the nsWindowMemoryReporter, as it + // only tracks inner windows. NotifyWindowIDDestroyed("outer-window-destroyed"); diff --git a/dom/base/nsWindowMemoryReporter.cpp b/dom/base/nsWindowMemoryReporter.cpp index 0978f49d78ed..693dba09d626 100644 --- a/dom/base/nsWindowMemoryReporter.cpp +++ b/dom/base/nsWindowMemoryReporter.cpp @@ -49,7 +49,7 @@ NS_IMPL_ISUPPORTS(nsWindowMemoryReporter, nsIMemoryReporter, nsIObserver, nsISupportsWeakReference) static nsresult -AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow, +AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindowOuter* aWindow, nsTabSizes* aSizes) { // Measure the window. @@ -58,8 +58,7 @@ AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow, aWindow->AddSizeOfIncludingThis(windowSizes); // Measure the inner window, if there is one. - nsGlobalWindow* inner = aWindow->IsOuterWindow() ? aWindow->GetCurrentInnerWindowInternal() - : nullptr; + nsGlobalWindowInner* inner = aWindow->GetCurrentInnerWindowInternal(); if (inner) { inner->AddSizeOfIncludingThis(windowSizes); } @@ -79,7 +78,7 @@ AddNonJSSizeOfWindowAndItsDescendents(nsGlobalWindow* aWindow, NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_STATE(child); - nsGlobalWindow* childWin = nsGlobalWindow::Cast(child); + nsGlobalWindowOuter* childWin = nsGlobalWindowOuter::Cast(child); rv = AddNonJSSizeOfWindowAndItsDescendents(childWin, aSizes); NS_ENSURE_SUCCESS(rv, rv); @@ -131,7 +130,7 @@ nsWindowMemoryReporter::Get() } static already_AddRefed -GetWindowURI(nsGlobalWindow* aWindow) +GetWindowURI(nsGlobalWindowInner* aWindow) { NS_ENSURE_TRUE(aWindow, nullptr); @@ -162,8 +161,16 @@ GetWindowURI(nsGlobalWindow* aWindow) return uri.forget(); } +// Forward to the inner window if we need to when getting the window's URI. +static already_AddRefed +GetWindowURI(nsGlobalWindowOuter* aWindow) +{ + NS_ENSURE_TRUE(aWindow, nullptr); + return GetWindowURI(aWindow->GetCurrentInnerWindowInternal()); +} + static void -AppendWindowURI(nsGlobalWindow *aWindow, nsACString& aStr, bool aAnonymize) +AppendWindowURI(nsGlobalWindowInner *aWindow, nsACString& aStr, bool aAnonymize) { nsCOMPtr uri = GetWindowURI(aWindow); @@ -233,7 +240,7 @@ ReportCount(const nsCString& aBasePath, const char* aPathTail, } static void -CollectWindowReports(nsGlobalWindow *aWindow, +CollectWindowReports(nsGlobalWindowInner *aWindow, amIAddonManager *addonManager, nsWindowSizes *aWindowTotalSizes, nsTHashtable *aGhostWindowIDs, @@ -247,7 +254,7 @@ CollectWindowReports(nsGlobalWindow *aWindow, // Avoid calling aWindow->GetTop() if there's no outer window. It will work // just fine, but will spew a lot of warnings. - nsGlobalWindow *top = nullptr; + nsGlobalWindowOuter *top = nullptr; nsCOMPtr location; if (aWindow->GetOuterWindow()) { // Our window should have a null top iff it has a null docshell. @@ -276,7 +283,7 @@ CollectWindowReports(nsGlobalWindow *aWindow, if (top) { windowPath += NS_LITERAL_CSTRING("top("); - AppendWindowURI(top, windowPath, aAnonymize); + AppendWindowURI(top->GetCurrentInnerWindowInternal(), windowPath, aAnonymize); windowPath.AppendPrintf(", id=%" PRIu64 ")", top->WindowID()); aTopWindowPaths->Put(aWindow->WindowID(), windowPath); @@ -538,14 +545,14 @@ CollectWindowReports(nsGlobalWindow *aWindow, #undef REPORT_COUNT } -typedef nsTArray< RefPtr > WindowArray; +typedef nsTArray< RefPtr > WindowArray; NS_IMETHODIMP nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize) { - nsGlobalWindow::WindowByIdTable* windowsById = - nsGlobalWindow::GetWindowsTable(); + nsGlobalWindowInner::InnerWindowByIdTable* windowsById = + nsGlobalWindowInner::GetWindowsTable(); NS_ENSURE_TRUE(windowsById, NS_OK); // Hold on to every window in memory so that window objects can't be @@ -560,14 +567,14 @@ nsWindowMemoryReporter::CollectReports(nsIHandleReportCallback* aHandleReport, nsTHashtable ghostWindows; CheckForGhostWindows(&ghostWindows); for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) { - nsGlobalWindow::WindowByIdTable* windowsById = - nsGlobalWindow::GetWindowsTable(); + nsGlobalWindowInner::InnerWindowByIdTable* windowsById = + nsGlobalWindowInner::GetWindowsTable(); if (!windowsById) { NS_WARNING("Couldn't get window-by-id hashtable?"); continue; } - nsGlobalWindow* window = windowsById->Get(iter.Get()->GetKey()); + nsGlobalWindowInner* window = windowsById->Get(iter.Get()->GetKey()); if (!window) { NS_WARNING("Could not look up window?"); continue; @@ -784,7 +791,7 @@ nsWindowMemoryReporter::Observe(nsISupports *aSubject, const char *aTopic, } void -nsWindowMemoryReporter::ObserveDOMWindowDetached(nsGlobalWindow* aWindow) +nsWindowMemoryReporter::ObserveDOMWindowDetached(nsGlobalWindowInner* aWindow) { nsWeakPtr weakWindow = do_GetWeakReference(static_cast(aWindow)); if (!weakWindow) { @@ -881,8 +888,8 @@ nsWindowMemoryReporter::CheckForGhostWindows( return; } - nsGlobalWindow::WindowByIdTable *windowsById = - nsGlobalWindow::GetWindowsTable(); + nsGlobalWindowInner::InnerWindowByIdTable *windowsById = + nsGlobalWindowInner::GetWindowsTable(); if (!windowsById) { NS_WARNING("GetWindowsTable returned null"); return; @@ -898,7 +905,7 @@ nsWindowMemoryReporter::CheckForGhostWindows( for (auto iter = windowsById->Iter(); !iter.Done(); iter.Next()) { // Null outer window implies null top, but calling GetTop() when there's no // outer window causes us to spew debug warnings. - nsGlobalWindow* window = iter.UserData(); + nsGlobalWindowInner* window = iter.UserData(); if (!window->GetOuterWindow() || !window->GetTopInternal()) { // This window is detached, so we don't care about its domain. continue; @@ -948,7 +955,7 @@ nsWindowMemoryReporter::CheckForGhostWindows( continue; } - nsCOMPtr uri = GetWindowURI(nsGlobalWindow::Cast(window)); + nsCOMPtr uri = GetWindowURI(nsGlobalWindowInner::Cast(window)); nsAutoCString domain; if (uri) { @@ -1004,8 +1011,8 @@ nsWindowMemoryReporter::UnlinkGhostWindows() return; } - nsGlobalWindow::WindowByIdTable* windowsById = - nsGlobalWindow::GetWindowsTable(); + nsGlobalWindowInner::InnerWindowByIdTable* windowsById = + nsGlobalWindowInner::GetWindowsTable(); if (!windowsById) { return; } @@ -1021,13 +1028,13 @@ nsWindowMemoryReporter::UnlinkGhostWindows() nsTHashtable ghostWindows; sWindowReporter->CheckForGhostWindows(&ghostWindows); for (auto iter = ghostWindows.ConstIter(); !iter.Done(); iter.Next()) { - nsGlobalWindow::WindowByIdTable* windowsById = - nsGlobalWindow::GetWindowsTable(); + nsGlobalWindowInner::InnerWindowByIdTable* windowsById = + nsGlobalWindowInner::GetWindowsTable(); if (!windowsById) { continue; } - RefPtr window = windowsById->Get(iter.Get()->GetKey()); + RefPtr window = windowsById->Get(iter.Get()->GetKey()); if (window) { window->RiskyUnlink(); } diff --git a/dom/base/nsWindowMemoryReporter.h b/dom/base/nsWindowMemoryReporter.h index 7e7df370fe5e..4c3d0c992458 100644 --- a/dom/base/nsWindowMemoryReporter.h +++ b/dom/base/nsWindowMemoryReporter.h @@ -101,7 +101,7 @@ public: #endif static nsWindowMemoryReporter* Get(); - void ObserveDOMWindowDetached(nsGlobalWindow* aWindow); + void ObserveDOMWindowDetached(nsGlobalWindowInner* aWindow); static int64_t GhostWindowsDistinguishedAmount();