OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
6 | 6 |
7 #include "content/browser/renderer_host/popup_menu_helper_mac.h" | 7 #include "content/browser/renderer_host/popup_menu_helper_mac.h" |
8 | 8 |
| 9 #include "base/mac/scoped_nsobject.h" |
9 #import "base/mac/scoped_sending_event.h" | 10 #import "base/mac/scoped_sending_event.h" |
10 #include "base/memory/scoped_nsobject.h" | |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 13 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
14 #include "content/browser/renderer_host/webmenurunner_mac.h" | 14 #include "content/browser/renderer_host/webmenurunner_mac.h" |
15 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #import "ui/base/cocoa/base_view.h" | 17 #import "ui/base/cocoa/base_view.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
(...skipping 21 matching lines...) Expand all Loading... |
42 // Only single selection list boxes show a popup on Mac. | 42 // Only single selection list boxes show a popup on Mac. |
43 DCHECK(!allow_multiple_selection); | 43 DCHECK(!allow_multiple_selection); |
44 | 44 |
45 if (!g_allow_showing_popup_menus) | 45 if (!g_allow_showing_popup_menus) |
46 return; | 46 return; |
47 | 47 |
48 // Retain the Cocoa view for the duration of the pop-up so that it can't be | 48 // Retain the Cocoa view for the duration of the pop-up so that it can't be |
49 // dealloced if my Destroy() method is called while the pop-up's up (which | 49 // dealloced if my Destroy() method is called while the pop-up's up (which |
50 // would in turn delete me, causing a crash once the -runMenuInView | 50 // would in turn delete me, causing a crash once the -runMenuInView |
51 // call returns. That's what was happening in <http://crbug.com/33250>). | 51 // call returns. That's what was happening in <http://crbug.com/33250>). |
52 RenderWidgetHostViewMac* rwhvm = | 52 RenderWidgetHostViewMac* rwhvm = |
53 static_cast<RenderWidgetHostViewMac*>(GetRenderWidgetHostView()); | 53 static_cast<RenderWidgetHostViewMac*>(GetRenderWidgetHostView()); |
54 scoped_nsobject<RenderWidgetHostViewCocoa> cocoa_view | 54 base::scoped_nsobject<RenderWidgetHostViewCocoa> cocoa_view( |
55 ([rwhvm->cocoa_view() retain]); | 55 [rwhvm->cocoa_view() retain]); |
56 | 56 |
57 // Display the menu. | 57 // Display the menu. |
58 scoped_nsobject<WebMenuRunner> menu_runner; | 58 base::scoped_nsobject<WebMenuRunner> menu_runner; |
59 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items | 59 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items |
60 fontSize:item_font_size | 60 fontSize:item_font_size |
61 rightAligned:right_aligned]); | 61 rightAligned:right_aligned]); |
62 | 62 |
63 { | 63 { |
64 // Make sure events can be pumped while the menu is up. | 64 // Make sure events can be pumped while the menu is up. |
65 base::MessageLoop::ScopedNestableTaskAllower allow( | 65 base::MessageLoop::ScopedNestableTaskAllower allow( |
66 base::MessageLoop::current()); | 66 base::MessageLoop::current()); |
67 | 67 |
68 // One of the events that could be pumped is |window.close()|. | 68 // One of the events that could be pumped is |window.close()|. |
69 // User-initiated event-tracking loops protect against this by | 69 // User-initiated event-tracking loops protect against this by |
70 // setting flags in -[CrApplication sendEvent:], but since | 70 // setting flags in -[CrApplication sendEvent:], but since |
71 // web-content menus are initiated by IPC message the setup has to | 71 // web-content menus are initiated by IPC message the setup has to |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 void PopupMenuHelper::Observe(int type, | 104 void PopupMenuHelper::Observe(int type, |
105 const NotificationSource& source, | 105 const NotificationSource& source, |
106 const NotificationDetails& details) { | 106 const NotificationDetails& details) { |
107 DCHECK(type == NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); | 107 DCHECK(type == NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); |
108 DCHECK(Source<RenderWidgetHost>(source).ptr() == render_view_host_); | 108 DCHECK(Source<RenderWidgetHost>(source).ptr() == render_view_host_); |
109 render_view_host_ = NULL; | 109 render_view_host_ = NULL; |
110 } | 110 } |
111 | 111 |
112 } // namespace content | 112 } // namespace content |
OLD | NEW |