Fix stale superview bounds when positioning WebContentsViewMac during resize
Major
Commit Hash:
ef2fe534f68541754f74820212624d55a79c5a78
Commit Time: 2026-01-22 22:20:56
Impact Level: Major
Generated By: webview2-upstream-sentry
📋 Summary
This commit fixes incorrect frame positioning in WebContentsNSViewBridge::SetBounds() caused by stale superview.bounds during resize, when BridgedContentView::setFrameSize triggers UpdateWindowGeometry before the NSView's frame is updated. Changes span multiple layers: the Mojo interface web_contents_ns_view_bridge.mojom adds a superview_height parameter to SetBounds; NativeViewHostMac obtains the authoritative superview height from Widget::GetClientAreaBoundsInScreen() and passes it in; WebContentsViewMac forwards the height to both in-process and out-of-process (Remote Cocoa) paths; WebContentsNSViewBridge::SetBounds uses the passed superview_height instead of [superview bounds].size.height for Y flipping; the ViewsHostableView interface is updated accordingly.
🎯 Impact Analysis
This change has a direct and significant impact on WebView2Mac. Edge downstream has a HostingWebContentsNSViewBridge class in content/app_shim_remote_cocoa/edge_embedded_browser/ that inherits from WebContentsNSViewBridge and overrides SetBounds. The upstream signature change from (const gfx::Rect&) to (const gfx::Rect&, int32_t superview_height) has already been reflected in the downstream override. However, the downstream SetBounds implementation uses its own coordinate transformation logic (via hostingNSView.bounds.size.height and convertRect:fromView:), still reading hostingNSView.bounds at call time, which may suffer from the same stale-bounds issue during resize that this upstream commit fixes. It is recommended to evaluate whether the downstream HostingWebContentsNSViewBridge::SetBounds should also use the passed superview_height instead of hostingNSView.bounds.size.height for consistent resize correctness.
Impacted Classes:
remote_cocoa::WebContentsNSViewBridge
content::WebContentsViewMac
ui::ViewsHostableView
views::NativeViewHostMac
embedded_browser_webview::HostingWebContentsNSViewBridge