Bug 1241763: Don't fire dom-window-destroyed on outer windows. r=bz

This commit is contained in:
Kyle Huey 2016-01-22 10:27:54 -08:00
parent 0fbc58d746
commit a1459ad2d7
4 changed files with 19 additions and 12 deletions

View File

@ -1622,6 +1622,9 @@ nsGlobalWindow::FreeInnerObjects()
// other members that the window destroyed observers could
// re-create.
NotifyDOMWindowDestroyed(this);
if (auto* reporter = nsWindowMemoryReporter::Get()) {
reporter->ObserveDOMWindowDetached(this);
}
mInnerObjectsFreed = true;
@ -2932,8 +2935,9 @@ nsGlobalWindow::DetachFromDocShell()
inner->FreeInnerObjects();
}
// Make sure that this is called before we null out the document.
NotifyDOMWindowDestroyed(this);
if (auto* reporter = nsWindowMemoryReporter::Get()) {
reporter->ObserveDOMWindowDetached(this);
}
NotifyWindowIDDestroyed("outer-window-destroyed");

View File

@ -17,6 +17,7 @@
#include "js/TypeDecls.h"
#include "nsRefPtrHashtable.h"
// Only fired for inner windows.
#define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
#define DOM_WINDOW_FROZEN_TOPIC "dom-window-frozen"
#define DOM_WINDOW_THAWED_TOPIC "dom-window-thawed"

View File

@ -111,10 +111,6 @@ nsWindowMemoryReporter::Init()
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
// DOM_WINDOW_DESTROYED_TOPIC announces what we call window "detachment",
// when a window's docshell is set to nullptr.
os->AddObserver(sWindowReporter, DOM_WINDOW_DESTROYED_TOPIC,
/* weakRef = */ true);
os->AddObserver(sWindowReporter, "after-minimize-memory-usage",
/* weakRef = */ true);
os->AddObserver(sWindowReporter, "cycle-collector-begin",
@ -127,6 +123,12 @@ nsWindowMemoryReporter::Init()
RegisterGhostWindowsDistinguishedAmount(GhostWindowsReporter::DistinguishedAmount);
}
/* static */ nsWindowMemoryReporter*
nsWindowMemoryReporter::Get()
{
return sWindowReporter;
}
static already_AddRefed<nsIURI>
GetWindowURI(nsIDOMWindow *aWindow)
{
@ -614,9 +616,7 @@ NS_IMETHODIMP
nsWindowMemoryReporter::Observe(nsISupports *aSubject, const char *aTopic,
const char16_t *aData)
{
if (!strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC)) {
ObserveDOMWindowDetached(aSubject);
} else if (!strcmp(aTopic, "after-minimize-memory-usage")) {
if (!strcmp(aTopic, "after-minimize-memory-usage")) {
ObserveAfterMinimizeMemoryUsage();
} else if (!strcmp(aTopic, "cycle-collector-begin")) {
if (mCheckTimer) {
@ -638,9 +638,9 @@ nsWindowMemoryReporter::Observe(nsISupports *aSubject, const char *aTopic,
}
void
nsWindowMemoryReporter::ObserveDOMWindowDetached(nsISupports* aWindow)
nsWindowMemoryReporter::ObserveDOMWindowDetached(nsGlobalWindow* aWindow)
{
nsWeakPtr weakWindow = do_GetWeakReference(aWindow);
nsWeakPtr weakWindow = do_GetWeakReference(static_cast<nsIDOMEventTarget*>(aWindow));
if (!weakWindow) {
NS_WARNING("Couldn't take weak reference to a window?");
return;

View File

@ -158,6 +158,9 @@ public:
static void UnlinkGhostWindows();
#endif
static nsWindowMemoryReporter* Get();
void ObserveDOMWindowDetached(nsGlobalWindow* aWindow);
private:
~nsWindowMemoryReporter();
@ -199,7 +202,6 @@ private:
*/
uint32_t GetGhostTimeout();
void ObserveDOMWindowDetached(nsISupports* aWindow);
void ObserveAfterMinimizeMemoryUsage();
/**