// services/network/public/mojom/document_isolation_policy.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 "services/network/public/mojom/document_isolation_policy.mojom.h"
#include <math.h>
#include <stdint.h>
#include <utility>
#include "base/debug/alias.h"
#include "base/notreached.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 "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/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 "services/network/public/mojom/document_isolation_policy.mojom-params-data.h"
#include "services/network/public/mojom/document_isolation_policy.mojom-shared-message-ids.h"

#include "services/network/public/mojom/document_isolation_policy.mojom-import-headers.h"
#include "services/network/public/mojom/document_isolation_policy.mojom-test-utils.h"


namespace network::mojom {
DocumentIsolationPolicy::DocumentIsolationPolicy()
    : value(DocumentIsolationPolicyValue::kNone),
      reporting_endpoint(),
      report_only_value(DocumentIsolationPolicyValue::kNone),
      report_only_reporting_endpoint() {}

DocumentIsolationPolicy::DocumentIsolationPolicy(
    DocumentIsolationPolicyValue value_in,
    const std::optional<std::string>& reporting_endpoint_in,
    DocumentIsolationPolicyValue report_only_value_in,
    const std::optional<std::string>& report_only_reporting_endpoint_in)
    : value(std::move(value_in)),
      reporting_endpoint(std::move(reporting_endpoint_in)),
      report_only_value(std::move(report_only_value_in)),
      report_only_reporting_endpoint(std::move(report_only_reporting_endpoint_in)) {}

DocumentIsolationPolicy::~DocumentIsolationPolicy() = default;

void DocumentIsolationPolicy::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "value"), this->value,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type DocumentIsolationPolicyValue>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "reporting_endpoint"), this->reporting_endpoint,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::optional<std::string>&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "report_only_value"), this->report_only_value,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type DocumentIsolationPolicyValue>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "report_only_reporting_endpoint"), this->report_only_reporting_endpoint,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::optional<std::string>&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool DocumentIsolationPolicy::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
// The declaration includes the definition on other builds.

DocumentIsolationPolicyReporter::IPCStableHashFunction DocumentIsolationPolicyReporter::MessageToMethodInfo_(mojo::Message& message) {
#if !BUILDFLAG(IS_FUCHSIA)
  switch (static_cast<messages::DocumentIsolationPolicyReporter>(message.name())) {
    case messages::DocumentIsolationPolicyReporter::kQueueCorpViolationReport: {
      return &DocumentIsolationPolicyReporter::QueueCorpViolationReport_Sym::IPCStableHash;
    }
    case messages::DocumentIsolationPolicyReporter::kClone: {
      return &DocumentIsolationPolicyReporter::Clone_Sym::IPCStableHash;
    }
  }
#endif  // !BUILDFLAG(IS_FUCHSIA)
  return nullptr;
}


const char* DocumentIsolationPolicyReporter::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::DocumentIsolationPolicyReporter>(message.name())) {
      case messages::DocumentIsolationPolicyReporter::kQueueCorpViolationReport:
            return "Receive network::mojom::DocumentIsolationPolicyReporter::QueueCorpViolationReport";
      case messages::DocumentIsolationPolicyReporter::kClone:
            return "Receive network::mojom::DocumentIsolationPolicyReporter::Clone";
    }
  } else {
    switch (static_cast<messages::DocumentIsolationPolicyReporter>(message.name())) {
      case messages::DocumentIsolationPolicyReporter::kQueueCorpViolationReport:
            return "Receive reply network::mojom::DocumentIsolationPolicyReporter::QueueCorpViolationReport";
      case messages::DocumentIsolationPolicyReporter::kClone:
            return "Receive reply network::mojom::DocumentIsolationPolicyReporter::Clone";
    }
  }
  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 DocumentIsolationPolicyReporter::QueueCorpViolationReport_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 = 0x03f9e04d;  // IPCStableHash for network::mojom::DocumentIsolationPolicyReporter::QueueCorpViolationReport
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t DocumentIsolationPolicyReporter::Clone_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 = 0xba5e450e;  // IPCStableHash for network::mojom::DocumentIsolationPolicyReporter::Clone
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
# endif // !BUILDFLAG(IS_FUCHSIA)

