Restore windows to spaces on a system restart

Commit: 51341b3f | 2026-03-17 21:55:39

← Back to List

Restore windows to spaces on a system restart

Minor
Commit Hash: 51341b3f92d8927d176cc9e95337affbc1725783
Commit Time: 2026-03-17 21:55:39
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit adds the ability to automatically restore windows to their original spaces after a macOS system restart. Key changes include:
1. Overrides the private AppKit method _handleCoreEvent:withReplyEvent: in BrowserCrApplication to intercept kCoreEventClass AppleEvents and check for the keyAERestoreAppState parameter. The presence of this parameter indicates macOS relaunched Chrome after a system restart, triggering MoveWindowsToOriginalSpacesUponRestoration() to mark windows for space restoration.
2. Renames the static method on NativeWidgetMacNSWindowHost from SetMoveWindowsToOriginalSpacesUponRestoration(bool) to MoveWindowsToOriginalSpacesUponRestoration() (removed parameter, now a one-way set-true operation).
3. Updated the call in ChromeBrowserMainPartsMac to only invoke when kWasRestarted is true.
4. Added a TODO comment in chrome/app_shim/app_shim_application.mm noting duplicate code with chrome_browser_application_mac.mm that needs cleanup.

🎯 Impact Analysis

The impact of this change on WebView2Mac is minor. Key analysis:

1. **NativeWidgetMacNSWindowHost API rename**: The static method was renamed from SetMoveWindowsToOriginalSpacesUponRestoration(bool) to MoveWindowsToOriginalSpacesUponRestoration(). Edge repo already has the previous version of this method, so all call sites need to be updated upon integration. The method itself only sets a global flag variable without changing runtime behavior logic.

2. **System restart detection is in Chrome browser layer**: The new _handleCoreEvent:withReplyEvent: override is in BrowserCrApplication (Chrome browser process's NSApplication subclass), which is not in WebView2Mac's code path. WebView2Mac's Browser process uses the standard Chromium process startup flow and does not go through BrowserCrApplication.

3. **WebView2Mac does not involve space restoration**: Consistent with previous related commits (daf1cc3, f9a6ce0), WebView2Mac's embedded windows do not use the independent workspace restoration mechanism. state_restoration_data is typically empty in WebView2Mac scenarios, so the restore_space flag has no practical effect.

4. **App shim layer TODO comment**: The TODO comment added in chrome/app_shim/app_shim_application.mm notes duplicate code with chrome_browser_application_mac.mm needs cleanup, which may affect future app shim process AppleEvent handling. However, there are no code changes currently. WebView2Mac's app shim process (running within the host app process) does not use AppShimApplication and is therefore unaffected.

Impacted Classes:

views::NativeWidgetMacNSWindowHost BrowserCrApplication