• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that can
3 // be found in the LICENSE file.
4 
5 #ifndef CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
6 #define CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
7 #pragma once
8 
9 #include "libcef/browser/menu_model_impl.h"
10 
11 #include "libcef/browser/menu_runner.h"
12 
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/context_menu_params.h"
15 #include "content/public/browser/web_contents_observer.h"
16 
17 namespace content {
18 class RenderFrameHost;
19 class WebContents;
20 }  // namespace content
21 
22 class AlloyBrowserHostImpl;
23 class CefRunContextMenuCallback;
24 
25 class CefMenuManager : public CefMenuModelImpl::Delegate,
26                        public content::WebContentsObserver {
27  public:
28   CefMenuManager(AlloyBrowserHostImpl* browser,
29                  std::unique_ptr<CefMenuRunner> runner);
30 
31   CefMenuManager(const CefMenuManager&) = delete;
32   CefMenuManager& operator=(const CefMenuManager&) = delete;
33 
34   ~CefMenuManager() override;
35 
36   // Delete the runner to free any platform constructs.
37   void Destroy();
38 
39   // Returns true if the context menu is currently showing.
40   bool IsShowingContextMenu();
41 
42   // Create the context menu.
43   bool CreateContextMenu(const content::ContextMenuParams& params);
44   void CancelContextMenu();
45 
46  private:
47   // CefMenuModelImpl::Delegate methods.
48   void ExecuteCommand(CefRefPtr<CefMenuModelImpl> source,
49                       int command_id,
50                       cef_event_flags_t event_flags) override;
51   void MenuWillShow(CefRefPtr<CefMenuModelImpl> source) override;
52   void MenuClosed(CefRefPtr<CefMenuModelImpl> source) override;
53   bool FormatLabel(CefRefPtr<CefMenuModelImpl> source,
54                    std::u16string& label) override;
55 
56   void ExecuteCommandCallback(int command_id, cef_event_flags_t event_flags);
57 
58   // Create the default menu model.
59   void CreateDefaultModel();
60   // Execute the default command handling.
61   void ExecuteDefaultCommand(int command_id);
62 
63   // Returns true if the specified id is a custom context menu command.
64   bool IsCustomContextMenuCommand(int command_id);
65 
66   // AlloyBrowserHostImpl pointer is guaranteed to outlive this object.
67   AlloyBrowserHostImpl* browser_;
68 
69   std::unique_ptr<CefMenuRunner> runner_;
70 
71   CefRefPtr<CefMenuModelImpl> model_;
72   content::ContextMenuParams params_;
73 
74   // Not owned by this class.
75   CefRunContextMenuCallback* custom_menu_callback_;
76 
77   // Must be the last member.
78   base::WeakPtrFactory<CefMenuManager> weak_ptr_factory_;
79 };
80 
81 #endif  // CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
82