Bug 1779559 - Make tabbrowser manage chrome BC activeness. r=Gijs
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 19 Jul 2022 19:25:47 +0000
changeset 624415 939cb6d24171250dc1790ff85e41e8741fd547d2
parent 624414 e0cb69d5cb5acb07f911638d00381f1e2b0643b9
child 624416 02862be5276fce949fad6ef1e261b3aacfc8aaf6
push id166431
push userealvarez@mozilla.com
push dateTue, 19 Jul 2022 19:28:19 +0000
treeherderautoland@02862be5276f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1779559
milestone104.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1779559 - Make tabbrowser manage chrome BC activeness. r=Gijs Just like it manages content, so that we stop chrome animations and such in hidden or fully-occluded windows too. This already happened on macOS for minimized windows via PauseCompositor, but this should be better and more consistent. Differential Revision: https://phabricator.services.mozilla.com/D151818
browser/base/content/tabbrowser.js
browser/base/content/test/general/browser_minimize.js
widget/cocoa/nsCocoaWindow.mm
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -5630,24 +5630,25 @@
           }
           this.selectedTab = tab;
           window.focus();
           aEvent.preventDefault();
           break;
         }
         case "sizemodechange":
         case "occlusionstatechange":
-          if (aEvent.target == window && !this._switcher) {
-            this.selectedBrowser.preserveLayers(
+          if (aEvent.target == window) {
+            const inactive =
               window.windowState == window.STATE_MINIMIZED ||
-                window.isFullyOccluded
-            );
-            this.selectedBrowser.docShellIsActive = this.shouldActivateDocShell(
-              this.selectedBrowser
-            );
+              window.isFullyOccluded;
+            window.browsingContext.isActive = !inactive;
+            if (!this._switcher) {
+              this.selectedBrowser.preserveLayers(inactive);
+              this.selectedBrowser.docShellIsActive = !inactive;
+            }
           }
           break;
       }
     },
 
     observe(aSubject, aTopic, aData) {
       switch (aTopic) {
         case "contextual-identity-updated": {
--- a/browser/base/content/test/general/browser_minimize.js
+++ b/browser/base/content/test/general/browser_minimize.js
@@ -5,25 +5,27 @@ add_task(async function() {
   registerCleanupFunction(function() {
     window.restore();
   });
   function isActive() {
     return gBrowser.selectedTab.linkedBrowser.docShellIsActive;
   }
 
   ok(isActive(), "Docshell should be active when starting the test");
+  ok(!document.hidden, "Top level window should be visible");
 
   info("Calling window.minimize");
   let promiseSizeModeChange = BrowserTestUtils.waitForEvent(
     window,
     "sizemodechange"
   );
   window.minimize();
   await promiseSizeModeChange;
   ok(!isActive(), "Docshell should be Inactive");
+  ok(document.hidden, "Top level window should be hidden");
 
   info("Calling window.restore");
   promiseSizeModeChange = BrowserTestUtils.waitForEvent(
     window,
     "sizemodechange"
   );
   window.restore();
   // On Ubuntu `window.restore` doesn't seem to work, use a timer to make the
@@ -38,9 +40,10 @@ add_task(async function() {
     ),
   ]);
   // The sizemodechange event can sometimes be fired before the
   // occlusionstatechange event, especially in chaos mode.
   if (window.isFullyOccluded) {
     await BrowserTestUtils.waitForEvent(window, "occlusionstatechange");
   }
   ok(isActive(), "Docshell should be active again");
+  ok(!document.hidden, "Top level window should be visible");
 });
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2154,70 +2154,28 @@ void nsCocoaWindow::PauseCompositor() {
   if (!mainChildView) {
     return;
   }
   CompositorBridgeChild* remoteRenderer = mainChildView->GetRemoteRenderer();
   if (!remoteRenderer) {
     return;
   }
   remoteRenderer->SendPause();
-
-  // Now that the compositor has paused, we also try to mark the browser window
-  // docshell inactive to stop any animations. This does not affect docshells
-  // for browsers in other processes, but browser UI code should be managing
-  // their active state appropriately.
-  if (!mWidgetListener) {
-    return;
-  }
-  PresShell* presShell = mWidgetListener->GetPresShell();
-  if (!presShell) {
-    return;
-  }
-  nsPresContext* presContext = presShell->GetPresContext();
-  if (!presContext) {
-    return;
-  }
-  BrowsingContext* bc = presContext->Document()->GetBrowsingContext();
-  if (!bc) {
-    return;
-  }
-  Unused << bc->SetExplicitActive(ExplicitActiveStatus::Inactive);
 }
 
 void nsCocoaWindow::ResumeCompositor() {
   nsIWidget* mainChildView = static_cast<nsIWidget*>([[mWindow mainChildView] widget]);
   if (!mainChildView) {
     return;
   }
   CompositorBridgeChild* remoteRenderer = mainChildView->GetRemoteRenderer();
   if (!remoteRenderer) {
     return;
   }
   remoteRenderer->SendResume();
-
-  // Now that the compositor has resumed, we also try to mark the browser window
-  // docshell active to restart any animations. This does not affect docshells
-  // for browsers in other processes, but browser UI code should be managing
-  // their active state appropriately.
-  if (!mWidgetListener) {
-    return;
-  }
-  PresShell* presShell = mWidgetListener->GetPresShell();
-  if (!presShell) {
-    return;
-  }
-  nsPresContext* presContext = presShell->GetPresContext();
-  if (!presContext) {
-    return;
-  }
-  BrowsingContext* bc = presContext->Document()->GetBrowsingContext();
-  if (!bc) {
-    return;
-  }
-  Unused << bc->SetExplicitActive(ExplicitActiveStatus::Active);
 }
 
 void nsCocoaWindow::SetMenuBar(RefPtr<nsMenuBarX>&& aMenuBar) {
   if (!mWindow) {
     mMenuBar = nullptr;
     return;
   }
   mMenuBar = std::move(aMenuBar);