xref: /aosp_15_r20/external/cronet/url/mojom/origin_mojom_traits.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef URL_MOJOM_ORIGIN_MOJOM_TRAITS_H_
6 #define URL_MOJOM_ORIGIN_MOJOM_TRAITS_H_
7 
8 #include <optional>
9 
10 #include "base/component_export.h"
11 #include "base/unguessable_token.h"
12 #include "mojo/public/cpp/base/unguessable_token_mojom_traits.h"
13 #include "mojo/public/cpp/bindings/optional_as_pointer.h"
14 #include "url/mojom/origin.mojom-shared.h"
15 #include "url/origin.h"
16 
17 namespace mojo {
18 
19 template <>
COMPONENT_EXPORT(URL_MOJOM_TRAITS)20 struct COMPONENT_EXPORT(URL_MOJOM_TRAITS)
21     StructTraits<url::mojom::OriginDataView, url::Origin> {
22   static const std::string& scheme(const url::Origin& r) {
23     return r.GetTupleOrPrecursorTupleIfOpaque().scheme();
24   }
25   static const std::string& host(const url::Origin& r) {
26     return r.GetTupleOrPrecursorTupleIfOpaque().host();
27   }
28   static uint16_t port(const url::Origin& r) {
29     return r.GetTupleOrPrecursorTupleIfOpaque().port();
30   }
31   static mojo::OptionalAsPointer<const base::UnguessableToken> nonce_if_opaque(
32       const url::Origin& r) {
33     return mojo::OptionalAsPointer(r.GetNonceForSerialization());
34   }
35   static bool Read(url::mojom::OriginDataView data, url::Origin* out);
36 };
37 
38 }  // namespace mojo
39 
40 #endif  // URL_MOJOM_ORIGIN_MOJOM_TRAITS_H_
41