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 enhances the |
| 23 /// <code>chrome.vpnProvider</code> JavaScript API by providing a high |
| 24 /// performance path for packet handling. |
| 25 /// |
| 26 /// Permissions: Apps permission <code>vpnProvider</code> is required for |
| 27 /// <code>VpnProvider.Bind()</code>. |
| 28 /// |
| 29 /// Typical usage: |
| 30 /// - Create a <code>VpnProvider</code> instance. |
| 31 /// - Register callbacks via <code>VpnProvider.GetUnbindEvent()</code> and |
| 32 /// <code>VpnProvider.ReceivePacket()</code>. |
| 33 /// - In the extension follow the usual workflow for configuring a VPN |
| 34 /// connection via the <code>chrome.vpnProvider</code> API until the step for |
| 35 /// notifying the connection state as "connected". |
| 36 /// - Bind to the previously created connection using |
| 37 /// <code>VpnProvider.Bind()</code>. |
| 38 /// - Notify the connection state as "connected" from JavaScript using |
| 39 /// <code>chrome.vpnProvider.notifyConnectionStateChanged</code>. |
| 40 /// - When the steps above are completed without errors, a virtual tunnel is |
| 41 /// created to the network stack of Chrome OS. IP packets can be sent through |
| 42 /// the tunnel using <code>VpnProvider.SendPacket()</code> and any packets |
| 43 /// originating on the Chrome OS device will be received using the callback |
| 44 /// registered for <code>VpnProvider.ReceivePacket()</code>. |
| 45 /// - When the user disconnects from the VPN configuration or there is an error |
| 46 /// the callback registered using <code>VpnProvider.GetUnbindEvent()</code> |
| 47 /// will be called. |
| 48 class VpnProvider : public Resource { |
| 49 public: |
| 50 /// Constructs a VpnProvider object. |
| 51 /// |
| 52 /// @param[in] instance The instance with which this resource will be |
| 53 /// associated. |
| 54 explicit VpnProvider(const InstanceHandle& instance); |
| 55 |
| 56 /// Destructs a VpnProvider object. |
| 57 virtual ~VpnProvider(); |
| 58 |
| 59 /// Static function for determining whether the browser supports the |
| 60 /// <code>VpnProvider</code> interface. |
| 61 /// |
| 62 /// @return true if the interface is available, false otherwise. |
| 63 static bool IsAvailable(); |
| 64 |
| 65 /// Binds to an existing configuration created from JavaScript by |
| 66 /// <code>chrome.vpnProvider.createConfig</code>. All packets will be routed |
| 67 /// via <code>SendPacket</code> and <code>ReceivePacket</code>. The user |
| 68 /// should register callbacks via <code>GetUnbindEvent</code> and |
| 69 /// <code>ReceivePacket</code> before calling <code>Bind()</code>. |
| 70 /// |
| 71 /// @param[in] configuration_id The configuration id from the callback of |
| 72 /// <code>chrome.vpnProvider.createConfig</code>. This <code>Var</code> must |
| 73 /// be of string type. |
| 74 /// |
| 75 /// @param[in] configuration_name The configuration name as defined by the |
| 76 /// user when calling <code>chrome.vpnProvider.createConfig</code>. This |
| 77 /// <code>Var</code> must be of string type. |
| 78 /// |
| 79 /// @param[in] callback A <code>CompletionCallback</code> to be called on |
| 80 /// completion. |
| 81 /// |
| 82 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 83 /// Returns <code>PP_ERROR_INPROGRESS</code> if a previous call to |
| 84 /// <code>Bind()</code> has not completed. |
| 85 /// Returns <code>PP_ERROR_BADARGUMENT</code> if the <code>Var</code> type of |
| 86 /// either <code>configuration_id</code> or <code>configuration_name</code> is |
| 87 /// not of string type. |
| 88 /// Returns <code>PP_ERROR_NOACCESS</code> if the caller does the have the |
| 89 /// required "vpnProvider" permission. |
| 90 /// Returns <code>PP_ERROR_FAILED</code> if <code>connection_id</code> and |
| 91 /// <code>connection_name</code> could not be matched with the existing |
| 92 /// connection, or if the plugin originates from a different extension than |
| 93 /// the one that created the connection. |
| 94 int32_t Bind(const Var& configuration_id, |
| 95 const Var& configuration_name, |
| 96 const CompletionCallback& callback); |
| 97 |
| 98 /// Registers a callback that will be called when the current configuration |
| 99 /// gets unbound. The callback should be registered before calling |
| 100 /// <code>Bind()</code>. |
| 101 /// |
| 102 /// @param[in] callback A <code>CompletionCallback</code> called when the |
| 103 /// current configuration gets unbound. |
| 104 /// |
| 105 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 106 /// Returns <code>PP_ERROR_INPROGRESS</code> if a previous call to |
| 107 /// <code>GetUnbindEvent()</code> has not completed. |
| 108 int32_t GetUnbindEvent(const CompletionCallback& callback); |
| 109 |
| 110 /// Sends an IP packet through the tunnel created for the VPN session. This |
| 111 /// will succeed only when the VPN session is owned by the module and |
| 112 /// connection is bound. |
| 113 /// |
| 114 /// @param[in] packet IP packet to be sent to the platform. The |
| 115 /// <code>Var</code> must be of ArrayBuffer type. |
| 116 /// |
| 117 /// @param[in] callback A <code>CompletionCallback</code> to be called on |
| 118 /// completion. |
| 119 /// |
| 120 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 121 /// Returns <code>PP_ERROR_FAILED</code> if the connection is not bound. |
| 122 /// Returns <code>PP_ERROR_INPROGRESS</code> if a previous call to |
| 123 /// <code>SendPacket()</code> has not completed. |
| 124 /// Returns <code>PP_ERROR_BADARGUMENT</code> if the <code>Var</code> type of |
| 125 /// <code>packet</code> is not of ArrayBuffer type. |
| 126 int32_t SendPacket(const Var& packet, const CompletionCallback& callback); |
| 127 |
| 128 /// Receives an IP packet from the tunnel for the VPN session. This function |
| 129 /// only returns a single packet. That is, this function must be called at |
| 130 /// least N times to receive N packets, no matter the size of each packet. The |
| 131 /// callback should be registered before calling <code>Bind()</code>. |
| 132 /// |
| 133 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 134 /// called upon completion of ReceivePacket. It will be passed an ArrayBuffer |
| 135 /// type <code>Var</code> containing an IP packet to be sent to the platform. |
| 136 /// |
| 137 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 138 /// Returns <code>PP_ERROR_INPROGRESS</code> if a previous call to |
| 139 /// <code>ReceivePacket()</code> has not completed. |
| 140 int32_t ReceivePacket(const CompletionCallbackWithOutput<Var>& callback); |
| 141 |
| 142 private: |
| 143 InstanceHandle associated_instance_; |
| 144 }; |
| 145 |
| 146 } // namespace pp |
| 147 |
| 148 #endif // PPAPI_CPP_VPN_PROVIDER_H_ |
OLD | NEW |