From 2ae314ff8f17b6ed74ace8acaae6b68ebdae5182 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 3 May 2016 17:58:57 +1000 Subject: [PATCH] Bug 1267568 part 1 - Add a weak ptr to nsGlobalChromeWindow to remember the pres shell we set the fullscreen change flag. r=smaug This addresses the review comment from bug 1177155 comment 16 so that the assertion and code to avoid breaking assertion in valid path are no longer needed. MozReview-Commit-ID: GHIYQwyoejC --HG-- extra : source : 3a7d540381d12f58b6b1b150528312150e0c8893 --- dom/base/nsGlobalWindow.cpp | 28 ++++++++++++++++------------ dom/base/nsGlobalWindow.h | 4 ++++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 0d0ac00c9b11..c6e9cfa6de25 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -6461,13 +6461,6 @@ nsGlobalWindow::SetFullscreenInternal(FullscreenReason aReason, } } - // If we didn't setup the widget, we may need to manually set this - // flag, or the assertion in FinishFullscreenChange is violated. - if (nsCOMPtr presShell = mDocShell->GetPresShell()) { - if (!presShell->IsInFullscreenChange()) { - presShell->SetIsInFullscreenChange(true); - } - } FinishFullscreenChange(aFullScreen); return NS_OK; } @@ -6481,8 +6474,15 @@ nsGlobalWindow::SetWidgetFullscreen(FullscreenReason aReason, bool aIsFullscreen MOZ_ASSERT(!AsOuter()->GetFrameElementInternal(), "Content window should not call this"); MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); - if (nsCOMPtr presShell = mDocShell->GetPresShell()) { - presShell->SetIsInFullscreenChange(true); + if (!NS_WARN_IF(!IsChromeWindow())) { + auto chromeWin = static_cast(this); + if (!NS_WARN_IF(chromeWin->mFullscreenPresShell)) { + if (nsIPresShell* shell = mDocShell->GetPresShell()) { + chromeWin->mFullscreenPresShell = do_GetWeakReference(shell); + MOZ_ASSERT(chromeWin->mFullscreenPresShell); + shell->SetIsInFullscreenChange(true); + } + } } nsresult rv = aReason == FullscreenReason::ForFullscreenMode ? // If we enter fullscreen for fullscreen mode, we want @@ -6524,9 +6524,13 @@ nsGlobalWindow::FinishFullscreenChange(bool aIsFullscreen) // respond visually if we are kicked into full screen mode DispatchCustomEvent(NS_LITERAL_STRING("fullscreen")); - if (nsCOMPtr presShell = mDocShell->GetPresShell()) { - MOZ_ASSERT(presShell->IsInFullscreenChange()); - presShell->SetIsInFullscreenChange(false); + if (!NS_WARN_IF(!IsChromeWindow())) { + auto chromeWin = static_cast(this); + if (nsCOMPtr shell = + do_QueryReferent(chromeWin->mFullscreenPresShell)) { + shell->SetIsInFullscreenChange(false); + chromeWin->mFullscreenPresShell = nullptr; + } } if (!mWakeLock && mFullScreen) { diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index 9739fa6f2d92..382f081d7cb7 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -1979,6 +1979,10 @@ public: nsCOMPtr mBrowserDOMWindow; nsCOMPtr mMessageManager; nsInterfaceHashtable mGroupMessageManagers; + // A weak pointer to the nsPresShell that we are doing fullscreen for. + // The pointer being set indicates we've set the IsInFullscreenChange + // flag on this pres shell. + nsWeakPtr mFullscreenPresShell; }; /*