context_menu_controller.cc 991 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/views/context_menu_controller.h"
  5. #include "base/auto_reset.h"
  6. namespace views {
  7. ContextMenuController::ContextMenuController() = default;
  8. ContextMenuController::~ContextMenuController() = default;
  9. void ContextMenuController::ShowContextMenuForView(
  10. View* source,
  11. const gfx::Point& point,
  12. ui::MenuSourceType source_type) {
  13. // Use a boolean flag to early-exit out of re-entrant behavior.
  14. if (is_opening_)
  15. return;
  16. is_opening_ = true;
  17. // We might get deleted while showing the context menu (including as a result
  18. // of showing it). If so, we need to make sure we're not accessing
  19. // |is_opening_|.
  20. auto weak_ptr = weak_factory_.GetWeakPtr();
  21. ShowContextMenuForViewImpl(source, point, source_type);
  22. if (!weak_ptr)
  23. return;
  24. is_opening_ = false;
  25. }
  26. } // namespace views