• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "base/component_export.h"
10 #include "base/unguessable_token.h"
11 #include "mojo/public/cpp/base/unguessable_token_mojom_traits.h"
12 #include "mojo/public/cpp/bindings/optional_as_pointer.h"
13 #include "url/mojom/origin.mojom-shared.h"
14 #include "url/origin.h"
15 
16 namespace mojo {
17 
18 template <>
COMPONENT_EXPORT(URL_MOJOM_TRAITS)19 struct COMPONENT_EXPORT(URL_MOJOM_TRAITS)
20     StructTraits<url::mojom::OriginDataView, url::Origin> {
21   static const std::string& scheme(const url::Origin& r) {
22     return r.GetTupleOrPrecursorTupleIfOpaque().scheme();
23   }
24   static const std::string& host(const url::Origin& r) {
25     return r.GetTupleOrPrecursorTupleIfOpaque().host();
26   }
27   static uint16_t port(const url::Origin& r) {
28     return r.GetTupleOrPrecursorTupleIfOpaque().port();
29   }
30   static mojo::OptionalAsPointer<const base::UnguessableToken> nonce_if_opaque(
31       const url::Origin& r) {
32     return mojo::OptionalAsPointer(r.GetNonceForSerialization());
33   }
34   static bool Read(url::mojom::OriginDataView data, url::Origin* out);
35 };
36 
37 }  // namespace mojo
38 
39 #endif  // URL_MOJOM_ORIGIN_MOJOM_TRAITS_H_
40