Browse Source

fix: detach native view when its removed from parent on macOS (#43922)

Right now DelayedNativeViewHost attaches its underlying native view
when it's being attached to a widget but it doesn't detach it when
it's being detached. It may lead to use-after-free and crash.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Cezary Kulakowski <[email protected]>
trop[bot] 6 months ago
parent
commit
134176a1d1
1 changed files with 2 additions and 0 deletions
  1. 2 0
      shell/browser/ui/cocoa/delayed_native_view_host.mm

+ 2 - 0
shell/browser/ui/cocoa/delayed_native_view_host.mm

@@ -15,6 +15,8 @@ DelayedNativeViewHost::~DelayedNativeViewHost() = default;
 
 void DelayedNativeViewHost::ViewHierarchyChanged(
     const views::ViewHierarchyChangedDetails& details) {
+  if (!details.is_add && native_view())
+    Detach();
   NativeViewHost::ViewHierarchyChanged(details);
   if (details.is_add && GetWidget() && !native_view())
     Attach(native_view_);