blob: 2964835cb0e27d0110fcf404af16c54167224218 [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]a3010332010-11-12 07:09:3517#include "ppapi/c/dev/ppb_cursor_control_dev.h"
[email protected]f56279c2011-02-02 18:12:3118#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h"
[email protected]43a40202010-11-12 16:25:0119#include "ppapi/c/dev/ppb_font_dev.h"
20#include "ppapi/c/dev/ppb_fullscreen_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]9ca952d2010-11-11 20:43:5036#include "ppapi/c/ppp_instance.h"
[email protected]b697e1a2011-01-06 22:20:2837#include "ppapi/c/private/ppb_flash.h"
[email protected]5cf8a5b2011-03-09 19:00:0538#include "ppapi/c/private/ppb_flash_clipboard.h"
[email protected]d07fa3792011-02-24 18:58:0139#include "ppapi/c/private/ppb_flash_file.h"
[email protected]7358d572011-02-15 18:44:4040#include "ppapi/c/private/ppb_flash_menu.h"
[email protected]7d3782f2011-03-29 19:16:2341#include "ppapi/c/private/ppb_flash_net_connector.h"
[email protected]917a44b02011-01-13 17:07:2942#include "ppapi/c/private/ppb_pdf.h"
[email protected]5f2517612010-12-02 22:36:4843#include "ppapi/c/trusted/ppb_url_loader_trusted.h"
[email protected]9ca952d2010-11-11 20:43:5044#include "ppapi/proxy/ppapi_messages.h"
[email protected]5d84d012010-12-02 17:17:2145#include "ppapi/proxy/ppb_audio_config_proxy.h"
46#include "ppapi/proxy/ppb_audio_proxy.h"
[email protected]ae971c22011-04-17 00:13:2247#include "ppapi/proxy/ppb_broker_proxy.h"
[email protected]43a40202010-11-12 16:25:0148#include "ppapi/proxy/ppb_buffer_proxy.h"
[email protected]9ca952d2010-11-11 20:43:5049#include "ppapi/proxy/ppb_char_set_proxy.h"
[email protected]d38c57402011-03-11 20:20:5650#include "ppapi/proxy/ppb_console_proxy.h"
[email protected]f56279c2011-02-02 18:12:3151#include "ppapi/proxy/ppb_context_3d_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3352#include "ppapi/proxy/ppb_core_proxy.h"
[email protected]a3010332010-11-12 07:09:3553#include "ppapi/proxy/ppb_cursor_control_proxy.h"
[email protected]4deeb432011-02-17 23:59:3954#include "ppapi/proxy/ppb_file_chooser_proxy.h"
55#include "ppapi/proxy/ppb_file_ref_proxy.h"
[email protected]ce482df2011-02-21 23:49:1656#include "ppapi/proxy/ppb_file_system_proxy.h"
[email protected]5cf8a5b2011-03-09 19:00:0557#include "ppapi/proxy/ppb_flash_clipboard_proxy.h"
[email protected]d07fa3792011-02-24 18:58:0158#include "ppapi/proxy/ppb_flash_file_proxy.h"
[email protected]5f2517612010-12-02 22:36:4859#include "ppapi/proxy/ppb_flash_proxy.h"
[email protected]7358d572011-02-15 18:44:4060#include "ppapi/proxy/ppb_flash_menu_proxy.h"
[email protected]7d3782f2011-03-29 19:16:2361#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
[email protected]9ca952d2010-11-11 20:43:5062#include "ppapi/proxy/ppb_font_proxy.h"
[email protected]a3010332010-11-12 07:09:3563#include "ppapi/proxy/ppb_fullscreen_proxy.h"
[email protected]f56279c2011-02-02 18:12:3164#include "ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3365#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
66#include "ppapi/proxy/ppb_image_data_proxy.h"
67#include "ppapi/proxy/ppb_instance_proxy.h"
[email protected]f56279c2011-02-02 18:12:3168#include "ppapi/proxy/ppb_opengles2_proxy.h"
[email protected]43a40202010-11-12 16:25:0169#include "ppapi/proxy/ppb_pdf_proxy.h"
[email protected]f56279c2011-02-02 18:12:3170#include "ppapi/proxy/ppb_surface_3d_proxy.h"
[email protected]799d1ab2010-11-09 17:16:2871#include "ppapi/proxy/ppb_testing_proxy.h"
72#include "ppapi/proxy/ppb_url_loader_proxy.h"
73#include "ppapi/proxy/ppb_url_request_info_proxy.h"
74#include "ppapi/proxy/ppb_url_response_info_proxy.h"
[email protected]9ca245e2011-03-18 01:50:3175#include "ppapi/proxy/ppb_url_util_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3376#include "ppapi/proxy/ppb_var_deprecated_proxy.h"
77#include "ppapi/proxy/ppp_class_proxy.h"
[email protected]8c3bd1d2011-04-12 20:01:4278#include "ppapi/proxy/ppp_graphics_3d_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3379#include "ppapi/proxy/ppp_instance_proxy.h"
80#include "ppapi/proxy/var_serialization_rules.h"
81
82namespace pp {
83namespace proxy {
84
[email protected]465faa22011-02-08 16:31:4685namespace {
86
87struct InterfaceList {
88 InterfaceList();
89
90 static InterfaceList* GetInstance();
91
92 void AddPPP(const InterfaceProxy::Info* info);
93 void AddPPB(const InterfaceProxy::Info* info);
94
95 typedef std::map<std::string, const InterfaceProxy::Info*> NameToInfo;
96 NameToInfo name_to_plugin_info_;
97 NameToInfo name_to_browser_info_;
98
99 const InterfaceProxy::Info* id_to_plugin_info_[INTERFACE_ID_COUNT];
100 const InterfaceProxy::Info* id_to_browser_info_[INTERFACE_ID_COUNT];
101};
102
103InterfaceList::InterfaceList() {
[email protected]ce482df2011-02-21 23:49:16104 memset(id_to_plugin_info_, 0, sizeof(id_to_plugin_info_));
105 memset(id_to_browser_info_, 0, sizeof(id_to_browser_info_));
[email protected]465faa22011-02-08 16:31:46106
107 // PPB (browser) interfaces.
108 AddPPB(PPB_AudioConfig_Proxy::GetInfo());
109 AddPPB(PPB_Audio_Proxy::GetInfo());
[email protected]ae971c22011-04-17 00:13:22110 AddPPB(PPB_Broker_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46111 AddPPB(PPB_Buffer_Proxy::GetInfo());
112 AddPPB(PPB_CharSet_Proxy::GetInfo());
[email protected]d38c57402011-03-11 20:20:56113 AddPPB(PPB_Console_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46114 AddPPB(PPB_Context3D_Proxy::GetInfo());
115 AddPPB(PPB_Core_Proxy::GetInfo());
116 AddPPB(PPB_CursorControl_Proxy::GetInfo());
[email protected]4deeb432011-02-17 23:59:39117 AddPPB(PPB_FileChooser_Proxy::GetInfo());
118 AddPPB(PPB_FileRef_Proxy::GetInfo());
[email protected]ce482df2011-02-21 23:49:16119 AddPPB(PPB_FileSystem_Proxy::GetInfo());
[email protected]5cf8a5b2011-03-09 19:00:05120 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo());
[email protected]d062d962011-03-02 01:27:26121 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo());
[email protected]d07fa3792011-02-24 18:58:01122 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46123 AddPPB(PPB_Flash_Proxy::GetInfo());
[email protected]7358d572011-02-15 18:44:40124 AddPPB(PPB_Flash_Menu_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46125 AddPPB(PPB_Font_Proxy::GetInfo());
126 AddPPB(PPB_Fullscreen_Proxy::GetInfo());
127 AddPPB(PPB_GLESChromiumTextureMapping_Proxy::GetInfo());
128 AddPPB(PPB_Graphics2D_Proxy::GetInfo());
129 AddPPB(PPB_ImageData_Proxy::GetInfo());
130 AddPPB(PPB_Instance_Proxy::GetInfo());
131 AddPPB(PPB_OpenGLES2_Proxy::GetInfo());
132 AddPPB(PPB_PDF_Proxy::GetInfo());
133 AddPPB(PPB_Surface3D_Proxy::GetInfo());
134 AddPPB(PPB_Testing_Proxy::GetInfo());
135 AddPPB(PPB_URLLoader_Proxy::GetInfo());
136 AddPPB(PPB_URLLoaderTrusted_Proxy::GetInfo());
137 AddPPB(PPB_URLRequestInfo_Proxy::GetInfo());
138 AddPPB(PPB_URLResponseInfo_Proxy::GetInfo());
[email protected]9ca245e2011-03-18 01:50:31139 AddPPB(PPB_URLUtil_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46140 AddPPB(PPB_Var_Deprecated_Proxy::GetInfo());
141
[email protected]7d3782f2011-03-29 19:16:23142#ifdef ENABLE_FLAPPER_HACKS
143 AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo());
144#endif
145
[email protected]465faa22011-02-08 16:31:46146 // PPP (plugin) interfaces.
[email protected]8c3bd1d2011-04-12 20:01:42147 AddPPP(PPP_Graphics3D_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46148 AddPPP(PPP_Instance_Proxy::GetInfo());
149}
150
151void InterfaceList::AddPPP(const InterfaceProxy::Info* info) {
152 DCHECK(name_to_plugin_info_.find(info->name) ==
153 name_to_plugin_info_.end());
154 DCHECK(info->id > 0 && info->id < INTERFACE_ID_COUNT);
155 DCHECK(id_to_plugin_info_[info->id] == NULL);
156
157 name_to_plugin_info_[info->name] = info;
158 id_to_plugin_info_[info->id] = info;
159}
160
161void InterfaceList::AddPPB(const InterfaceProxy::Info* info) {
162 DCHECK(name_to_browser_info_.find(info->name) ==
163 name_to_browser_info_.end());
164 DCHECK(info->id > 0 && info->id < INTERFACE_ID_COUNT);
165 DCHECK(id_to_browser_info_[info->id] == NULL);
166
167 name_to_browser_info_[std::string(info->name)] = info;
168 id_to_browser_info_[info->id] = info;
169}
170
171// static
172InterfaceList* InterfaceList::GetInstance() {
173 return Singleton<InterfaceList>::get();
174}
175
176} // namespace
177
[email protected]5d84d012010-12-02 17:17:21178Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle,
179 GetInterfaceFunc local_get_interface)
[email protected]e2614c62011-04-16 22:12:45180 : ProxyChannel(remote_process_handle),
[email protected]5f2517612010-12-02 22:36:48181 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
[email protected]c2932f5e2010-11-03 03:22:33182 local_get_interface_(local_get_interface),
[email protected]709a847e2010-11-10 01:16:11183 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
[email protected]c2932f5e2010-11-03 03:22:33184}
185
186Dispatcher::~Dispatcher() {
187}
188
[email protected]a95986a82010-12-24 06:19:28189bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
[email protected]c2932f5e2010-11-03 03:22:33190 // Control messages.
191 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
[email protected]a95986a82010-12-24 06:19:28192 bool handled = true;
[email protected]c2932f5e2010-11-03 03:22:33193 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg)
[email protected]c2932f5e2010-11-03 03:22:33194 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_,
195 CallbackTracker::ReceiveExecuteSerializedCallback)
[email protected]a95986a82010-12-24 06:19:28196 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]c2932f5e2010-11-03 03:22:33197 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28198 return handled;
[email protected]c2932f5e2010-11-03 03:22:33199 }
[email protected]a95986a82010-12-24 06:19:28200 return false;
[email protected]c2932f5e2010-11-03 03:22:33201}
202
[email protected]465faa22011-02-08 16:31:46203// static
204const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(
205 const std::string& name) {
206 const InterfaceList* list = InterfaceList::GetInstance();
207 InterfaceList::NameToInfo::const_iterator found =
208 list->name_to_browser_info_.find(name);
209 if (found == list->name_to_browser_info_.end())
210 return NULL;
211 return found->second;
212}
213
214// static
215const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(InterfaceID id) {
216 if (id <= 0 || id >= INTERFACE_ID_COUNT)
217 return NULL;
218 const InterfaceList* list = InterfaceList::GetInstance();
219 return list->id_to_browser_info_[id];
220}
221
222// static
223const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo(
224 const std::string& name) {
225 const InterfaceList* list = InterfaceList::GetInstance();
226 InterfaceList::NameToInfo::const_iterator found =
227 list->name_to_plugin_info_.find(name);
228 if (found == list->name_to_plugin_info_.end())
229 return NULL;
230 return found->second;
231}
232
233// static
234const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo(InterfaceID id) {
235 if (id <= 0 || id >= INTERFACE_ID_COUNT)
236 return NULL;
237 const InterfaceList* list = InterfaceList::GetInstance();
238 return list->id_to_plugin_info_[id];
239}
240
[email protected]c2932f5e2010-11-03 03:22:33241void Dispatcher::SetSerializationRules(
242 VarSerializationRules* var_serialization_rules) {
243 serialization_rules_.reset(var_serialization_rules);
244}
245
[email protected]84396dbc2011-04-14 06:33:42246const void* Dispatcher::GetLocalInterface(const char* interface_name) {
247 return local_get_interface_(interface_name);
[email protected]c2932f5e2010-11-03 03:22:33248}
249
[email protected]1609d0d2011-04-15 22:06:21250MessageLoop* Dispatcher::GetIPCMessageLoop() {
[email protected]e2614c62011-04-16 22:12:45251 return delegate()->GetIPCMessageLoop();
[email protected]1609d0d2011-04-15 22:06:21252}
253
254void Dispatcher::AddIOThreadMessageFilter(
255 IPC::ChannelProxy::MessageFilter* filter) {
[email protected]e2614c62011-04-16 22:12:45256 channel()->AddFilter(filter);
[email protected]c2932f5e2010-11-03 03:22:33257}
258
[email protected]c2932f5e2010-11-03 03:22:33259} // namespace proxy
260} // namespace pp