diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 79e3c69f010..0a64e0acf89 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -1509,7 +1509,6 @@ nsGlobalWindow::FreeInnerObjects() } // Remove our reference to the document and the document principal. - mDoc = nullptr; mFocusedNode = nullptr; if (mApplicationCache) { @@ -8911,6 +8910,9 @@ NS_IMPL_REMOVE_SYSTEM_EVENT_LISTENER(nsGlobalWindow) NS_IMETHODIMP nsGlobalWindow::DispatchEvent(nsIDOMEvent* aEvent, bool* aRetVal) { + MOZ_ASSERT(!IsInnerWindow() || IsCurrentInnerWindow(), + "We should only fire events on the current inner window."); + FORWARD_TO_INNER(DispatchEvent, (aEvent, aRetVal), NS_OK); if (!mDoc) { @@ -9040,10 +9042,7 @@ nsIScriptContext* nsGlobalWindow::GetContextForEventHandlers(nsresult* aRv) { *aRv = NS_ERROR_UNEXPECTED; - if (IsInnerWindow()) { - nsPIDOMWindow* outer = GetOuterWindow(); - NS_ENSURE_TRUE(outer && outer->GetCurrentInnerWindow() == this, nullptr); - } + NS_ENSURE_TRUE(!IsInnerWindow() || IsCurrentInnerWindow(), nullptr); nsIScriptContext* scx; if ((scx = GetContext())) { @@ -10699,7 +10698,7 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, // need to fire only one idle event while the window is frozen. mNotifyIdleObserversIdleOnThaw = true; mNotifyIdleObserversActiveOnThaw = false; - } else if (mOuterWindow && mOuterWindow->GetCurrentInnerWindow() == this) { + } else if (IsCurrentInnerWindow()) { HandleIdleActiveEvent(); } return NS_OK; @@ -10710,13 +10709,17 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, if (IsFrozen()) { mNotifyIdleObserversActiveOnThaw = true; mNotifyIdleObserversIdleOnThaw = false; - } else if (mOuterWindow && mOuterWindow->GetCurrentInnerWindow() == this) { + } else if (IsCurrentInnerWindow()) { ScheduleActiveTimerCallback(); } return NS_OK; } - if (IsInnerWindow() && !nsCRT::strcmp(aTopic, "dom-storage2-changed")) { + if (!nsCRT::strcmp(aTopic, "dom-storage2-changed")) { + if (!IsInnerWindow() || !IsCurrentInnerWindow()) { + return NS_OK; + } + nsIPrincipal *principal; nsresult rv; diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 45f524d779f..78914a8ad34 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -327,6 +327,15 @@ public: return mIsInnerWindow; } + // Returns true if this object has an outer window and it is the current inner + // window of that outer. Only call this on inner windows. + bool IsCurrentInnerWindow() const + { + MOZ_ASSERT(IsInnerWindow(), + "It doesn't make sense to call this on outer windows."); + return mOuterWindow && mOuterWindow->GetCurrentInnerWindow() == this; + } + bool IsOuterWindow() const { return !IsInnerWindow(); diff --git a/dom/gamepad/GamepadService.cpp b/dom/gamepad/GamepadService.cpp index ba118b3d09a..879b6b3cedf 100644 --- a/dom/gamepad/GamepadService.cpp +++ b/dom/gamepad/GamepadService.cpp @@ -209,7 +209,7 @@ GamepadService::NewButtonEvent(uint32_t aIndex, uint32_t aButton, bool aPressed, --i; // Only send events to non-background windows - if (!listeners[i]->GetOuterWindow() || + if (!listeners[i]->IsCurrentInnerWindow() || listeners[i]->GetOuterWindow()->IsBackground()) { continue; } @@ -274,7 +274,7 @@ GamepadService::NewAxisMoveEvent(uint32_t aIndex, uint32_t aAxis, double aValue) --i; // Only send events to non-background windows - if (!listeners[i]->GetOuterWindow() || + if (!listeners[i]->IsCurrentInnerWindow() || listeners[i]->GetOuterWindow()->IsBackground()) { continue; } @@ -340,7 +340,7 @@ GamepadService::NewConnectionEvent(uint32_t aIndex, bool aConnected) --i; // Only send events to non-background windows - if (!listeners[i]->GetOuterWindow() || + if (!listeners[i]->IsCurrentInnerWindow() || listeners[i]->GetOuterWindow()->IsBackground()) { continue; } @@ -525,6 +525,7 @@ GamepadServiceTest::CreateService() GamepadServiceTest::GamepadServiceTest() { /* member initializers and constructor code */ + nsRefPtr service = GamepadService::GetService(); } /* uint32_t addGamepad (in string id, in unsigned long mapping, in unsigned long numButtons, in unsigned long numAxes); */