| // services/device/public/mojom/geolocation.mojom-blink.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 "services/device/public/mojom/geolocation.mojom-blink.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 "services/device/public/mojom/geolocation.mojom-params-data.h" |
| #include "services/device/public/mojom/geolocation.mojom-shared-message-ids.h" |
| |
| #include "services/device/public/mojom/geolocation.mojom-blink-import-headers.h" |
| #include "services/device/public/mojom/geolocation.mojom-blink-test-utils.h" |
| #include "mojo/public/cpp/bindings/lib/wtf_serialization.h" |
| |
| |
| #ifndef SERVICES_DEVICE_PUBLIC_MOJOM_GEOLOCATION_MOJOM_BLINK_JUMBO_H_ |
| #define SERVICES_DEVICE_PUBLIC_MOJOM_GEOLOCATION_MOJOM_BLINK_JUMBO_H_ |
| #endif |
| |
| |
| |
| namespace device { |
| namespace mojom { |
| namespace blink { |
| const char Geolocation::Name_[] = "device.mojom.Geolocation"; |
| |
| std::pair<uint32_t, const void*> Geolocation::MessageToMethodInfo_(mojo::Message& message) { |
| switch (message.name()) { |
| case internal::kGeolocation_SetHighAccuracy_Name: { |
| constexpr uint32_t value = base::MD5Hash32Constexpr( |
| "(Impl)device::mojom::Geolocation::SetHighAccuracy"); |
| #if BUILDFLAG(IS_FUCHSIA) |
| return std::make_pair(value, nullptr); |
| #else |
| return std::make_pair(value, reinterpret_cast<const void*>(&Geolocation::SetHighAccuracy_Sym::IPCSymbol)); |
| #endif // BUILDFLAG(IS_FUCHSIA) |
| } |
| case internal::kGeolocation_QueryNextPosition_Name: { |
| constexpr uint32_t value = base::MD5Hash32Constexpr( |
| "(Impl)device::mojom::Geolocation::QueryNextPosition"); |
| #if BUILDFLAG(IS_FUCHSIA) |
| return std::make_pair(value, nullptr); |
| #else |
| return std::make_pair(value, reinterpret_cast<const void*>(&Geolocation::QueryNextPosition_Sym::IPCSymbol)); |
| #endif // BUILDFLAG(IS_FUCHSIA) |
| } |
| } |
| return std::make_pair(0, nullptr); |
| } |
| |
| |
| const char* Geolocation::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::kGeolocation_SetHighAccuracy_Name: |
| return "Receive device::mojom::Geolocation::SetHighAccuracy"; |
| case internal::kGeolocation_QueryNextPosition_Name: |
| return "Receive device::mojom::Geolocation::QueryNextPosition"; |
| } |
| } else { |
| switch (message.name()) { |
| case internal::kGeolocation_SetHighAccuracy_Name: |
| return "Receive reply device::mojom::Geolocation::SetHighAccuracy"; |
| case internal::kGeolocation_QueryNextPosition_Name: |
| return "Receive reply device::mojom::Geolocation::QueryNextPosition"; |
| } |
| } |
| 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 Geolocation::SetHighAccuracy_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 Geolocation::QueryNextPosition_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 Geolocation_QueryNextPosition_ForwardToCallback |
| : public mojo::MessageReceiver { |
| public: |
| Geolocation_QueryNextPosition_ForwardToCallback( |
| Geolocation::QueryNextPositionCallback callback |
| ) : callback_(std::move(callback)) { |
| } |
| |
| Geolocation_QueryNextPosition_ForwardToCallback(const Geolocation_QueryNextPosition_ForwardToCallback&) = delete; |
| Geolocation_QueryNextPosition_ForwardToCallback& operator=(const Geolocation_QueryNextPosition_ForwardToCallback&) = delete; |
| |
| bool Accept(mojo::Message* message) override; |
| private: |
| Geolocation::QueryNextPositionCallback callback_; |
| }; |
| |
| GeolocationProxy::GeolocationProxy(mojo::MessageReceiverWithResponder* receiver) |
| : receiver_(receiver) { |
| } |
| |
| void GeolocationProxy::SetHighAccuracy( |
| bool in_high_accuracy) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send device::mojom::Geolocation::SetHighAccuracy", "input_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("high_accuracy"), in_high_accuracy, |
| "<value of type bool>"); |
| }); |
| #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::kGeolocation_SetHighAccuracy_Name, kFlags, 0, 0, nullptr); |
| mojo::internal::MessageFragment< |
| ::device::mojom::internal::Geolocation_SetHighAccuracy_Params_Data> params( |
| message); |
| params.Allocate(); |
| params->high_accuracy = in_high_accuracy; |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(Geolocation::Name_); |
| message.set_method_name("SetHighAccuracy"); |
| #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); |
| } |
| |
| void GeolocationProxy::QueryNextPosition( |
| QueryNextPositionCallback callback) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "Send device::mojom::Geolocation::QueryNextPosition"); |
| #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::kGeolocation_QueryNextPosition_Name, kFlags, 0, 0, nullptr); |
| mojo::internal::MessageFragment< |
| ::device::mojom::internal::Geolocation_QueryNextPosition_Params_Data> params( |
| message); |
| params.Allocate(); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(Geolocation::Name_); |
| message.set_method_name("QueryNextPosition"); |
| #endif |
| std::unique_ptr<mojo::MessageReceiver> responder( |
| new Geolocation_QueryNextPosition_ForwardToCallback( |
| std::move(callback))); |
| ::mojo::internal::SendMessage(*receiver_, message, std::move(responder)); |
| } |
| class Geolocation_QueryNextPosition_ProxyToResponder : public ::mojo::internal::ProxyToResponder { |
| public: |
| static Geolocation::QueryNextPositionCallback CreateCallback( |
| ::mojo::Message& message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| std::unique_ptr<Geolocation_QueryNextPosition_ProxyToResponder> proxy( |
| new Geolocation_QueryNextPosition_ProxyToResponder( |
| message, std::move(responder))); |
| return base::BindOnce(&Geolocation_QueryNextPosition_ProxyToResponder::Run, |
| std::move(proxy)); |
| } |
| |
| ~Geolocation_QueryNextPosition_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: |
| Geolocation_QueryNextPosition_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) |
| << "Geolocation::QueryNextPositionCallback 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( |
| ::device::mojom::blink::GeopositionPtr in_geoposition); |
| }; |
| |
| bool Geolocation_QueryNextPosition_ForwardToCallback::Accept( |
| mojo::Message* message) { |
| |
| DCHECK(message->is_serialized()); |
| internal::Geolocation_QueryNextPosition_ResponseParams_Data* params = |
| reinterpret_cast< |
| internal::Geolocation_QueryNextPosition_ResponseParams_Data*>( |
| message->mutable_payload()); |
| |
| bool success = true; |
| ::device::mojom::blink::GeopositionPtr p_geoposition{}; |
| Geolocation_QueryNextPosition_ResponseParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadGeoposition(&p_geoposition)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| Geolocation::Name_, 1, true); |
| return false; |
| } |
| if (!callback_.is_null()) |
| std::move(callback_).Run( |
| std::move(p_geoposition)); |
| return true; |
| } |
| |
| void Geolocation_QueryNextPosition_ProxyToResponder::Run( |
| ::device::mojom::blink::GeopositionPtr in_geoposition) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send reply device::mojom::Geolocation::QueryNextPosition", "async_response_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("geoposition"), in_geoposition, |
| "<value of type ::device::mojom::blink::GeopositionPtr>"); |
| }); |
| #endif |
| |
| const uint32_t kFlags = mojo::Message::kFlagIsResponse | |
| ((is_sync_) ? mojo::Message::kFlagIsSync : 0) | |
| ((true) ? 0 : mojo::Message::kFlagNoInterrupt); |
| |
| mojo::Message message( |
| internal::kGeolocation_QueryNextPosition_Name, kFlags, 0, 0, nullptr); |
| mojo::internal::MessageFragment< |
| ::device::mojom::internal::Geolocation_QueryNextPosition_ResponseParams_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->geoposition)::BaseType> geoposition_fragment( |
| params.message()); |
| mojo::internal::Serialize<::device::mojom::GeopositionDataView>( |
| in_geoposition, geoposition_fragment); |
| params->geoposition.Set( |
| geoposition_fragment.is_null() ? nullptr : geoposition_fragment.data()); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| params->geoposition.is_null(), |
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| "null geoposition in "); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(Geolocation::Name_); |
| message.set_method_name("QueryNextPosition"); |
| #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 GeolocationStubDispatch::Accept( |
| Geolocation* impl, |
| mojo::Message* message) { |
| switch (message->header()->name) { |
| case internal::kGeolocation_SetHighAccuracy_Name: { |
| |
| DCHECK(message->is_serialized()); |
| internal::Geolocation_SetHighAccuracy_Params_Data* params = |
| reinterpret_cast<internal::Geolocation_SetHighAccuracy_Params_Data*>( |
| message->mutable_payload()); |
| |
| bool success = true; |
| bool p_high_accuracy{}; |
| Geolocation_SetHighAccuracy_ParamsDataView input_data_view(params, message); |
| |
| if (success) |
| p_high_accuracy = input_data_view.high_accuracy(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| Geolocation::Name_, 0, false); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->SetHighAccuracy( |
| std::move(p_high_accuracy)); |
| return true; |
| } |
| case internal::kGeolocation_QueryNextPosition_Name: { |
| break; |
| } |
| } |
| return false; |
| } |
| |
| // static |
| bool GeolocationStubDispatch::AcceptWithResponder( |
| Geolocation* 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::kGeolocation_SetHighAccuracy_Name: { |
| break; |
| } |
| case internal::kGeolocation_QueryNextPosition_Name: { |
| |
| internal::Geolocation_QueryNextPosition_Params_Data* params = |
| reinterpret_cast< |
| internal::Geolocation_QueryNextPosition_Params_Data*>( |
| message->mutable_payload()); |
| |
| bool success = true; |
| Geolocation_QueryNextPosition_ParamsDataView input_data_view(params, message); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| Geolocation::Name_, 1, false); |
| return false; |
| } |
| Geolocation::QueryNextPositionCallback callback = |
| Geolocation_QueryNextPosition_ProxyToResponder::CreateCallback( |
| *message, std::move(responder)); |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->QueryNextPosition(std::move(callback)); |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| |
| static const mojo::internal::GenericValidationInfo kGeolocationValidationInfo[] = { |
| {&internal::Geolocation_SetHighAccuracy_Params_Data::Validate, |
| nullptr /* no response */}, |
| {&internal::Geolocation_QueryNextPosition_Params_Data::Validate, |
| &internal::Geolocation_QueryNextPosition_ResponseParams_Data::Validate}, |
| }; |
| |
| bool GeolocationRequestValidator::Accept(mojo::Message* message) { |
| const char* name = ::device::mojom::blink::Geolocation::Name_; |
| return mojo::internal::ValidateRequestGenericPacked(message, name, kGeolocationValidationInfo); |
| } |
| |
| bool GeolocationResponseValidator::Accept(mojo::Message* message) { |
| const char* name = ::device::mojom::blink::Geolocation::Name_; |
| return mojo::internal::ValidateResponseGenericPacked(message, name, kGeolocationValidationInfo); |
| } |
| |
| |
| } // namespace blink |
| } // namespace mojom |
| } // namespace device |
| |
| |
| 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 device { |
| namespace mojom { |
| namespace blink { |
| |
| |
| void GeolocationInterceptorForTesting::SetHighAccuracy(bool high_accuracy) { |
| GetForwardingInterface()->SetHighAccuracy(std::move(high_accuracy)); |
| } |
| void GeolocationInterceptorForTesting::QueryNextPosition(QueryNextPositionCallback callback) { |
| GetForwardingInterface()->QueryNextPosition(std::move(callback)); |
| } |
| GeolocationAsyncWaiter::GeolocationAsyncWaiter( |
| Geolocation* proxy) : proxy_(proxy) {} |
| |
| GeolocationAsyncWaiter::~GeolocationAsyncWaiter() = default; |
| |
| void GeolocationAsyncWaiter::QueryNextPosition( |
| ::device::mojom::blink::GeopositionPtr* out_geoposition) { |
| base::RunLoop loop; |
| proxy_->QueryNextPosition( |
| base::BindOnce( |
| [](base::RunLoop* loop, |
| ::device::mojom::blink::GeopositionPtr* out_geoposition |
| , |
| ::device::mojom::blink::GeopositionPtr geoposition) {*out_geoposition = std::move(geoposition); |
| loop->Quit(); |
| }, |
| &loop, |
| out_geoposition)); |
| loop.Run(); |
| } |
| |
| |
| |
| |
| |
| } // namespace blink |
| } // namespace mojom |
| } // namespace device |
| |
| |
| #if defined(__clang__) |
| #pragma clang diagnostic pop |
| #endif |