Bug 1328070 - Update window activation state when the owner content is swapped. r?enn draft
authorTing-Yu Chou <janus926@gmail.com>
Thu, 06 Apr 2017 15:58:02 +0800
changeset 556954 d08908ba2336558dd681195a4ff59d10ae46e3cf
parent 556622 ec8d1d3db50c85037e8077c32c8403570a5df493
child 622972 ac2523cc1981f20678b154e7384134ef6802ea35
push id52635
push userbmo:janus926@gmail.com
push dateThu, 06 Apr 2017 10:36:35 +0000
reviewersenn
bugs1328070
milestone55.0a1
Bug 1328070 - Update window activation state when the owner content is swapped. r?enn MozReview-Commit-ID: 58uYaH7iFIU
dom/base/nsFrameLoader.cpp
--- 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);