| // 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 "services/device/public/interfaces/geolocation_context.mojom.h" |
| |
| #include <math.h> |
| #include <stdint.h> |
| #include <utility> |
| |
| #include "base/logging.h" |
| #include "base/run_loop.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 "services/device/public/interfaces/geolocation_context.mojom-shared-message-ids.h" |
| #include "mojo/common/time_struct_traits.h" |
| namespace device { |
| namespace mojom { |
| const char GeolocationContext::Name_[] = "device::mojom::GeolocationContext"; |
| |
| GeolocationContextProxy::GeolocationContextProxy(mojo::MessageReceiverWithResponder* receiver) |
| : receiver_(receiver) { |
| } |
| |
| void GeolocationContextProxy::BindGeolocation( |
| ::device::mojom::GeolocationRequest in_request) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::GeolocationContext::BindGeolocation"); |
| #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::kGeolocationContext_BindGeolocation_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::GeolocationContext_BindGeolocation_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| mojo::internal::Serialize<::device::mojom::GeolocationRequestDataView>( |
| in_request, ¶ms->request, &serialization_context); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| !mojo::internal::IsHandleOrInterfaceValid(params->request), |
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, |
| "invalid request in GeolocationContext.BindGeolocation request"); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| // 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)); |
| } |
| |
| void GeolocationContextProxy::SetOverride( |
| ::device::mojom::GeopositionPtr in_geoposition) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::GeolocationContext::SetOverride"); |
| #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::kGeolocationContext_SetOverride_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::GeolocationContext_SetOverride_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| typename decltype(params->geoposition)::BaseType::BufferWriter |
| geoposition_writer; |
| mojo::internal::Serialize<::device::mojom::GeopositionDataView>( |
| in_geoposition, buffer, &geoposition_writer, &serialization_context); |
| params->geoposition.Set( |
| geoposition_writer.is_null() ? nullptr : geoposition_writer.data()); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| params->geoposition.is_null(), |
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| "null geoposition in GeolocationContext.SetOverride request"); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| // 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)); |
| } |
| |
| void GeolocationContextProxy::ClearOverride( |
| ) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::GeolocationContext::ClearOverride"); |
| #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::kGeolocationContext_ClearOverride_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::GeolocationContext_ClearOverride_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| // 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 GeolocationContextStubDispatch::Accept( |
| GeolocationContext* impl, |
| mojo::Message* message) { |
| switch (message->header()->name) { |
| case internal::kGeolocationContext_BindGeolocation_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::GeolocationContext::BindGeolocation", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::GeolocationContext_BindGeolocation_Params_Data* params = |
| reinterpret_cast<internal::GeolocationContext_BindGeolocation_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| ::device::mojom::GeolocationRequest p_request{}; |
| GeolocationContext_BindGeolocation_ParamsDataView input_data_view(params, &serialization_context); |
| |
| p_request = |
| input_data_view.TakeRequest<decltype(p_request)>(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "GeolocationContext::BindGeolocation deserializer"); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->BindGeolocation( |
| std::move(p_request)); |
| return true; |
| } |
| case internal::kGeolocationContext_SetOverride_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::GeolocationContext::SetOverride", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::GeolocationContext_SetOverride_Params_Data* params = |
| reinterpret_cast<internal::GeolocationContext_SetOverride_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| ::device::mojom::GeopositionPtr p_geoposition{}; |
| GeolocationContext_SetOverride_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!input_data_view.ReadGeoposition(&p_geoposition)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "GeolocationContext::SetOverride deserializer"); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->SetOverride( |
| std::move(p_geoposition)); |
| return true; |
| } |
| case internal::kGeolocationContext_ClearOverride_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::GeolocationContext::ClearOverride", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::GeolocationContext_ClearOverride_Params_Data* params = |
| reinterpret_cast<internal::GeolocationContext_ClearOverride_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| GeolocationContext_ClearOverride_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "GeolocationContext::ClearOverride deserializer"); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->ClearOverride(); |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| // static |
| bool GeolocationContextStubDispatch::AcceptWithResponder( |
| GeolocationContext* impl, |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| switch (message->header()->name) { |
| case internal::kGeolocationContext_BindGeolocation_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::GeolocationContext::BindGeolocation", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| case internal::kGeolocationContext_SetOverride_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::GeolocationContext::SetOverride", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| case internal::kGeolocationContext_ClearOverride_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::GeolocationContext::ClearOverride", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| } |
| return false; |
| } |
| |
| bool GeolocationContextRequestValidator::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, |
| "GeolocationContext RequestValidator"); |
| |
| switch (message->header()->name) { |
| case internal::kGeolocationContext_BindGeolocation_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::GeolocationContext_BindGeolocation_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kGeolocationContext_SetOverride_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::GeolocationContext_SetOverride_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kGeolocationContext_ClearOverride_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::GeolocationContext_ClearOverride_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; |
| } |
| |
| void GeolocationContextInterceptorForTesting::BindGeolocation(::device::mojom::GeolocationRequest request) { |
| GetForwardingInterface()->BindGeolocation(std::move(request)); |
| } |
| void GeolocationContextInterceptorForTesting::SetOverride(::device::mojom::GeopositionPtr geoposition) { |
| GetForwardingInterface()->SetOverride(std::move(geoposition)); |
| } |
| void GeolocationContextInterceptorForTesting::ClearOverride() { |
| GetForwardingInterface()->ClearOverride(); |
| } |
| GeolocationContextAsyncWaiter::GeolocationContextAsyncWaiter( |
| GeolocationContext* proxy) : proxy_(proxy) {} |
| |
| GeolocationContextAsyncWaiter::~GeolocationContextAsyncWaiter() = default; |
| |
| |
| } // namespace mojom |
| } // namespace device |
| |
| namespace mojo { |
| |
| } // namespace mojo |
| |
| #if defined(__clang__) |
| #pragma clang diagnostic pop |
| #elif defined(_MSC_VER) |
| #pragma warning(pop) |
| #endif |