chromium/chrome/browser/ui/views/tab_sharing/tab_sharing_ui_views.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/ui/views/tab_sharing/tab_sharing_ui_views.h"

#include <string>
#include <utility>

#include "base/feature_list.h"
#include "base/memory/ptr_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/media/webrtc/capture_policy_utils.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/webrtc/same_origin_observer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/sad_tab_helper.h"
#include "chrome/browser/ui/views/tab_sharing/tab_capture_contents_border_helper.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "extensions/common/constants.h"
#include "net/base/url_util.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/views/border.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_content_manager.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager.h"
#include "chrome/browser/chromeos/policy/dlp/dlp_rules_manager_factory.h"
#endif

#if BUILDFLAG(IS_WIN)
#include "ui/views/widget/native_widget_aura.h"
#endif

namespace {

TabRole;
GlobalRenderFrameHostId;
RenderFrameHost;
WebContents;

// Replace InfoBars when updating their content to avoid an animation instead of
// removing the old InfoBar and then adding the new one, which causes an
// animation flickering.
BASE_FEATURE();

#if BUILDFLAG(IS_CHROMEOS)
bool g_apply_dlp_for_all_users_for_testing_ = false;
#endif

std::u16string GetTabName(WebContents* tab) {}

GlobalRenderFrameHostId GetGlobalId(WebContents* web_contents) {}

uint32_t GetHash(const ui::ImageModel& image) {}

WebContents* WebContentsFromId(GlobalRenderFrameHostId rfh_id) {}

url::Origin GetOriginFromId(GlobalRenderFrameHostId rfh_id) {}

bool CapturerRestrictedToSameOrigin(GlobalRenderFrameHostId capturer_id) {}

TabRole GetTabRole(bool is_capturing_tab, bool is_captured_tab) {}

}  // namespace

uint32_t TabSharingUIViews::next_capture_session_id_ =;

// static
std::unique_ptr<TabSharingUI> TabSharingUI::Create(
    GlobalRenderFrameHostId capturer,
    const content::DesktopMediaID& media_id,
    const std::u16string& capturer_name,
    bool favicons_used_for_switch_to_tab_button,
    bool app_preferred_current_tab,
    TabSharingInfoBarDelegate::TabShareType capture_type,
    bool captured_surface_control_active) {}

TabSharingUIViews::TabSharingUIViews(
    GlobalRenderFrameHostId capturer,
    const content::DesktopMediaID& media_id,
    const std::u16string& capturer_name,
    bool favicons_used_for_switch_to_tab_button,
    bool app_preferred_current_tab,
    TabSharingInfoBarDelegate::TabShareType capture_type,
    bool captured_surface_control_active)
    :{}

TabSharingUIViews::~TabSharingUIViews() {}

gfx::NativeViewId TabSharingUIViews::OnStarted(
    base::OnceClosure stop_callback,
    content::MediaStreamUI::SourceCallback source_callback,
    const std::vector<content::DesktopMediaID>& media_ids) {}

void TabSharingUIViews::OnRegionCaptureRectChanged(
    const std::optional<gfx::Rect>& region_capture_rect) {}

void TabSharingUIViews::StartSharing(infobars::InfoBar* infobar) {}

void TabSharingUIViews::StopSharing() {}

void TabSharingUIViews::OnBrowserAdded(Browser* browser) {}

void TabSharingUIViews::OnBrowserRemoved(Browser* browser) {}

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

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

void TabSharingUIViews::OnInfoBarRemoved(infobars::InfoBar* infobar,
                                         bool animate) {}

void TabSharingUIViews::PrimaryPageChanged(content::Page& page) {}

void TabSharingUIViews::WebContentsDestroyed() {}

#if BUILDFLAG(IS_CHROMEOS)
void TabSharingUIViews::OnConfidentialityChanged(
    policy::DlpRulesManager::Level old_restriction_level,
    policy::DlpRulesManager::Level new_restriction_level,
    content::WebContents* web_contents) {
  DCHECK(old_restriction_level != new_restriction_level);
  if (old_restriction_level == policy::DlpRulesManager::Level::kBlock ||
      new_restriction_level == policy::DlpRulesManager::Level::kBlock) {
    // We only call this function if it was previously blocked or should be
    // blocked now.
    CreateInfobarForWebContents(web_contents);
  }
}

// static
void TabSharingUIViews::ApplyDlpForAllUsersForTesting() {
  g_apply_dlp_for_all_users_for_testing_ = true;
}
#endif

void TabSharingUIViews::CreateInfobarsForAllTabs() {}

void TabSharingUIViews::CreateInfobarForWebContents(WebContents* contents) {}

void TabSharingUIViews::RemoveInfobarsForAllTabs() {}

void TabSharingUIViews::CreateTabCaptureIndicator() {}

void TabSharingUIViews::FaviconPeriodicUpdate(size_t share_session_seq_num) {}

void TabSharingUIViews::RefreshFavicons() {}

void TabSharingUIViews::MaybeUpdateFavicon(
    WebContents* focus_target,
    std::optional<uint32_t>* current_hash,
    WebContents* infobar_owner) {}

ui::ImageModel TabSharingUIViews::TabFavicon(WebContents* web_contents) const {}

ui::ImageModel TabSharingUIViews::TabFavicon(
    GlobalRenderFrameHostId rfh_id) const {}

void TabSharingUIViews::SetTabFaviconForTesting(
    content::WebContents* web_contents,
    const ui::ImageModel& favicon) {}

void TabSharingUIViews::StopCaptureDueToPolicy(content::WebContents* contents) {}

void TabSharingUIViews::UpdateTabCaptureData(WebContents* contents,
                                             TabCaptureUpdate update) {}

bool TabSharingUIViews::IsShareInsteadButtonPossible(
    content::WebContents* web_contents) const {}

bool TabSharingUIViews::IsCapturableByCapturer(const Profile* profile) const {}

void TabSharingUIViews::OnCapturedSurfaceControlByCapturer() {}

TabSharingUIViews::CapturedSurfaceControlObserver::
    CapturedSurfaceControlObserver(content::WebContents* web_contents,
                                   base::OnceClosure callback)
    :{}

TabSharingUIViews::CapturedSurfaceControlObserver::
    ~CapturedSurfaceControlObserver() = default;

void TabSharingUIViews::CapturedSurfaceControlObserver::
    OnCapturedSurfaceControl() {}