• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 #include "url/mojom/scheme_host_port_mojom_traits.h"
6 
7 #include "base/strings/string_piece.h"
8 #include "url/mojom/scheme_host_port.mojom-shared.h"
9 #include "url/scheme_host_port.h"
10 
11 namespace mojo {
12 
13 // static
14 bool StructTraits<url::mojom::SchemeHostPortDataView, url::SchemeHostPort>::
Read(url::mojom::SchemeHostPortDataView data,url::SchemeHostPort * out)15     Read(url::mojom::SchemeHostPortDataView data, url::SchemeHostPort* out) {
16   base::StringPiece scheme, host;
17   if (!data.ReadScheme(&scheme) || !data.ReadHost(&host))
18     return false;
19 
20   *out = url::SchemeHostPort(scheme, host, data.port());
21 
22   // Consider it an error if the output SchemeHostPort is not valid, but
23   // non-empty values were received over Mojo.
24   return out->IsValid() || (scheme.empty() && host.empty() && data.port() == 0);
25 }
26 
27 }  // namespace mojo
28