OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 void ContextMenuNotificationObserver::Observe( | 28 void ContextMenuNotificationObserver::Observe( |
29 int type, | 29 int type, |
30 const content::NotificationSource& source, | 30 const content::NotificationSource& source, |
31 const content::NotificationDetails& details) { | 31 const content::NotificationDetails& details) { |
32 DCHECK_EQ(chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, type); | 32 DCHECK_EQ(chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, type); |
33 | 33 |
34 RenderViewContextMenu* context_menu = | 34 RenderViewContextMenu* context_menu = |
35 content::Source<RenderViewContextMenu>(source).ptr(); | 35 content::Source<RenderViewContextMenu>(source).ptr(); |
36 base::ThreadTaskRunnerHandle::Get()->PostTask( | 36 base::ThreadTaskRunnerHandle::Get()->PostTask( |
37 FROM_HERE, base::Bind(&ContextMenuNotificationObserver::ExecuteCommand, | 37 FROM_HERE, |
38 base::Unretained(this), context_menu)); | 38 base::BindOnce(&ContextMenuNotificationObserver::ExecuteCommand, |
| 39 base::Unretained(this), context_menu)); |
39 } | 40 } |
40 | 41 |
41 void ContextMenuNotificationObserver::ExecuteCommand( | 42 void ContextMenuNotificationObserver::ExecuteCommand( |
42 RenderViewContextMenu* context_menu) { | 43 RenderViewContextMenu* context_menu) { |
43 context_menu->ExecuteCommand(command_to_execute_, 0); | 44 context_menu->ExecuteCommand(command_to_execute_, 0); |
44 context_menu->Cancel(); | 45 context_menu->Cancel(); |
45 } | 46 } |
46 | 47 |
47 ContextMenuWaiter::ContextMenuWaiter(const content::NotificationSource& source) | 48 ContextMenuWaiter::ContextMenuWaiter(const content::NotificationSource& source) |
48 : menu_visible_(false) { | 49 : menu_visible_(false) { |
49 registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, | 50 registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, |
50 content::NotificationService::AllSources()); | 51 content::NotificationService::AllSources()); |
51 } | 52 } |
52 | 53 |
53 ContextMenuWaiter::~ContextMenuWaiter() { | 54 ContextMenuWaiter::~ContextMenuWaiter() { |
54 } | 55 } |
55 | 56 |
56 void ContextMenuWaiter::Observe(int type, | 57 void ContextMenuWaiter::Observe(int type, |
57 const content::NotificationSource& source, | 58 const content::NotificationSource& source, |
58 const content::NotificationDetails& details) { | 59 const content::NotificationDetails& details) { |
59 switch (type) { | 60 switch (type) { |
60 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { | 61 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { |
61 menu_visible_ = true; | 62 menu_visible_ = true; |
62 RenderViewContextMenu* context_menu = | 63 RenderViewContextMenu* context_menu = |
63 content::Source<RenderViewContextMenu>(source).ptr(); | 64 content::Source<RenderViewContextMenu>(source).ptr(); |
64 base::ThreadTaskRunnerHandle::Get()->PostTask( | 65 base::ThreadTaskRunnerHandle::Get()->PostTask( |
65 FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel, | 66 FROM_HERE, base::BindOnce(&ContextMenuWaiter::Cancel, |
66 base::Unretained(this), context_menu)); | 67 base::Unretained(this), context_menu)); |
67 break; | 68 break; |
68 } | 69 } |
69 | 70 |
70 default: | 71 default: |
71 NOTREACHED(); | 72 NOTREACHED(); |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 void ContextMenuWaiter::WaitForMenuOpenAndClose() { | 76 void ContextMenuWaiter::WaitForMenuOpenAndClose() { |
76 content::WindowedNotificationObserver menu_observer( | 77 content::WindowedNotificationObserver menu_observer( |
77 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, | 78 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, |
78 content::NotificationService::AllSources()); | 79 content::NotificationService::AllSources()); |
79 if (!menu_visible_) | 80 if (!menu_visible_) |
80 menu_observer.Wait(); | 81 menu_observer.Wait(); |
81 | 82 |
82 content::RunAllPendingInMessageLoop(); | 83 content::RunAllPendingInMessageLoop(); |
83 menu_visible_ = false; | 84 menu_visible_ = false; |
84 } | 85 } |
85 | 86 |
86 content::ContextMenuParams& ContextMenuWaiter::params() { | 87 content::ContextMenuParams& ContextMenuWaiter::params() { |
87 return params_; | 88 return params_; |
88 } | 89 } |
89 | 90 |
90 void ContextMenuWaiter::Cancel(RenderViewContextMenu* context_menu) { | 91 void ContextMenuWaiter::Cancel(RenderViewContextMenu* context_menu) { |
91 params_ = context_menu->params(); | 92 params_ = context_menu->params(); |
92 context_menu->Cancel(); | 93 context_menu->Cancel(); |
93 } | 94 } |
OLD | NEW |