Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / ppapi / cpp / network_list.cc
blob12c3bf4c96ce91f45070b3a0b3d4854a36698aba
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/network_list.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/cpp/array_output.h"
9 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module_impl.h"
11 #include "ppapi/cpp/net_address.h"
12 #include "ppapi/cpp/var.h"
14 namespace pp {
16 namespace {
18 template <> const char* interface_name<PPB_NetworkList_1_0>() {
19 return PPB_NETWORKLIST_INTERFACE_1_0;
22 } // namespace
24 NetworkList::NetworkList() {
27 NetworkList::NetworkList(PassRef, PP_Resource resource)
28 : Resource(PASS_REF, resource) {
31 // static
32 bool NetworkList::IsAvailable() {
33 return has_interface<PPB_NetworkList_1_0>();
36 uint32_t NetworkList::GetCount() const {
37 if (!has_interface<PPB_NetworkList_1_0>())
38 return 0;
39 return get_interface<PPB_NetworkList_1_0>()->GetCount(pp_resource());
42 std::string NetworkList::GetName(uint32_t index) const {
43 if (!has_interface<PPB_NetworkList_1_0>())
44 return std::string();
45 Var result(PASS_REF,
46 get_interface<PPB_NetworkList_1_0>()->GetName(
47 pp_resource(), index));
48 return result.is_string() ? result.AsString() : std::string();
51 PP_NetworkList_Type NetworkList::GetType(uint32_t index) const {
52 if (!has_interface<PPB_NetworkList_1_0>())
53 return PP_NETWORKLIST_TYPE_ETHERNET;
54 return get_interface<PPB_NetworkList_1_0>()->GetType(
55 pp_resource(), index);
58 PP_NetworkList_State NetworkList::GetState(uint32_t index) const {
59 if (!has_interface<PPB_NetworkList_1_0>())
60 return PP_NETWORKLIST_STATE_DOWN;
61 return get_interface<PPB_NetworkList_1_0>()->GetState(
62 pp_resource(), index);
65 int32_t NetworkList::GetIpAddresses(
66 uint32_t index,
67 std::vector<NetAddress>* addresses) const {
68 if (!has_interface<PPB_NetworkList_1_0>())
69 return PP_ERROR_NOINTERFACE;
70 if (!addresses)
71 return PP_ERROR_BADARGUMENT;
73 ResourceArrayOutputAdapter<NetAddress> adapter(addresses);
74 return get_interface<PPB_NetworkList_1_0>()->GetIpAddresses(
75 pp_resource(), index, adapter.pp_array_output());
78 std::string NetworkList::GetDisplayName(uint32_t index) const {
79 if (!has_interface<PPB_NetworkList_1_0>())
80 return std::string();
81 Var result(PASS_REF,
82 get_interface<PPB_NetworkList_1_0>()->GetDisplayName(
83 pp_resource(), index));
84 return result.is_string() ? result.AsString() : std::string();
87 uint32_t NetworkList::GetMTU(uint32_t index) const {
88 if (!has_interface<PPB_NetworkList_1_0>())
89 return 0;
90 return get_interface<PPB_NetworkList_1_0>()->GetMTU(
91 pp_resource(), index);
94 } // namespace pp