blob: a1c99749db0c2b9b8fc4b5d09ac169c3342f5bc5 [file] [log] [blame]
[email protected]b697e1a2011-01-06 22:20:281// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]c2932f5e2010-11-03 03:22:332// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/proxy/dispatcher.h"
6
7#include <string.h> // For memset.
8
9#include <map>
10
[email protected]709a847e2010-11-10 01:16:1111#include "base/compiler_specific.h"
[email protected]c2932f5e2010-11-03 03:22:3312#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/singleton.h"
[email protected]43a40202010-11-12 16:25:0114#include "ppapi/c/dev/ppb_buffer_dev.h"
[email protected]9ca952d2010-11-11 20:43:5015#include "ppapi/c/dev/ppb_char_set_dev.h"
[email protected]f56279c2011-02-02 18:12:3116#include "ppapi/c/dev/ppb_context_3d_dev.h"
[email protected]f682ad72011-04-20 15:25:5517#include "ppapi/c/dev/ppb_crypto_dev.h"
[email protected]a3010332010-11-12 07:09:3518#include "ppapi/c/dev/ppb_cursor_control_dev.h"
[email protected]f56279c2011-02-02 18:12:3119#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h"
[email protected]43a40202010-11-12 16:25:0120#include "ppapi/c/dev/ppb_font_dev.h"
[email protected]f56279c2011-02-02 18:12:3121#include "ppapi/c/dev/ppb_opengles_dev.h"
22#include "ppapi/c/dev/ppb_surface_3d_dev.h"
[email protected]799d1ab2010-11-09 17:16:2823#include "ppapi/c/dev/ppb_testing_dev.h"
[email protected]9ca245e2011-03-18 01:50:3124#include "ppapi/c/dev/ppb_url_util_dev.h"
[email protected]c2932f5e2010-11-03 03:22:3325#include "ppapi/c/dev/ppb_var_deprecated.h"
26#include "ppapi/c/pp_errors.h"
[email protected]b9a59842011-01-15 01:04:0027#include "ppapi/c/ppb_audio.h"
28#include "ppapi/c/ppb_audio_config.h"
[email protected]c2932f5e2010-11-03 03:22:3329#include "ppapi/c/ppb_core.h"
30#include "ppapi/c/ppb_graphics_2d.h"
31#include "ppapi/c/ppb_image_data.h"
32#include "ppapi/c/ppb_instance.h"
[email protected]5a3f62852010-11-10 21:43:0133#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"
[email protected]0925622c2011-06-08 20:22:0236#include "ppapi/c/ppb_var.h"
[email protected]9ca952d2010-11-11 20:43:5037#include "ppapi/c/ppp_instance.h"
[email protected]b697e1a2011-01-06 22:20:2838#include "ppapi/c/private/ppb_flash.h"
[email protected]5cf8a5b2011-03-09 19:00:0539#include "ppapi/c/private/ppb_flash_clipboard.h"
[email protected]d07fa3792011-02-24 18:58:0140#include "ppapi/c/private/ppb_flash_file.h"
[email protected]7358d572011-02-15 18:44:4041#include "ppapi/c/private/ppb_flash_menu.h"
[email protected]7d3782f2011-03-29 19:16:2342#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]373a95a2011-07-01 16:58:1443#include "ppapi/c/private/ppb_flash_tcp_socket.h"
[email protected]917a44b02011-01-13 17:07:2944#include "ppapi/c/private/ppb_pdf.h"
[email protected]5f2517612010-12-02 22:36:4845#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
[email protected]9ca952d2010-11-11 20:43:5046#include "ppapi/proxy/ppapi_messages.h"
[email protected]5d84d012010-12-02 17:17:2147#include "ppapi/proxy/ppb_audio_config_proxy.h"
48#include "ppapi/proxy/ppb_audio_proxy.h"
[email protected]ae971c22011-04-17 00:13:2249#include "ppapi/proxy/ppb_broker_proxy.h"
[email protected]43a40202010-11-12 16:25:0150#include "ppapi/proxy/ppb_buffer_proxy.h"
[email protected]9ca952d2010-11-11 20:43:5051#include "ppapi/proxy/ppb_char_set_proxy.h"
[email protected]d38c57402011-03-11 20:20:5652#include "ppapi/proxy/ppb_console_proxy.h"
[email protected]f56279c2011-02-02 18:12:3153#include "ppapi/proxy/ppb_context_3d_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3354#include "ppapi/proxy/ppb_core_proxy.h"
[email protected]f682ad72011-04-20 15:25:5555#include "ppapi/proxy/ppb_crypto_proxy.h"
[email protected]a3010332010-11-12 07:09:3556#include "ppapi/proxy/ppb_cursor_control_proxy.h"
[email protected]4deeb432011-02-17 23:59:3957#include "ppapi/proxy/ppb_file_chooser_proxy.h"
58#include "ppapi/proxy/ppb_file_ref_proxy.h"
[email protected]ce482df2011-02-21 23:49:1659#include "ppapi/proxy/ppb_file_system_proxy.h"
[email protected]5cf8a5b2011-03-09 19:00:0560#include "ppapi/proxy/ppb_flash_clipboard_proxy.h"
[email protected]d07fa3792011-02-24 18:58:0161#include "ppapi/proxy/ppb_flash_file_proxy.h"
[email protected]5f2517612010-12-02 22:36:4862#include "ppapi/proxy/ppb_flash_proxy.h"
[email protected]7358d572011-02-15 18:44:4063#include "ppapi/proxy/ppb_flash_menu_proxy.h"
[email protected]7d3782f2011-03-29 19:16:2364#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
[email protected]373a95a2011-07-01 16:58:1465#include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h"
[email protected]9ca952d2010-11-11 20:43:5066#include "ppapi/proxy/ppb_font_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3367#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
[email protected]0e50fc4d2011-08-01 15:33:5168#include "ppapi/proxy/ppb_graphics_3d_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3369#include "ppapi/proxy/ppb_image_data_proxy.h"
[email protected]493d14212011-07-07 15:38:4870#include "ppapi/proxy/ppb_input_event_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3371#include "ppapi/proxy/ppb_instance_proxy.h"
[email protected]dc0156ac2011-07-06 22:17:1472#include "ppapi/proxy/ppb_memory_proxy.h"
[email protected]f56279c2011-02-02 18:12:3173#include "ppapi/proxy/ppb_opengles2_proxy.h"
[email protected]43a40202010-11-12 16:25:0174#include "ppapi/proxy/ppb_pdf_proxy.h"
[email protected]f56279c2011-02-02 18:12:3175#include "ppapi/proxy/ppb_surface_3d_proxy.h"
[email protected]799d1ab2010-11-09 17:16:2876#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"
[email protected]9ca245e2011-03-18 01:50:3180#include "ppapi/proxy/ppb_url_util_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3381#include "ppapi/proxy/ppb_var_deprecated_proxy.h"
[email protected]0925622c2011-06-08 20:22:0282#include "ppapi/proxy/ppb_var_proxy.h"
[email protected]7ace8ad2011-08-06 03:23:5883#include "ppapi/proxy/ppb_video_decoder_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3384#include "ppapi/proxy/ppp_class_proxy.h"
[email protected]8c3bd1d2011-04-12 20:01:4285#include "ppapi/proxy/ppp_graphics_3d_proxy.h"
[email protected]493d14212011-07-07 15:38:4886#include "ppapi/proxy/ppp_input_event_proxy.h"
[email protected]792f1ca32011-05-25 16:43:4387#include "ppapi/proxy/ppp_instance_private_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3388#include "ppapi/proxy/ppp_instance_proxy.h"
[email protected]b20df1c2011-08-03 14:38:2489#include "ppapi/proxy/ppp_messaging_proxy.h"
[email protected]7ace8ad2011-08-06 03:23:5890#include "ppapi/proxy/ppp_video_decoder_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3391#include "ppapi/proxy/var_serialization_rules.h"
92
93namespace pp {
94namespace proxy {
95
[email protected]465faa22011-02-08 16:31:4696namespace {
97
98struct InterfaceList {
99 InterfaceList();
100
101 static InterfaceList* GetInstance();
102
103 void AddPPP(const InterfaceProxy::Info* info);
104 void AddPPB(const InterfaceProxy::Info* info);
105
106 typedef std::map<std::string, const InterfaceProxy::Info*> NameToInfo;
107 NameToInfo name_to_plugin_info_;
108 NameToInfo name_to_browser_info_;
109
[email protected]ceadc392011-06-15 23:04:24110 // Note that there can be multiple interface names mapping to the same ID.
111 // In this case, the ID will map to one of them. This is temporary while
112 // we're converting to the thunk system, when that is complete, we need to
113 // have a better way of handling multiple interface implemented by one
114 // proxy object.
[email protected]465faa22011-02-08 16:31:46115 const InterfaceProxy::Info* id_to_browser_info_[INTERFACE_ID_COUNT];
116};
117
118InterfaceList::InterfaceList() {
[email protected]ce482df2011-02-21 23:49:16119 memset(id_to_browser_info_, 0, sizeof(id_to_browser_info_));
[email protected]465faa22011-02-08 16:31:46120
121 // PPB (browser) interfaces.
122 AddPPB(PPB_AudioConfig_Proxy::GetInfo());
123 AddPPB(PPB_Audio_Proxy::GetInfo());
[email protected]ae971c22011-04-17 00:13:22124 AddPPB(PPB_Broker_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46125 AddPPB(PPB_Buffer_Proxy::GetInfo());
126 AddPPB(PPB_CharSet_Proxy::GetInfo());
[email protected]d38c57402011-03-11 20:20:56127 AddPPB(PPB_Console_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46128 AddPPB(PPB_Context3D_Proxy::GetInfo());
[email protected]e18e6392011-06-22 20:57:00129 AddPPB(PPB_Context3D_Proxy::GetTextureMappingInfo());
[email protected]465faa22011-02-08 16:31:46130 AddPPB(PPB_Core_Proxy::GetInfo());
[email protected]f682ad72011-04-20 15:25:55131 AddPPB(PPB_Crypto_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46132 AddPPB(PPB_CursorControl_Proxy::GetInfo());
[email protected]4deeb432011-02-17 23:59:39133 AddPPB(PPB_FileChooser_Proxy::GetInfo());
134 AddPPB(PPB_FileRef_Proxy::GetInfo());
[email protected]ce482df2011-02-21 23:49:16135 AddPPB(PPB_FileSystem_Proxy::GetInfo());
[email protected]5cf8a5b2011-03-09 19:00:05136 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo());
[email protected]d062d962011-03-02 01:27:26137 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo());
[email protected]d07fa3792011-02-24 18:58:01138 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo());
[email protected]7358d572011-02-15 18:44:40139 AddPPB(PPB_Flash_Menu_Proxy::GetInfo());
[email protected]f3579d12011-07-22 15:47:42140 AddPPB(PPB_Flash_Proxy::GetInfo());
[email protected]373a95a2011-07-01 16:58:14141 AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46142 AddPPB(PPB_Font_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46143 AddPPB(PPB_Graphics2D_Proxy::GetInfo());
[email protected]0e50fc4d2011-08-01 15:33:51144 AddPPB(PPB_Graphics3D_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46145 AddPPB(PPB_ImageData_Proxy::GetInfo());
[email protected]f3579d12011-07-22 15:47:42146 AddPPB(PPB_InputEvent_Proxy::GetInputEventInfo());
147 AddPPB(PPB_InputEvent_Proxy::GetKeyboardInputEventInfo());
148 AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo());
149 AddPPB(PPB_InputEvent_Proxy::GetWheelInputEventInfo());
[email protected]ceadc392011-06-15 23:04:24150 AddPPB(PPB_Instance_Proxy::GetInfo0_5());
[email protected]7d0284e02011-07-13 03:48:24151 AddPPB(PPB_Instance_Proxy::GetInfo1_0());
[email protected]ceadc392011-06-15 23:04:24152 AddPPB(PPB_Instance_Proxy::GetInfoFullscreen());
[email protected]7f801d82011-07-08 23:30:11153 AddPPB(PPB_Instance_Proxy::GetInfoMessaging());
154 AddPPB(PPB_Instance_Proxy::GetInfoPrivate());
[email protected]dc0156ac2011-07-06 22:17:14155 AddPPB(PPB_Memory_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46156 AddPPB(PPB_OpenGLES2_Proxy::GetInfo());
157 AddPPB(PPB_PDF_Proxy::GetInfo());
158 AddPPB(PPB_Surface3D_Proxy::GetInfo());
159 AddPPB(PPB_Testing_Proxy::GetInfo());
160 AddPPB(PPB_URLLoader_Proxy::GetInfo());
[email protected]bf712f8e2011-06-17 02:10:45161 AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo());
[email protected]465faa22011-02-08 16:31:46162 AddPPB(PPB_URLRequestInfo_Proxy::GetInfo());
163 AddPPB(PPB_URLResponseInfo_Proxy::GetInfo());
[email protected]9ca245e2011-03-18 01:50:31164 AddPPB(PPB_URLUtil_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46165 AddPPB(PPB_Var_Deprecated_Proxy::GetInfo());
[email protected]0925622c2011-06-08 20:22:02166 AddPPB(PPB_Var_Proxy::GetInfo());
[email protected]7ace8ad2011-08-06 03:23:58167 AddPPB(PPB_VideoDecoder_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46168
[email protected]7d3782f2011-03-29 19:16:23169#ifdef ENABLE_FLAPPER_HACKS
170 AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo());
171#endif
172
[email protected]465faa22011-02-08 16:31:46173 // PPP (plugin) interfaces.
[email protected]8c3bd1d2011-04-12 20:01:42174 AddPPP(PPP_Graphics3D_Proxy::GetInfo());
[email protected]493d14212011-07-07 15:38:48175 AddPPP(PPP_InputEvent_Proxy::GetInfo());
[email protected]792f1ca32011-05-25 16:43:43176 AddPPP(PPP_Instance_Private_Proxy::GetInfo());
[email protected]13a8f492011-07-20 19:55:39177 AddPPP(PPP_Instance_Proxy::GetInfo1_0());
[email protected]b20df1c2011-08-03 14:38:24178 AddPPP(PPP_Messaging_Proxy::GetInfo());
[email protected]7ace8ad2011-08-06 03:23:58179 AddPPP(PPP_VideoDecoder_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46180}
181
182void InterfaceList::AddPPP(const InterfaceProxy::Info* info) {
183 DCHECK(name_to_plugin_info_.find(info->name) ==
184 name_to_plugin_info_.end());
[email protected]ceadc392011-06-15 23:04:24185 DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT);
[email protected]465faa22011-02-08 16:31:46186
187 name_to_plugin_info_[info->name] = info;
[email protected]465faa22011-02-08 16:31:46188}
189
190void InterfaceList::AddPPB(const InterfaceProxy::Info* info) {
191 DCHECK(name_to_browser_info_.find(info->name) ==
192 name_to_browser_info_.end());
[email protected]ceadc392011-06-15 23:04:24193 DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT);
194 DCHECK(info->id == INTERFACE_ID_NONE ||
195 id_to_browser_info_[info->id] == NULL);
[email protected]465faa22011-02-08 16:31:46196
197 name_to_browser_info_[std::string(info->name)] = info;
[email protected]ceadc392011-06-15 23:04:24198 if (info->id != INTERFACE_ID_NONE)
199 id_to_browser_info_[info->id] = info;
[email protected]465faa22011-02-08 16:31:46200}
201
202// static
203InterfaceList* InterfaceList::GetInstance() {
204 return Singleton<InterfaceList>::get();
205}
206
207} // namespace
208
[email protected]5d84d012010-12-02 17:17:21209Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle,
210 GetInterfaceFunc local_get_interface)
[email protected]e2614c62011-04-16 22:12:45211 : ProxyChannel(remote_process_handle),
[email protected]5f2517612010-12-02 22:36:48212 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
[email protected]c2932f5e2010-11-03 03:22:33213 local_get_interface_(local_get_interface),
[email protected]709a847e2010-11-10 01:16:11214 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
[email protected]c2932f5e2010-11-03 03:22:33215}
216
217Dispatcher::~Dispatcher() {
218}
219
[email protected]a95986a82010-12-24 06:19:28220bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
[email protected]c2932f5e2010-11-03 03:22:33221 // Control messages.
222 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
[email protected]a95986a82010-12-24 06:19:28223 bool handled = true;
[email protected]c2932f5e2010-11-03 03:22:33224 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg)
[email protected]c2932f5e2010-11-03 03:22:33225 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_,
226 CallbackTracker::ReceiveExecuteSerializedCallback)
[email protected]a95986a82010-12-24 06:19:28227 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]c2932f5e2010-11-03 03:22:33228 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28229 return handled;
[email protected]c2932f5e2010-11-03 03:22:33230 }
[email protected]a95986a82010-12-24 06:19:28231 return false;
[email protected]c2932f5e2010-11-03 03:22:33232}
233
[email protected]465faa22011-02-08 16:31:46234// static
235const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(
236 const std::string& name) {
237 const InterfaceList* list = InterfaceList::GetInstance();
238 InterfaceList::NameToInfo::const_iterator found =
239 list->name_to_browser_info_.find(name);
240 if (found == list->name_to_browser_info_.end())
241 return NULL;
242 return found->second;
243}
244
245// static
246const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(InterfaceID id) {
247 if (id <= 0 || id >= INTERFACE_ID_COUNT)
248 return NULL;
249 const InterfaceList* list = InterfaceList::GetInstance();
250 return list->id_to_browser_info_[id];
251}
252
253// static
254const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo(
255 const std::string& name) {
256 const InterfaceList* list = InterfaceList::GetInstance();
257 InterfaceList::NameToInfo::const_iterator found =
258 list->name_to_plugin_info_.find(name);
259 if (found == list->name_to_plugin_info_.end())
260 return NULL;
261 return found->second;
262}
263
[email protected]c2932f5e2010-11-03 03:22:33264void Dispatcher::SetSerializationRules(
265 VarSerializationRules* var_serialization_rules) {
266 serialization_rules_.reset(var_serialization_rules);
267}
268
[email protected]84396dbc2011-04-14 06:33:42269const void* Dispatcher::GetLocalInterface(const char* interface_name) {
270 return local_get_interface_(interface_name);
[email protected]c2932f5e2010-11-03 03:22:33271}
272
[email protected]92bf9062011-05-02 18:00:49273base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() {
[email protected]e2614c62011-04-16 22:12:45274 return delegate()->GetIPCMessageLoop();
[email protected]1609d0d2011-04-15 22:06:21275}
276
277void Dispatcher::AddIOThreadMessageFilter(
278 IPC::ChannelProxy::MessageFilter* filter) {
[email protected]e2614c62011-04-16 22:12:45279 channel()->AddFilter(filter);
[email protected]c2932f5e2010-11-03 03:22:33280}
281
[email protected]c2932f5e2010-11-03 03:22:33282} // namespace proxy
283} // namespace pp