blob: 6fe4d003ae9bdf8a05b21fcb0947ae01ddceaddd [file] [log] [blame]
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4056)
#pragma warning(disable:4065)
#pragma warning(disable:4756)
#endif
#include "components/mirroring/mojom/mirroring_service_host.mojom-blink.h"
#include <math.h>
#include <stdint.h>
#include <utility>
#include "base/hash/md5_constexpr.h"
#include "base/logging.h"
#include "base/run_loop.h"
#include "base/task/common/task_annotator.h"
#include "mojo/public/cpp/bindings/lib/message_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization_util.h"
#include "mojo/public/cpp/bindings/lib/unserialized_message_context.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_context.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
#include "components/mirroring/mojom/mirroring_service_host.mojom-params-data.h"
#include "components/mirroring/mojom/mirroring_service_host.mojom-shared-message-ids.h"
#include "components/mirroring/mojom/mirroring_service_host.mojom-blink-import-headers.h"
#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
#ifndef COMPONENTS_MIRRORING_MOJOM_MIRRORING_SERVICE_HOST_MOJOM_BLINK_JUMBO_H_
#define COMPONENTS_MIRRORING_MOJOM_MIRRORING_SERVICE_HOST_MOJOM_BLINK_JUMBO_H_
#endif
namespace mirroring {
namespace mojom {
namespace blink {
const char MirroringServiceHost::Name_[] = "mirroring.mojom.MirroringServiceHost";
MirroringServiceHostProxy::MirroringServiceHostProxy(mojo::MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
void MirroringServiceHostProxy::Start(
::mirroring::mojom::blink::SessionParametersPtr in_params, ::mirroring::mojom::blink::SessionObserverPtr in_observer, ::mirroring::mojom::blink::CastMessageChannelPtr in_outbound_channel, ::mirroring::mojom::blink::CastMessageChannelRequest in_inbound_channel) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::MirroringServiceHost::Start");
#endif
const bool kExpectsResponse = false;
const bool kIsSync = false;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0);
mojo::Message message(
internal::kMirroringServiceHost_Start_Name, kFlags, 0, 0, nullptr);
auto* buffer = message.payload_buffer();
::mirroring::mojom::internal::MirroringServiceHost_Start_Params_Data::BufferWriter
params;
mojo::internal::SerializationContext serialization_context;
params.Allocate(buffer);
typename decltype(params->params)::BaseType::BufferWriter
params_writer;
mojo::internal::Serialize<::mirroring::mojom::SessionParametersDataView>(
in_params, buffer, &params_writer, &serialization_context);
params->params.Set(
params_writer.is_null() ? nullptr : params_writer.data());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
params->params.is_null(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null params in MirroringServiceHost.Start request");
mojo::internal::Serialize<::mirroring::mojom::SessionObserverPtrDataView>(
in_observer, &params->observer, &serialization_context);
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(params->observer),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid observer in MirroringServiceHost.Start request");
mojo::internal::Serialize<::mirroring::mojom::CastMessageChannelPtrDataView>(
in_outbound_channel, &params->outbound_channel, &serialization_context);
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(params->outbound_channel),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid outbound_channel in MirroringServiceHost.Start request");
mojo::internal::Serialize<::mirroring::mojom::CastMessageChannelRequestDataView>(
in_inbound_channel, &params->inbound_channel, &serialization_context);
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(params->inbound_channel),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid inbound_channel in MirroringServiceHost.Start request");
message.AttachHandlesFromSerializationContext(
&serialization_context);
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(MirroringServiceHost::Name_);
message.set_method_name("Start");
#endif
// This return value may be ignored as false implies the Connector has
// encountered an error, which will be visible through other means.
ignore_result(receiver_->Accept(&message));
}
// static
bool MirroringServiceHostStubDispatch::Accept(
MirroringServiceHost* impl,
mojo::Message* message) {
switch (message->header()->name) {
case internal::kMirroringServiceHost_Start_Name: {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom",
"(Impl)<class 'jinja2::utils::Namespace'>::MirroringServiceHost::Start",
"message", message->name());
#endif
static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
"(Impl)<class 'jinja2::utils::Namespace'>::MirroringServiceHost::Start");
base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);
mojo::internal::MessageDispatchContext context(message);
DCHECK(message->is_serialized());
internal::MirroringServiceHost_Start_Params_Data* params =
reinterpret_cast<internal::MirroringServiceHost_Start_Params_Data*>(
message->mutable_payload());
mojo::internal::SerializationContext serialization_context;
serialization_context.TakeHandlesFromMessage(message);
bool success = true;
::mirroring::mojom::blink::SessionParametersPtr p_params{};
::mirroring::mojom::blink::SessionObserverPtr p_observer{};
::mirroring::mojom::blink::CastMessageChannelPtr p_outbound_channel{};
::mirroring::mojom::blink::CastMessageChannelRequest p_inbound_channel{};
MirroringServiceHost_Start_ParamsDataView input_data_view(params, &serialization_context);
if (!input_data_view.ReadParams(&p_params))
success = false;
p_observer =
input_data_view.TakeObserver<decltype(p_observer)>();
p_outbound_channel =
input_data_view.TakeOutboundChannel<decltype(p_outbound_channel)>();
p_inbound_channel =
input_data_view.TakeInboundChannel<decltype(p_inbound_channel)>();
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
MirroringServiceHost::Name_, 0, false);
return false;
}
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->Start(
std::move(p_params),
std::move(p_observer),
std::move(p_outbound_channel),
std::move(p_inbound_channel));
return true;
}
}
return false;
}
// static
bool MirroringServiceHostStubDispatch::AcceptWithResponder(
MirroringServiceHost* impl,
mojo::Message* message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
switch (message->header()->name) {
case internal::kMirroringServiceHost_Start_Name: {
break;
}
}
return false;
}
bool MirroringServiceHostRequestValidator::Accept(mojo::Message* message) {
if (!message->is_serialized() ||
mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
return true;
}
mojo::internal::ValidationContext validation_context(
message->payload(), message->payload_num_bytes(),
message->handles()->size(), message->payload_num_interface_ids(), message,
"MirroringServiceHost RequestValidator");
switch (message->header()->name) {
case internal::kMirroringServiceHost_Start_Name: {
if (!mojo::internal::ValidateMessageIsRequestWithoutResponse(
message, &validation_context)) {
return false;
}
if (!mojo::internal::ValidateMessagePayload<
internal::MirroringServiceHost_Start_Params_Data>(
message, &validation_context)) {
return false;
}
return true;
}
default:
break;
}
// Unrecognized message.
ReportValidationError(
&validation_context,
mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
return false;
}
} // namespace blink
} // namespace mojom
} // namespace mirroring
namespace mojo {
} // namespace mojo
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning(pop)
#endif