Bug 1779559 - Make tabbrowser manage chrome BC activeness. r=Gijs
☠☠ backed out by 32c8e8bcdf98 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 19 Jul 2022 09:43:06 +0000
changeset 624362 a68a015349ede84c40990ee3accd34d74805dc23
parent 624361 25ac7edb57412835d83837b34d10e90c347eccbe
child 624363 23fe4f24d483d144c31dbaad09b6d9b51969672d
push id166393
push userealvarez@mozilla.com
push dateTue, 19 Jul 2022 09:53:31 +0000
treeherderautoland@23fe4f24d483 [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);