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 #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 /// Typical usage: |
| 23 /// - Create VPN configurations using the |
| 24 /// <code>VpnProvider.CreateConfig()</code> method. A VPN configuration is |
| 25 /// a persistent entry shown to the user in a native Chrome OS UI. The user |
| 26 /// can select a VPN configuration from a list and connect to it or disconnect |
| 27 /// from it. |
| 28 /// - Register callbacks to the events via |
| 29 /// <code>VpnProvider.GetPlatformMessage()</code>, |
| 30 /// <code>VpnProvider.GetPacket()</code>, |
| 31 /// <code>VpnProvider.GetConfigMessage()</code> and |
| 32 /// <code>VpnProvider.GetUIMessage()</code>. |
| 33 /// - When the user connects to the VPN configuration, the |
| 34 /// <code>VpnProvider.GetPlatformMessage()</code> callback will be called with |
| 35 /// the message <code>PP_VPN_PROVIDER_PLATFORM_MESSAGE_CONNECTED</code>. |
| 36 /// We refer to the period between the messages |
| 37 /// <code>PP_VPN_PROVIDER_PLATFORM_MESSAGE_CONNECTED</code> and |
| 38 /// <code>PP_VPN_PROVIDER_PLATFORM_MESSAGE_DISCONNECTED</code> as a VPN |
| 39 /// session. In this time period, the module that receives the message is said |
| 40 /// to own the VPN session. |
| 41 /// - You will need to re-register the callbacks after they are called. |
| 42 /// - Initiate connection to the VPN server and start the VPN client. |
| 43 /// - Set the Parameters of the connection using |
| 44 /// <code>VpnProvider.SetParameters()</code> . |
| 45 /// - Notify the connection state as |
| 46 /// <code>PP_VPN_PROVIDER_CONNECTION_STATE_CONNECTED</code> using |
| 47 /// <code>VpnProvider.NotifyConnectionStateChanged()</code>. |
| 48 /// - When the steps above are completed without errors, a virtual tunnel is |
| 49 /// created to the network stack of Chrome OS. IP packets can be sent through |
| 50 /// the tunnel using <code>VpnProvider.SendPacket()</code> and any packets |
| 51 /// originating on the Chrome OS device will be received using the callback of |
| 52 /// <code>VpnProvider.GetPacket()</code>. |
| 53 /// - When the user disconnects from the VPN configuration, the |
| 54 /// <code>VpnProvider.GetPlatformMessage()</code> callback will be fired |
| 55 /// with the message <code>PP_VPN_PROVIDER_PLATFORM_MESSAGE_DISCONNECTED |
| 56 /// </code>. |
| 57 /// - If the VPN configuration is no longer necessary, it can be destroyed using |
| 58 /// <code>VpnProvider.DestroyConfig()</code> |
| 59 |
| 60 /// The <code>VpnProvider</code> class providing a way to implement a VPN |
| 61 /// client. |
| 62 class VpnProvider : public Resource { |
| 63 public: |
| 64 /// Constructs a VpnProvider object. |
| 65 /// |
| 66 /// @param[in] instance The instance with which this resource will be |
| 67 /// associated. |
| 68 explicit VpnProvider(Instance* instance); |
| 69 |
| 70 /// Destructs a WebSocket object. |
| 71 virtual ~VpnProvider(); |
| 72 |
| 73 /// Static function for determining whether the browser supports the |
| 74 /// <code>VpnProvider</code> interface. |
| 75 /// |
| 76 /// @return true if the interface is available, false otherwise. |
| 77 static bool IsAvailable(); |
| 78 |
| 79 /// Creates a new VPN configuration that persists across multiple login |
| 80 /// sessions of the user. |
| 81 /// |
| 82 /// @param[in] name The name of the VPN configuration. |
| 83 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 84 /// called upon completion of CreateConfig. It will be passed a string |
| 85 /// <code>Var</code> containing the appropriate ID string for |
| 86 /// <code>name</code>. |
| 87 int32_t CreateConfig(const std::string& name, |
| 88 const CompletionCallbackWithOutput<Var>& callback); |
| 89 |
| 90 /// Destroys a VPN configuration created using this API. |
| 91 /// |
| 92 /// @param[in] name The name of the VPN configuration. |
| 93 /// @param[in] callback A <code>CompletionCallback</code> to be |
| 94 /// called upon completion of DestroyConfig. |
| 95 int32_t DestroyConfig(const std::string& id, |
| 96 const CompletionCallback& callback); |
| 97 |
| 98 /// Sets the parameters for the VPN session. This should be called immediately |
| 99 /// after <code>PP_VPN_PROVIDER_CONNECTION_STATE_CONNECTED</code> is received |
| 100 /// from the platform. This will succeed only when the VPN session is owned |
| 101 /// by the module. |
| 102 /// |
| 103 /// @param[in] address IP address for the VPN interface in CIDR notation. IPv4 |
| 104 /// is currently the only supported mode. |
| 105 /// @param[in] broadcast_address IP address for the VPN interface in CIDR |
| 106 /// notation. IPv4 is currently the only supported mode. |
| 107 /// @param[in] mtu MTU setting for the VPN interface. Default: 1500 bytes. |
| 108 /// @param[in] exclusion_list Exclude network traffic to the list of IP blocks |
| 109 /// in CIDR notation from the tunnel. This can be used to bypass traffic to |
| 110 /// and from the VPN server. When many rules match a destination, the rule |
| 111 /// with the longest matching prefix wins. Entries that correspond to the same |
| 112 /// CIDR block are treated as duplicates. Such duplicates in the collated |
| 113 /// (exclusion_list + inclusion_list) list are eliminated and the exact |
| 114 /// duplicate entry that will be eliminated is undefined. |
| 115 /// @param[in] inclusion_list Include network traffic to the list of IP blocks |
| 116 /// in CIDR notation to the tunnel. This parameter can be used to set up a |
| 117 /// split tunnel. By default no traffic is directed to the tunnel. Adding the |
| 118 /// entry "0.0.0.0/0" to this list gets all the user traffic redirected to the |
| 119 /// tunnel. When many rules match a destination, the rule with the longest |
| 120 /// matching prefix wins. Entries that correspond to the same CIDR block are |
| 121 /// treated as duplicates. Such duplicates in the collated (exclusion_list + |
| 122 /// inclusion_list) list are eliminated and the exact duplicate entry that |
| 123 /// will be eliminated is undefined. |
| 124 /// @param[in] domain_search A list of search domains. Default: no search |
| 125 /// domain. |
| 126 /// @param[in] dns_servers List of IPs for the DNS servers. |
| 127 /// @param[in] callback A <code>CompletionCallback</code> to be |
| 128 /// called upon completion of DestroyConfig. |
| 129 int32_t SetParameters(const std::string& address, |
| 130 const std::string& broadcast_address, |
| 131 const int32_t& mtu, |
| 132 const std::vector<std::string>& exclusion_list, |
| 133 const std::vector<std::string>& inclusion_list, |
| 134 const std::vector<std::string>& domain_search, |
| 135 const std::vector<std::string>& dns_servers, |
| 136 const CompletionCallback& callback); |
| 137 |
| 138 /// Sends an IP packet through the tunnel created for the VPN session. This |
| 139 /// will succeed only when the VPN session is owned by the module. |
| 140 /// |
| 141 /// @param[in] data IP packet to be sent to the platform. Its received |
| 142 /// <code>Var</code> will be of ArrayBuffer type. |
| 143 int32_t SendPacket(const Var& packet); |
| 144 |
| 145 /// Notifies the VPN session state to the platform. This will succeed only |
| 146 /// when the VPN session is owned by the module. |
| 147 /// |
| 148 /// @param[in] status VPN session state of the VPN client. |
| 149 /// @param[in] callback A <code>CompletionCallback</code> to be |
| 150 /// called upon completion of NotifyConnectionStateChanged. |
| 151 int32_t NotifyConnectionStateChanged(PP_VpnProvider_VpnConnectionState status, |
| 152 const CompletionCallback& callback); |
| 153 |
| 154 /// Receives an IP packet from the tunnel for the VPN session. |
| 155 /// This interface only returns a single packet. That is, this interface must |
| 156 /// be called at least N times to receive N packets, no matter the size of |
| 157 /// each packet. |
| 158 /// |
| 159 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 160 /// called upon completion of GetPacket. It will be passed an ArrayBuffer type |
| 161 /// <code>Var</code> containing an IP packet to be sent to the platform. |
| 162 /// |
| 163 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 164 /// If an error is detected or connection is closed, GetPacket() returns |
| 165 /// <code>PP_ERROR_FAILED</code> after all buffered messages are received. |
| 166 /// Until buffered packets become empty, GetPacket() continues to return |
| 167 /// <code>PP_OK</code> as if connection is still established without errors. |
| 168 int32_t GetPacket(const CompletionCallbackWithOutput<Var>& callback); |
| 169 |
| 170 /// Receives a platform message from the platform for a VPN configuration. |
| 171 /// This interface only returns a single message. That is, this interface must |
| 172 /// be called at least N times to receive N messages. |
| 173 /// |
| 174 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 175 /// called upon completion of GetPlatformMessage. It will be passed a |
| 176 /// VarDictionary type <code>Var</code> containing a platform message. Its key |
| 177 /// value pairs must be interpreted as: |
| 178 /// - "id": A string <code>Var</code> containing the ID of the configuration |
| 179 /// the message is intended for. |
| 180 /// - "message": A int <code>Var</code> containing the message type received |
| 181 /// from the platform. It must interpreted as a value in |
| 182 /// <code>PP_VpnProvider_PlatformMessage</code>. |
| 183 /// - "error": A string <code>Var</code> containing the error message when |
| 184 /// there is an error. |
| 185 /// |
| 186 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 187 /// If an error is detected or connection is closed, GetPlatformMessage() |
| 188 /// returns <code>PP_ERROR_FAILED</code> after all buffered messages are |
| 189 /// received. Until buffered packets become empty, GetPlatformMessage() |
| 190 /// continues to return <code>PP_OK</code> as if connection is still |
| 191 /// established without errors. |
| 192 int32_t GetPlatformMessage(const CompletionCallbackWithOutput<Var>& callback); |
| 193 |
| 194 /// Receives an event from the platform for the creation or destruction of a |
| 195 /// VPN configuration. |
| 196 /// This interface only returns a single message. That is, this interface must |
| 197 /// be called at least N times to receive N messages. |
| 198 /// |
| 199 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 200 /// called upon completion of GetPlatformMessage. It will be passed a |
| 201 /// VarDictionary type <code>Var</code> containing a platform message. Its key |
| 202 /// value pairs must be interpreted as: |
| 203 /// - "id": A string <code>Var</code> containing the ID of the configuration |
| 204 /// the message is intended for. |
| 205 /// - "message": A int <code>Var</code> containing the message type received |
| 206 /// from the platform. It must interpreted as a value in |
| 207 /// <code>PP_VpnProvider_ConfigMessage</code>. |
| 208 /// - "name": A string <code>Var</code> containing the bame of the |
| 209 /// configuration created. |
| 210 /// - "data": A <code>Var</code> containing configuration data provided by the |
| 211 /// administrator. |
| 212 /// |
| 213 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 214 /// If an error is detected or connection is closed, GetConfigMessage() |
| 215 /// returns <code>PP_ERROR_FAILED</code> after all buffered messages are |
| 216 /// received. Until buffered packets become empty, GetConfigMessage() |
| 217 /// continues to return <code>PP_OK</code> as if connection is still |
| 218 /// established without errors. |
| 219 int32_t GetConfigMessage(const CompletionCallbackWithOutput<Var>& callback); |
| 220 |
| 221 /// Receives an UI event for the extension. UI events are signals from the |
| 222 /// platform that indicate to the app that a UI dialog needs to be shown to |
| 223 /// the user. |
| 224 /// This interface only returns a single message. That is, this interface must |
| 225 /// be called at least N times to receive N messages. |
| 226 /// |
| 227 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 228 /// called upon completion of GetPlatformMessage. It will be passed a |
| 229 /// VarDictionary type <code>Var</code> containing a platform message. Its key |
| 230 /// value pairs must be interpreted as: |
| 231 /// - "event": A int <code>Var</code> containing the event type received |
| 232 /// from the platform. It must interpreted as a value in |
| 233 /// <code>PP_VpnProvider_UIEvent</code>. |
| 234 /// - "id": A string <code>Var</code> containing the ID of the configuration |
| 235 /// the event is intended for. |
| 236 /// |
| 237 /// @return An int32_t containing an error code from <code>pp_errors.h</code>. |
| 238 /// If an error is detected or connection is closed, GetUIMessage() returns |
| 239 /// <code>PP_ERROR_FAILED</code> after all buffered messages are received. |
| 240 /// Until buffered packets become empty, GetUIMessage() continues to return |
| 241 /// <code>PP_OK</code> as if connection is still established without errors. |
| 242 int32_t GetUIMessage(const CompletionCallbackWithOutput<Var>& callback); |
| 243 |
| 244 private: |
| 245 InstanceHandle associated_instance_; |
| 246 }; |
| 247 |
| 248 } // namespace pp |
| 249 |
| 250 #endif // PPAPI_CPP_VPN_PROVIDER_H_ |
OLD | NEW |