| Index: ppapi/cpp/vpn_provider.cc
|
| diff --git a/ppapi/cpp/vpn_provider.cc b/ppapi/cpp/vpn_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..975f995485ca8326134e4c286acbb11bd949d3df
|
| --- /dev/null
|
| +++ b/ppapi/cpp/vpn_provider.cc
|
| @@ -0,0 +1,171 @@
|
| +// Copyright 2015 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 "ppapi/cpp/vpn_provider.h"
|
| +
|
| +#include "ppapi/c/ppb_vpn_provider.h"
|
| +#include "ppapi/cpp/instance.h"
|
| +#include "ppapi/cpp/instance_handle.h"
|
| +#include "ppapi/cpp/module.h"
|
| +#include "ppapi/cpp/module_impl.h"
|
| +#include "ppapi/cpp/var_array.h"
|
| +
|
| +namespace pp {
|
| +
|
| +namespace {
|
| +
|
| +template <>
|
| +const char* interface_name<PPB_VpnProvider_0_1>() {
|
| + return PPB_VPNPROVIDER_INTERFACE_0_1;
|
| +}
|
| +} // namespace
|
| +
|
| +VpnProvider::VpnProvider(Instance* instance) : associated_instance_(instance) {
|
| + instance->AddPerInstanceObject(PPB_VPNPROVIDER_INTERFACE_0_1, this);
|
| +
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + PassRefFromConstructor(get_interface<PPB_VpnProvider_0_1>()->Create(
|
| + associated_instance_.pp_instance()));
|
| + }
|
| +}
|
| +
|
| +VpnProvider::~VpnProvider() {
|
| + Instance::RemovePerInstanceObject(associated_instance_,
|
| + PPB_VPNPROVIDER_INTERFACE_0_1, this);
|
| +}
|
| +
|
| +// static
|
| +bool VpnProvider::IsAvailable() {
|
| + return has_interface<PPB_VpnProvider_0_1>();
|
| +}
|
| +
|
| +int32_t VpnProvider::CreateConfig(
|
| + const std::string& name,
|
| + const CompletionCallbackWithOutput<Var>& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + pp::Var name_var(name);
|
| + return get_interface<PPB_VpnProvider_0_1>()->CreateConfig(
|
| + pp_resource(), name_var.pp_var(), callback.output(),
|
| + callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::DestroyConfig(const std::string& id,
|
| + const CompletionCallback& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + pp::Var id_var(id);
|
| +
|
| + return get_interface<PPB_VpnProvider_0_1>()->DestroyConfig(
|
| + pp_resource(), id_var.pp_var(), callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::SetParameters(
|
| + const std::string& address,
|
| + const std::string& broadcastAddress,
|
| + const int32_t& mtu,
|
| + const std::vector<std::string>& exclusionList,
|
| + const std::vector<std::string>& inclusionList,
|
| + const std::vector<std::string>& domainSearch,
|
| + const std::vector<std::string>& dnsServers,
|
| + const CompletionCallback& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + pp::Var address_var(address);
|
| + pp::Var broadcastAddress_var(broadcastAddress);
|
| +
|
| + // Convert protocols to C interface.
|
| + VarArray exclusionList_var;
|
| + exclusionList_var.SetLength(exclusionList.size());
|
| + if (exclusionList.size()) {
|
| + for (uint32_t i = 0; i < exclusionList.size(); ++i)
|
| + exclusionList_var.Set(i, Var(exclusionList[i]));
|
| + }
|
| +
|
| + VarArray inclusionList_var;
|
| + inclusionList_var.SetLength(inclusionList.size());
|
| + if (inclusionList.size()) {
|
| + for (uint32_t i = 0; i < inclusionList.size(); ++i)
|
| + inclusionList_var.Set(i, Var(inclusionList[i]));
|
| + }
|
| +
|
| + VarArray domains_var;
|
| + domains_var.SetLength(domainSearch.size());
|
| + if (domainSearch.size()) {
|
| + for (uint32_t i = 0; i < domainSearch.size(); ++i)
|
| + domains_var.Set(i, Var(domainSearch[i]));
|
| + }
|
| +
|
| + VarArray dnsServers_var;
|
| + dnsServers_var.SetLength(dnsServers.size());
|
| + if (dnsServers.size()) {
|
| + for (uint32_t i = 0; i < dnsServers.size(); ++i)
|
| + dnsServers_var.Set(i, Var(dnsServers[i]));
|
| + }
|
| +
|
| + return get_interface<PPB_VpnProvider_0_1>()->SetParameters(
|
| + pp_resource(), address_var.pp_var(), broadcastAddress_var.pp_var(), mtu,
|
| + exclusionList_var.pp_var(), inclusionList_var.pp_var(),
|
| + domains_var.pp_var(), dnsServers_var.pp_var(),
|
| + callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::SendPacket(const Var& packet) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + return get_interface<PPB_VpnProvider_0_1>()->SendPacket(pp_resource(),
|
| + packet.pp_var());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::NotifyConnectionStateChanged(
|
| + PP_VpnProvider_VpnConnectionState status,
|
| + const CompletionCallback& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + return get_interface<PPB_VpnProvider_0_1>()->NotifyConnectionStateChanged(
|
| + pp_resource(), status, callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::GetPacket(
|
| + const CompletionCallbackWithOutput<Var>& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + return get_interface<PPB_VpnProvider_0_1>()->GetPacket(
|
| + pp_resource(), callback.output(), callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::GetPlatformMessage(
|
| + const CompletionCallbackWithOutput<Var>& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + return get_interface<PPB_VpnProvider_0_1>()->GetPlatformMessage(
|
| + pp_resource(), callback.output(), callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::GetConfigMessage(
|
| + const CompletionCallbackWithOutput<Var>& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + return get_interface<PPB_VpnProvider_0_1>()->GetConfigMessage(
|
| + pp_resource(), callback.output(), callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +int32_t VpnProvider::GetUIMessage(
|
| + const CompletionCallbackWithOutput<Var>& callback) {
|
| + if (has_interface<PPB_VpnProvider_0_1>()) {
|
| + return get_interface<PPB_VpnProvider_0_1>()->GetUIMessage(
|
| + pp_resource(), callback.output(), callback.pp_completion_callback());
|
| + }
|
| + return PP_ERROR_NOINTERFACE;
|
| +}
|
| +
|
| +} // namespace pp
|
|
|