OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #ifndef PPAPI_CPP_VPN_PROVIDER_H_ |
| 6 #define PPAPI_CPP_VPN_PROVIDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "ppapi/c/ppb_vpn_provider.h" |
| 11 #include "ppapi/cpp/completion_callback.h" |
| 12 |
| 13 namespace pp { |
| 14 |
| 15 class InstanceHandle; |
| 16 |
| 17 /// @file |
| 18 /// This file defines the VpnProvider interface providing a way to implement a |
| 19 /// VPN client. |
| 20 /// Important: This API is available only on Chrome OS. |
| 21 |
| 22 /// The <code>VpnProvider</code> class providing a way to implement a VPN |
| 23 /// client. |
| 24 class VpnProvider : public Resource { |
| 25 public: |
| 26 /// Constructs a VpnProvider object. |
| 27 /// |
| 28 /// @param[in] instance The instance with which this resource will be |
| 29 /// associated. |
| 30 explicit VpnProvider(const InstanceHandle& instance); |
| 31 |
| 32 /// Destructs a WebSocket object. |
| 33 virtual ~VpnProvider(); |
| 34 |
| 35 /// Static function for determining whether the browser supports the |
| 36 /// <code>VpnProvider</code> interface. |
| 37 /// |
| 38 /// @return true if the interface is available, false otherwise. |
| 39 static bool IsAvailable(); |
| 40 |
| 41 /// Binds to an existing configuration created by |
| 42 /// <code>chrome.vpnProvider.createConfig</code>. All packets will be routed |
| 43 /// via <code>SendPacket</code> and <code>ReceivePacket</code>. |
| 44 /// |
| 45 /// @param[in] configuration_id The configuration id from the callback of |
| 46 /// <code>chrome.vpnProvider.createConfig</code>. |
| 47 /// |
| 48 /// @param[in] configuration_name The configuration name as defined by the |
| 49 /// user when calling <code>chrome.vpnProvider.createConfig</code>. |
| 50 /// |
| 51 /// @param[in] callback A <code>CompletionCallback</code> to be |
| 52 /// called upon completion of Bind. |
| 53 int32_t Bind(const Var& configuration_id, |
| 54 const Var& configuration_name, |
| 55 const CompletionCallback& callback); |
| 56 |
| 57 /// GetUnbindEvent() registers a callback that will be called when the current |
| 58 /// configuration gets unbound. |
| 59 /// |
| 60 /// @param[in] callback A <code>PP_CompletionCallback</code> called when |
| 61 /// the current configuration gets unbound. |
| 62 int32_t GetUnbindEvent(const CompletionCallback& callback); |
| 63 |
| 64 /// Sends an IP packet through the tunnel created for the VPN session. This |
| 65 /// will succeed only when the VPN session is owned by the module. |
| 66 /// |
| 67 /// @param[in] data IP packet to be sent to the platform. The <code>Var</code> |
| 68 /// will be of ArrayBuffer type. |
| 69 int32_t SendPacket(const Var& packet, const CompletionCallback& callback); |
| 70 |
| 71 /// Receives an IP packet from the tunnel for the VPN session. |
| 72 /// This function only returns a single packet. That is, this function must |
| 73 /// be called at least N times to receive N packets, no matter the size of |
| 74 /// each packet. |
| 75 /// |
| 76 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 77 /// called upon completion of ReceivePacket. It will be passed an ArrayBuffer |
| 78 /// type <code>Var</code> containing an IP packet to be sent to the platform. |
| 79 /// |
| 80 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 81 /// If an error is detected or connection is closed, ReceivePacket() returns |
| 82 /// <code>PP_ERROR_FAILED</code> after all buffered messages are received. |
| 83 /// Until buffered packets become empty, ReceivePacket() continues to return |
| 84 /// <code>PP_OK</code> as if connection is still established without errors. |
| 85 int32_t ReceivePacket(const CompletionCallbackWithOutput<Var>& callback); |
| 86 |
| 87 private: |
| 88 InstanceHandle associated_instance_; |
| 89 }; |
| 90 |
| 91 } // namespace pp |
| 92 |
| 93 #endif // PPAPI_CPP_VPN_PROVIDER_H_ |
OLD | NEW |