From 0ca10cda09da10de2958c5a00337f0df573fd6c2 Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Thu, 27 Feb 2020 13:01:49 +0000 Subject: [PATCH] Bug 1618117 - Use BrowsingContext for activeness check in FocusOuter. r=nika Differential Revision: https://phabricator.services.mozilla.com/D64299 --HG-- extra : moz-landing-system : lando --- dom/base/nsGlobalWindowOuter.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 69110ce40ffc..8848d11e762c 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -4835,15 +4835,22 @@ void nsGlobalWindowOuter::FocusOuter(CallerType aCallerType) { RevisePopupAbuseLevel(PopupBlocker::GetPopupControlState()) < PopupBlocker::openBlocked); - nsCOMPtr activeDOMWindow; - fm->GetActiveWindow(getter_AddRefs(activeDOMWindow)); + bool isActive = false; + if (XRE_IsParentProcess()) { + nsCOMPtr activeWindow = fm->GetActiveWindow(); - nsCOMPtr rootItem; - mDocShell->GetInProcessRootTreeItem(getter_AddRefs(rootItem)); - nsCOMPtr rootWin = - rootItem ? rootItem->GetWindow() : nullptr; - auto* activeWindow = nsPIDOMWindowOuter::From(activeDOMWindow); - bool isActive = (rootWin == activeWindow); + nsCOMPtr rootItem; + mDocShell->GetInProcessRootTreeItem(getter_AddRefs(rootItem)); + nsCOMPtr rootWin = + rootItem ? rootItem->GetWindow() : nullptr; + isActive = (rootWin == activeWindow); + } else { + BrowsingContext* activeBrowsingContext = fm->GetActiveBrowsingContext(); + BrowsingContext* bc = GetBrowsingContext(); + if (bc) { + isActive = (activeBrowsingContext == bc->Top()); + } + } nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (treeOwnerAsWin && (canFocus || isActive)) {