#include "chrome/browser/media/router/providers/cast/cast_internal_message_util.h"
#include <string>
#include <string_view>
#include <utility>
#include "base/base64url.h"
#include "base/hash/sha1.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/strings/escape.h"
#include "components/media_router/common/discovery/media_sink_internal.h"
#include "components/media_router/common/providers/cast/cast_media_source.h"
#include "components/media_router/common/providers/cast/channel/cast_device_capability.h"
#include "components/media_router/common/providers/cast/channel/enum_table.h"
CastDeviceCapability;
CastDeviceCapabilitySet;
namespace cast_util {
CastInternalMessage;
template <>
const EnumTable<CastInternalMessage::Type>&
EnumTable<CastInternalMessage::Type>::GetInstance() { … }
template <>
const EnumTable<CastInternalMessage::ErrorCode>&
EnumTable<CastInternalMessage::ErrorCode>::GetInstance() { … }
}
namespace media_router {
namespace {
constexpr char kBackdropAppId[] = …;
bool GetString(const base::Value::Dict& value,
const std::string& key,
std::string* out) { … }
void CopyValueWithDefault(const base::Value::Dict& from,
const std::string& key,
base::Value default_value,
base::Value::Dict& to) { … }
void CopyValue(const base::Value::Dict& from,
const std::string& key,
base::Value::Dict& to) { … }
CastInternalMessage::Type CastInternalMessageTypeFromString(
const std::string& type) { … }
std::string CastInternalMessageTypeToString(CastInternalMessage::Type type) { … }
constexpr char kReceiverActionTypeCast[] = …;
constexpr char kReceiverActionTypeStop[] = …;
base::Value::List CapabilitiesToListValue(
CastDeviceCapabilitySet capabilities) { … }
std::string GetReceiverLabel(const MediaSinkInternal& sink,
const std::string& hash_token) { … }
base::Value::Dict CreateReceiver(const MediaSinkInternal& sink,
const std::string& hash_token) { … }
blink::mojom::PresentationConnectionMessagePtr CreateMessageCommon(
CastInternalMessage::Type type,
base::Value::Dict payload,
const std::string& client_id,
std::optional<int> sequence_number = std::nullopt) { … }
blink::mojom::PresentationConnectionMessagePtr CreateReceiverActionMessage(
const std::string& client_id,
const MediaSinkInternal& sink,
const std::string& hash_token,
const char* action_type) { … }
base::Value::Dict CreateAppMessageBody(
const std::string& session_id,
const openscreen::cast::proto::CastMessage& cast_message) { … }
blink::mojom::PresentationConnectionMessagePtr CreateSessionMessage(
const CastSession& session,
const std::string& client_id,
const MediaSinkInternal& sink,
const std::string& hash_token,
CastInternalMessage::Type type) { … }
}
std::unique_ptr<CastInternalMessage> CastInternalMessage::From(
base::Value::Dict message) { … }
CastInternalMessage::~CastInternalMessage() = default;
CastInternalMessage::CastInternalMessage(
Type type,
const std::string& client_id,
std::optional<int> sequence_number,
const std::string& session_id,
const std::string& namespace_or_v2_type,
base::Value message_body)
: … { … }
std::unique_ptr<CastSession> CastSession::From(
const MediaSinkInternal& sink,
const base::Value::Dict& receiver_status) { … }
CastSession::CastSession() = default;
CastSession::~CastSession() = default;
std::string CastSession::GetRouteDescription() const { … }
void CastSession::UpdateSession(std::unique_ptr<CastSession> from) { … }
void CastSession::UpdateMedia(const base::Value::List& media) { … }
blink::mojom::PresentationConnectionMessagePtr CreateReceiverActionCastMessage(
const std::string& client_id,
const MediaSinkInternal& sink,
const std::string& hash_token) { … }
blink::mojom::PresentationConnectionMessagePtr CreateReceiverActionStopMessage(
const std::string& client_id,
const MediaSinkInternal& sink,
const std::string& hash_token) { … }
blink::mojom::PresentationConnectionMessagePtr CreateNewSessionMessage(
const CastSession& session,
const std::string& client_id,
const MediaSinkInternal& sink,
const std::string& hash_token) { … }
blink::mojom::PresentationConnectionMessagePtr CreateUpdateSessionMessage(
const CastSession& session,
const std::string& client_id,
const MediaSinkInternal& sink,
const std::string& hash_token) { … }
blink::mojom::PresentationConnectionMessagePtr CreateAppMessageAck(
const std::string& client_id,
int sequence_number) { … }
blink::mojom::PresentationConnectionMessagePtr CreateAppMessage(
const std::string& session_id,
const std::string& client_id,
const openscreen::cast::proto::CastMessage& cast_message) { … }
blink::mojom::PresentationConnectionMessagePtr CreateV2Message(
const std::string& client_id,
const base::Value::Dict& payload,
std::optional<int> sequence_number) { … }
blink::mojom::PresentationConnectionMessagePtr CreateLeaveSessionAckMessage(
const std::string& client_id,
std::optional<int> sequence_number) { … }
blink::mojom::PresentationConnectionMessagePtr CreateErrorMessage(
const std::string& client_id,
base::Value::Dict error,
std::optional<int> sequence_number) { … }
base::Value::List SupportedMediaCommandsToListValue(int media_commands) { … }
}