From 71fc09547a749679edbdf09187c8ecd3f6b9c585 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 29 Jun 2014 17:31:13 +0200 Subject: [PATCH] Bug 968804 - Part m: Add outer window assertions to DispatchCustomEvent; r=khuey --- dom/base/nsGlobalWindow.cpp | 14 +++++++------- dom/base/nsGlobalWindow.h | 2 +- dom/base/nsPIDOMWindow.h | 4 +++- toolkit/components/alerts/nsXULAlerts.cpp | 3 ++- xpfe/appshell/src/nsWebShellWindow.cpp | 4 +++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 3d17e502a10..69e9dee5ff0 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -5818,12 +5818,12 @@ nsGlobalWindow::GetChildWindow(const nsAString& aName) } bool -nsGlobalWindow::DispatchCustomEvent(const char *aEventName) +nsGlobalWindow::DispatchCustomEvent(const nsAString& aEventName) { + MOZ_ASSERT(IsOuterWindow()); + bool defaultActionEnabled = true; - nsContentUtils::DispatchTrustedEvent(mDoc, - GetOuterWindow(), - NS_ConvertASCIItoUTF16(aEventName), + nsContentUtils::DispatchTrustedEvent(mDoc, ToSupports(this), aEventName, true, true, &defaultActionEnabled); return defaultActionEnabled; @@ -5999,7 +5999,7 @@ nsGlobalWindow::SetFullScreenInternal(bool aFullScreen, bool aRequireTrust) // dispatch a "fullscreen" DOM event so that XUL apps can // respond visually if we are kicked into full screen mode - if (!DispatchCustomEvent("fullscreen")) { + if (!DispatchCustomEvent(NS_LITERAL_STRING("fullscreen"))) { return NS_OK; } @@ -8435,7 +8435,7 @@ nsGlobalWindow::Close(ErrorResult& aError) bool wasInClose = mInClose; mInClose = true; - if (!DispatchCustomEvent("DOMWindowClose")) { + if (!DispatchCustomEvent(NS_LITERAL_STRING("DOMWindowClose"))) { // Someone chose to prevent the default action for this event, if // so, let's not close this window after all... @@ -8474,7 +8474,7 @@ nsGlobalWindow::ForceClose() mInClose = true; - DispatchCustomEvent("DOMWindowClose"); + DispatchCustomEvent(NS_LITERAL_STRING("DOMWindowClose")); FinalClose(); } diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 091e0324f30..8713d7cf35a 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -487,9 +487,9 @@ public: virtual void MaybeUpdateTouchState(); virtual void UpdateTouchState(); - virtual bool DispatchCustomEvent(const char *aEventName); // Outer windows only. + virtual bool DispatchCustomEvent(const nsAString& aEventName); bool DispatchResizeEvent(const mozilla::CSSIntSize& aSize); virtual void RefreshCompartmentPrincipal(); diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index f06cf5a715b..b1819f7b850 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -677,8 +677,10 @@ public: /** * Dispatch a custom event with name aEventName targeted at this window. * Returns whether the default action should be performed. + * + * Outer windows only. */ - virtual bool DispatchCustomEvent(const char *aEventName) = 0; + virtual bool DispatchCustomEvent(const nsAString& aEventName) = 0; /** * Notify the active inner window that the document principal may have changed diff --git a/toolkit/components/alerts/nsXULAlerts.cpp b/toolkit/components/alerts/nsXULAlerts.cpp index 3d3b685ce05..b54defaa801 100644 --- a/toolkit/components/alerts/nsXULAlerts.cpp +++ b/toolkit/components/alerts/nsXULAlerts.cpp @@ -152,7 +152,8 @@ nsXULAlerts::CloseAlert(const nsAString& aAlertName) nsIDOMWindow* alert = mNamedWindows.GetWeak(aAlertName); nsCOMPtr domWindow = do_QueryInterface(alert); if (domWindow) { - domWindow->DispatchCustomEvent("XULAlertClose"); + MOZ_ASSERT(domWindow->IsOuterWindow()); + domWindow->DispatchCustomEvent(NS_LITERAL_STRING("XULAlertClose")); } return NS_OK; } diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 35036544e7f..940f50d4985 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -330,6 +330,8 @@ nsWebShellWindow::SizeModeChanged(nsSizeMode sizeMode) nsCOMPtr ourWindow = mDocShell ? mDocShell->GetWindow() : nullptr; if (ourWindow) { + MOZ_ASSERT(ourWindow->IsOuterWindow()); + // Let the application know if it's in fullscreen mode so it // can update its UI. if (sizeMode == nsSizeMode_Fullscreen) { @@ -340,7 +342,7 @@ nsWebShellWindow::SizeModeChanged(nsSizeMode sizeMode) } // And always fire a user-defined sizemodechange event on the window - ourWindow->DispatchCustomEvent("sizemodechange"); + ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("sizemodechange")); } // Note the current implementation of SetSizeMode just stores