diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 3d17e502a10e..69e9dee5ff09 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 091e0324f30e..8713d7cf35ab 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 f06cf5a715b6..b1819f7b8501 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 3d3b685ce057..b54defaa8013 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 35036544e7ff..940f50d49854 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