blob: d3671a64c36f9c527545d7e6f388aef711fde90a [file] [log] [blame]
// content/shell/common/shell_controller.test-mojom.cc is auto generated by mojom_bindings_generator.py, do not edit
// Copyright 2013 The Chromium Authors
// 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"
#endif
#include "content/shell/common/shell_controller.test-mojom.h"
#include <math.h>
#include <stdint.h>
#include <utility>
#include "base/debug/alias.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "base/types/cxx23_to_underlying.h"
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.h"
#include "mojo/public/cpp/bindings/lib/generated_code_util.h"
#include "mojo/public/cpp/bindings/lib/message_internal.h"
#include "mojo/public/cpp/bindings/lib/proxy_to_responder.h"
#include "mojo/public/cpp/bindings/lib/send_message_helper.h"
#include "mojo/public/cpp/bindings/lib/serialization.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_errors.h"
#include "mojo/public/cpp/bindings/mojo_buildflags.h"
#include "mojo/public/cpp/bindings/urgent_message_scope.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
#include "content/shell/common/shell_controller.test-mojom-params-data.h"
#include "content/shell/common/shell_controller.test-mojom-shared-message-ids.h"
#include "content/shell/common/shell_controller.test-mojom-import-headers.h"
#include "content/shell/common/shell_controller.test-mojom-test-utils.h"
namespace content::mojom {
// The declaration includes the definition on other builds.
ShellController::IPCStableHashFunction ShellController::MessageToMethodInfo_(mojo::Message& message) {
#if !BUILDFLAG(IS_FUCHSIA)
switch (static_cast<messages::ShellController>(message.name())) {
case messages::ShellController::kGetSwitchValue: {
return &ShellController::GetSwitchValue_Sym::IPCStableHash;
}
case messages::ShellController::kExecuteJavaScript: {
return &ShellController::ExecuteJavaScript_Sym::IPCStableHash;
}
case messages::ShellController::kShutDown: {
return &ShellController::ShutDown_Sym::IPCStableHash;
}
}
#endif // !BUILDFLAG(IS_FUCHSIA)
return nullptr;
}
const char* ShellController::MessageToMethodName_(mojo::Message& message) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
bool is_response = message.has_flag(mojo::Message::kFlagIsResponse);
if (!is_response) {
switch (static_cast<messages::ShellController>(message.name())) {
case messages::ShellController::kGetSwitchValue:
return "Receive content::mojom::ShellController::GetSwitchValue";
case messages::ShellController::kExecuteJavaScript:
return "Receive content::mojom::ShellController::ExecuteJavaScript";
case messages::ShellController::kShutDown:
return "Receive content::mojom::ShellController::ShutDown";
}
} else {
switch (static_cast<messages::ShellController>(message.name())) {
case messages::ShellController::kGetSwitchValue:
return "Receive reply content::mojom::ShellController::GetSwitchValue";
case messages::ShellController::kExecuteJavaScript:
return "Receive reply content::mojom::ShellController::ExecuteJavaScript";
case messages::ShellController::kShutDown:
return "Receive reply content::mojom::ShellController::ShutDown";
}
}
return "Receive unknown mojo message";
#else
bool is_response = message.has_flag(mojo::Message::kFlagIsResponse);
if (is_response) {
return "Receive mojo reply";
} else {
return "Receive mojo message";
}
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
}
#if !BUILDFLAG(IS_FUCHSIA)
uint32_t ShellController::GetSwitchValue_Sym::IPCStableHash() {
// This method's address is used for identifying the mojo method name after
// symbolization. So each IPCStableHash should have a unique address.
// We cannot use NO_CODE_FOLDING() here - it relies on the uniqueness of
// __LINE__ value, which is not unique across different mojo modules.
// The code below is very similar to NO_CODE_FOLDING, but it uses a unique
// hash instead of __LINE__.
static constexpr uint32_t kHash = 0xb22d6681; // IPCStableHash for content::mojom::ShellController::GetSwitchValue
const uint32_t hash = kHash;
base::debug::Alias(&hash);
return hash;
}
uint32_t ShellController::ExecuteJavaScript_Sym::IPCStableHash() {
// This method's address is used for identifying the mojo method name after
// symbolization. So each IPCStableHash should have a unique address.
// We cannot use NO_CODE_FOLDING() here - it relies on the uniqueness of
// __LINE__ value, which is not unique across different mojo modules.
// The code below is very similar to NO_CODE_FOLDING, but it uses a unique
// hash instead of __LINE__.
static constexpr uint32_t kHash = 0x82b4afda; // IPCStableHash for content::mojom::ShellController::ExecuteJavaScript
const uint32_t hash = kHash;
base::debug::Alias(&hash);
return hash;
}
uint32_t ShellController::ShutDown_Sym::IPCStableHash() {
// This method's address is used for identifying the mojo method name after
// symbolization. So each IPCStableHash should have a unique address.
// We cannot use NO_CODE_FOLDING() here - it relies on the uniqueness of
// __LINE__ value, which is not unique across different mojo modules.
// The code below is very similar to NO_CODE_FOLDING, but it uses a unique
// hash instead of __LINE__.
static constexpr uint32_t kHash = 0x5412630f; // IPCStableHash for content::mojom::ShellController::ShutDown
const uint32_t hash = kHash;
base::debug::Alias(&hash);
return hash;
}
# endif // !BUILDFLAG(IS_FUCHSIA)
class ShellController_GetSwitchValue_ForwardToCallback
: public mojo::MessageReceiver {
public:
ShellController_GetSwitchValue_ForwardToCallback(
ShellController::GetSwitchValueCallback callback
) : callback_(std::move(callback)) {
}
ShellController_GetSwitchValue_ForwardToCallback(const ShellController_GetSwitchValue_ForwardToCallback&) = delete;
ShellController_GetSwitchValue_ForwardToCallback& operator=(const ShellController_GetSwitchValue_ForwardToCallback&) = delete;
bool Accept(mojo::Message* message) override;
private:
ShellController::GetSwitchValueCallback callback_;
};
class ShellController_ExecuteJavaScript_ForwardToCallback
: public mojo::MessageReceiver {
public:
ShellController_ExecuteJavaScript_ForwardToCallback(
ShellController::ExecuteJavaScriptCallback callback
) : callback_(std::move(callback)) {
}
ShellController_ExecuteJavaScript_ForwardToCallback(const ShellController_ExecuteJavaScript_ForwardToCallback&) = delete;
ShellController_ExecuteJavaScript_ForwardToCallback& operator=(const ShellController_ExecuteJavaScript_ForwardToCallback&) = delete;
bool Accept(mojo::Message* message) override;
private:
ShellController::ExecuteJavaScriptCallback callback_;
};
ShellControllerProxy::ShellControllerProxy(mojo::MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
void ShellControllerProxy::GetSwitchValue(
const std::string& in_name, GetSwitchValueCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send content::mojom::ShellController::GetSwitchValue", "input_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("name"), in_name,
"<value of type const std::string&>");
});
#endif
const bool kExpectsResponse = true;
const bool kIsSync = false;
const bool kAllowInterrupt = true;
const bool is_urgent = false;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt) |
((is_urgent) ? mojo::Message::kFlagIsUrgent : 0);
const size_t estimated_payload_size =
0;
mojo::Message message(
base::to_underlying(messages::ShellController::kGetSwitchValue), kFlags, estimated_payload_size);
mojo::internal::MessageFragment<
::content::mojom::internal::ShellController_GetSwitchValue_Params_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<
typename decltype(params->name)::BaseType> name_fragment(
params.message());
mojo::internal::Serialize<mojo::StringDataView>(
in_name,
name_fragment);
params->name.Set(
name_fragment.is_null() ? nullptr : name_fragment.data());
MOJO_INTERNAL_CHECK_SERIALIZATION(
mojo::internal::SendValidation::kDefault,
!(params->name.is_null()),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null name in ShellController.GetSwitchValue request");
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ShellController::Name_);
message.set_method_name("GetSwitchValue");
#endif
std::unique_ptr<mojo::MessageReceiver> responder(
new ShellController_GetSwitchValue_ForwardToCallback(
std::move(callback)));
::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder));
}
void ShellControllerProxy::ExecuteJavaScript(
const ::std::u16string& in_script, ExecuteJavaScriptCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send content::mojom::ShellController::ExecuteJavaScript", "input_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("script"), in_script,
"<value of type const ::std::u16string&>");
});
#endif
const bool kExpectsResponse = true;
const bool kIsSync = false;
const bool kAllowInterrupt = true;
const bool is_urgent = false;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt) |
((is_urgent) ? mojo::Message::kFlagIsUrgent : 0);
const size_t estimated_payload_size =
0;
mojo::Message message(
base::to_underlying(messages::ShellController::kExecuteJavaScript), kFlags, estimated_payload_size);
mojo::internal::MessageFragment<
::content::mojom::internal::ShellController_ExecuteJavaScript_Params_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<
typename decltype(params->script)::BaseType> script_fragment(
params.message());
mojo::internal::Serialize<::mojo_base::mojom::String16DataView>(
in_script,
script_fragment);
params->script.Set(
script_fragment.is_null() ? nullptr : script_fragment.data());
MOJO_INTERNAL_CHECK_SERIALIZATION(
mojo::internal::SendValidation::kDefault,
!(params->script.is_null()),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null script in ShellController.ExecuteJavaScript request");
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ShellController::Name_);
message.set_method_name("ExecuteJavaScript");
#endif
std::unique_ptr<mojo::MessageReceiver> responder(
new ShellController_ExecuteJavaScript_ForwardToCallback(
std::move(callback)));
::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder));
}
void ShellControllerProxy::ShutDown(
) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT0("mojom", "Send content::mojom::ShellController::ShutDown");
#endif
const bool kExpectsResponse = false;
const bool kIsSync = false;
const bool kAllowInterrupt = true;
const bool is_urgent = false;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt) |
((is_urgent) ? mojo::Message::kFlagIsUrgent : 0);
const size_t estimated_payload_size =
0;
mojo::Message message(
base::to_underlying(messages::ShellController::kShutDown), kFlags, estimated_payload_size);
mojo::internal::MessageFragment<
::content::mojom::internal::ShellController_ShutDown_Params_Data> params(
message);
params.Allocate();
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ShellController::Name_);
message.set_method_name("ShutDown");
#endif
// This return value may be ignored as false implies the Connector has
// encountered an error, which will be visible through other means.
::mojo::internal::SendMojoMessage(*receiver_, message);
}
class ShellController_GetSwitchValue_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
public:
static ShellController::GetSwitchValueCallback CreateCallback(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
std::unique_ptr<ShellController_GetSwitchValue_ProxyToResponder> proxy(
new ShellController_GetSwitchValue_ProxyToResponder(
message, std::move(responder)));
return base::BindOnce(&ShellController_GetSwitchValue_ProxyToResponder::Run,
std::move(proxy));
}
~ShellController_GetSwitchValue_ProxyToResponder() {
#if DCHECK_IS_ON()
if (responder_) {
// If we're being destroyed without being run, we want to ensure the
// binding endpoint has been closed. This checks for that asynchronously.
// We pass a bound generated callback to handle the response so that any
// resulting DCHECK stack will have useful interface type information.
// Instantiate a ScopedFizzleBlockShutdownTasks to allow this request to
// fizzle if this happens after shutdown and the endpoint is bound to a
// BLOCK_SHUTDOWN sequence.
base::ThreadPoolInstance::ScopedFizzleBlockShutdownTasks fizzler;
responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
}
#endif
}
private:
ShellController_GetSwitchValue_ProxyToResponder(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder)
: ::mojo::internal::ProxyToResponder(message, std::move(responder)) {
}
#if DCHECK_IS_ON()
static void OnIsConnectedComplete(bool connected) {
DCHECK(!connected)
<< "ShellController::GetSwitchValueCallback was destroyed without "
<< "first either being run or its corresponding binding being closed. "
<< "It is an error to drop response callbacks which still correspond "
<< "to an open interface pipe.";
}
#endif
void Run(
const std::optional<std::string>& in_value);
};
bool ShellController_GetSwitchValue_ForwardToCallback::Accept(
mojo::Message* message) {
DCHECK(message->is_serialized());
internal::ShellController_GetSwitchValue_ResponseParams_Data* params =
reinterpret_cast<
internal::ShellController_GetSwitchValue_ResponseParams_Data*>(
message->mutable_payload());
// Validation for ShellController.0
bool success = true;
std::optional<std::string> p_value{};
ShellController_GetSwitchValue_ResponseParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadValue(&p_value))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ShellController::Name_, 0, true);
return false;
}
if (!callback_.is_null()) {
std::move(callback_).Run(
std::move(p_value));
}
return true;
}
void ShellController_GetSwitchValue_ProxyToResponder::Run(
const std::optional<std::string>& in_value) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send reply content::mojom::ShellController::GetSwitchValue", "async_response_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("value"), in_value,
"<value of type const std::optional<std::string>&>");
});
#endif
const uint32_t kFlags = mojo::Message::kFlagIsResponse |
((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
((true) ? 0 : mojo::Message::kFlagNoInterrupt) |
((false) ? mojo::Message::kFlagIsUrgent : 0);
const size_t estimated_payload_size =
0;
mojo::Message message(
base::to_underlying(messages::ShellController::kGetSwitchValue), kFlags, estimated_payload_size);
mojo::internal::MessageFragment<
::content::mojom::internal::ShellController_GetSwitchValue_ResponseParams_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<
typename decltype(params->value)::BaseType> value_fragment(
params.message());
mojo::internal::Serialize<mojo::StringDataView>(
in_value,
value_fragment);
params->value.Set(
value_fragment.is_null() ? nullptr : value_fragment.data());
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ShellController::Name_);
message.set_method_name("GetSwitchValue");
#endif
message.set_request_id(request_id_);
message.set_trace_nonce(trace_nonce_);
::mojo::internal::SendMojoMessage(*responder_, message);
// SendMojoMessage() fails silently if the responder connection is closed,
// or if the message is malformed.
//
// TODO(darin): If Accept() returns false due to a malformed message, that
// may be good reason to close the connection. However, we don't have a
// way to do that from here. We should add a way.
responder_ = nullptr;
}
class ShellController_ExecuteJavaScript_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
public:
static ShellController::ExecuteJavaScriptCallback CreateCallback(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
std::unique_ptr<ShellController_ExecuteJavaScript_ProxyToResponder> proxy(
new ShellController_ExecuteJavaScript_ProxyToResponder(
message, std::move(responder)));
return base::BindOnce(&ShellController_ExecuteJavaScript_ProxyToResponder::Run,
std::move(proxy));
}
~ShellController_ExecuteJavaScript_ProxyToResponder() {
#if DCHECK_IS_ON()
if (responder_) {
// If we're being destroyed without being run, we want to ensure the
// binding endpoint has been closed. This checks for that asynchronously.
// We pass a bound generated callback to handle the response so that any
// resulting DCHECK stack will have useful interface type information.
// Instantiate a ScopedFizzleBlockShutdownTasks to allow this request to
// fizzle if this happens after shutdown and the endpoint is bound to a
// BLOCK_SHUTDOWN sequence.
base::ThreadPoolInstance::ScopedFizzleBlockShutdownTasks fizzler;
responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
}
#endif
}
private:
ShellController_ExecuteJavaScript_ProxyToResponder(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder)
: ::mojo::internal::ProxyToResponder(message, std::move(responder)) {
}
#if DCHECK_IS_ON()
static void OnIsConnectedComplete(bool connected) {
DCHECK(!connected)
<< "ShellController::ExecuteJavaScriptCallback was destroyed without "
<< "first either being run or its corresponding binding being closed. "
<< "It is an error to drop response callbacks which still correspond "
<< "to an open interface pipe.";
}
#endif
void Run(
::base::Value in_value);
};
bool ShellController_ExecuteJavaScript_ForwardToCallback::Accept(
mojo::Message* message) {
DCHECK(message->is_serialized());
internal::ShellController_ExecuteJavaScript_ResponseParams_Data* params =
reinterpret_cast<
internal::ShellController_ExecuteJavaScript_ResponseParams_Data*>(
message->mutable_payload());
// Validation for ShellController.1
bool success = true;
::base::Value p_value{};
ShellController_ExecuteJavaScript_ResponseParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadValue(&p_value))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ShellController::Name_, 1, true);
return false;
}
if (!callback_.is_null()) {
std::move(callback_).Run(
std::move(p_value));
}
return true;
}
void ShellController_ExecuteJavaScript_ProxyToResponder::Run(
::base::Value in_value) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send reply content::mojom::ShellController::ExecuteJavaScript", "async_response_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("value"), in_value,
"<value of type ::base::Value>");
});
#endif
const uint32_t kFlags = mojo::Message::kFlagIsResponse |
((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
((true) ? 0 : mojo::Message::kFlagNoInterrupt) |
((false) ? mojo::Message::kFlagIsUrgent : 0);
const size_t estimated_payload_size =
0;
mojo::Message message(
base::to_underlying(messages::ShellController::kExecuteJavaScript), kFlags, estimated_payload_size);
mojo::internal::MessageFragment<
::content::mojom::internal::ShellController_ExecuteJavaScript_ResponseParams_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<decltype(params->value)>
value_fragment(params.message());
value_fragment.Claim(&params->value);
mojo::internal::Serialize<::mojo_base::mojom::ValueDataView>(
in_value,
value_fragment,
true);
MOJO_INTERNAL_CHECK_SERIALIZATION(
mojo::internal::SendValidation::kDefault,
!(params->value.is_null()),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null value in ");
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(ShellController::Name_);
message.set_method_name("ExecuteJavaScript");
#endif
message.set_request_id(request_id_);
message.set_trace_nonce(trace_nonce_);
::mojo::internal::SendMojoMessage(*responder_, message);
// SendMojoMessage() fails silently if the responder connection is closed,
// or if the message is malformed.
//
// TODO(darin): If Accept() returns false due to a malformed message, that
// may be good reason to close the connection. However, we don't have a
// way to do that from here. We should add a way.
responder_ = nullptr;
}
// static
bool ShellControllerStubDispatch::Accept(
ShellController* impl,
mojo::Message* message) {
switch (static_cast<messages::ShellController>(message->header()->name)) {
case messages::ShellController::kGetSwitchValue: {
break;
}
case messages::ShellController::kExecuteJavaScript: {
break;
}
case messages::ShellController::kShutDown: {
DCHECK(message->is_serialized());
internal::ShellController_ShutDown_Params_Data* params =
reinterpret_cast<internal::ShellController_ShutDown_Params_Data*>(
message->mutable_payload());
// Validation for ShellController.2
bool success = true;
ShellController_ShutDown_ParamsDataView input_data_view(params, message);
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ShellController::Name_, 2, false);
return false;
}
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->ShutDown( );
return true;
}
}
return false;
}
// static
bool ShellControllerStubDispatch::AcceptWithResponder(
ShellController* impl,
mojo::Message* message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
[[maybe_unused]] const bool message_is_sync =
message->has_flag(mojo::Message::kFlagIsSync);
[[maybe_unused]] const uint64_t request_id = message->request_id();
switch (static_cast<messages::ShellController>(message->header()->name)) {
case messages::ShellController::kGetSwitchValue: {
internal::ShellController_GetSwitchValue_Params_Data* params =
reinterpret_cast<
internal::ShellController_GetSwitchValue_Params_Data*>(
message->mutable_payload());
// Validation for ShellController.0
bool success = true;
std::string p_name{};
ShellController_GetSwitchValue_ParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadName(&p_name))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ShellController::Name_, 0, false);
return false;
}
auto callback =
ShellController_GetSwitchValue_ProxyToResponder::CreateCallback(
*message, std::move(responder));
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->GetSwitchValue(
std::move(p_name), std::move(callback));
return true;
}
case messages::ShellController::kExecuteJavaScript: {
internal::ShellController_ExecuteJavaScript_Params_Data* params =
reinterpret_cast<
internal::ShellController_ExecuteJavaScript_Params_Data*>(
message->mutable_payload());
// Validation for ShellController.1
bool success = true;
::std::u16string p_script{};
ShellController_ExecuteJavaScript_ParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadScript(&p_script))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
ShellController::Name_, 1, false);
return false;
}
auto callback =
ShellController_ExecuteJavaScript_ProxyToResponder::CreateCallback(
*message, std::move(responder));
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->ExecuteJavaScript(
std::move(p_script), std::move(callback));
return true;
}
case messages::ShellController::kShutDown: {
break;
}
}
return false;
}
namespace {
} // namespace
static const mojo::internal::GenericValidationInfo kShellControllerValidationInfo[] = {
{ &internal::ShellController_GetSwitchValue_Params_Data::Validate,
&internal::ShellController_GetSwitchValue_ResponseParams_Data::Validate},
{ &internal::ShellController_ExecuteJavaScript_Params_Data::Validate,
&internal::ShellController_ExecuteJavaScript_ResponseParams_Data::Validate},
{ &internal::ShellController_ShutDown_Params_Data::Validate,
nullptr /* no response */},
};
bool ShellControllerRequestValidator::Accept(mojo::Message* message) {
return mojo::internal::ValidateRequestGenericPacked(
message,
::content::mojom::ShellController::Name_,
kShellControllerValidationInfo);
}
bool ShellControllerResponseValidator::Accept(mojo::Message* message) {
return mojo::internal::ValidateResponseGenericPacked(
message,
::content::mojom::ShellController::Name_,
kShellControllerValidationInfo);
}
} // content::mojom
namespace mojo {
} // namespace mojo
// Symbols declared in the -test-utils.h header are defined here instead of a
// separate .cc file to save compile time.
namespace content::mojom {
void ShellControllerInterceptorForTesting::GetSwitchValue(const std::string& name, GetSwitchValueCallback callback) {
GetForwardingInterface()->GetSwitchValue(
std::move(name)
, std::move(callback));
}
void ShellControllerInterceptorForTesting::ExecuteJavaScript(const ::std::u16string& script, ExecuteJavaScriptCallback callback) {
GetForwardingInterface()->ExecuteJavaScript(
std::move(script)
, std::move(callback));
}
void ShellControllerInterceptorForTesting::ShutDown() {
GetForwardingInterface()->ShutDown();
}
ShellControllerAsyncWaiter::ShellControllerAsyncWaiter(
ShellController* proxy) : proxy_(proxy) {}
ShellControllerAsyncWaiter::~ShellControllerAsyncWaiter() = default;
void ShellControllerAsyncWaiter::GetSwitchValue(
const std::string& name, std::optional<std::string>* out_value) {
base::RunLoop loop;
proxy_->GetSwitchValue(
std::move(name),
base::BindOnce(
[](base::RunLoop* loop,
std::optional<std::string>* out_value
,
const std::optional<std::string>& value) {*out_value = std::move(value);
loop->Quit();
},
&loop,
out_value));
loop.Run();
}
std::optional<std::string> ShellControllerAsyncWaiter::GetSwitchValue(
const std::string& name) {
std::optional<std::string> async_wait_result;
GetSwitchValue(std::move(name),&async_wait_result);
return async_wait_result;
}
void ShellControllerAsyncWaiter::ExecuteJavaScript(
const ::std::u16string& script, ::base::Value* out_value) {
base::RunLoop loop;
proxy_->ExecuteJavaScript(
std::move(script),
base::BindOnce(
[](base::RunLoop* loop,
::base::Value* out_value
,
::base::Value value) {*out_value = std::move(value);
loop->Quit();
},
&loop,
out_value));
loop.Run();
}
::base::Value ShellControllerAsyncWaiter::ExecuteJavaScript(
const ::std::u16string& script) {
::base::Value async_wait_result;
ExecuteJavaScript(std::move(script),&async_wait_result);
return async_wait_result;
}
} // content::mojom
#if defined(__clang__)
#pragma clang diagnostic pop
#endif