chromium/chrome/browser/ui/webui/tab_strip/tab_strip_page_handler.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/tab_strip/tab_strip_page_handler.h"

#include <algorithm>
#include <memory>
#include <optional>

#include "base/containers/fixed_flat_map.h"
#include "base/containers/span.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/trace_event.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_group_theme.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
#include "chrome/browser/ui/tabs/tab_renderer_data.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui_embedder.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui_metrics.h"
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui_util.h"
#include "chrome/browser/ui/webui/theme_source.h"
#include "chrome/browser/ui/webui/util/image_util.h"
#include "chrome/browser/ui/webui/webui_util_desktop.h"
#include "chrome/grit/generated_resources.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/common/drop_data.h"
#include "third_party/blink/public/common/input/web_gesture_event.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/theme_provider.h"
#include "ui/color/color_id.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/gesture_event_details.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/range/range.h"
#include "url/gurl.h"

// This should be after all other #includes.
#if defined(_WINDOWS_)  // Detect whether windows.h was included.
#include "base/win/windows_h_disallowed.h"
#endif  // defined(_WINDOWS_)

namespace {

// Delay in milliseconds of when the dragging UI should be shown for touch drag.
// Note: For better user experience, this is made shorter than
// EventType::kGestureLongPress delay, which is too long for this case, e.g.,
// about 650ms.
constexpr base::TimeDelta kTouchLongpressDelay =;

class WebUIBackgroundMenuModel : public ui::SimpleMenuModel {};

class WebUIBackgroundContextMenu : public ui::SimpleMenuModel::Delegate,
                                   public WebUIBackgroundMenuModel {};

class WebUITabContextMenu : public ui::SimpleMenuModel::Delegate,
                            public TabMenuModel {};

}  // namespace

TabStripPageHandler::~TabStripPageHandler() {}

TabStripPageHandler::TabStripPageHandler(
    mojo::PendingReceiver<tab_strip::mojom::PageHandler> receiver,
    mojo::PendingRemote<tab_strip::mojom::Page> page,
    content::WebUI* web_ui,
    Browser* browser,
    TabStripUIEmbedder* embedder)
    :{}

void TabStripPageHandler::NotifyLayoutChanged() {}

void TabStripPageHandler::NotifyReceivedKeyboardFocus() {}

void TabStripPageHandler::NotifyContextMenuClosed() {}

// TabStripModelObserver:
void TabStripPageHandler::OnTabGroupChanged(const TabGroupChange& change) {}

void TabStripPageHandler::TabGroupedStateChanged(
    std::optional<tab_groups::TabGroupId> group,
    tabs::TabModel* tab,
    int index) {}

void TabStripPageHandler::OnTabStripModelChanged(
    TabStripModel* tab_strip_model,
    const TabStripModelChange& change,
    const TabStripSelectionChange& selection) {}

void TabStripPageHandler::TabChangedAt(content::WebContents* contents,
                                       int index,
                                       TabChangeType change_type) {}

void TabStripPageHandler::TabPinnedStateChanged(TabStripModel* tab_strip_model,
                                                content::WebContents* contents,
                                                int index) {}

void TabStripPageHandler::TabBlockedStateChanged(content::WebContents* contents,
                                                 int index) {}

bool TabStripPageHandler::PreHandleGestureEvent(
    content::WebContents* source,
    const blink::WebGestureEvent& event) {}

bool TabStripPageHandler::CanDragEnter(
    content::WebContents* source,
    const content::DropData& data,
    blink::DragOperationsMask operations_allowed) {}

bool TabStripPageHandler::IsPrivileged() {}

void TabStripPageHandler::OnLongPressTimer() {}

tab_strip::mojom::TabPtr TabStripPageHandler::GetTabData(
    content::WebContents* contents,
    int index) {}

tab_strip::mojom::TabGroupVisualDataPtr TabStripPageHandler::GetTabGroupData(
    TabGroup* group) {}

void TabStripPageHandler::GetTabs(GetTabsCallback callback) {}

void TabStripPageHandler::GetGroupVisualData(
    GetGroupVisualDataCallback callback) {}

void TabStripPageHandler::GroupTab(int32_t tab_id,
                                   const std::string& group_id_string) {}

void TabStripPageHandler::UngroupTab(int32_t tab_id) {}

void TabStripPageHandler::MoveGroup(const std::string& group_id_string,
                                    int32_t to_index) {}

void TabStripPageHandler::MoveTab(int32_t tab_id, int32_t to_index) {}

void TabStripPageHandler::CloseContainer() {}

void TabStripPageHandler::CloseTab(int32_t tab_id, bool tab_was_swiped) {}

void TabStripPageHandler::ShowBackgroundContextMenu(int32_t location_x,
                                                    int32_t location_y) {}

void TabStripPageHandler::ShowEditDialogForGroup(
    const std::string& group_id_string,
    int32_t location_x,
    int32_t location_y,
    int32_t width,
    int32_t height) {}

void TabStripPageHandler::ShowTabContextMenu(int32_t tab_id,
                                             int32_t location_x,
                                             int32_t location_y) {}

void TabStripPageHandler::GetLayout(GetLayoutCallback callback) {}

void TabStripPageHandler::SetThumbnailTracked(int32_t tab_id,
                                              bool thumbnail_tracked) {}

void TabStripPageHandler::ReportTabActivationDuration(uint32_t duration_ms) {}

void TabStripPageHandler::ReportTabDataReceivedDuration(uint32_t tab_count,
                                                        uint32_t duration_ms) {}

void TabStripPageHandler::ReportTabCreationDuration(uint32_t tab_count,
                                                    uint32_t duration_ms) {}

// Callback passed to |thumbnail_tracker_|. Called when a tab's thumbnail
// changes, or when we start watching the tab.
void TabStripPageHandler::HandleThumbnailUpdate(
    content::WebContents* tab,
    ThumbnailTracker::CompressedThumbnailData image) {}

void TabStripPageHandler::OnTabCloseCancelled(content::WebContents* tab) {}

// Reports a histogram using the format
// WebUITabStrip.|histogram_fragment|.[tab count bucket].
void TabStripPageHandler::ReportTabDurationHistogram(
    const char* histogram_fragment,
    int tab_count,
    base::TimeDelta duration) {}

gfx::ImageSkia TabStripPageHandler::ThemeFavicon(const gfx::ImageSkia& source,
                                                 bool active_tab_icon) {}

void TabStripPageHandler::ActivateTab(int32_t tab_id) {}

void TabStripPageHandler::OnThemeChanged() {}

void TabStripPageHandler::OnNativeThemeUpdated(
    ui::NativeTheme* observed_theme) {}