Skip to content

Commit

Permalink
Use absl::Cleanup rather than base::AutoReset in DisplayPopupMenu
Browse files Browse the repository at this point in the history
Since RenderWidgetHostNSViewBridge might get deleted while displaying a
popup menu, it is not safe to use base::AutoReset to reset the
showing_popup_menu_ member. So use absl::Cleanup with a weak pointer
instead.

(cherry picked from commit 5c897e0)

Bug: 338162110
Change-Id: Ic907b2e6541d095eebee2c13a778b2d46afa54ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5564186
Reviewed-by: Leonard Grey <[email protected]>
Commit-Queue: Marijn Kruisselbrink <[email protected]>
Cr-Original-Commit-Position: refs/heads/main@{#1305164}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5571680
Commit-Queue: Rubber Stamper <[email protected]>
Bot-Commit: Rubber Stamper <[email protected]>
Auto-Submit: Marijn Kruisselbrink <[email protected]>
Cr-Commit-Position: refs/branch-heads/6478@{#598}
Cr-Branched-From: e6143ac-refs/heads/main@{#1300313}
  • Loading branch information
mkruisselbrink authored and Chromium LUCI CQ committed May 25, 2024
1 parent 3cc7b54 commit fdf61f6
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "base/apple/bridging.h"
#include "base/apple/foundation_util.h"
#include "base/apple/scoped_cftyperef.h"
#include "base/auto_reset.h"
#include "base/functional/bind.h"
#import "base/mac/scoped_sending_event.h"
#import "base/message_loop/message_pump_apple.h"
Expand All @@ -21,6 +20,7 @@
#import "content/app_shim_remote_cocoa/web_menu_runner_mac.h"
#include "content/common/mac/attributed_string_type_converters.h"
#import "skia/ext/skia_utils_mac.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/blink/public/common/input/web_gesture_event.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#import "ui/base/cocoa/animation_utils.h"
Expand Down Expand Up @@ -427,7 +427,14 @@ void Hide() override {
rightAligned:menu->right_aligned];

{
base::AutoReset<bool> running(&showing_popup_menu_, true);
// We can't use base::AutoReset to set and reset `showing_popup_menu_` as
// `this` might be destroyed by the time showing the menu finishes.
showing_popup_menu_ = true;
absl::Cleanup running([weak_self]() {
if (weak_self) {
weak_self->showing_popup_menu_ = false;
}
});

PopupMenuRunner mojo_host(std::move(menu->receiver), runner);

Expand Down

0 comments on commit fdf61f6

Please sign in to comment.