From cfa69d93e96c025287861e52e317a1c6a5bda2f7 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Fri, 16 Oct 2015 14:40:30 -0700 Subject: [PATCH] Bug 1215398 - Hoist the IsCallerChrome call in CanMoveResizeWindows to the script-only entry points. r=bz --- dom/base/nsGlobalWindow.cpp | 56 ++++++++++++++++++------------------- dom/base/nsGlobalWindow.h | 12 ++++---- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 4a5af5115cb1..af6df45fda56 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -6882,12 +6882,12 @@ nsGlobalWindow::MakeScriptDialogTitle(nsAString &aOutTitle) } bool -nsGlobalWindow::CanMoveResizeWindows() +nsGlobalWindow::CanMoveResizeWindows(bool aCallerIsChrome) { MOZ_ASSERT(IsOuterWindow()); // When called from chrome, we can avoid the following checks. - if (!nsContentUtils::IsCallerChrome()) { + if (!aCallerIsChrome) { // Don't allow scripts to move or resize windows that were not opened by a // script. if (!mHadOriginalOpener) { @@ -7603,7 +7603,7 @@ nsGlobalWindow::Print() } void -nsGlobalWindow::MoveToOuter(int32_t aXPos, int32_t aYPos, ErrorResult& aError) +nsGlobalWindow::MoveToOuter(int32_t aXPos, int32_t aYPos, ErrorResult& aError, bool aCallerIsChrome) { MOZ_RELEASE_ASSERT(IsOuterWindow()); /* @@ -7611,7 +7611,7 @@ nsGlobalWindow::MoveToOuter(int32_t aXPos, int32_t aYPos, ErrorResult& aError) * prevent window.moveTo() by exiting early */ - if (!CanMoveResizeWindows() || IsFrame()) { + if (!CanMoveResizeWindows(aCallerIsChrome) || IsFrame()) { return; } @@ -7633,22 +7633,22 @@ nsGlobalWindow::MoveToOuter(int32_t aXPos, int32_t aYPos, ErrorResult& aError) void nsGlobalWindow::MoveTo(int32_t aXPos, int32_t aYPos, ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(MoveToOuter, (aXPos, aYPos, aError), aError, ); + FORWARD_TO_OUTER_OR_THROW(MoveToOuter, (aXPos, aYPos, aError, nsContentUtils::IsCallerChrome()), aError, ); } NS_IMETHODIMP nsGlobalWindow::MoveTo(int32_t aXPos, int32_t aYPos) { - FORWARD_TO_INNER(MoveTo, (aXPos, aYPos), NS_ERROR_UNEXPECTED); + FORWARD_TO_OUTER(MoveTo, (aXPos, aYPos), NS_ERROR_UNEXPECTED); ErrorResult rv; - MoveTo(aXPos, aYPos, rv); + MoveToOuter(aXPos, aYPos, rv, /* aCallerIsChrome = */ true); return rv.StealNSResult(); } void -nsGlobalWindow::MoveByOuter(int32_t aXDif, int32_t aYDif, ErrorResult& aError) +nsGlobalWindow::MoveByOuter(int32_t aXDif, int32_t aYDif, ErrorResult& aError, bool aCallerIsChrome) { MOZ_RELEASE_ASSERT(IsOuterWindow()); @@ -7657,7 +7657,7 @@ nsGlobalWindow::MoveByOuter(int32_t aXDif, int32_t aYDif, ErrorResult& aError) * prevent window.moveBy() by exiting early */ - if (!CanMoveResizeWindows() || IsFrame()) { + if (!CanMoveResizeWindows(aCallerIsChrome) || IsFrame()) { return; } @@ -7693,22 +7693,22 @@ nsGlobalWindow::MoveByOuter(int32_t aXDif, int32_t aYDif, ErrorResult& aError) void nsGlobalWindow::MoveBy(int32_t aXDif, int32_t aYDif, ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(MoveByOuter, (aXDif, aYDif, aError), aError, ); + FORWARD_TO_OUTER_OR_THROW(MoveByOuter, (aXDif, aYDif, aError, nsContentUtils::IsCallerChrome()), aError, ); } NS_IMETHODIMP nsGlobalWindow::MoveBy(int32_t aXDif, int32_t aYDif) { - FORWARD_TO_INNER(MoveBy, (aXDif, aYDif), NS_ERROR_UNEXPECTED); + FORWARD_TO_OUTER(MoveBy, (aXDif, aYDif), NS_ERROR_UNEXPECTED); ErrorResult rv; - MoveBy(aXDif, aYDif, rv); + MoveByOuter(aXDif, aYDif, rv, /* aCallerIsChrome = */ true); return rv.StealNSResult(); } void -nsGlobalWindow::ResizeToOuter(int32_t aWidth, int32_t aHeight, ErrorResult& aError) +nsGlobalWindow::ResizeToOuter(int32_t aWidth, int32_t aHeight, ErrorResult& aError, bool aCallerIsChrome) { MOZ_RELEASE_ASSERT(IsOuterWindow()); @@ -7730,7 +7730,7 @@ nsGlobalWindow::ResizeToOuter(int32_t aWidth, int32_t aHeight, ErrorResult& aErr * prevent window.resizeTo() by exiting early */ - if (!CanMoveResizeWindows() || IsFrame()) { + if (!CanMoveResizeWindows(aCallerIsChrome) || IsFrame()) { return; } @@ -7751,23 +7751,23 @@ nsGlobalWindow::ResizeToOuter(int32_t aWidth, int32_t aHeight, ErrorResult& aErr void nsGlobalWindow::ResizeTo(int32_t aWidth, int32_t aHeight, ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(ResizeToOuter, (aWidth, aHeight, aError), aError, ); + FORWARD_TO_OUTER_OR_THROW(ResizeToOuter, (aWidth, aHeight, aError, nsContentUtils::IsCallerChrome()), aError, ); } NS_IMETHODIMP nsGlobalWindow::ResizeTo(int32_t aWidth, int32_t aHeight) { - FORWARD_TO_INNER(ResizeTo, (aWidth, aHeight), NS_ERROR_UNEXPECTED); + FORWARD_TO_OUTER(ResizeTo, (aWidth, aHeight), NS_ERROR_UNEXPECTED); ErrorResult rv; - ResizeTo(aWidth, aHeight, rv); + ResizeToOuter(aWidth, aHeight, rv, nsContentUtils::IsCallerChrome()); return rv.StealNSResult(); } void nsGlobalWindow::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, - ErrorResult& aError) + ErrorResult& aError, bool aCallerIsChrome) { MOZ_RELEASE_ASSERT(IsOuterWindow()); @@ -7796,7 +7796,7 @@ nsGlobalWindow::ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, * prevent window.resizeBy() by exiting early */ - if (!CanMoveResizeWindows() || IsFrame()) { + if (!CanMoveResizeWindows(aCallerIsChrome) || IsFrame()) { return; } @@ -7832,22 +7832,22 @@ void nsGlobalWindow::ResizeBy(int32_t aWidthDif, int32_t aHeightDif, ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(ResizeByOuter, (aWidthDif, aHeightDif, aError), aError, ); + FORWARD_TO_OUTER_OR_THROW(ResizeByOuter, (aWidthDif, aHeightDif, aError, nsContentUtils::IsCallerChrome()), aError, ); } NS_IMETHODIMP nsGlobalWindow::ResizeBy(int32_t aWidthDif, int32_t aHeightDif) { - FORWARD_TO_INNER(ResizeBy, (aWidthDif, aHeightDif), NS_ERROR_UNEXPECTED); + FORWARD_TO_OUTER(ResizeBy, (aWidthDif, aHeightDif), NS_ERROR_UNEXPECTED); ErrorResult rv; - ResizeBy(aWidthDif, aHeightDif, rv); + ResizeByOuter(aWidthDif, aHeightDif, rv, /* aCallerIsChrome = */ true); return rv.StealNSResult(); } void -nsGlobalWindow::SizeToContentOuter(ErrorResult& aError) +nsGlobalWindow::SizeToContentOuter(ErrorResult& aError, bool aCallerIsChrome) { MOZ_RELEASE_ASSERT(IsOuterWindow()); @@ -7860,7 +7860,7 @@ nsGlobalWindow::SizeToContentOuter(ErrorResult& aError) * prevent window.sizeToContent() by exiting early */ - if (!CanMoveResizeWindows() || IsFrame()) { + if (!CanMoveResizeWindows(aCallerIsChrome) || IsFrame()) { return; } @@ -7899,16 +7899,16 @@ nsGlobalWindow::SizeToContentOuter(ErrorResult& aError) void nsGlobalWindow::SizeToContent(ErrorResult& aError) { - FORWARD_TO_OUTER_OR_THROW(SizeToContentOuter, (aError), aError, ); + FORWARD_TO_OUTER_OR_THROW(SizeToContentOuter, (aError, nsContentUtils::IsCallerChrome()), aError, ); } NS_IMETHODIMP nsGlobalWindow::SizeToContent() { - FORWARD_TO_INNER(SizeToContent, (), NS_ERROR_UNEXPECTED); + FORWARD_TO_OUTER(SizeToContent, (), NS_ERROR_UNEXPECTED); ErrorResult rv; - SizeToContent(rv); + SizeToContentOuter(rv, /* aCallerIsChrome = */ true); return rv.StealNSResult(); } @@ -14734,7 +14734,7 @@ nsGlobalWindow::SetReplaceableWindowCoord(JSContext* aCx, * just treat this the way we would an IDL replaceable property. */ nsGlobalWindow* outer = GetOuterWindowInternal(); - if (!outer || !outer->CanMoveResizeWindows() || outer->IsFrame()) { + if (!outer || !outer->CanMoveResizeWindows(nsContentUtils::IsCallerChrome()) || outer->IsFrame()) { RedefineProperty(aCx, aPropName, aValue, aError); return; } diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index f23b3b397ff8..e16d42944520 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -983,14 +983,14 @@ public: already_AddRefed MatchMedia(const nsAString& aQuery, mozilla::ErrorResult& aError); nsScreen* GetScreen(mozilla::ErrorResult& aError); - void MoveToOuter(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError); + void MoveToOuter(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError, bool aCallerIsChrome); void MoveTo(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError); - void MoveByOuter(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError); + void MoveByOuter(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError, bool aCallerIsChrome); void MoveBy(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError); - void ResizeToOuter(int32_t aWidth, int32_t aHeight, mozilla::ErrorResult& aError); + void ResizeToOuter(int32_t aWidth, int32_t aHeight, mozilla::ErrorResult& aError, bool aCallerIsChrome); void ResizeTo(int32_t aWidth, int32_t aHeight, mozilla::ErrorResult& aError); - void ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, mozilla::ErrorResult& aError); + void ResizeByOuter(int32_t aWidthDif, int32_t aHeightDif, mozilla::ErrorResult& aError, bool aCallerIsChrome); void ResizeBy(int32_t aWidthDif, int32_t aHeightDif, mozilla::ErrorResult& aError); void Scroll(double aXScroll, double aYScroll); @@ -1052,7 +1052,7 @@ public: GetDefaultComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt, mozilla::ErrorResult& aError); - void SizeToContentOuter(mozilla::ErrorResult& aError); + void SizeToContentOuter(mozilla::ErrorResult& aError, bool aCallerIsChrome); void SizeToContent(mozilla::ErrorResult& aError); mozilla::dom::Crypto* GetCrypto(mozilla::ErrorResult& aError); nsIControllers* GetControllersOuter(mozilla::ErrorResult& aError); @@ -1471,7 +1471,7 @@ public: static void MakeScriptDialogTitle(nsAString &aOutTitle); // Outer windows only. - bool CanMoveResizeWindows(); + bool CanMoveResizeWindows(bool aCallerIsChrome); // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to // just flush our parent and only flush ourselves if we think we need to.