DocumentIsolationPolicyReporterProxy::DocumentIsolationPolicyReporterProxy(mojo::MessageReceiverWithResponder* receiver)
    : receiver_(receiver) {
}

void DocumentIsolationPolicyReporterProxy::QueueCorpViolationReport(
    const ::GURL& in_blocked_url, ::network::mojom::RequestDestination in_destination, bool in_report_only) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send network::mojom::DocumentIsolationPolicyReporter::QueueCorpViolationReport", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("blocked_url"), in_blocked_url,
                        "<value of type const ::GURL&>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("destination"), in_destination,
                        "<value of type ::network::mojom::RequestDestination>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("report_only"), in_report_only,
                        "<value of type bool>");
   });
#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(
      std::to_underlying(messages::DocumentIsolationPolicyReporter::kQueueCorpViolationReport), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::network::mojom::internal::DocumentIsolationPolicyReporter_QueueCorpViolationReport_Params_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->blocked_url)::BaseType> blocked_url_fragment(
          params.message());
  
  mojo::internal::Serialize<::url::mojom::UrlDataView>(
    in_blocked_url,
    blocked_url_fragment);

  params->blocked_url.Set(
      blocked_url_fragment.is_null() ? nullptr : blocked_url_fragment.data());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(params->blocked_url.is_null()),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
    "null blocked_url in DocumentIsolationPolicyReporter.QueueCorpViolationReport request");

  
  mojo::internal::Serialize<::network::mojom::RequestDestination>(
    in_destination,
    &params->destination);

  params->report_only = in_report_only;

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(DocumentIsolationPolicyReporter::Name_);
  message.set_method_name("QueueCorpViolationReport");
#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);
}

void DocumentIsolationPolicyReporterProxy::Clone(
    ::mojo::PendingReceiver<DocumentIsolationPolicyReporter> in_receiver) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send network::mojom::DocumentIsolationPolicyReporter::Clone", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("receiver"), in_receiver,
                        "<value of type ::mojo::PendingReceiver<DocumentIsolationPolicyReporter>>");
   });
#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(
      std::to_underlying(messages::DocumentIsolationPolicyReporter::kClone), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::network::mojom::internal::DocumentIsolationPolicyReporter_Clone_Params_Data> params(
          message);
  params.Allocate();

  
  mojo::internal::Serialize<mojo::InterfaceRequestDataView<::network::mojom::DocumentIsolationPolicyReporterInterfaceBase>>(
    in_receiver,
    &params->receiver,
    &params.message());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(!mojo::internal::IsHandleOrInterfaceValid(params->receiver)),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
    "invalid receiver in DocumentIsolationPolicyReporter.Clone request");

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(DocumentIsolationPolicyReporter::Name_);
  message.set_method_name("Clone");
#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);
}

// static
bool DocumentIsolationPolicyReporterStubDispatch::Accept(
    DocumentIsolationPolicyReporter* impl,
    mojo::Message* message) {
  switch (static_cast<messages::DocumentIsolationPolicyReporter>(message->header()->name)) {
    case messages::DocumentIsolationPolicyReporter::kQueueCorpViolationReport: {
      DCHECK(message->is_serialized());
      internal::DocumentIsolationPolicyReporter_QueueCorpViolationReport_Params_Data* params =
          reinterpret_cast<internal::DocumentIsolationPolicyReporter_QueueCorpViolationReport_Params_Data*>(
              message->mutable_payload());
      

      // Validation for DocumentIsolationPolicyReporter.0
      bool success = true;
      ::GURL p_blocked_url{};
      ::network::mojom::RequestDestination p_destination{};
      bool p_report_only{};
      DocumentIsolationPolicyReporter_QueueCorpViolationReport_ParamsDataView input_data_view(params, message);
      
      if (success && !input_data_view.ReadBlockedUrl(&p_blocked_url))
        success = false;
      if (success && !input_data_view.ReadDestination(&p_destination))
        success = false;
      if (success)
        p_report_only = input_data_view.report_only();
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            DocumentIsolationPolicyReporter::Name_, 0, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->QueueCorpViolationReport(        
        std::move(p_blocked_url), 
        std::move(p_destination), 
        std::move(p_report_only));
      return true;
    }
    case messages::DocumentIsolationPolicyReporter::kClone: {
      DCHECK(message->is_serialized());
      internal::DocumentIsolationPolicyReporter_Clone_Params_Data* params =
          reinterpret_cast<internal::DocumentIsolationPolicyReporter_Clone_Params_Data*>(
              message->mutable_payload());
      

      // Validation for DocumentIsolationPolicyReporter.1
      bool success = true;
      ::mojo::PendingReceiver<DocumentIsolationPolicyReporter> p_receiver{};
      DocumentIsolationPolicyReporter_Clone_ParamsDataView input_data_view(params, message);
      
      if (success) {
        p_receiver =
            input_data_view.TakeReceiver<decltype(p_receiver)>();
      }
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            DocumentIsolationPolicyReporter::Name_, 1, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->Clone(        
        std::move(p_receiver));
      return true;
    }
  }
  return false;
}

