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 ~CefMenuManager() override; 31 32 // Delete the runner to free any platform constructs. 33 void Destroy(); 34 35 // Returns true if the context menu is currently showing. 36 bool IsShowingContextMenu(); 37 38 // Create the context menu. 39 bool CreateContextMenu(const content::ContextMenuParams& params); 40 void CancelContextMenu(); 41 42 private: 43 // CefMenuModelImpl::Delegate methods. 44 void ExecuteCommand(CefRefPtr<CefMenuModelImpl> source, 45 int command_id, 46 cef_event_flags_t event_flags) override; 47 void MenuWillShow(CefRefPtr<CefMenuModelImpl> source) override; 48 void MenuClosed(CefRefPtr<CefMenuModelImpl> source) override; 49 bool FormatLabel(CefRefPtr<CefMenuModelImpl> source, 50 std::u16string& label) override; 51 52 void ExecuteCommandCallback(int command_id, cef_event_flags_t event_flags); 53 54 // Create the default menu model. 55 void CreateDefaultModel(); 56 // Execute the default command handling. 57 void ExecuteDefaultCommand(int command_id); 58 59 // Returns true if the specified id is a custom context menu command. 60 bool IsCustomContextMenuCommand(int command_id); 61 62 // AlloyBrowserHostImpl pointer is guaranteed to outlive this object. 63 AlloyBrowserHostImpl* browser_; 64 65 std::unique_ptr<CefMenuRunner> runner_; 66 67 CefRefPtr<CefMenuModelImpl> model_; 68 content::ContextMenuParams params_; 69 70 // Not owned by this class. 71 CefRunContextMenuCallback* custom_menu_callback_; 72 73 // Must be the last member. 74 base::WeakPtrFactory<CefMenuManager> weak_ptr_factory_; 75 76 DISALLOW_COPY_AND_ASSIGN(CefMenuManager); 77 }; 78 79 #endif // CEF_LIBCEF_BROWSER_MENU_MANAGER_H_ 80