| // content/shell/common/shell_controller.test-mojom.cc is auto generated by mojom_bindings_generator.py, do not edit |
| |
| // 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" |
| #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/hash/md5_constexpr.h" |
| #include "base/run_loop.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/trace_event/trace_event.h" |
| #include "base/trace_event/typed_macros.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/send_message_helper.h" |
| #include "mojo/public/cpp/bindings/lib/proxy_to_responder.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/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" |
| |
| |
| #ifndef CONTENT_SHELL_COMMON_SHELL_CONTROLLER_TEST_MOJOM_JUMBO_H_ |
| #define CONTENT_SHELL_COMMON_SHELL_CONTROLLER_TEST_MOJOM_JUMBO_H_ |
| #endif |
| |
| |
| |
| namespace content { |
| namespace mojom { |
| const char ShellController::Name_[] = "content.mojom.ShellController"; |
| |
| std::pair<uint32_t, const void*> ShellController::MessageToMethodInfo_(mojo::Message& message) { |
| switch (message.name()) { |
| case internal::kShellController_GetSwitchValue_Name: { |
| constexpr uint32_t value = base::MD5Hash32Constexpr( |
| "(Impl)content::mojom::ShellController::GetSwitchValue"); |
| #if BUILDFLAG(IS_FUCHSIA) |
| return std::make_pair(value, nullptr); |
| #else |
| return std::make_pair(value, reinterpret_cast<const void*>(&ShellController::GetSwitchValue_Sym::IPCSymbol)); |
| #endif // BUILDFLAG(IS_FUCHSIA) |
| } |
| case internal::kShellController_ExecuteJavaScript_Name: { |
| constexpr uint32_t value = base::MD5Hash32Constexpr( |
| "(Impl)content::mojom::ShellController::ExecuteJavaScript"); |
| #if BUILDFLAG(IS_FUCHSIA) |
| return std::make_pair(value, nullptr); |
| #else |
| return std::make_pair(value, reinterpret_cast<const void*>(&ShellController::ExecuteJavaScript_Sym::IPCSymbol)); |
| #endif // BUILDFLAG(IS_FUCHSIA) |
| } |
| case internal::kShellController_ShutDown_Name: { |
| constexpr uint32_t value = base::MD5Hash32Constexpr( |
| "(Impl)content::mojom::ShellController::ShutDown"); |
| #if BUILDFLAG(IS_FUCHSIA) |
| return std::make_pair(value, nullptr); |
| #else |
| return std::make_pair(value, reinterpret_cast<const void*>(&ShellController::ShutDown_Sym::IPCSymbol)); |
| #endif // BUILDFLAG(IS_FUCHSIA) |
| } |
| } |
| return std::make_pair(0, 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 (message.name()) { |
| case internal::kShellController_GetSwitchValue_Name: |
| return "Receive content::mojom::ShellController::GetSwitchValue"; |
| case internal::kShellController_ExecuteJavaScript_Name: |
| return "Receive content::mojom::ShellController::ExecuteJavaScript"; |
| case internal::kShellController_ShutDown_Name: |
| return "Receive content::mojom::ShellController::ShutDown"; |
| } |
| } else { |
| switch (message.name()) { |
| case internal::kShellController_GetSwitchValue_Name: |
| return "Receive reply content::mojom::ShellController::GetSwitchValue"; |
| case internal::kShellController_ExecuteJavaScript_Name: |
| return "Receive reply content::mojom::ShellController::ExecuteJavaScript"; |
| case internal::kShellController_ShutDown_Name: |
| 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) |
| void ShellController::GetSwitchValue_Sym::IPCSymbol() { |
| // This method's address is used for indetifiying the mojo method name after |
| // symblozation. So each IPCSymbol should have a unique address. |
| NO_CODE_FOLDING(); |
| } |
| void ShellController::ExecuteJavaScript_Sym::IPCSymbol() { |
| // This method's address is used for indetifiying the mojo method name after |
| // symblozation. So each IPCSymbol should have a unique address. |
| NO_CODE_FOLDING(); |
| } |
| void ShellController::ShutDown_Sym::IPCSymbol() { |
| // This method's address is used for indetifiying the mojo method name after |
| // symblozation. So each IPCSymbol should have a unique address. |
| NO_CODE_FOLDING(); |
| } |
| # 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 uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0) | |
| ((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt); |
| |
| mojo::Message message( |
| internal::kShellController_GetSwitchValue_Name, kFlags, 0, 0, nullptr); |
| 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_DLOG_SERIALIZATION_WARNING( |
| 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::SendMessage(*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 uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0) | |
| ((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt); |
| |
| mojo::Message message( |
| internal::kShellController_ExecuteJavaScript_Name, kFlags, 0, 0, nullptr); |
| 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_DLOG_SERIALIZATION_WARNING( |
| 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::SendMessage(*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 uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0) | |
| ((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt); |
| |
| mojo::Message message( |
| internal::kShellController_ShutDown_Name, kFlags, 0, 0, nullptr); |
| 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::SendMessage(*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. |
| 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 absl::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()); |
| |
| bool success = true; |
| absl::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 absl::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 absl::optional<std::string>&>"); |
| }); |
| #endif |
| |
| const uint32_t kFlags = mojo::Message::kFlagIsResponse | |
| ((is_sync_) ? mojo::Message::kFlagIsSync : 0) | |
| ((true) ? 0 : mojo::Message::kFlagNoInterrupt); |
| |
| mojo::Message message( |
| internal::kShellController_GetSwitchValue_Name, kFlags, 0, 0, nullptr); |
| 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::SendMessage(*responder_, message); |
| // SendMessage 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. |
| 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()); |
| |
| 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); |
| |
| mojo::Message message( |
| internal::kShellController_ExecuteJavaScript_Name, kFlags, 0, 0, nullptr); |
| 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(¶ms->value); |
| mojo::internal::Serialize<::mojo_base::mojom::ValueDataView>( |
| in_value, value_fragment, true); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| 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::SendMessage(*responder_, message); |
| // SendMessage 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 (message->header()->name) { |
| case internal::kShellController_GetSwitchValue_Name: { |
| break; |
| } |
| case internal::kShellController_ExecuteJavaScript_Name: { |
| break; |
| } |
| case internal::kShellController_ShutDown_Name: { |
| |
| DCHECK(message->is_serialized()); |
| internal::ShellController_ShutDown_Params_Data* params = |
| reinterpret_cast<internal::ShellController_ShutDown_Params_Data*>( |
| message->mutable_payload()); |
| |
| 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 (message->header()->name) { |
| case internal::kShellController_GetSwitchValue_Name: { |
| |
| internal::ShellController_GetSwitchValue_Params_Data* params = |
| reinterpret_cast< |
| internal::ShellController_GetSwitchValue_Params_Data*>( |
| message->mutable_payload()); |
| |
| 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; |
| } |
| ShellController::GetSwitchValueCallback 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 internal::kShellController_ExecuteJavaScript_Name: { |
| |
| internal::ShellController_ExecuteJavaScript_Params_Data* params = |
| reinterpret_cast< |
| internal::ShellController_ExecuteJavaScript_Params_Data*>( |
| message->mutable_payload()); |
| |
| 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; |
| } |
| ShellController::ExecuteJavaScriptCallback 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 internal::kShellController_ShutDown_Name: { |
| break; |
| } |
| } |
| return false; |
| } |
| |
| |
| static const std::pair<uint32_t, mojo::internal::GenericValidationInfo> kShellControllerValidationInfo[] = { |
| {internal::kShellController_GetSwitchValue_Name, |
| {&internal::ShellController_GetSwitchValue_Params_Data::Validate, |
| &internal::ShellController_GetSwitchValue_ResponseParams_Data::Validate}}, |
| {internal::kShellController_ExecuteJavaScript_Name, |
| {&internal::ShellController_ExecuteJavaScript_Params_Data::Validate, |
| &internal::ShellController_ExecuteJavaScript_ResponseParams_Data::Validate}}, |
| {internal::kShellController_ShutDown_Name, |
| {&internal::ShellController_ShutDown_Params_Data::Validate, |
| nullptr /* no response */}}, |
| }; |
| |
| bool ShellControllerRequestValidator::Accept(mojo::Message* message) { |
| const char* name = ::content::mojom::ShellController::Name_; |
| return mojo::internal::ValidateRequestGeneric(message, name, kShellControllerValidationInfo); |
| } |
| |
| bool ShellControllerResponseValidator::Accept(mojo::Message* message) { |
| const char* name = ::content::mojom::ShellController::Name_; |
| return mojo::internal::ValidateResponseGeneric(message, name, kShellControllerValidationInfo); |
| |
| } |
| |
| |
| } // namespace mojom |
| } // namespace content |
| |
| |
| 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 { |
| namespace 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, absl::optional<std::string>* out_value) { |
| base::RunLoop loop; |
| proxy_->GetSwitchValue(std::move(name), |
| base::BindOnce( |
| [](base::RunLoop* loop, |
| absl::optional<std::string>* out_value |
| , |
| const absl::optional<std::string>& value) {*out_value = std::move(value); |
| loop->Quit(); |
| }, |
| &loop, |
| out_value)); |
| loop.Run(); |
| } |
| 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(); |
| } |
| |
| |
| |
| |
| |
| } // namespace mojom |
| } // namespace content |
| |
| |
| #if defined(__clang__) |
| #pragma clang diagnostic pop |
| #endif |