// static
bool DocumentIsolationPolicyReporterStubDispatch::AcceptWithResponder(
    DocumentIsolationPolicyReporter* 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::DocumentIsolationPolicyReporter>(message->header()->name)) {
    case messages::DocumentIsolationPolicyReporter::kQueueCorpViolationReport: {
      break;
    }
    case messages::DocumentIsolationPolicyReporter::kClone: {
      break;
    }
  }
  return false;
}
namespace {
}  // namespace
static const mojo::internal::GenericValidationInfo kDocumentIsolationPolicyReporterValidationInfo[] = {
    { &internal::DocumentIsolationPolicyReporter_QueueCorpViolationReport_Params_Data::Validate,
     nullptr /* no response */},
    { &internal::DocumentIsolationPolicyReporter_Clone_Params_Data::Validate,
     nullptr /* no response */},
};

bool DocumentIsolationPolicyReporterRequestValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateRequestGenericPacked(
    message,
    ::network::mojom::DocumentIsolationPolicyReporter::Name_,
    kDocumentIsolationPolicyReporterValidationInfo);
}



}  // network::mojom


namespace mojo {


// static
bool StructTraits<::network::mojom::DocumentIsolationPolicy::DataView, ::network::mojom::DocumentIsolationPolicyPtr>::Read(
    ::network::mojom::DocumentIsolationPolicy::DataView input,
    ::network::mojom::DocumentIsolationPolicyPtr* output) {
  bool success = true;
  ::network::mojom::DocumentIsolationPolicyPtr result(::network::mojom::DocumentIsolationPolicy::New());
  
      if (success && !input.ReadValue(&result->value))
        success = false;
      if (success && !input.ReadReportingEndpoint(&result->reporting_endpoint))
        success = false;
      if (success && !input.ReadReportOnlyValue(&result->report_only_value))
        success = false;
      if (success && !input.ReadReportOnlyReportingEndpoint(&result->report_only_reporting_endpoint))
        success = false;
  *output = std::move(result);
  return success;
}

}  // namespace mojo


// Symbols declared in the -test-utils.h header are defined here instead of a
// separate .cc file to save compile time.


namespace network::mojom {


void DocumentIsolationPolicyReporterInterceptorForTesting::QueueCorpViolationReport(const ::GURL& blocked_url, ::network::mojom::RequestDestination destination, bool report_only) {
  GetForwardingInterface()->QueueCorpViolationReport(
    std::move(blocked_url)
    , 
    std::move(destination)
    , 
    std::move(report_only)
    );
}
void DocumentIsolationPolicyReporterInterceptorForTesting::Clone(::mojo::PendingReceiver<DocumentIsolationPolicyReporter> receiver) {
  GetForwardingInterface()->Clone(
    std::move(receiver)
    );
}
DocumentIsolationPolicyReporterAsyncWaiter::DocumentIsolationPolicyReporterAsyncWaiter(
    DocumentIsolationPolicyReporter* proxy) : proxy_(proxy) {}

DocumentIsolationPolicyReporterAsyncWaiter::~DocumentIsolationPolicyReporterAsyncWaiter() = default;







}  // network::mojom


#if defined(__clang__)
#pragma clang diagnostic pop
#endif