Always initialize occlusion detection

Commit: 604b4bc1 | 2026-02-10 20:47:32+00:00

← Back to List

Always initialize occlusion detection

Minor
Commit Hash: 604b4bc199ccc6e167785effb3988f77fab9fcdf
Commit Time: 2026-02-10 20:47:32+00:00
Impact Level: Minor
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This commit fixes an occlusion detection initialization logic issue in WebContentsViewCocoa. Previously, when manual occlusion detection was disabled, WebContentsViewCocoa would disable *all* occlusion detection, including that provided by the OS. Now, the WebContentsOcclusionCheckerMac shared instance is initialized regardless of whether manual occlusion detection is supported. This is because WebContentsOcclusionCheckerMac already has internal logic to determine whether to register for manual occlusion-related notifications, so there's no need to perform an additional check in WebContentsViewCocoa.

Key changes include:
1. Removed the check for manualOcclusionDetectionSupportedForCurrentMacOSVersion from the +initialize method in web_contents_view_cocoa.mm (5 lines deleted)
2. Adjusted the order of API comments in web_contents_occlusion_checker_mac.h (moved "API exposed for testing" comment before method declarations)

🎯 Impact Analysis

This change has a positive impact on WebView2Mac. In the WebView2Mac dependency report, HostingWebContentsNSViewBridge inherits from remote_cocoa::WebContentsNSViewBridge, and WebContentsViewCocoa is the NSView representation layer for WebContents on macOS, serving as a core component of the Remote Cocoa architecture.

Specific impact analysis:

1. **Functional Improvement**: This change ensures that WebContentsViewCocoa can receive and respond to occlusion state notifications provided by the OS, even on macOS versions that don't support manual occlusion detection (such as 13.0-13.2 and 26.0+). This is crucial for WebView2Mac's visibility management, as it affects web content rendering optimization and resource management.

2. **Performance Optimization**: Proper occlusion detection allows WebView2Mac to pause or reduce rendering activities when occluded, thereby conserving system resources. The previous logic error could cause WebView2Mac to continue rendering at full speed even when the view is completely occluded, wasting CPU and GPU resources.

3. **Compatibility Enhancement**: This fix improves behavioral consistency across different macOS versions. The internal logic of WebContentsOcclusionCheckerMac can already properly handle version differences (via the isManualOcclusionDetectionEnabled method), so performing redundant checks at the WebContentsViewCocoa level is unnecessary and could lead to logic errors.

4. **Direct Impact on WebView2Mac**: WebView2Mac uses WebContentsViewCocoa through the Remote Cocoa architecture to manage the visibility state of web content. This fix ensures that the updateWebContentsVisibility method can properly receive occlusion state change notifications (via the windowChangedOcclusionState: method), which is critical for correctly triggering the OnWindowVisibilityChanged callback.

5. **No Downstream Adaptation Required**: This is a pure upstream fix that doesn't involve interface changes or behavioral semantic changes. WebView2Mac downstream code requires no modifications to benefit from this improvement.

Impacted Classes:

WebContentsViewCocoa WebContentsOcclusionCheckerMac remote_cocoa::WebContentsNSViewBridge