diff --git a/ui/ozone/platform/wayland/host/wayland_bubble.cc b/ui/ozone/platform/wayland/host/wayland_bubble.cc index 5b1a967bc881c..13aec3b5f79a7 100644 --- a/ui/ozone/platform/wayland/host/wayland_bubble.cc +++ b/ui/ozone/platform/wayland/host/wayland_bubble.cc @@ -34,8 +34,18 @@ void WaylandBubble::Show(bool inactive) { return; } + // delegate()->OnStateUpdate (reached via UpdateWindowScale / + // AddToParentAsSubsurface) may synchronously destroy `this`. See the + // weak-guard at WaylandWindow::MaybeApplyLatestStateRequest. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); UpdateWindowScale(false); + if (!weak_this) { + return; + } AddToParentAsSubsurface(); + if (!weak_this) { + return; + } WaylandWindow::Show(inactive); } @@ -61,7 +71,13 @@ void WaylandBubble::SetBoundsInDIP(const gfx::Rect& bounds_dip) { // There is currently no guarantee that the 2 compositor frames arrive // together atomically. auto old_bounds_dip = GetBoundsInDIP(); + // delegate()->OnStateUpdate (reached via SetBoundsInDIP -> + // MaybeApplyLatestStateRequest) may synchronously destroy `this`. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); WaylandWindow::SetBoundsInDIP(bounds_dip); + if (!weak_this) { + return; + } // TODO(crbug.com/329145822): Don't apply position immediately here, wait for // ackconfigure, otherwise it might jitter if offset changes. @@ -92,7 +108,13 @@ void WaylandBubble::Deactivate() { } void WaylandBubble::UpdateWindowScale(bool update_bounds) { + // delegate()->OnStateUpdate (reached via SetWindowScale -> + // MaybeApplyLatestStateRequest) may synchronously destroy `this`. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); WaylandWindow::UpdateWindowScale(update_bounds); + if (!weak_this) { + return; + } if (subsurface_) { SetSubsurfacePosition(); } @@ -127,7 +149,13 @@ void WaylandBubble::AddToParentAsSubsurface() { CHECK(parent_window()); // We need to make sure that window scale matches the parent window. + // delegate()->OnStateUpdate (reached via UpdateWindowScale) may synchronously + // destroy `this`. + auto weak_this = weak_ptr_factory_.GetWeakPtr(); UpdateWindowScale(true); + if (!weak_this) { + return; + } subsurface_ = root_surface()->CreateSubsurface(parent_window()->root_surface());