#include "chrome/browser/ui/media_router/media_router_ui.h"
#include <utility>
#include <vector>
#include "base/atomic_sequence_num.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/media/router/providers/wired_display/wired_display_media_route_provider.h"
#include "chrome/browser/media/webrtc/desktop_media_picker_controller.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/media_router/media_sink_with_cast_modes.h"
#include "chrome/browser/ui/media_router/ui_media_sink.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/media_router/browser/issue_manager.h"
#include "components/media_router/browser/issues_observer.h"
#include "components/media_router/browser/log_util.h"
#include "components/media_router/browser/media_router.h"
#include "components/media_router/browser/media_router_factory.h"
#include "components/media_router/browser/media_routes_observer.h"
#include "components/media_router/browser/presentation/presentation_service_delegate_impl.h"
#include "components/media_router/common/media_route.h"
#include "components/media_router/common/media_sink.h"
#include "components/media_router/common/media_source.h"
#include "components/media_router/common/route_request_result.h"
#include "components/sessions/content/session_tab_helper.h"
#include "components/url_formatter/elide_url.h"
#include "third_party/icu/source/i18n/unicode/coll.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/display.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#include "ui/base/cocoa/permissions_utils.h"
#endif
namespace media_router {
namespace {
constexpr char kLoggerComponent[] = …;
bool IssueMatches(const Issue& issue, const UIMediaSink& ui_sink) { … }
void MaybeReportCastingSource(MediaCastMode cast_mode,
const RouteRequestResult& result) { … }
const CastModeSet CreateMediaCastModeSet(const MediaCastMode& cast_mode) { … }
}
MediaRouterUI::MediaRouterUI(
std::unique_ptr<MediaRouteStarter> media_route_starter)
: … { … }
MediaRouterUI::~MediaRouterUI() { … }
std::unique_ptr<MediaRouterUI> MediaRouterUI::CreateMediaRouterUI(
MediaRouterUIParameters params) { … }
std::unique_ptr<MediaRouterUI> MediaRouterUI::CreateWithDefaultMediaSource(
content::WebContents* initiator) { … }
std::unique_ptr<MediaRouterUI>
MediaRouterUI::CreateWithDefaultMediaSourceAndMirroring(
content::WebContents* initiator) { … }
std::unique_ptr<MediaRouterUI>
MediaRouterUI::CreateWithStartPresentationContext(
content::WebContents* initiator,
std::unique_ptr<StartPresentationContext> context) { … }
std::unique_ptr<MediaRouterUI>
MediaRouterUI::CreateWithStartPresentationContextAndMirroring(
content::WebContents* initiator,
std::unique_ptr<StartPresentationContext> context) { … }
std::unique_ptr<MediaRouterUI>
MediaRouterUI::CreateWithMediaSessionRemotePlayback(
content::WebContents* initiator,
media::VideoCodec video_codec,
media::AudioCodec audio_codec) { … }
void MediaRouterUI::DetachFromMediaRouteStarter() { … }
void MediaRouterUI::AddObserver(CastDialogController::Observer* observer) { … }
void MediaRouterUI::RemoveObserver(CastDialogController::Observer* observer) { … }
void MediaRouterUI::StartCasting(const std::string& sink_id,
MediaCastMode cast_mode) { … }
void MediaRouterUI::StopCasting(const std::string& route_id) { … }
void MediaRouterUI::ClearIssue(const Issue::Id& issue_id) { … }
void MediaRouterUI::FreezeRoute(const std::string& route_id) { … }
void MediaRouterUI::UnfreezeRoute(const std::string& route_id) { … }
std::unique_ptr<MediaRouteStarter> MediaRouterUI::TakeMediaRouteStarter() { … }
void MediaRouterUI::RegisterDestructor(base::OnceClosure destructor) { … }
bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id,
MediaCastMode cast_mode) { … }
void MediaRouterUI::TerminateRoute(const MediaRoute::Id& route_id) { … }
std::vector<MediaSinkWithCastModes> MediaRouterUI::GetEnabledSinks() const { … }
void MediaRouterUI::AddIssue(const IssueInfo& issue) { … }
void MediaRouterUI::RemoveIssue(const Issue::Id& issue_id) { … }
void MediaRouterUI::LogMediaSinkStatus() { … }
MediaRouterUI::UiIssuesObserver::UiIssuesObserver(IssueManager* issue_manager,
MediaRouterUI* ui)
: … { … }
MediaRouterUI::UiIssuesObserver::~UiIssuesObserver() = default;
void MediaRouterUI::UiIssuesObserver::OnIssue(const Issue& issue) { … }
void MediaRouterUI::UiIssuesObserver::OnIssuesCleared() { … }
MediaRouterUI::UIMediaRoutesObserver::UIMediaRoutesObserver(
MediaRouter* router,
const RoutesUpdatedCallback& callback)
: … { … }
MediaRouterUI::UIMediaRoutesObserver::~UIMediaRoutesObserver() = default;
void MediaRouterUI::UIMediaRoutesObserver::OnRoutesUpdated(
const std::vector<MediaRoute>& routes) { … }
void MediaRouterUI::Init() { … }
void MediaRouterUI::OnSourceUpdated(std::u16string& source_name) { … }
void MediaRouterUI::OnFreezeInfoChanged() { … }
void MediaRouterUI::UpdateSinks() { … }
void MediaRouterUI::SendIssueForRouteTimeout(
MediaCastMode cast_mode,
const MediaSink::Id& sink_id,
const std::u16string& presentation_request_source_name) { … }
std::u16string MediaRouterUI::GetSinkFriendlyNameFromId(
const MediaSink::Id& sink_id) { … }
void MediaRouterUI::SendIssueForUserNotAllowed(const MediaSink::Id& sink_id) { … }
void MediaRouterUI::SendIssueForNotificationDisabled(
const MediaSink::Id& sink_id) { … }
void MediaRouterUI::SendIssueForScreenPermission(const MediaSink::Id& sink_id) { … }
void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode,
const MediaSink::Id& sink_id) { … }
void MediaRouterUI::SendIssueForTabAudioNotSupported(
const MediaSink::Id& sink_id) { … }
IssueManager* MediaRouterUI::GetIssueManager() { … }
void MediaRouterUI::StartObservingIssues() { … }
void MediaRouterUI::OnIssue(const Issue& issue) { … }
void MediaRouterUI::OnIssueCleared() { … }
void MediaRouterUI::OnRoutesUpdated(const std::vector<MediaRoute>& routes) { … }
void MediaRouterUI::OnSinksUpdated(
const std::vector<MediaSinkWithCastModes>& sinks) { … }
void MediaRouterUI::OnRouteResponseReceived(
int route_request_id,
const MediaSink::Id& sink_id,
MediaCastMode cast_mode,
const std::u16string& presentation_request_source_name,
const RouteRequestResult& result) { … }
void MediaRouterUI::UpdateModelHeader(const std::u16string& source_name) { … }
UIMediaSink MediaRouterUI::ConvertToUISink(const MediaSinkWithCastModes& sink,
const MediaRoute* route,
const std::optional<Issue>& issue) { … }
void MediaRouterUI::StopObservingMirroringMediaControllerHosts() { … }
MediaRouter* MediaRouterUI::GetMediaRouter() const { … }
}