#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include <limits>
#include <memory>
#include <utility>
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tab_ui_helper.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_keyed_service.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_service_factory.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_utils.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_deletion_dialog_controller.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_network_state.h"
#include "chrome/browser/ui/tabs/tab_renderer_data.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_user_gesture_details.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/tabs/tab.h"
#include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/tabs/tab_strip_types.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/web_app_tabbed_utils.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/feature_engagement/public/event_constants.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/saved_tab_groups/features.h"
#include "components/tab_groups/tab_group_color.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/peak_gpu_memory_tracker_factory.h"
#include "content/public/browser/web_contents.h"
#include "ipc/ipc_message.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/models/menu_model.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/range/range.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/widget/widget.h"
#include "url/origin.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/system_web_apps/types/system_web_app_delegate.h"
#endif
UserMetricsAction;
WebContents;
namespace {
BrowserView* GetSourceBrowserViewInTabDragging() { … }
}
class BrowserTabStripController::TabContextMenuContents
: public ui::SimpleMenuModel::Delegate { … };
BrowserTabStripController::BrowserTabStripController(
TabStripModel* model,
BrowserView* browser_view,
std::unique_ptr<TabMenuModelFactory> menu_model_factory_override)
: … { … }
BrowserTabStripController::~BrowserTabStripController() { … }
void BrowserTabStripController::InitFromModel(TabStrip* tabstrip) { … }
bool BrowserTabStripController::IsCommandEnabledForTab(
TabStripModel::ContextMenuCommand command_id,
const Tab* tab) const { … }
void BrowserTabStripController::ExecuteCommandForTab(
TabStripModel::ContextMenuCommand command_id,
const Tab* tab) { … }
bool BrowserTabStripController::IsTabPinned(const Tab* tab) const { … }
const ui::ListSelectionModel&
BrowserTabStripController::GetSelectionModel() const { … }
int BrowserTabStripController::GetCount() const { … }
bool BrowserTabStripController::IsValidIndex(int index) const { … }
bool BrowserTabStripController::IsActiveTab(int model_index) const { … }
std::optional<int> BrowserTabStripController::GetActiveIndex() const { … }
bool BrowserTabStripController::IsTabSelected(int model_index) const { … }
bool BrowserTabStripController::IsTabPinned(int model_index) const { … }
void BrowserTabStripController::SelectTab(int model_index,
const ui::Event& event) { … }
void BrowserTabStripController::ExtendSelectionTo(int model_index) { … }
void BrowserTabStripController::ToggleSelected(int model_index) { … }
void BrowserTabStripController::AddSelectionFromAnchorTo(int model_index) { … }
void BrowserTabStripController::OnCloseTab(
int model_index,
CloseTabSource source,
base::OnceCallback<void()> callback) { … }
void BrowserTabStripController::CloseTab(int model_index) { … }
void BrowserTabStripController::ToggleTabAudioMute(int model_index) { … }
void BrowserTabStripController::AddTabToGroup(
int model_index,
const tab_groups::TabGroupId& group) { … }
void BrowserTabStripController::RemoveTabFromGroup(int model_index) { … }
void BrowserTabStripController::MoveTab(int start_index, int final_index) { … }
void BrowserTabStripController::MoveGroup(const tab_groups::TabGroupId& group,
int final_index) { … }
void BrowserTabStripController::ToggleTabGroupCollapsedState(
const tab_groups::TabGroupId group,
ToggleTabGroupCollapsedStateOrigin origin) { … }
void BrowserTabStripController::ShowContextMenuForTab(
Tab* tab,
const gfx::Point& p,
ui::MenuSourceType source_type) { … }
void BrowserTabStripController::CloseContextMenuForTesting() { … }
int BrowserTabStripController::HasAvailableDragActions() const { … }
void BrowserTabStripController::OnDropIndexUpdate(
const std::optional<int> index,
const bool drop_before) { … }
void BrowserTabStripController::CreateNewTab() { … }
void BrowserTabStripController::CreateNewTabWithLocation(
const std::u16string& location) { … }
void BrowserTabStripController::OnStartedDragging(bool dragging_window) { … }
void BrowserTabStripController::OnStoppedDragging() { … }
void BrowserTabStripController::OnKeyboardFocusedTabChanged(
std::optional<int> index) { … }
std::u16string BrowserTabStripController::GetGroupTitle(
const tab_groups::TabGroupId& group) const { … }
std::u16string BrowserTabStripController::GetGroupContentString(
const tab_groups::TabGroupId& group) const { … }
tab_groups::TabGroupColorId BrowserTabStripController::GetGroupColorId(
const tab_groups::TabGroupId& group) const { … }
bool BrowserTabStripController::IsGroupCollapsed(
const tab_groups::TabGroupId& group) const { … }
void BrowserTabStripController::SetVisualDataForGroup(
const tab_groups::TabGroupId& group,
const tab_groups::TabGroupVisualData& visual_data) { … }
std::optional<int> BrowserTabStripController::GetFirstTabInGroup(
const tab_groups::TabGroupId& group) const { … }
gfx::Range BrowserTabStripController::ListTabsInGroup(
const tab_groups::TabGroupId& group) const { … }
bool BrowserTabStripController::IsFrameCondensed() const { … }
bool BrowserTabStripController::HasVisibleBackgroundTabShapes() const { … }
bool BrowserTabStripController::EverHasVisibleBackgroundTabShapes() const { … }
bool BrowserTabStripController::CanDrawStrokes() const { … }
SkColor BrowserTabStripController::GetFrameColor(
BrowserFrameActiveState active_state) const { … }
std::optional<int> BrowserTabStripController::GetCustomBackgroundId(
BrowserFrameActiveState active_state) const { … }
std::u16string BrowserTabStripController::GetAccessibleTabName(
const Tab* tab) const { … }
Profile* BrowserTabStripController::GetProfile() const { … }
const Browser* BrowserTabStripController::GetBrowser() const { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
bool BrowserTabStripController::IsLockedForOnTask() {
return browser_view_->browser()->IsLockedForOnTask();
}
#endif
void BrowserTabStripController::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) { … }
void BrowserTabStripController::OnTabWillBeAdded() { … }
void BrowserTabStripController::OnTabWillBeRemoved(
content::WebContents* contents,
int index) { … }
void BrowserTabStripController::OnTabGroupChanged(
const TabGroupChange& change) { … }
void BrowserTabStripController::TabChangedAt(WebContents* contents,
int model_index,
TabChangeType change_type) { … }
void BrowserTabStripController::TabPinnedStateChanged(
TabStripModel* tab_strip_model,
WebContents* contents,
int model_index) { … }
void BrowserTabStripController::TabBlockedStateChanged(WebContents* contents,
int model_index) { … }
void BrowserTabStripController::TabGroupedStateChanged(
std::optional<tab_groups::TabGroupId> group,
tabs::TabModel* tab,
int index) { … }
void BrowserTabStripController::SetTabNeedsAttentionAt(int index,
bool attention) { … }
bool BrowserTabStripController::IsFrameButtonsRightAligned() const { … }
BrowserNonClientFrameView* BrowserTabStripController::GetFrameView() { … }
const BrowserNonClientFrameView* BrowserTabStripController::GetFrameView()
const { … }
void BrowserTabStripController::SetTabDataAt(content::WebContents* web_contents,
int model_index) { … }
void BrowserTabStripController::AddTab(WebContents* contents, int index) { … }
void BrowserTabStripController::OnDiscardRingTreatmentEnabledChanged() { … }