Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / components / renderer_context_menu / context_menu_delegate.cc
blobe9fbd97e4887b3a7515b3874a5940b8ceb4286ef
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"
9 namespace {
11 const char kMenuDelegateUserDataKey[] = "RendererContextMenuMenuDelegate";
13 class ContextMenuDelegateUserData : public base::SupportsUserData::Data {
14 public:
15 explicit ContextMenuDelegateUserData(ContextMenuDelegate* menu_delegate)
16 : menu_delegate_(menu_delegate) {}
17 ~ContextMenuDelegateUserData() override {}
18 ContextMenuDelegate* menu_delegate() { return menu_delegate_; }
20 private:
21 ContextMenuDelegate* menu_delegate_; // not owned by us.
24 } // namespace
26 ContextMenuDelegate::ContextMenuDelegate(content::WebContents* web_contents) {
27 web_contents->SetUserData(&kMenuDelegateUserDataKey,
28 new ContextMenuDelegateUserData(this));
31 ContextMenuDelegate::~ContextMenuDelegate() {
34 // static
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;