OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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_PROXY_VPN_PROVIDER_RESOURCE_H_ |
| 6 #define PPAPI_PROXY_VPN_PROVIDER_RESOURCE_H_ |
| 7 |
| 8 #include "ppapi/c/ppb_vpn_provider.h" |
| 9 #include "ppapi/proxy/plugin_dispatcher.h" |
| 10 #include "ppapi/proxy/plugin_resource.h" |
| 11 #include "ppapi/shared_impl/tracked_callback.h" |
| 12 #include "ppapi/thunk/ppb_vpn_provider_api.h" |
| 13 |
| 14 namespace ppapi { |
| 15 namespace proxy { |
| 16 |
| 17 class PPAPI_PROXY_EXPORT VpnProviderResource |
| 18 : public PluginResource, |
| 19 public NON_EXPORTED_BASE(thunk::PPB_VpnProvider_API) { |
| 20 public: |
| 21 VpnProviderResource(Connection connection, PP_Instance instance); |
| 22 virtual ~VpnProviderResource(); |
| 23 |
| 24 // PluginResource implementation. |
| 25 virtual thunk::PPB_VpnProvider_API* AsPPB_VpnProvider_API() override; |
| 26 |
| 27 // PPB_VpnProvider_API implementation. |
| 28 virtual int32_t CreateConfig( |
| 29 const PP_Var& name, |
| 30 PP_Var* id, |
| 31 const scoped_refptr<TrackedCallback>& callback) override; |
| 32 virtual int32_t DestroyConfig( |
| 33 const PP_Var& id, |
| 34 const scoped_refptr<TrackedCallback>& callback) override; |
| 35 virtual int32_t SetParameters( |
| 36 const PP_Var& address, |
| 37 const PP_Var& broadcast_address, |
| 38 int32_t mtu, |
| 39 const PP_Var& exclusion_list, |
| 40 const PP_Var& inclusion_list, |
| 41 const PP_Var& domain_search, |
| 42 const PP_Var& dns_servers, |
| 43 const scoped_refptr<TrackedCallback>& callback) override; |
| 44 virtual int32_t SendPacket(const PP_Var& packet) override; |
| 45 virtual int32_t NotifyConnectionStateChanged( |
| 46 PP_VpnProvider_VpnConnectionState status, |
| 47 const scoped_refptr<TrackedCallback>& callback) override; |
| 48 virtual int32_t GetPacket( |
| 49 PP_Var* packet, |
| 50 const scoped_refptr<TrackedCallback>& callback) override; |
| 51 virtual int32_t GetPlatformMessage( |
| 52 PP_Var* message, |
| 53 const scoped_refptr<TrackedCallback>& callback) override; |
| 54 virtual int32_t GetConfigMessage( |
| 55 PP_Var* message, |
| 56 const scoped_refptr<TrackedCallback>& callback) override; |
| 57 virtual int32_t GetUIMessage( |
| 58 PP_Var* message, |
| 59 const scoped_refptr<TrackedCallback>& callback) override; |
| 60 |
| 61 private: |
| 62 // PluginResource overrides. |
| 63 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, |
| 64 const IPC::Message& msg) override; |
| 65 |
| 66 // PPB_VpnProvider IPC Replies |
| 67 void OnPluginMsgCreateConfigReply(const ResourceMessageReplyParams& params, |
| 68 int32_t result, |
| 69 const std::string& id); |
| 70 void OnPluginMsgDestroyConfigReply(const ResourceMessageReplyParams& params, |
| 71 int32_t result); |
| 72 void OnPluginMsgSetParametersReply(const ResourceMessageReplyParams& params, |
| 73 int32_t result); |
| 74 void OnPluginMsgNotifyConnectionStateChangedReply( |
| 75 const ResourceMessageReplyParams& params, |
| 76 int32_t result); |
| 77 |
| 78 // Browser callbacks |
| 79 void OnPluginMsgOnPlatformMessage(const ResourceMessageReplyParams& params, |
| 80 const std::string& id, |
| 81 PP_VpnProvider_PlatformMessage status, |
| 82 const std::string& message); |
| 83 void OnPluginMsgOnPacketReceived(const ResourceMessageReplyParams& params, |
| 84 const std::vector<char>& data); |
| 85 void OnPluginMsgOnConfigEvent(const ResourceMessageReplyParams& params, |
| 86 const std::string& id, |
| 87 PP_VpnProvider_ConfigMessage message, |
| 88 const std::string& name, |
| 89 const std::string& data); |
| 90 void OnPluginMsgOnUIEvent(const ResourceMessageReplyParams& params, |
| 91 PP_VpnProvider_UIEvent event, |
| 92 const std::string& id); |
| 93 |
| 94 // Picks up a received message and moves it to user receiving buffer. This |
| 95 // function is used in both Get*() for fast returning path, and |
| 96 // OnPluginMsgOn*() for delayed callback invocations. |
| 97 void WritePacket(); |
| 98 void WritePlatformMessage(); |
| 99 void WriteConfigMessage(); |
| 100 void WriteUIMessage(); |
| 101 |
| 102 // Holds user callbacks to invoke later. |
| 103 scoped_refptr<TrackedCallback> create_config_callback_; |
| 104 scoped_refptr<TrackedCallback> destroy_config_callback_; |
| 105 scoped_refptr<TrackedCallback> set_parameters_callback_; |
| 106 scoped_refptr<TrackedCallback> send_state_change_notification_callback_; |
| 107 |
| 108 scoped_refptr<TrackedCallback> get_packet_callback_; |
| 109 scoped_refptr<TrackedCallback> get_platform_message_callback_; |
| 110 scoped_refptr<TrackedCallback> get_config_message_callback_; |
| 111 scoped_refptr<TrackedCallback> get_ui_message_callback_; |
| 112 |
| 113 // Keeps a pointer to the callback variable provided. |
| 114 // Received data will be copied to this variable on ready. |
| 115 PP_Var* create_config_callback_var_; |
| 116 PP_Var* get_packet_callback_var_; |
| 117 PP_Var* get_platform_message_callback_var_; |
| 118 PP_Var* get_config_message_callback_var_; |
| 119 PP_Var* get_ui_message_callback_var_; |
| 120 |
| 121 // Keeps received data. |
| 122 std::queue<scoped_refptr<Var>> received_packets_; |
| 123 std::queue<scoped_refptr<Var>> received_platform_messages_; |
| 124 std::queue<scoped_refptr<Var>> received_config_messages_; |
| 125 std::queue<scoped_refptr<Var>> received_ui_messages_; |
| 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(VpnProviderResource); |
| 128 }; |
| 129 |
| 130 } // namespace proxy |
| 131 } // namespace ppapi |
| 132 |
| 133 #endif // PPAPI_PROXY_VPN_PROVIDER_RESOURCE_H_ |
OLD | NEW |