| // Copyright 2023 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_VIEWS_SIDE_PANEL_SEARCH_COMPANION_SEARCH_COMPANION_SIDE_PANEL_COORDINATOR_H_ |
| #define CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SEARCH_COMPANION_SEARCH_COMPANION_SIDE_PANEL_COORDINATOR_H_ |
| |
| #include <memory> |
| |
| #include "base/memory/raw_ptr.h" |
| #include "base/memory/raw_ref.h" |
| #include "base/scoped_observation.h" |
| #include "chrome/browser/ui/browser_user_data.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| #include "chrome/browser/ui/views/frame/browser_view.h" |
| #include "chrome/browser/ui/views/side_panel/side_panel_entry.h" |
| #include "components/search_engines/template_url_service.h" |
| #include "components/search_engines/template_url_service_observer.h" |
| |
| class Browser; |
| class Profile; |
| |
| // SearchCompanionSidePanelCoordinator handles the creation and registration of |
| // the search companion SidePanelEntry. |
| class SearchCompanionSidePanelCoordinator |
| : public BrowserUserData<SearchCompanionSidePanelCoordinator>, |
| public TabStripModelObserver, |
| public TemplateURLServiceObserver { |
| public: |
| explicit SearchCompanionSidePanelCoordinator(Browser* browser); |
| SearchCompanionSidePanelCoordinator( |
| const SearchCompanionSidePanelCoordinator&) = delete; |
| SearchCompanionSidePanelCoordinator& operator=( |
| const SearchCompanionSidePanelCoordinator&) = delete; |
| ~SearchCompanionSidePanelCoordinator() override; |
| |
| static bool IsSupported(Profile* profile, bool include_dsp_check = true); |
| |
| bool Show(); |
| BrowserView* GetBrowserView(); |
| std::u16string GetTooltipForToolbarButton(); |
| |
| std::u16string name() { return name_; } |
| const gfx::VectorIcon& icon() { return *icon_; } |
| |
| // TabStripModelObserver: |
| void OnTabStripModelChanged( |
| TabStripModel* tab_strip_model, |
| const TabStripModelChange& change, |
| const TabStripSelectionChange& selection) override; |
| |
| private: |
| friend class BrowserUserData<SearchCompanionSidePanelCoordinator>; |
| |
| void CreateAndRegisterEntriesForExistingWebContents( |
| TabStripModel* tab_strip_model); |
| void DeregisterEntriesForExistingWebContents(TabStripModel* tab_strip_model); |
| |
| // TemplateURLServiceObserver: |
| void OnTemplateURLServiceChanged() override; |
| void OnTemplateURLServiceShuttingDown() override; |
| |
| raw_ptr<Browser> browser_; |
| std::u16string name_; |
| const raw_ref<const gfx::VectorIcon, ExperimentalAsh> icon_; |
| bool dsp_is_google_ = false; |
| |
| base::ScopedObservation<TemplateURLService, TemplateURLServiceObserver> |
| template_url_service_observation_{this}; |
| |
| BROWSER_USER_DATA_KEY_DECL(); |
| }; |
| |
| #endif // CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SEARCH_COMPANION_SEARCH_COMPANION_SIDE_PANEL_COORDINATOR_H_ |