revert_code_health_clean_up_stale_macwebcontentsocclusion.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: David Sanders <[email protected]>
  3. Date: Wed, 8 Jan 2025 23:53:27 -0800
  4. Subject: Revert "Code Health: Clean up stale MacWebContentsOcclusion"
  5. Chrome has removed this WebContentsOcclusion feature flag upstream,
  6. which is now causing our visibility tests to break. This patch
  7. restores the legacy occlusion behavior to ensure the roll can continue
  8. while we debug the issue.
  9. This patch can be removed when the root cause because the visibility
  10. specs failing on MacOS only is debugged and fixed. It should be removed
  11. before Electron 35's stable date.
  12. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/6078344
  13. This partially (leaves the removal of the feature flag) reverts
  14. ef865130abd5539e7bce12308659b19980368f12.
  15. diff --git a/content/app_shim_remote_cocoa/web_contents_view_cocoa.mm b/content/app_shim_remote_cocoa/web_contents_view_cocoa.mm
  16. index 2991489fae8a4eecad97b1ecb2271f096d9a9229..6c735286bf901fc7ff3872830d83fe119dd3bd33 100644
  17. --- a/content/app_shim_remote_cocoa/web_contents_view_cocoa.mm
  18. +++ b/content/app_shim_remote_cocoa/web_contents_view_cocoa.mm
  19. @@ -126,13 +126,11 @@ @implementation WebContentsViewCocoa {
  20. gfx::Rect _windowControlsOverlayRect;
  21. + BOOL _inFullScreenTransition;
  22. BOOL _willSetWebContentsOccludedAfterDelay;
  23. }
  24. -+ (void)initialize {
  25. - // Create the WebContentsOcclusionCheckerMac shared instance.
  26. - [WebContentsOcclusionCheckerMac sharedInstance];
  27. -}
  28. ++ (void)initialize { }
  29. - (instancetype)initWithViewsHostableView:(ui::ViewsHostableView*)v {
  30. self = [super initWithFrame:NSZeroRect tracking:YES];
  31. @@ -487,6 +485,20 @@ - (void)updateWebContentsVisibility {
  32. [self updateWebContentsVisibility:visibility];
  33. }
  34. +- (void)legacyUpdateWebContentsVisibility {
  35. + using remote_cocoa::mojom::Visibility;
  36. + if (!_host || _inFullScreenTransition)
  37. + return;
  38. + Visibility visibility = Visibility::kVisible;
  39. + if ([self isHiddenOrHasHiddenAncestor] || ![self window])
  40. + visibility = Visibility::kHidden;
  41. + else if ([[self window] occlusionState] & NSWindowOcclusionStateVisible)
  42. + visibility = Visibility::kVisible;
  43. + else
  44. + visibility = Visibility::kOccluded;
  45. + _host->OnWindowVisibilityChanged(visibility);
  46. +}
  47. +
  48. - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize {
  49. // Subviews do not participate in auto layout unless the the size this view
  50. // changes. This allows RenderWidgetHostViewMac::SetBounds(..) to select a
  51. @@ -509,11 +521,20 @@ - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
  52. NSWindow* oldWindow = [self window];
  53. + _inFullScreenTransition = NO;
  54. if (oldWindow) {
  55. - [notificationCenter
  56. - removeObserver:self
  57. - name:NSWindowDidChangeOcclusionStateNotification
  58. - object:oldWindow];
  59. + NSArray* notificationsToRemove = @[
  60. + NSWindowDidChangeOcclusionStateNotification,
  61. + NSWindowWillEnterFullScreenNotification,
  62. + NSWindowDidEnterFullScreenNotification,
  63. + NSWindowWillExitFullScreenNotification,
  64. + NSWindowDidExitFullScreenNotification
  65. + ];
  66. + for (NSString* notificationName in notificationsToRemove) {
  67. + [notificationCenter removeObserver:self
  68. + name:notificationName
  69. + object:oldWindow];
  70. + }
  71. }
  72. if (newWindow) {
  73. @@ -521,27 +542,49 @@ - (void)viewWillMoveToWindow:(NSWindow*)newWindow {
  74. selector:@selector(windowChangedOcclusionState:)
  75. name:NSWindowDidChangeOcclusionStateNotification
  76. object:newWindow];
  77. + // The fullscreen transition causes spurious occlusion notifications.
  78. + // See https://crbug.com/1081229
  79. + [notificationCenter addObserver:self
  80. + selector:@selector(fullscreenTransitionStarted:)
  81. + name:NSWindowWillEnterFullScreenNotification
  82. + object:newWindow];
  83. + [notificationCenter addObserver:self
  84. + selector:@selector(fullscreenTransitionComplete:)
  85. + name:NSWindowDidEnterFullScreenNotification
  86. + object:newWindow];
  87. + [notificationCenter addObserver:self
  88. + selector:@selector(fullscreenTransitionStarted:)
  89. + name:NSWindowWillExitFullScreenNotification
  90. + object:newWindow];
  91. + [notificationCenter addObserver:self
  92. + selector:@selector(fullscreenTransitionComplete:)
  93. + name:NSWindowDidExitFullScreenNotification
  94. + object:newWindow];
  95. }
  96. }
  97. - (void)windowChangedOcclusionState:(NSNotification*)aNotification {
  98. - // Only respond to occlusion notifications sent by the occlusion checker.
  99. - NSDictionary* userInfo = [aNotification userInfo];
  100. - NSString* occlusionCheckerKey = [WebContentsOcclusionCheckerMac className];
  101. - if (userInfo[occlusionCheckerKey] != nil)
  102. - [self updateWebContentsVisibility];
  103. + [self legacyUpdateWebContentsVisibility];
  104. +}
  105. +
  106. +- (void)fullscreenTransitionStarted:(NSNotification*)notification {
  107. + _inFullScreenTransition = YES;
  108. +}
  109. +
  110. +- (void)fullscreenTransitionComplete:(NSNotification*)notification {
  111. + _inFullScreenTransition = NO;
  112. }
  113. - (void)viewDidMoveToWindow {
  114. - [self updateWebContentsVisibility];
  115. + [self legacyUpdateWebContentsVisibility];
  116. }
  117. - (void)viewDidHide {
  118. - [self updateWebContentsVisibility];
  119. + [self legacyUpdateWebContentsVisibility];
  120. }
  121. - (void)viewDidUnhide {
  122. - [self updateWebContentsVisibility];
  123. + [self legacyUpdateWebContentsVisibility];
  124. }
  125. // ViewsHostable protocol implementation.