// third_party/blink/public/mojom/loader/referrer.mojom.h 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.

#ifndef THIRD_PARTY_BLINK_PUBLIC_MOJOM_LOADER_REFERRER_MOJOM_H_
#define THIRD_PARTY_BLINK_PUBLIC_MOJOM_LOADER_REFERRER_MOJOM_H_

#include <stdint.h>

#include <limits>
#include <optional>
#include <type_traits>
#include <utility>
#include "mojo/public/cpp/bindings/clone_traits.h"
#include "mojo/public/cpp/bindings/equals_traits.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
#include "mojo/public/cpp/bindings/lib/serialization.h"

#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h"

#include "third_party/blink/public/mojom/loader/referrer.mojom-features.h"  // IWYU pragma: export
#include "third_party/blink/public/mojom/loader/referrer.mojom-shared.h"  // IWYU pragma: export
#include "third_party/blink/public/mojom/loader/referrer.mojom-forward.h"  // IWYU pragma: export
#include "url/mojom/url.mojom.h"
#include "services/network/public/mojom/referrer_policy.mojom-forward.h"
#include <string>
#include <vector>




#include "third_party/blink/public/common/common_export.h"




namespace blink::mojom {








class BLINK_COMMON_EXPORT Referrer {
 public:
  template <typename T>
  using EnableIfSame = std::enable_if_t<std::is_same<Referrer, T>::value>;
  using DataView = ReferrerDataView;
  using Data_ = internal::Referrer_Data;

  template <typename... Args>
  static ReferrerPtr New(Args&&... args) {
    return ReferrerPtr(
        std::in_place, std::forward<Args>(args)...);
  }

  template <typename U>
  static ReferrerPtr From(const U& u) {
    return mojo::TypeConverter<ReferrerPtr, U>::Convert(u);
  }

  template <typename U>
  U To() const {
    return mojo::TypeConverter<U, Referrer>::Convert(*this);
  }


  Referrer();

  Referrer(
      const ::GURL& url,
      ::network::mojom::ReferrerPolicy policy);


  ~Referrer();

  // Clone() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Clone() or copy
  // constructor/assignment are available for members.
  template <typename StructPtrType = ReferrerPtr>
  ReferrerPtr Clone() const;

  // Equals() is a template so it is only instantiated if it is used. Thus, the
  // bindings generator does not need to know whether Equals() or == operator
  // are available for members.
  template <typename T, Referrer::EnableIfSame<T>* = nullptr>
  bool Equals(const T& other) const;

  template <typename T, Referrer::EnableIfSame<T>* = nullptr>
  bool operator==(const T& rhs) const { return Equals(rhs); }

  template <typename T, Referrer::EnableIfSame<T>* = nullptr>
  bool operator!=(const T& rhs) const { return !operator==(rhs); }

  template <mojo::internal::SendValidation send_validation, typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        Referrer::DataView, std::vector<uint8_t>, send_validation>(input);
  }

  template <typename UserType>
  static std::vector<uint8_t> Serialize(UserType* input) {
    return mojo::internal::SerializeImpl<
        Referrer::DataView, std::vector<uint8_t>>(input);
  }

  template <typename UserType>
  static mojo::Message SerializeAsMessage(UserType* input) {
    return mojo::internal::SerializeAsMessageImpl<
        Referrer::DataView>(input);
  }

  // The returned Message is serialized only if the message is moved
  // cross-process or cross-language. Otherwise if the message is Deserialized
  // as the same UserType |input| will just be moved to |output| in
  // DeserializeFromMessage.
  template <typename UserType>
  static mojo::Message WrapAsMessage(UserType input) {
    return mojo::Message(std::make_unique<
        internal::Referrer_UnserializedMessageContext<
            UserType, Referrer::DataView>>(0, 0, std::move(input)),
        MOJO_CREATE_MESSAGE_FLAG_NONE);
  }

