diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc index ee67004697199..b99ab5d9254c1 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc @@ -447,14 +447,21 @@ void DesktopWindowTreeHostPlatform::Show(ui::mojom::WindowShowState show_state, platform_window()->Show(DetermineInactivity(show_state)); switch (show_state) { - case ui::mojom::WindowShowState::kMaximized: + case ui::mojom::WindowShowState::kMaximized: { + // platform_window()->Maximize() may synchronously dispatch + // OnBoundsChanged, which may delete |this|. + auto weak_ptr = GetWeakPtr(); platform_window()->Maximize(); + if (!weak_ptr) { + return; + } if (!restore_bounds.IsEmpty()) { // Enforce |restored_bounds_in_pixels_| since calling Maximize() could // have reset it. platform_window()->SetRestoredBoundsInDIP(restore_bounds); } break; + } case ui::mojom::WindowShowState::kMinimized: platform_window()->Minimize(); break; @@ -644,7 +651,13 @@ bool DesktopWindowTreeHostPlatform::IsActive() const { } void DesktopWindowTreeHostPlatform::Maximize() { + // platform_window()->Maximize() may synchronously dispatch OnBoundsChanged + // (e.g. on X11 when the window is fullscreen), which may delete |this|. + auto weak_ptr = GetWeakPtr(); platform_window()->Maximize(); + if (!weak_ptr) { + return; + } if (IsMinimized()) { Show(ui::mojom::WindowShowState::kNormal, gfx::Rect()); }