Upload upstream chromium 114.0.5735.31
[platform/framework/web/chromium-efl.git] / components / renderer_context_menu / context_menu_delegate.cc
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/renderer_context_menu/context_menu_delegate.h"
6
7 #include <memory>
8
9 #include "base/memory/raw_ptr.h"
10 #include "content/public/browser/web_contents.h"
11
12 namespace {
13
14 const char kMenuDelegateUserDataKey[] = "RendererContextMenuMenuDelegate";
15
16 class ContextMenuDelegateUserData : public base::SupportsUserData::Data {
17  public:
18   explicit ContextMenuDelegateUserData(ContextMenuDelegate* menu_delegate)
19       : menu_delegate_(menu_delegate) {}
20   ~ContextMenuDelegateUserData() override {}
21   ContextMenuDelegate* menu_delegate() { return menu_delegate_; }
22
23  private:
24   raw_ptr<ContextMenuDelegate, DanglingUntriaged>
25       menu_delegate_;  // not owned by us.
26 };
27
28 }  // namespace
29
30 ContextMenuDelegate::ContextMenuDelegate(content::WebContents* web_contents) {
31   web_contents->SetUserData(
32       &kMenuDelegateUserDataKey,
33       std::make_unique<ContextMenuDelegateUserData>(this));
34 }
35
36 ContextMenuDelegate::~ContextMenuDelegate() {
37 }
38
39 // static
40 ContextMenuDelegate* ContextMenuDelegate::FromWebContents(
41     content::WebContents* web_contents) {
42   ContextMenuDelegateUserData* user_data =
43       static_cast<ContextMenuDelegateUserData*>(
44           web_contents->GetUserData(&kMenuDelegateUserDataKey));
45   return user_data ? user_data->menu_delegate() : nullptr;
46 }