  template <typename UserType>
  static bool Deserialize(const void* data,
                          size_t data_num_bytes,
                          UserType* output) {
    mojo::Message message;
    return mojo::internal::DeserializeImpl<Referrer::DataView>(
        message, data, data_num_bytes, output, Validate);
  }

  template <typename UserType>
  static bool Deserialize(base::span<const uint8_t> input,
                          UserType* output) {
    return Referrer::Deserialize(
        input.empty() ? nullptr : input.data(), input.size(), output);
  }

  template <typename UserType>
  static bool DeserializeFromMessage(mojo::Message input,
                                     UserType* output) {
    auto context = input.TakeUnserializedContext<
        internal::Referrer_UnserializedMessageContext<
            UserType, Referrer::DataView>>();
    if (context) {
      *output = std::move(context->TakeData());
      return true;
    }
    input.SerializeIfNecessary();
    return mojo::internal::DeserializeImpl<Referrer::DataView>(
        input, input.payload(), input.payload_num_bytes(), output, Validate);
  }

  
  ::GURL url;
  
  ::network::mojom::ReferrerPolicy policy;

  // Serialise this struct into a trace.
  void WriteIntoTrace(perfetto::TracedValue traced_context) const;

 private:
  static bool Validate(const void* data,
                       mojo::internal::ValidationContext* validation_context);
};

// The comparison operators are templates, so they are only instantiated if they
// are used. Thus, the bindings generator does not need to know whether
// comparison operators are available for members.
template <typename T, Referrer::EnableIfSame<T>* = nullptr>
bool operator<(const T& lhs, const T& rhs);

template <typename T, Referrer::EnableIfSame<T>* = nullptr>
bool operator<=(const T& lhs, const T& rhs) {
  return !(rhs < lhs);
}

template <typename T, Referrer::EnableIfSame<T>* = nullptr>
bool operator>(const T& lhs, const T& rhs) {
  return rhs < lhs;
}

template <typename T, Referrer::EnableIfSame<T>* = nullptr>
bool operator>=(const T& lhs, const T& rhs) {
  return !(lhs < rhs);
}

template <typename StructPtrType>
ReferrerPtr Referrer::Clone() const {
  return New(
      mojo::Clone(url),
      mojo::Clone(policy)
  );
}

template <typename T, Referrer::EnableIfSame<T>*>
bool Referrer::Equals(const T& other_struct) const {
  if (!mojo::Equals(this->url, other_struct.url))
    return false;
  if (!mojo::Equals(this->policy, other_struct.policy))
    return false;
  return true;
}

template <typename T, Referrer::EnableIfSame<T>*>
bool operator<(const T& lhs, const T& rhs) {
  if (lhs.url < rhs.url)
    return true;
  if (rhs.url < lhs.url)
    return false;
  if (lhs.policy < rhs.policy)
    return true;
  if (rhs.policy < lhs.policy)
    return false;
  return false;
}


}  // blink::mojom

namespace mojo {


template <>
struct BLINK_COMMON_EXPORT StructTraits<::blink::mojom::Referrer::DataView,
                                         ::blink::mojom::ReferrerPtr> {
  static bool IsNull(const ::blink::mojom::ReferrerPtr& input) { return !input; }
  static void SetToNull(::blink::mojom::ReferrerPtr* output) { output->reset(); }

  static const decltype(::blink::mojom::Referrer::url)& url(
      const ::blink::mojom::ReferrerPtr& input) {
    return input->url;
  }

  static decltype(::blink::mojom::Referrer::policy) policy(
      const ::blink::mojom::ReferrerPtr& input) {
    return input->policy;
  }

  static bool Read(::blink::mojom::Referrer::DataView input, ::blink::mojom::ReferrerPtr* output);
};

}  // namespace mojo

#endif  // THIRD_PARTY_BLINK_PUBLIC_MOJOM_LOADER_REFERRER_MOJOM_H_