From 419b10fad5d205a1fb4608a540557e3b56f87ded Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Mon, 2 Mar 2020 13:16:10 +0000 Subject: [PATCH] Bug 1618163 - Use BrowsingContext for activeness check in nsXULPopupManager::MayShowPopup. r=NeilDeakin Differential Revision: https://phabricator.services.mozilla.com/D64353 --HG-- extra : moz-landing-system : lando --- layout/xul/nsXULPopupManager.cpp | 58 +++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/layout/xul/nsXULPopupManager.cpp b/layout/xul/nsXULPopupManager.cpp index a2fbb3830627..6c8d65bff639 100644 --- a/layout/xul/nsXULPopupManager.cpp +++ b/layout/xul/nsXULPopupManager.cpp @@ -1585,36 +1585,64 @@ bool nsXULPopupManager::MayShowPopup(nsMenuPopupFrame* aPopup) { } // if the popup was just rolled up, don't reopen it - if (mozilla::widget::nsAutoRollup::GetLastRollup() == aPopup->GetContent()) + if (mozilla::widget::nsAutoRollup::GetLastRollup() == aPopup->GetContent()) { return false; + } - nsCOMPtr dsti = aPopup->PresContext()->GetDocShell(); - nsCOMPtr baseWin = do_QueryInterface(dsti); - if (!baseWin) return false; + nsCOMPtr docShell = aPopup->PresContext()->GetDocShell(); + + nsCOMPtr baseWin = do_QueryInterface(docShell); + if (!baseWin) { + return false; + } nsCOMPtr root; - dsti->GetInProcessRootTreeItem(getter_AddRefs(root)); + docShell->GetInProcessRootTreeItem(getter_AddRefs(root)); if (!root) { return false; } nsCOMPtr rootWin = root->GetWindow(); - // chrome shells can always open popups, but other types of shells can only - // open popups when they are focused and visible - if (dsti->ItemType() != nsIDocShellTreeItem::typeChrome) { - // only allow popups in active windows - nsIFocusManager* fm = nsFocusManager::GetFocusManager(); - if (!fm || !rootWin) return false; + if (XRE_IsParentProcess()) { + // chrome shells can always open popups, but other types of shells can only + // open popups when they are focused and visible + if (docShell->ItemType() != nsIDocShellTreeItem::typeChrome) { + // only allow popups in active windows + nsFocusManager* fm = nsFocusManager::GetFocusManager(); + if (!fm || !rootWin) { + return false; + } - nsCOMPtr activeWindow; - fm->GetActiveWindow(getter_AddRefs(activeWindow)); - if (activeWindow != rootWin) return false; + nsCOMPtr activeWindow = fm->GetActiveWindow(); + if (activeWindow != rootWin) { + return false; + } + // only allow popups in visible frames + bool visible; + baseWin->GetVisibility(&visible); + if (!visible) { + return false; + } + } + } else { // only allow popups in visible frames bool visible; baseWin->GetVisibility(&visible); - if (!visible) return false; + if (!visible) { + return false; + } + + nsFocusManager* fm = nsFocusManager::GetFocusManager(); + BrowsingContext* bc = docShell->GetBrowsingContext(); + if (!fm || !bc) { + return false; + } + + if (fm->GetActiveBrowsingContext() != bc->Top()) { + return false; + } } // platforms respond differently when an popup is opened in a minimized