Cherry pick PR #10416: feat(lifecycle): implement race-free and spec-compliant application lifecycle transitions#10788
Open
jellefoks wants to merge 1 commit into
Open
Conversation
This fixes missing visibilityChange events on resume caused by early focus signaling. How it works: The fix blocks focus at the narrowest point in the browser process, in `WebContentsImpl::Focus()`, while waiting for the reveal acknowledgment from the web application. It also ignores OS-initiated focus events in `PlatformWindowStarboard::ProcessFocusEvent` and defers all focus-triggering actions until `OnPageVisibilityVisible`. This commit fixes the missing `visibilitychange` event in the YTS test by deferring the focus event until AFTER the web application has acknowledged that it received the visibility change signal. Previously, the focus event was delivered too early, causing race conditions. By ignoring early focus events and only triggering focus after the web app calls `PageVisibilityVisible` via Mojo, we ensure the strict sequence: [Unfreeze -> Reveal -> Focus], which satisfies the YTS test requirements. Detailed changes: 1. Blink Side (Detecting Visibility and Sending Signal) - third_party/blink/renderer/modules/cobalt/h5vcc_runtime/h_5_vcc_runtime.h & .cc: Inherits from PageVisibilityObserver to listen for visibility changes in Blink. Implements PageVisibilityChanged() to send a Mojo message (PageVisibilityVisible) to the browser process when the page becomes visible on resume. 2. Mojo Interface - cobalt/browser/h5vcc_runtime/public/mojom/h5vcc_runtime.mojom: Adds the PageVisibilityVisible() method to the H5vccRuntime interface to bridge the signal from Blink to the browser. 3. Browser Side (Receiving Signal and State Management) - cobalt/browser/h5vcc_runtime/h5vcc_runtime_impl.h & .cc: Receives the PageVisibilityVisible Mojo call from Blink. Calls OnPageVisibilityVisible on ShellPlatformDelegate. - cobalt/shell/browser/shell_platform_delegate.h & .cc: Maintains the waiting_for_reveal_ack_ state. In OnReveal(), sets this flag to true and informs Starboard. In OnPageVisibilityVisible(), clears the flag and triggers all the deferred actions (showing windows and applying focus). 4. Browser Side (Deferring Actions and Ignoring Early Focus) - cobalt/shell/browser/shell_platform_data_aura.cc: Constructor defers calling host_->window()->Show() if waiting_for_reveal_ack() is true. - cobalt/shell/browser/shell_platform_delegate_aura.cc: SetContents() defers showing the content window if waiting for reveal ACK. RevealShell() calls Show with kInactive to prevent automatic focus stealing on resume. - content/browser/web_contents/web_contents_impl.cc: Ignores calls to Focus() if waiting_for_reveal_ack() is true, preventing early programmatic focus. - ui/ozone/platform/starboard/platform_window_starboard.h & .cc: Maintains a static waiting_for_reveal_ack_ flag accessible by both Cobalt and Ozone. ProcessFocusEvent() and Activate() return early if this flag is true, ignoring OS-level focus events during resume. - cobalt/shell/browser/shell.h & .cc: Modifies Focus() and ActivateContents() to respect waiting_for_reveal_ack(). Adds ShouldFocusPageAfterCrash to also respect this flag. Bug: 477170017
Member
Author
|
The lifecycle PR (#10416) merged, and the cherry-pick to 26.eap is ready, and CI is running on it. #10788 and manually verified working and the same as main, except for:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refer to the original PR: #10416
This also brings in
cobalt/common/cobalt_thread_checker.hfrom #8905 but not the other changes from that PR.This PR implements a natively resilient and completely race-free application lifecycle transition framework for Cobalt (specifically targeting Evergreen RDK and Starboard systems). By strictly serializing transitions between visible, hidden, focused, blurred, frozen, and resumed states, this framework guarantees deterministic synchronization between native OS events, browser-side window widget mapping, and Blink Renderer Mojo updates—completely eliminating all high-speed race conditions, compositor DCHECK aborts, and focus de-synchronizations.
This CL introduces the following key behavioral guarantees and functional correctness enhancements:
visiblebefore the page gains active focus, eliminating any visibility-focus restore races.blurevent loop and Mojo ACKed it back. This guarantees that focus-loss completes atomically before the page document visibility state is concealed, enforcing absolute transition linearity.Verification Results
Bug: 477170017
Bug: 498107481
Bug: 505584259
Bug: 489821073
Bug: 491962441
Bug: 475990372
Bug: 494002968