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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.h"
7 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h"
8 #include "chrome/browser/ui/cocoa/tab_contents/render_view_context_menu_mac.h"
9 #include "chrome/browser/ui/cocoa/tab_contents/web_drag_bookmark_handler_mac.h"
10 #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h"
15 ChromeWebContentsViewDelegateMac::ChromeWebContentsViewDelegateMac(
16 content::WebContents* web_contents)
17 : bookmark_handler_(new WebDragBookmarkHandlerMac),
18 web_contents_(web_contents) {
21 ChromeWebContentsViewDelegateMac::~ChromeWebContentsViewDelegateMac() {
24 NSObject<RenderWidgetHostViewMacDelegate>*
25 ChromeWebContentsViewDelegateMac::CreateRenderWidgetHostViewDelegate(
26 content::RenderWidgetHost* render_widget_host) {
27 return [[ChromeRenderWidgetHostViewMacDelegate alloc]
28 initWithRenderWidgetHost:render_widget_host];
31 content::WebDragDestDelegate*
32 ChromeWebContentsViewDelegateMac::GetDragDestDelegate() {
33 return bookmark_handler_.get();
36 void ChromeWebContentsViewDelegateMac::ShowContextMenu(
37 const content::ContextMenuParams& params) {
38 // The renderer may send the "show context menu" message multiple times, one
39 // for each right click mouse event it receives. Normally, this doesn't happen
40 // because mouse events are not forwarded once the context menu is showing.
41 // However, there's a race - the context menu may not yet be showing when
42 // the second mouse event arrives. In this case, |ShowContextMenu()| will
43 // get called multiple times - if so, don't create another context menu.
44 // TODO(asvitkine): Fix the renderer so that it doesn't do this.
45 content::RenderWidgetHostView* widget_view =
46 web_contents_->GetRenderWidgetHostView();
47 if (widget_view && widget_view->IsShowingContextMenu())
50 context_menu_.reset(new RenderViewContextMenuMac(
53 web_contents_->GetView()->GetContentNativeView()));
54 context_menu_->Init();
59 content::WebContentsViewDelegate* CreateWebContentsViewDelegate(
60 content::WebContents* web_contents) {
61 return new ChromeWebContentsViewDelegateMac(web_contents);