Always restore windows to their original spaces
Minor
Commit Hash:
f9a6ce0cb2f15970c0d8f6e7f1517c6a6bab1178
Commit Time: 2026-03-13 15:14:02
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review:
View Upstream Review 🔗
📋 Summary
This commit changes the default behavior of window space (workspace) restoration on macOS. Previously, windows were only restored to their original spaces when Chrome auto-restarted (e.g., after an update); manual quit and restart would not restore spaces. This commit adds a default-enabled Feature Flag kAlwaysMoveWindowsToOriginalSpaces, making windows always restore to their original spaces regardless of the quit reason. The change only affects the restore_space field assignment when constructing StateRestorationData in NativeWidgetMacNSWindowHost::InitWindow(), changing from relying solely on the g_move_windows_to_original_spaces_upon_restoration global variable to also checking the Feature Flag.
🎯 Impact Analysis
The impact of this change on WebView2Mac is minor. Key analysis:
1. **Depends on prerequisite commit not yet in Edge**: This commit modifies code that depends on the StateRestorationData mojo struct and restore_space field introduced by a previous commit (daf1cc3). Edge's NativeWidgetMacNSWindowHost::InitWindow() still uses the old array state_restoration_data direct assignment, without the StateRestorationData struct or restore_space field. This commit must be merged together with its prerequisite.
2. **WebView2Mac windows typically don't involve space restoration**: WebView2Mac's embedded WebView windows run within the host app's window and don't use the independent top-level window workspace restoration mechanism. Window state restoration (state_restoration_data) is primarily used for browser top-level windows (like tab windows) to restore size, position, and fullscreen state during session restore. In WebView2Mac scenarios, state_restoration_data is typically empty, so this code path won't be triggered.
3. **Feature Flag as emergency switch**: The new kAlwaysMoveWindowsToOriginalSpaces Feature Flag is enabled by default but provides an emergency-off mechanism. If this behavior causes issues in certain scenarios, it can be disabled via the Feature Flag. For WebView2Mac, since space restoration is not involved, this Feature Flag has no practical impact.
4. **Minimal and safe code change**: Only adds one Feature Flag definition and one OR condition, without altering any existing logic paths. Risk is very low.
1. **Depends on prerequisite commit not yet in Edge**: This commit modifies code that depends on the StateRestorationData mojo struct and restore_space field introduced by a previous commit (daf1cc3). Edge's NativeWidgetMacNSWindowHost::InitWindow() still uses the old array
2. **WebView2Mac windows typically don't involve space restoration**: WebView2Mac's embedded WebView windows run within the host app's window and don't use the independent top-level window workspace restoration mechanism. Window state restoration (state_restoration_data) is primarily used for browser top-level windows (like tab windows) to restore size, position, and fullscreen state during session restore. In WebView2Mac scenarios, state_restoration_data is typically empty, so this code path won't be triggered.
3. **Feature Flag as emergency switch**: The new kAlwaysMoveWindowsToOriginalSpaces Feature Flag is enabled by default but provides an emergency-off mechanism. If this behavior causes issues in certain scenarios, it can be disabled via the Feature Flag. For WebView2Mac, since space restoration is not involved, this Feature Flag has no practical impact.
4. **Minimal and safe code change**: Only adds one Feature Flag definition and one OR condition, without altering any existing logic paths. Risk is very low.
Impacted Classes:
views::NativeWidgetMacNSWindowHost