Commit d81b759b authored by zhaobin's avatar zhaobin Committed by Commit bot

[net] Add a typemap for net::IPAddress

To resolve code review comments from https://codereview.chromium.org/2675033002/diff/280001/chrome/browser/media/router/mojo/media_router.mojom

Create an ip_address.mojom to be used by media_router.mojom

BUG=698423

Review-Url: https://codereview.chromium.org/2745643002
Cr-Commit-Position: refs/heads/master@{#456115}
parent 70482db4
...@@ -7,6 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -7,6 +7,7 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") { mojom("interfaces") {
sources = [ sources = [
"host_resolver_service.mojom", "host_resolver_service.mojom",
"ip_address.mojom",
"proxy_resolver_service.mojom", "proxy_resolver_service.mojom",
] ]
public_deps = [ public_deps = [
......
per-file *.mojom=set noparent per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module net.interfaces;
// Mirror of net::IPAddress.
struct IPAddress {
// IP address as a numeric value from most to least significant byte.
// Will be of length 4 for IPv4 addresses and 16 for IPv6.
array<uint8> address;
};
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//net/interfaces/ip_address.mojom"
public_headers = [ "//net/base/ip_address.h" ]
traits_headers = [ "//net/interfaces/ip_address_struct_traits.h" ]
sources = [
"//net/interfaces/ip_address_struct_traits.cc",
]
type_mappings = [ "net.interfaces.IPAddress=net::IPAddress" ]
public_deps = [
"//net",
]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/interfaces/ip_address_struct_traits.h"
namespace mojo {
// static
bool StructTraits<net::interfaces::IPAddressDataView, net::IPAddress>::Read(
net::interfaces::IPAddressDataView data,
net::IPAddress* out) {
std::vector<uint8_t> bytes;
if (!data.ReadAddress(&bytes))
return false;
*out = net::IPAddress(bytes);
return out->IsValid();
}
} // namespace mojo
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_
#define NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "net/base/ip_address.h"
#include "net/interfaces/ip_address.mojom.h"
namespace mojo {
template <>
struct StructTraits<net::interfaces::IPAddressDataView, net::IPAddress> {
static const std::vector<uint8_t>& address(const net::IPAddress& ip_address) {
return ip_address.bytes();
}
static bool Read(net::interfaces::IPAddressDataView obj, net::IPAddress* out);
};
} // namespace mojo
#endif // NET_INTERFACES_IP_ADDRESS_STRUCT_TRAITS_H_
...@@ -4,5 +4,6 @@ ...@@ -4,5 +4,6 @@
typemaps = [ typemaps = [
"//net/interfaces/host_resolver.typemap", "//net/interfaces/host_resolver.typemap",
"//net/interfaces/ip_address.typemap",
"//net/interfaces/proxy_resolver.typemap", "//net/interfaces/proxy_resolver.typemap",
] ]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment