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 
5 #include "ui/views/context_menu_controller.h"
6 
7 #include "base/auto_reset.h"
8 
9 namespace views {
10 
11 ContextMenuController::ContextMenuController() = default;
12 
13 ContextMenuController::~ContextMenuController() = default;
14 
ShowContextMenuForView(View * source,const gfx::Point & point,ui::MenuSourceType source_type)15 void ContextMenuController::ShowContextMenuForView(
16     View* source,
17     const gfx::Point& point,
18     ui::MenuSourceType source_type) {
19   // Use a boolean flag to early-exit out of re-entrant behavior.
20   if (is_opening_)
21     return;
22   is_opening_ = true;
23 
24   // We might get deleted while showing the context menu (including as a result
25   // of showing it). If so, we need to make sure we're not accessing
26   // |is_opening_|.
27   auto weak_ptr = weak_factory_.GetWeakPtr();
28 
29   ShowContextMenuForViewImpl(source, point, source_type);
30 
31   if (!weak_ptr)
32     return;
33 
34   is_opening_ = false;
35 }
36 
37 }  // namespace views
38