| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/popup_menu_helper_mac.h" | 7 #include "content/browser/tab_contents/popup_menu_helper_mac.h" |
| 8 | 8 |
| 9 #import "base/mac/scoped_sending_event.h" |
| 9 #include "base/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 13 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 13 #import "content/common/mac/scoped_sending_event.h" | |
| 14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
| 16 #import "ui/base/cocoa/base_view.h" | 16 #import "ui/base/cocoa/base_view.h" |
| 17 #include "webkit/glue/webmenurunner_mac.h" | 17 #include "webkit/glue/webmenurunner_mac.h" |
| 18 | 18 |
| 19 PopupMenuHelper::PopupMenuHelper(RenderViewHost* render_view_host) | 19 PopupMenuHelper::PopupMenuHelper(RenderViewHost* render_view_host) |
| 20 : render_view_host_(render_view_host) { | 20 : render_view_host_(render_view_host) { |
| 21 notification_registrar_.Add( | 21 notification_registrar_.Add( |
| 22 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 22 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 23 content::Source<RenderWidgetHost>(render_view_host)); | 23 content::Source<RenderWidgetHost>(render_view_host)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 | 47 |
| 48 { | 48 { |
| 49 // Make sure events can be pumped while the menu is up. | 49 // Make sure events can be pumped while the menu is up. |
| 50 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 50 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 51 | 51 |
| 52 // One of the events that could be pumped is |window.close()|. | 52 // One of the events that could be pumped is |window.close()|. |
| 53 // User-initiated event-tracking loops protect against this by | 53 // User-initiated event-tracking loops protect against this by |
| 54 // setting flags in -[CrApplication sendEvent:], but since | 54 // setting flags in -[CrApplication sendEvent:], but since |
| 55 // web-content menus are initiated by IPC message the setup has to | 55 // web-content menus are initiated by IPC message the setup has to |
| 56 // be done manually. | 56 // be done manually. |
| 57 content::mac::ScopedSendingEvent sending_event_scoper; | 57 base::mac::ScopedSendingEvent sending_event_scoper; |
| 58 | 58 |
| 59 // Now run a SYNCHRONOUS NESTED EVENT LOOP until the pop-up is finished. | 59 // Now run a SYNCHRONOUS NESTED EVENT LOOP until the pop-up is finished. |
| 60 [menu_runner runMenuInView:cocoa_view | 60 [menu_runner runMenuInView:cocoa_view |
| 61 withBounds:[cocoa_view flipRectToNSRect:bounds] | 61 withBounds:[cocoa_view flipRectToNSRect:bounds] |
| 62 initialIndex:selected_item]; | 62 initialIndex:selected_item]; |
| 63 } | 63 } |
| 64 | 64 |
| 65 if (!render_view_host_) { | 65 if (!render_view_host_) { |
| 66 // Bad news, the RenderViewHost got deleted while we were off running the | 66 // Bad news, the RenderViewHost got deleted while we were off running the |
| 67 // menu. Nothing to do. | 67 // menu. Nothing to do. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 | 78 |
| 79 void PopupMenuHelper::Observe( | 79 void PopupMenuHelper::Observe( |
| 80 int type, | 80 int type, |
| 81 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
| 82 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
| 83 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); | 83 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); |
| 84 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == render_view_host_); | 84 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == render_view_host_); |
| 85 render_view_host_ = NULL; | 85 render_view_host_ = NULL; |
| 86 } | 86 } |
| 87 | 87 |
| OLD | NEW |