/* Copyright 2016 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. */ /* From ppb_vpn_provider.idl modified Fri May 6 20:42:01 2016. */ #ifndef PPAPI_C_PPB_VPN_PROVIDER_H_ #define PPAPI_C_PPB_VPN_PROVIDER_H_ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_macros.h" #include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_var.h" #define PPB_VPNPROVIDER_INTERFACE_0_1 "PPB_VpnProvider;0.1" /* dev */ /** * @file * This file defines the PPB_VpnProvider interface. */ /** * @addtogroup Interfaces * @{ */ /** * Use the PPB_VpnProvider interface to implement a VPN client. * Important: This API is available only on Chrome OS. * * This interface enhances the chrome.vpnProvider JavaScript API by * providing a high performance path for packet handling. * * Permissions: Apps permission vpnProvider is required for * PPB_VpnProvider.Bind(). * * Typical usage: * - Create a PPB_VpnProvider instance. * - Register the callback for PPB_VpnProvider.ReceivePacket(). * - In the extension follow the usual workflow for configuring a VPN connection * via the chrome.vpnProvider API until the step for notifying * the connection state as "connected". * - Bind to the previously created connection using * PPB_VpnProvider.Bind(). * - Notify the connection state as "connected" from JavaScript using * chrome.vpnProvider.notifyConnectionStateChanged. * - When the steps above are completed without errors, a virtual tunnel is * created to the network stack of Chrome OS. IP packets can be sent through * the tunnel using PPB_VpnProvider.SendPacket() and any packets * originating on the Chrome OS device will be received using the callback * registered for PPB_VpnProvider.ReceivePacket(). * - When the user disconnects from the VPN configuration or there is an error * the extension will be notfied via * chrome.vpnProvider.onPlatformMessage. */ struct PPB_VpnProvider_0_1 { /* dev */ /** * Create() creates a VpnProvider instance. * * @param[in] instance A PP_Instance identifying the instance * with the VpnProvider. * * @return A PP_Resource corresponding to a VpnProvider if * successful. */ PP_Resource (*Create)(PP_Instance instance); /** * IsVpnProvider() determines if the provided resource is a * VpnProvider instance. * * @param[in] resource A PP_Resource corresponding to a * VpnProvider. * * @return Returns PP_TRUE if resource is a * PPB_VpnProvider, PP_FALSE if the * resource is invalid or some type other than * PPB_VpnProvider. */ PP_Bool (*IsVpnProvider)(PP_Resource resource); /** * Bind() binds to an existing configuration created from JavaScript by * chrome.vpnProvider.createConfig. All packets will be routed * via SendPacket and ReceivePacket. The user should * register the callback for ReceivePacket before calling * Bind(). * * @param[in] vpn_provider A PP_Resource corresponding to a * VpnProvider. * * @param[in] configuration_id A PP_VARTYPE_STRING representing * the configuration id from the callback of * chrome.vpnProvider.createConfig. * * @param[in] configuration_name A PP_VARTYPE_STRING representing * the configuration name as defined by the user when calling * chrome.vpnProvider.createConfig. * * @param[in] callback A PP_CompletionCallback called on * completion. * * @return An int32_t containing an error code from pp_errors.h. * Returns PP_ERROR_INPROGRESS if a previous call to * Bind() has not completed. * Returns PP_ERROR_BADARGUMENT if either * configuration_id or configuration_name are not of * type PP_VARTYPE_STRING. * Returns PP_ERROR_NOACCESS if the caller does the have the * required "vpnProvider" permission. * Returns PP_ERROR_FAILED if connection_id and * connection_name could not be matched with the existing * connection, or if the plugin originates from a different extension than the * one that created the connection. */ int32_t (*Bind)(PP_Resource vpn_provider, struct PP_Var configuration_id, struct PP_Var configuration_name, struct PP_CompletionCallback callback); /** * SendPacket() sends an IP packet through the tunnel created for the VPN * session. This will succeed only when the VPN session is owned by the * module and the connection is bound. * * @param[in] vpn_provider A PP_Resource corresponding to a * VpnProvider. * * @param[in] packet A PP_VARTYPE_ARRAY_BUFFER corresponding to * an IP packet to be sent to the platform. * * @param[in] callback A PP_CompletionCallback called on * completion. * * @return An int32_t containing an error code from pp_errors.h. * Returns PP_ERROR_FAILED if the connection is not bound. * Returns PP_ERROR_INPROGRESS if a previous call to * SendPacket() has not completed. * Returns PP_ERROR_BADARGUMENT if packet is not of * type PP_VARTYPE_ARRAY_BUFFER. */ int32_t (*SendPacket)(PP_Resource vpn_provider, struct PP_Var packet, struct PP_CompletionCallback callback); /** * ReceivePacket() receives an IP packet from the tunnel for the VPN session. * This function only returns a single packet. This function must be called at * least N times to receive N packets, no matter the size of each packet. The * callback should be registered before calling Bind(). * * @param[in] vpn_provider A PP_Resource corresponding to a * VpnProvider. * * @param[out] packet The received packet is copied to provided * packet. The packet must remain valid until * ReceivePacket() completes. Its received PP_VarType will be * PP_VARTYPE_ARRAY_BUFFER. * * @param[in] callback A PP_CompletionCallback called on * completion. * * @return An int32_t containing an error code from pp_errors.h. * Returns PP_ERROR_INPROGRESS if a previous call to * ReceivePacket() has not completed. */ int32_t (*ReceivePacket)(PP_Resource vpn_provider, struct PP_Var* packet, struct PP_CompletionCallback callback); }; /** * @} */ #endif /* PPAPI_C_PPB_VPN_PROVIDER_H_ */