| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/dispatcher.h" | 5 #include "ppapi/proxy/dispatcher.h" |
| 6 | 6 |
| 7 #include <string.h> // For memset. | 7 #include <string.h> // For memset. |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 14 #include "ppapi/c/dev/ppb_buffer_dev.h" | |
| 15 #include "ppapi/c/dev/ppb_char_set_dev.h" | |
| 16 #include "ppapi/c/dev/ppb_context_3d_dev.h" | |
| 17 #include "ppapi/c/dev/ppb_crypto_dev.h" | |
| 18 #include "ppapi/c/dev/ppb_cursor_control_dev.h" | |
| 19 #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" | |
| 20 #include "ppapi/c/dev/ppb_font_dev.h" | |
| 21 #include "ppapi/c/dev/ppb_surface_3d_dev.h" | |
| 22 #include "ppapi/c/dev/ppb_testing_dev.h" | |
| 23 #include "ppapi/c/dev/ppb_url_util_dev.h" | |
| 24 #include "ppapi/c/dev/ppb_var_deprecated.h" | |
| 25 #include "ppapi/c/pp_errors.h" | |
| 26 #include "ppapi/c/ppb_audio.h" | |
| 27 #include "ppapi/c/ppb_audio_config.h" | |
| 28 #include "ppapi/c/ppb_core.h" | |
| 29 #include "ppapi/c/ppb_graphics_2d.h" | |
| 30 #include "ppapi/c/ppb_image_data.h" | |
| 31 #include "ppapi/c/ppb_instance.h" | |
| 32 #include "ppapi/c/ppb_opengles.h" | |
| 33 #include "ppapi/c/ppb_url_loader.h" | |
| 34 #include "ppapi/c/ppb_url_request_info.h" | |
| 35 #include "ppapi/c/ppb_url_response_info.h" | |
| 36 #include "ppapi/c/ppb_var.h" | |
| 37 #include "ppapi/c/ppp_instance.h" | |
| 38 #include "ppapi/c/private/ppb_flash.h" | |
| 39 #include "ppapi/c/private/ppb_flash_clipboard.h" | |
| 40 #include "ppapi/c/private/ppb_flash_file.h" | |
| 41 #include "ppapi/c/private/ppb_flash_menu.h" | |
| 42 #include "ppapi/c/private/ppb_flash_net_connector.h" | |
| 43 #include "ppapi/c/private/ppb_flash_tcp_socket.h" | |
| 44 #include "ppapi/c/private/ppb_pdf.h" | |
| 45 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | |
| 46 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
| 47 #include "ppapi/proxy/ppb_audio_config_proxy.h" | |
| 48 #include "ppapi/proxy/ppb_audio_proxy.h" | |
| 49 #include "ppapi/proxy/ppb_broker_proxy.h" | |
| 50 #include "ppapi/proxy/ppb_buffer_proxy.h" | |
| 51 #include "ppapi/proxy/ppb_char_set_proxy.h" | |
| 52 #include "ppapi/proxy/ppb_console_proxy.h" | |
| 53 #include "ppapi/proxy/ppb_context_3d_proxy.h" | |
| 54 #include "ppapi/proxy/ppb_core_proxy.h" | |
| 55 #include "ppapi/proxy/ppb_crypto_proxy.h" | |
| 56 #include "ppapi/proxy/ppb_cursor_control_proxy.h" | |
| 57 #include "ppapi/proxy/ppb_file_chooser_proxy.h" | |
| 58 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
| 59 #include "ppapi/proxy/ppb_file_system_proxy.h" | |
| 60 #include "ppapi/proxy/ppb_flash_clipboard_proxy.h" | |
| 61 #include "ppapi/proxy/ppb_flash_file_proxy.h" | |
| 62 #include "ppapi/proxy/ppb_flash_proxy.h" | |
| 63 #include "ppapi/proxy/ppb_flash_menu_proxy.h" | |
| 64 #include "ppapi/proxy/ppb_flash_net_connector_proxy.h" | |
| 65 #include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" | |
| 66 #include "ppapi/proxy/ppb_font_proxy.h" | |
| 67 #include "ppapi/proxy/ppb_graphics_2d_proxy.h" | |
| 68 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" | |
| 69 #include "ppapi/proxy/ppb_image_data_proxy.h" | |
| 70 #include "ppapi/proxy/ppb_input_event_proxy.h" | |
| 71 #include "ppapi/proxy/ppb_instance_proxy.h" | |
| 72 #include "ppapi/proxy/ppb_memory_proxy.h" | |
| 73 #include "ppapi/proxy/ppb_opengles2_proxy.h" | |
| 74 #include "ppapi/proxy/ppb_pdf_proxy.h" | |
| 75 #include "ppapi/proxy/ppb_surface_3d_proxy.h" | |
| 76 #include "ppapi/proxy/ppb_testing_proxy.h" | |
| 77 #include "ppapi/proxy/ppb_url_loader_proxy.h" | |
| 78 #include "ppapi/proxy/ppb_url_request_info_proxy.h" | |
| 79 #include "ppapi/proxy/ppb_url_response_info_proxy.h" | |
| 80 #include "ppapi/proxy/ppb_url_util_proxy.h" | |
| 81 #include "ppapi/proxy/ppb_var_deprecated_proxy.h" | |
| 82 #include "ppapi/proxy/ppb_var_proxy.h" | |
| 83 #include "ppapi/proxy/ppb_video_capture_proxy.h" | |
| 84 #include "ppapi/proxy/ppb_video_decoder_proxy.h" | |
| 85 #include "ppapi/proxy/ppp_class_proxy.h" | |
| 86 #include "ppapi/proxy/ppp_graphics_3d_proxy.h" | |
| 87 #include "ppapi/proxy/ppp_input_event_proxy.h" | |
| 88 #include "ppapi/proxy/ppp_instance_private_proxy.h" | |
| 89 #include "ppapi/proxy/ppp_instance_proxy.h" | |
| 90 #include "ppapi/proxy/ppp_messaging_proxy.h" | |
| 91 #include "ppapi/proxy/ppp_mouse_lock_proxy.h" | |
| 92 #include "ppapi/proxy/ppp_video_decoder_proxy.h" | |
| 93 #include "ppapi/proxy/var_serialization_rules.h" | 15 #include "ppapi/proxy/var_serialization_rules.h" |
| 94 | 16 |
| 95 namespace ppapi { | 17 namespace ppapi { |
| 96 namespace proxy { | 18 namespace proxy { |
| 97 | 19 |
| 98 namespace { | |
| 99 | |
| 100 struct InterfaceList { | |
| 101 InterfaceList(); | |
| 102 | |
| 103 static InterfaceList* GetInstance(); | |
| 104 | |
| 105 void AddPPP(const InterfaceProxy::Info* info); | |
| 106 void AddPPB(const InterfaceProxy::Info* info); | |
| 107 | |
| 108 typedef std::map<std::string, const InterfaceProxy::Info*> NameToInfo; | |
| 109 NameToInfo name_to_plugin_info_; | |
| 110 NameToInfo name_to_browser_info_; | |
| 111 | |
| 112 // Note that there can be multiple interface names mapping to the same ID. | |
| 113 // In this case, the ID will map to one of them. This is temporary while | |
| 114 // we're converting to the thunk system, when that is complete, we need to | |
| 115 // have a better way of handling multiple interface implemented by one | |
| 116 // proxy object. | |
| 117 const InterfaceProxy::Info* id_to_browser_info_[INTERFACE_ID_COUNT]; | |
| 118 }; | |
| 119 | |
| 120 InterfaceList::InterfaceList() { | |
| 121 memset(id_to_browser_info_, 0, sizeof(id_to_browser_info_)); | |
| 122 | |
| 123 // PPB (browser) interfaces. | |
| 124 AddPPB(PPB_AudioConfig_Proxy::GetInfo()); | |
| 125 AddPPB(PPB_Audio_Proxy::GetInfo()); | |
| 126 AddPPB(PPB_Broker_Proxy::GetInfo()); | |
| 127 AddPPB(PPB_Buffer_Proxy::GetInfo()); | |
| 128 AddPPB(PPB_CharSet_Proxy::GetInfo()); | |
| 129 AddPPB(PPB_Console_Proxy::GetInfo()); | |
| 130 AddPPB(PPB_Context3D_Proxy::GetInfo()); | |
| 131 AddPPB(PPB_Context3D_Proxy::GetTextureMappingInfo()); | |
| 132 AddPPB(PPB_Core_Proxy::GetInfo()); | |
| 133 AddPPB(PPB_Crypto_Proxy::GetInfo()); | |
| 134 AddPPB(PPB_CursorControl_Proxy::GetInfo()); | |
| 135 AddPPB(PPB_FileChooser_Proxy::GetInfo()); | |
| 136 AddPPB(PPB_FileChooser_Proxy::GetInfo0_4()); | |
| 137 AddPPB(PPB_FileRef_Proxy::GetInfo()); | |
| 138 AddPPB(PPB_FileSystem_Proxy::GetInfo()); | |
| 139 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); | |
| 140 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); | |
| 141 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); | |
| 142 AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); | |
| 143 AddPPB(PPB_Flash_Proxy::GetInfo()); | |
| 144 AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); | |
| 145 AddPPB(PPB_Font_Proxy::GetInfo()); | |
| 146 AddPPB(PPB_Graphics2D_Proxy::GetInfo()); | |
| 147 AddPPB(PPB_Graphics3D_Proxy::GetInfo()); | |
| 148 AddPPB(PPB_ImageData_Proxy::GetInfo()); | |
| 149 AddPPB(PPB_InputEvent_Proxy::GetInputEventInfo()); | |
| 150 AddPPB(PPB_InputEvent_Proxy::GetKeyboardInputEventInfo()); | |
| 151 AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo1_0()); | |
| 152 AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo1_1()); | |
| 153 AddPPB(PPB_InputEvent_Proxy::GetWheelInputEventInfo()); | |
| 154 AddPPB(PPB_Instance_Proxy::GetInfo0_5()); | |
| 155 AddPPB(PPB_Instance_Proxy::GetInfo1_0()); | |
| 156 AddPPB(PPB_Instance_Proxy::GetInfoFullscreen()); | |
| 157 AddPPB(PPB_Instance_Proxy::GetInfoMessaging()); | |
| 158 AddPPB(PPB_Instance_Proxy::GetInfoMouseLock()); | |
| 159 AddPPB(PPB_Instance_Proxy::GetInfoPrivate()); | |
| 160 AddPPB(PPB_Memory_Proxy::GetInfo()); | |
| 161 AddPPB(PPB_OpenGLES2_Proxy::GetInfo()); | |
| 162 AddPPB(PPB_PDF_Proxy::GetInfo()); | |
| 163 AddPPB(PPB_Surface3D_Proxy::GetInfo()); | |
| 164 AddPPB(PPB_Testing_Proxy::GetInfo()); | |
| 165 AddPPB(PPB_URLLoader_Proxy::GetInfo()); | |
| 166 AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); | |
| 167 AddPPB(PPB_URLRequestInfo_Proxy::GetInfo()); | |
| 168 AddPPB(PPB_URLResponseInfo_Proxy::GetInfo()); | |
| 169 AddPPB(PPB_URLUtil_Proxy::GetInfo()); | |
| 170 AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); | |
| 171 AddPPB(PPB_Var_Proxy::GetInfo()); | |
| 172 AddPPB(PPB_VideoCapture_Proxy::GetInfo()); | |
| 173 AddPPB(PPB_VideoDecoder_Proxy::GetInfo()); | |
| 174 | |
| 175 #ifdef ENABLE_FLAPPER_HACKS | |
| 176 AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo()); | |
| 177 #endif | |
| 178 | |
| 179 // PPP (plugin) interfaces. | |
| 180 AddPPP(PPP_Graphics3D_Proxy::GetInfo()); | |
| 181 AddPPP(PPP_InputEvent_Proxy::GetInfo()); | |
| 182 AddPPP(PPP_Instance_Private_Proxy::GetInfo()); | |
| 183 AddPPP(PPP_Instance_Proxy::GetInfo1_0()); | |
| 184 AddPPP(PPP_Messaging_Proxy::GetInfo()); | |
| 185 AddPPP(PPP_MouseLock_Proxy::GetInfo()); | |
| 186 AddPPP(PPP_VideoCapture_Proxy::GetInfo()); | |
| 187 AddPPP(PPP_VideoDecoder_Proxy::GetInfo()); | |
| 188 } | |
| 189 | |
| 190 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { | |
| 191 DCHECK(name_to_plugin_info_.find(info->name) == | |
| 192 name_to_plugin_info_.end()); | |
| 193 DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT); | |
| 194 | |
| 195 name_to_plugin_info_[info->name] = info; | |
| 196 } | |
| 197 | |
| 198 void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { | |
| 199 DCHECK(name_to_browser_info_.find(info->name) == | |
| 200 name_to_browser_info_.end()); | |
| 201 DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT); | |
| 202 DCHECK(info->id == INTERFACE_ID_NONE || | |
| 203 id_to_browser_info_[info->id] == NULL); | |
| 204 | |
| 205 name_to_browser_info_[std::string(info->name)] = info; | |
| 206 if (info->id != INTERFACE_ID_NONE) | |
| 207 id_to_browser_info_[info->id] = info; | |
| 208 } | |
| 209 | |
| 210 // static | |
| 211 InterfaceList* InterfaceList::GetInstance() { | |
| 212 return Singleton<InterfaceList>::get(); | |
| 213 } | |
| 214 | |
| 215 } // namespace | |
| 216 | |
| 217 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, | 20 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, |
| 218 GetInterfaceFunc local_get_interface) | 21 GetInterfaceFunc local_get_interface) |
| 219 : ProxyChannel(remote_process_handle), | 22 : ProxyChannel(remote_process_handle), |
| 220 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. | 23 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. |
| 221 local_get_interface_(local_get_interface), | 24 local_get_interface_(local_get_interface), |
| 222 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 25 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 223 } | 26 } |
| 224 | 27 |
| 225 Dispatcher::~Dispatcher() { | 28 Dispatcher::~Dispatcher() { |
| 226 } | 29 } |
| 227 | 30 |
| 31 InterfaceProxy* Dispatcher::GetInterfaceProxy(InterfaceID id) { |
| 32 InterfaceProxy* proxy = proxies_[id].get(); |
| 33 if (!proxy) { |
| 34 // Handle the first time for a given API by creating the proxy for it. |
| 35 InterfaceProxy::Factory factory = |
| 36 InterfaceList::GetInstance()->GetFactoryForID(id); |
| 37 if (!factory) { |
| 38 NOTREACHED(); |
| 39 return NULL; |
| 40 } |
| 41 proxy = factory(this); |
| 42 DCHECK(proxy); |
| 43 proxies_[id].reset(proxy); |
| 44 } |
| 45 return proxy; |
| 46 } |
| 47 |
| 48 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { |
| 49 return delegate()->GetIPCMessageLoop(); |
| 50 } |
| 51 |
| 52 void Dispatcher::AddIOThreadMessageFilter( |
| 53 IPC::ChannelProxy::MessageFilter* filter) { |
| 54 channel()->AddFilter(filter); |
| 55 } |
| 56 |
| 228 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { | 57 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 229 // Control messages. | 58 // Control messages. |
| 230 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 59 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 231 bool handled = true; | 60 bool handled = true; |
| 232 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) | 61 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) |
| 233 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, | 62 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, |
| 234 CallbackTracker::ReceiveExecuteSerializedCallback) | 63 CallbackTracker::ReceiveExecuteSerializedCallback) |
| 235 IPC_MESSAGE_UNHANDLED(handled = false) | 64 IPC_MESSAGE_UNHANDLED(handled = false) |
| 236 IPC_END_MESSAGE_MAP() | 65 IPC_END_MESSAGE_MAP() |
| 237 return handled; | 66 return handled; |
| 238 } | 67 } |
| 239 return false; | |
| 240 } | |
| 241 | 68 |
| 242 // static | 69 if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { |
| 243 const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo( | 70 OnInvalidMessageReceived(); |
| 244 const std::string& name) { | 71 return true; |
| 245 const InterfaceList* list = InterfaceList::GetInstance(); | 72 } |
| 246 InterfaceList::NameToInfo::const_iterator found = | |
| 247 list->name_to_browser_info_.find(name); | |
| 248 if (found == list->name_to_browser_info_.end()) | |
| 249 return NULL; | |
| 250 return found->second; | |
| 251 } | |
| 252 | 73 |
| 253 // static | 74 InterfaceProxy* proxy = GetInterfaceProxy( |
| 254 const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(InterfaceID id) { | 75 static_cast<InterfaceID>(msg.routing_id())); |
| 255 if (id <= 0 || id >= INTERFACE_ID_COUNT) | 76 if (!proxy) { |
| 256 return NULL; | 77 NOTREACHED(); |
| 257 const InterfaceList* list = InterfaceList::GetInstance(); | 78 return true; |
| 258 return list->id_to_browser_info_[id]; | 79 } |
| 259 } | 80 return proxy->OnMessageReceived(msg); |
| 260 | |
| 261 // static | |
| 262 const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo( | |
| 263 const std::string& name) { | |
| 264 const InterfaceList* list = InterfaceList::GetInstance(); | |
| 265 InterfaceList::NameToInfo::const_iterator found = | |
| 266 list->name_to_plugin_info_.find(name); | |
| 267 if (found == list->name_to_plugin_info_.end()) | |
| 268 return NULL; | |
| 269 return found->second; | |
| 270 } | 81 } |
| 271 | 82 |
| 272 void Dispatcher::SetSerializationRules( | 83 void Dispatcher::SetSerializationRules( |
| 273 VarSerializationRules* var_serialization_rules) { | 84 VarSerializationRules* var_serialization_rules) { |
| 274 serialization_rules_.reset(var_serialization_rules); | 85 serialization_rules_.reset(var_serialization_rules); |
| 275 } | 86 } |
| 276 | 87 |
| 277 const void* Dispatcher::GetLocalInterface(const char* interface_name) { | 88 void Dispatcher::OnInvalidMessageReceived() { |
| 278 return local_get_interface_(interface_name); | |
| 279 } | |
| 280 | |
| 281 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { | |
| 282 return delegate()->GetIPCMessageLoop(); | |
| 283 } | |
| 284 | |
| 285 void Dispatcher::AddIOThreadMessageFilter( | |
| 286 IPC::ChannelProxy::MessageFilter* filter) { | |
| 287 channel()->AddFilter(filter); | |
| 288 } | 89 } |
| 289 | 90 |
| 290 } // namespace proxy | 91 } // namespace proxy |
| 291 } // namespace ppapi | 92 } // namespace ppapi |
| OLD | NEW |