OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #include "ppapi/cpp/vpn_provider.h" |
| 6 |
| 7 #include "ppapi/c/ppb_vpn_provider.h" |
| 8 #include "ppapi/cpp/instance.h" |
| 9 #include "ppapi/cpp/instance_handle.h" |
| 10 #include "ppapi/cpp/module.h" |
| 11 #include "ppapi/cpp/module_impl.h" |
| 12 #include "ppapi/cpp/var_array.h" |
| 13 |
| 14 namespace pp { |
| 15 |
| 16 namespace { |
| 17 |
| 18 template <> |
| 19 const char* interface_name<PPB_VpnProvider_0_1>() { |
| 20 return PPB_VPNPROVIDER_INTERFACE_0_1; |
| 21 } |
| 22 } // namespace |
| 23 |
| 24 VpnProvider::VpnProvider(Instance* instance) : associated_instance_(instance) { |
| 25 instance->AddPerInstanceObject(PPB_VPNPROVIDER_INTERFACE_0_1, this); |
| 26 |
| 27 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 28 PassRefFromConstructor(get_interface<PPB_VpnProvider_0_1>()->Create( |
| 29 associated_instance_.pp_instance())); |
| 30 } |
| 31 } |
| 32 |
| 33 VpnProvider::~VpnProvider() { |
| 34 Instance::RemovePerInstanceObject(associated_instance_, |
| 35 PPB_VPNPROVIDER_INTERFACE_0_1, this); |
| 36 } |
| 37 |
| 38 // static |
| 39 bool VpnProvider::IsAvailable() { |
| 40 return has_interface<PPB_VpnProvider_0_1>(); |
| 41 } |
| 42 |
| 43 int32_t VpnProvider::CreateConfig( |
| 44 const std::string& name, |
| 45 const CompletionCallbackWithOutput<Var>& callback) { |
| 46 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 47 pp::Var name_var(name); |
| 48 return get_interface<PPB_VpnProvider_0_1>()->CreateConfig( |
| 49 pp_resource(), name_var.pp_var(), callback.output(), |
| 50 callback.pp_completion_callback()); |
| 51 } |
| 52 return PP_ERROR_NOINTERFACE; |
| 53 } |
| 54 |
| 55 int32_t VpnProvider::DestroyConfig(const std::string& id, |
| 56 const CompletionCallback& callback) { |
| 57 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 58 pp::Var id_var(id); |
| 59 |
| 60 return get_interface<PPB_VpnProvider_0_1>()->DestroyConfig( |
| 61 pp_resource(), id_var.pp_var(), callback.pp_completion_callback()); |
| 62 } |
| 63 return PP_ERROR_NOINTERFACE; |
| 64 } |
| 65 |
| 66 int32_t VpnProvider::SetParameters( |
| 67 const std::string& address, |
| 68 const std::string& broadcastAddress, |
| 69 const int32_t& mtu, |
| 70 const std::vector<std::string>& exclusionList, |
| 71 const std::vector<std::string>& inclusionList, |
| 72 const std::vector<std::string>& domainSearch, |
| 73 const std::vector<std::string>& dnsServers, |
| 74 const CompletionCallback& callback) { |
| 75 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 76 pp::Var address_var(address); |
| 77 pp::Var broadcastAddress_var(broadcastAddress); |
| 78 |
| 79 // Convert protocols to C interface. |
| 80 VarArray exclusionList_var; |
| 81 exclusionList_var.SetLength(exclusionList.size()); |
| 82 if (exclusionList.size()) { |
| 83 for (uint32_t i = 0; i < exclusionList.size(); ++i) |
| 84 exclusionList_var.Set(i, Var(exclusionList[i])); |
| 85 } |
| 86 |
| 87 VarArray inclusionList_var; |
| 88 inclusionList_var.SetLength(inclusionList.size()); |
| 89 if (inclusionList.size()) { |
| 90 for (uint32_t i = 0; i < inclusionList.size(); ++i) |
| 91 inclusionList_var.Set(i, Var(inclusionList[i])); |
| 92 } |
| 93 |
| 94 VarArray domains_var; |
| 95 domains_var.SetLength(domainSearch.size()); |
| 96 if (domainSearch.size()) { |
| 97 for (uint32_t i = 0; i < domainSearch.size(); ++i) |
| 98 domains_var.Set(i, Var(domainSearch[i])); |
| 99 } |
| 100 |
| 101 VarArray dnsServers_var; |
| 102 dnsServers_var.SetLength(dnsServers.size()); |
| 103 if (dnsServers.size()) { |
| 104 for (uint32_t i = 0; i < dnsServers.size(); ++i) |
| 105 dnsServers_var.Set(i, Var(dnsServers[i])); |
| 106 } |
| 107 |
| 108 return get_interface<PPB_VpnProvider_0_1>()->SetParameters( |
| 109 pp_resource(), address_var.pp_var(), broadcastAddress_var.pp_var(), mtu, |
| 110 exclusionList_var.pp_var(), inclusionList_var.pp_var(), |
| 111 domains_var.pp_var(), dnsServers_var.pp_var(), |
| 112 callback.pp_completion_callback()); |
| 113 } |
| 114 return PP_ERROR_NOINTERFACE; |
| 115 } |
| 116 |
| 117 int32_t VpnProvider::SendPacket(const Var& packet) { |
| 118 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 119 return get_interface<PPB_VpnProvider_0_1>()->SendPacket(pp_resource(), |
| 120 packet.pp_var()); |
| 121 } |
| 122 return PP_ERROR_NOINTERFACE; |
| 123 } |
| 124 |
| 125 int32_t VpnProvider::NotifyConnectionStateChanged( |
| 126 PP_VpnProvider_VpnConnectionState status, |
| 127 const CompletionCallback& callback) { |
| 128 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 129 return get_interface<PPB_VpnProvider_0_1>()->NotifyConnectionStateChanged( |
| 130 pp_resource(), status, callback.pp_completion_callback()); |
| 131 } |
| 132 return PP_ERROR_NOINTERFACE; |
| 133 } |
| 134 |
| 135 int32_t VpnProvider::GetPacket( |
| 136 const CompletionCallbackWithOutput<Var>& callback) { |
| 137 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 138 return get_interface<PPB_VpnProvider_0_1>()->GetPacket( |
| 139 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 140 } |
| 141 return PP_ERROR_NOINTERFACE; |
| 142 } |
| 143 |
| 144 int32_t VpnProvider::GetPlatformMessage( |
| 145 const CompletionCallbackWithOutput<Var>& callback) { |
| 146 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 147 return get_interface<PPB_VpnProvider_0_1>()->GetPlatformMessage( |
| 148 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 149 } |
| 150 return PP_ERROR_NOINTERFACE; |
| 151 } |
| 152 |
| 153 int32_t VpnProvider::GetConfigMessage( |
| 154 const CompletionCallbackWithOutput<Var>& callback) { |
| 155 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 156 return get_interface<PPB_VpnProvider_0_1>()->GetConfigMessage( |
| 157 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 158 } |
| 159 return PP_ERROR_NOINTERFACE; |
| 160 } |
| 161 |
| 162 int32_t VpnProvider::GetUIMessage( |
| 163 const CompletionCallbackWithOutput<Var>& callback) { |
| 164 if (has_interface<PPB_VpnProvider_0_1>()) { |
| 165 return get_interface<PPB_VpnProvider_0_1>()->GetUIMessage( |
| 166 pp_resource(), callback.output(), callback.pp_completion_callback()); |
| 167 } |
| 168 return PP_ERROR_NOINTERFACE; |
| 169 } |
| 170 |
| 171 } // namespace pp |
OLD | NEW |