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
3 // found in the LICENSE file.
5 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h"
7 #include "content/public/browser/web_contents.h"
11 const char kMenuDelegateUserDataKey
[] = "RendererContextMenuMenuDelegate";
13 class ContextMenuDelegateUserData
: public base::SupportsUserData::Data
{
15 explicit ContextMenuDelegateUserData(ContextMenuDelegate
* menu_delegate
)
16 : menu_delegate_(menu_delegate
) {
18 virtual ~ContextMenuDelegateUserData() {}
19 ContextMenuDelegate
* menu_delegate() { return menu_delegate_
; }
22 ContextMenuDelegate
* menu_delegate_
; // not owned by us.
27 ContextMenuDelegate::ContextMenuDelegate(content::WebContents
* web_contents
) {
28 web_contents
->SetUserData(&kMenuDelegateUserDataKey
,
29 new ContextMenuDelegateUserData(this));
32 ContextMenuDelegate::~ContextMenuDelegate() {
36 ContextMenuDelegate
* ContextMenuDelegate::FromWebContents(
37 content::WebContents
* web_contents
) {
38 ContextMenuDelegateUserData
* user_data
=
39 static_cast<ContextMenuDelegateUserData
*>(
40 web_contents
->GetUserData(&kMenuDelegateUserDataKey
));
41 return user_data
? user_data
->menu_delegate() : NULL
;