#include "components/media_router/common/providers/cast/channel/cast_message_util.h"
#include <memory>
#include <string_view>
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/media_router/common/providers/cast/channel/cast_auth_util.h"
#include "components/media_router/common/providers/cast/channel/enum_table.h"
#include "third_party/openscreen/src/cast/common/channel/proto/cast_channel.pb.h"
Value;
EnumToString;
StringToEnum;
namespace cast_util {
CastMessageType;
GetAppAvailabilityResult;
AuthChallenge;
CastMessage;
template <>
const EnumTable<CastMessageType>& EnumTable<CastMessageType>::GetInstance() { … }
template <>
const EnumTable<cast_channel::V2MessageType>&
EnumTable<cast_channel::V2MessageType>::GetInstance() { … }
template <>
const EnumTable<GetAppAvailabilityResult>&
EnumTable<GetAppAvailabilityResult>::GetInstance() { … }
}
namespace cast_channel {
namespace {
constexpr std::string_view kCastReservedNamespacePrefix = …;
constexpr const char* kReservedNamespaces[] = …;
constexpr int kVirtualConnectSdkType = …;
constexpr int kVirtualConnectTypeLocal = …;
constexpr int kVirtualConnectionClosedByPeer = …;
void FillCommonCastMessageFields(CastMessage* message,
const std::string& source_id,
const std::string& destination_id,
const std::string& message_namespace) { … }
CastMessage CreateKeepAliveMessage(std::string_view keep_alive_type) { … }
int GetVirtualConnectPlatformValue() { … }
std::string_view GetRemappedMediaRequestType(std::string_view v2_message_type) { … }
}
std::ostream& operator<<(std::ostream& lhs, const CastMessage& rhs) { … }
bool IsCastMessageValid(const CastMessage& message_proto) { … }
bool IsCastReservedNamespace(std::string_view message_namespace) { … }
CastMessageType ParseMessageTypeFromPayload(const base::Value::Dict& payload) { … }
const char* ToString(CastMessageType message_type) { … }
const char* ToString(V2MessageType message_type) { … }
CastMessageType CastMessageTypeFromString(const std::string& type) { … }
V2MessageType V2MessageTypeFromString(const std::string& type) { … }
std::string AuthMessageToString(const DeviceAuthMessage& message) { … }
void CreateAuthChallengeMessage(CastMessage* message_proto,
const AuthContext& auth_context) { … }
bool IsAuthMessage(const CastMessage& message) { … }
bool IsReceiverMessage(const CastMessage& message) { … }
bool IsPlatformSenderMessage(const CastMessage& message) { … }
CastMessage CreateKeepAlivePingMessage() { … }
CastMessage CreateKeepAlivePongMessage() { … }
CastMessage CreateVirtualConnectionRequest(
const std::string& source_id,
const std::string& destination_id,
VirtualConnectionType connection_type,
const std::string& user_agent,
const std::string& browser_version) { … }
CastMessage CreateVirtualConnectionClose(const std::string& source_id,
const std::string& destination_id) { … }
CastMessage CreateGetAppAvailabilityRequest(const std::string& source_id,
int request_id,
const std::string& app_id) { … }
CastMessage CreateReceiverStatusRequest(const std::string& source_id,
int request_id) { … }
CastMessage CreateLaunchRequest(
const std::string& source_id,
int request_id,
const std::string& app_id,
const std::string& locale,
const std::vector<std::string>& supported_app_types,
const std::optional<base::Value>& app_params) { … }
CastMessage CreateStopRequest(const std::string& source_id,
int request_id,
const std::string& session_id) { … }
CastMessage CreateCastMessage(const std::string& message_namespace,
const base::Value& message,
const std::string& source_id,
const std::string& destination_id) { … }
CastMessage CreateMediaRequest(const base::Value::Dict& body,
int request_id,
const std::string& source_id,
const std::string& destination_id) { … }
CastMessage CreateSetVolumeRequest(const base::Value::Dict& body,
int request_id,
const std::string& source_id) { … }
bool IsMediaRequestMessageType(V2MessageType type) { … }
const char* ToString(GetAppAvailabilityResult result) { … }
std::optional<int> GetRequestIdFromResponse(const Value::Dict& payload) { … }
GetAppAvailabilityResult GetAppAvailabilityResultFromResponse(
const Value::Dict& payload,
const std::string& app_id) { … }
LaunchSessionResponse::LaunchSessionResponse() = default;
LaunchSessionResponse::LaunchSessionResponse(LaunchSessionResponse&& other) =
default;
LaunchSessionResponse& LaunchSessionResponse::operator=(
LaunchSessionResponse&& other) = default;
LaunchSessionResponse::~LaunchSessionResponse() = default;
LaunchSessionResponse GetLaunchSessionResponseError(std::string error_msg) { … }
LaunchSessionResponse GetLaunchSessionResponse(
const base::Value::Dict& payload) { … }
VirtualConnectionType GetConnectionType(const std::string& destination_id) { … }
}