Bug 1328070 - Update window activation state when the owner content is swapped. r?enn
MozReview-Commit-ID: 58uYaH7iFIU
--- a/dom/base/nsFrameLoader.cpp
+++ b/dom/base/nsFrameLoader.cpp
@@ -1069,16 +1069,26 @@ class MOZ_RAII AutoResetInShow {
explicit AutoResetInShow(nsFrameLoader* aFrameLoader MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mFrameLoader(aFrameLoader)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
~AutoResetInShow() { mFrameLoader->mInShow = false; }
};
+static bool
+ParentWindowIsActive(nsIDocument* aDoc)
+{
+ nsCOMPtr<nsPIWindowRoot> root = nsContentUtils::GetWindowRoot(aDoc);
+ if (root) {
+ nsPIDOMWindowOuter* rootWin = root->GetWindow();
+ return rootWin && rootWin->IsActive();
+ }
+ return false;
+}
bool
nsFrameLoader::Show(int32_t marginWidth, int32_t marginHeight,
int32_t scrollbarPrefX, int32_t scrollbarPrefY,
nsSubDocumentFrame* frame)
{
if (mInShow) {
return false;
@@ -1251,27 +1261,17 @@ nsFrameLoader::ShowRemoteFrame(const Scr
RefPtr<layers::LayerManager> layerManager =
nsContentUtils::LayerManagerForDocument(mOwnerContent->GetComposedDoc());
if (!layerManager) {
// This is just not going to work.
return false;
}
- nsPIDOMWindowOuter* win = mOwnerContent->OwnerDoc()->GetWindow();
- bool parentIsActive = false;
- if (win) {
- nsCOMPtr<nsPIWindowRoot> windowRoot =
- nsGlobalWindow::Cast(win)->GetTopWindowRoot();
- if (windowRoot) {
- nsPIDOMWindowOuter* topWin = windowRoot->GetWindow();
- parentIsActive = topWin && topWin->IsActive();
- }
- }
- mRemoteBrowser->Show(size, parentIsActive);
+ mRemoteBrowser->Show(size, ParentWindowIsActive(mOwnerContent->OwnerDoc()));
mRemoteBrowserShown = true;
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIFrameLoader*, this),
"remote-browser-shown", nullptr);
}
} else {
@@ -1460,16 +1460,22 @@ nsFrameLoader::SwapWithOtherRemoteLoader
aOther->MaybeUpdatePrimaryTabParent(eTabParentRemoved);
SetOwnerContent(otherContent);
aOther->SetOwnerContent(ourContent);
mRemoteBrowser->SetOwnerElement(otherContent);
aOther->mRemoteBrowser->SetOwnerElement(ourContent);
+ // Update window activation state for the swapped owner content.
+ Unused << mRemoteBrowser->Manager()->AsContentParent()->SendParentActivated(
+ mRemoteBrowser, ParentWindowIsActive(otherContent->OwnerDoc()));
+ Unused << aOther->mRemoteBrowser->Manager()->AsContentParent()->SendParentActivated(
+ aOther->mRemoteBrowser, ParentWindowIsActive(ourContent->OwnerDoc()));
+
MaybeUpdatePrimaryTabParent(eTabParentChanged);
aOther->MaybeUpdatePrimaryTabParent(eTabParentChanged);
RefPtr<nsFrameMessageManager> ourMessageManager = mMessageManager;
RefPtr<nsFrameMessageManager> otherMessageManager = aOther->mMessageManager;
// Swap and setup things in parent message managers.
if (ourMessageManager) {
ourMessageManager->SetCallback(aOther);