| // Copyright 2024 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef CHROME_BROWSER_UI_BROWSER_ACTIONS_H_ |
| #define CHROME_BROWSER_UI_BROWSER_ACTIONS_H_ |
| |
| #include <memory> |
| #include <string> |
| |
| #include "base/memory/raw_ptr.h" |
| #include "base/memory/raw_ref.h" |
| #include "ui/base/unowned_user_data/scoped_unowned_user_data.h" |
| |
| class BrowserActionPrefsListener; |
| class BrowserWindowInterface; |
| class Profile; |
| |
| namespace actions { |
| class ActionItem; |
| } // namespace actions |
| |
| // Actions that a user can take that are scoped to a browser window. |
| class BrowserActions { |
| public: |
| DECLARE_USER_DATA(BrowserActions); |
| |
| static BrowserActions* From(BrowserWindowInterface* browser); |
| static const BrowserActions* From(const BrowserWindowInterface* browser); |
| |
| explicit BrowserActions(BrowserWindowInterface* bwi); |
| BrowserActions(const BrowserActions&) = delete; |
| BrowserActions& operator=(const BrowserActions&) = delete; |
| ~BrowserActions(); |
| |
| static std::u16string GetCleanTitleAndTooltipText(std::u16string string); |
| |
| actions::ActionItem* root_action_item() const { return root_action_item_; } |
| |
| // Initialization is separate from construction to allow more precise timing. |
| void InitializeBrowserActions(); |
| |
| // Registers a window-scoped action item. |
| actions::ActionItem* RegisterAction( |
| std::unique_ptr<actions::ActionItem> action_item); |
| |
| void set_root_action_item_for_testing(actions::ActionItem* item) { |
| root_action_item_ = item; |
| } |
| |
| private: |
| // Helper functions to initialize actions grouped roughly by their type. |
| void InitializeSidePanelActions(); |
| void InitializePageActionIconActions(); |
| void InitializeChromeMenuActions(); |
| void InitializeToolbarAndMiscActions(); |
| void InitializeNavigationActions(); |
| void InitializeSubmenuActions(); |
| |
| // Creates all the listeners for the action items that update different states |
| // and property of the action item. |
| void AddListeners(); |
| |
| raw_ptr<actions::ActionItem> root_action_item_ = nullptr; |
| std::unique_ptr<BrowserActionPrefsListener> browser_action_prefs_listener_; |
| const raw_ref<BrowserWindowInterface> bwi_; |
| const raw_ref<Profile> profile_; |
| ui::ScopedUnownedUserData<BrowserActions> scoped_unowned_user_data_; |
| }; |
| |
| #endif // CHROME_BROWSER_UI_BROWSER_ACTIONS_H_ |