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 "components/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
) {}
17 ~ContextMenuDelegateUserData() override
{}
18 ContextMenuDelegate
* menu_delegate() { return menu_delegate_
; }
21 ContextMenuDelegate
* menu_delegate_
; // not owned by us.
26 ContextMenuDelegate::ContextMenuDelegate(content::WebContents
* web_contents
) {
27 web_contents
->SetUserData(&kMenuDelegateUserDataKey
,
28 new ContextMenuDelegateUserData(this));
31 ContextMenuDelegate::~ContextMenuDelegate() {
35 ContextMenuDelegate
* ContextMenuDelegate::FromWebContents(
36 content::WebContents
* web_contents
) {
37 ContextMenuDelegateUserData
* user_data
=
38 static_cast<ContextMenuDelegateUserData
*>(
39 web_contents
->GetUserData(&kMenuDelegateUserDataKey
));
40 return user_data
? user_data
->menu_delegate() : NULL
;