blob: 36f8f0ab0dda639f26d540247f8993c7952e42a3 [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]43a40202010-11-12 16:25:0147#include "ppapi/proxy/ppb_buffer_proxy.h"
[email protected]9ca952d2010-11-11 20:43:5048#include "ppapi/proxy/ppb_char_set_proxy.h"
[email protected]d38c57402011-03-11 20:20:5649#include "ppapi/proxy/ppb_console_proxy.h"
[email protected]f56279c2011-02-02 18:12:3150#include "ppapi/proxy/ppb_context_3d_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3351#include "ppapi/proxy/ppb_core_proxy.h"
[email protected]a3010332010-11-12 07:09:3552#include "ppapi/proxy/ppb_cursor_control_proxy.h"
[email protected]4deeb432011-02-17 23:59:3953#include "ppapi/proxy/ppb_file_chooser_proxy.h"
54#include "ppapi/proxy/ppb_file_ref_proxy.h"
[email protected]ce482df2011-02-21 23:49:1655#include "ppapi/proxy/ppb_file_system_proxy.h"
[email protected]5cf8a5b2011-03-09 19:00:0556#include "ppapi/proxy/ppb_flash_clipboard_proxy.h"
[email protected]d07fa3792011-02-24 18:58:0157#include "ppapi/proxy/ppb_flash_file_proxy.h"
[email protected]5f2517612010-12-02 22:36:4858#include "ppapi/proxy/ppb_flash_proxy.h"
[email protected]7358d572011-02-15 18:44:4059#include "ppapi/proxy/ppb_flash_menu_proxy.h"
[email protected]7d3782f2011-03-29 19:16:2360#include "ppapi/proxy/ppb_flash_net_connector_proxy.h"
[email protected]9ca952d2010-11-11 20:43:5061#include "ppapi/proxy/ppb_font_proxy.h"
[email protected]a3010332010-11-12 07:09:3562#include "ppapi/proxy/ppb_fullscreen_proxy.h"
[email protected]f56279c2011-02-02 18:12:3163#include "ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3364#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
65#include "ppapi/proxy/ppb_image_data_proxy.h"
66#include "ppapi/proxy/ppb_instance_proxy.h"
[email protected]f56279c2011-02-02 18:12:3167#include "ppapi/proxy/ppb_opengles2_proxy.h"
[email protected]43a40202010-11-12 16:25:0168#include "ppapi/proxy/ppb_pdf_proxy.h"
[email protected]f56279c2011-02-02 18:12:3169#include "ppapi/proxy/ppb_surface_3d_proxy.h"
[email protected]799d1ab2010-11-09 17:16:2870#include "ppapi/proxy/ppb_testing_proxy.h"
71#include "ppapi/proxy/ppb_url_loader_proxy.h"
72#include "ppapi/proxy/ppb_url_request_info_proxy.h"
73#include "ppapi/proxy/ppb_url_response_info_proxy.h"
[email protected]9ca245e2011-03-18 01:50:3174#include "ppapi/proxy/ppb_url_util_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3375#include "ppapi/proxy/ppb_var_deprecated_proxy.h"
76#include "ppapi/proxy/ppp_class_proxy.h"
[email protected]8c3bd1d2011-04-12 20:01:4277#include "ppapi/proxy/ppp_graphics_3d_proxy.h"
[email protected]c2932f5e2010-11-03 03:22:3378#include "ppapi/proxy/ppp_instance_proxy.h"
79#include "ppapi/proxy/var_serialization_rules.h"
80
81namespace pp {
82namespace proxy {
83
[email protected]465faa22011-02-08 16:31:4684namespace {
85
86struct InterfaceList {
87 InterfaceList();
88
89 static InterfaceList* GetInstance();
90
91 void AddPPP(const InterfaceProxy::Info* info);
92 void AddPPB(const InterfaceProxy::Info* info);
93
94 typedef std::map<std::string, const InterfaceProxy::Info*> NameToInfo;
95 NameToInfo name_to_plugin_info_;
96 NameToInfo name_to_browser_info_;
97
98 const InterfaceProxy::Info* id_to_plugin_info_[INTERFACE_ID_COUNT];
99 const InterfaceProxy::Info* id_to_browser_info_[INTERFACE_ID_COUNT];
100};
101
102InterfaceList::InterfaceList() {
[email protected]ce482df2011-02-21 23:49:16103 memset(id_to_plugin_info_, 0, sizeof(id_to_plugin_info_));
104 memset(id_to_browser_info_, 0, sizeof(id_to_browser_info_));
[email protected]465faa22011-02-08 16:31:46105
106 // PPB (browser) interfaces.
107 AddPPB(PPB_AudioConfig_Proxy::GetInfo());
108 AddPPB(PPB_Audio_Proxy::GetInfo());
109 AddPPB(PPB_Buffer_Proxy::GetInfo());
110 AddPPB(PPB_CharSet_Proxy::GetInfo());
[email protected]d38c57402011-03-11 20:20:56111 AddPPB(PPB_Console_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46112 AddPPB(PPB_Context3D_Proxy::GetInfo());
113 AddPPB(PPB_Core_Proxy::GetInfo());
114 AddPPB(PPB_CursorControl_Proxy::GetInfo());
[email protected]4deeb432011-02-17 23:59:39115 AddPPB(PPB_FileChooser_Proxy::GetInfo());
116 AddPPB(PPB_FileRef_Proxy::GetInfo());
[email protected]ce482df2011-02-21 23:49:16117 AddPPB(PPB_FileSystem_Proxy::GetInfo());
[email protected]5cf8a5b2011-03-09 19:00:05118 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo());
[email protected]d062d962011-03-02 01:27:26119 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo());
[email protected]d07fa3792011-02-24 18:58:01120 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46121 AddPPB(PPB_Flash_Proxy::GetInfo());
[email protected]7358d572011-02-15 18:44:40122 AddPPB(PPB_Flash_Menu_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46123 AddPPB(PPB_Font_Proxy::GetInfo());
124 AddPPB(PPB_Fullscreen_Proxy::GetInfo());
125 AddPPB(PPB_GLESChromiumTextureMapping_Proxy::GetInfo());
126 AddPPB(PPB_Graphics2D_Proxy::GetInfo());
127 AddPPB(PPB_ImageData_Proxy::GetInfo());
128 AddPPB(PPB_Instance_Proxy::GetInfo());
129 AddPPB(PPB_OpenGLES2_Proxy::GetInfo());
130 AddPPB(PPB_PDF_Proxy::GetInfo());
131 AddPPB(PPB_Surface3D_Proxy::GetInfo());
132 AddPPB(PPB_Testing_Proxy::GetInfo());
133 AddPPB(PPB_URLLoader_Proxy::GetInfo());
134 AddPPB(PPB_URLLoaderTrusted_Proxy::GetInfo());
135 AddPPB(PPB_URLRequestInfo_Proxy::GetInfo());
136 AddPPB(PPB_URLResponseInfo_Proxy::GetInfo());
[email protected]9ca245e2011-03-18 01:50:31137 AddPPB(PPB_URLUtil_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46138 AddPPB(PPB_Var_Deprecated_Proxy::GetInfo());
139
[email protected]7d3782f2011-03-29 19:16:23140#ifdef ENABLE_FLAPPER_HACKS
141 AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo());
142#endif
143
[email protected]465faa22011-02-08 16:31:46144 // PPP (plugin) interfaces.
[email protected]8c3bd1d2011-04-12 20:01:42145 AddPPP(PPP_Graphics3D_Proxy::GetInfo());
[email protected]465faa22011-02-08 16:31:46146 AddPPP(PPP_Instance_Proxy::GetInfo());
147}
148
149void InterfaceList::AddPPP(const InterfaceProxy::Info* info) {
150 DCHECK(name_to_plugin_info_.find(info->name) ==
151 name_to_plugin_info_.end());
152 DCHECK(info->id > 0 && info->id < INTERFACE_ID_COUNT);
153 DCHECK(id_to_plugin_info_[info->id] == NULL);
154
155 name_to_plugin_info_[info->name] = info;
156 id_to_plugin_info_[info->id] = info;
157}
158
159void InterfaceList::AddPPB(const InterfaceProxy::Info* info) {
160 DCHECK(name_to_browser_info_.find(info->name) ==
161 name_to_browser_info_.end());
162 DCHECK(info->id > 0 && info->id < INTERFACE_ID_COUNT);
163 DCHECK(id_to_browser_info_[info->id] == NULL);
164
165 name_to_browser_info_[std::string(info->name)] = info;
166 id_to_browser_info_[info->id] = info;
167}
168
169// static
170InterfaceList* InterfaceList::GetInstance() {
171 return Singleton<InterfaceList>::get();
172}
173
174} // namespace
175
[email protected]5d84d012010-12-02 17:17:21176Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle,
177 GetInterfaceFunc local_get_interface)
[email protected]e2614c62011-04-16 22:12:45178 : ProxyChannel(remote_process_handle),
[email protected]5f2517612010-12-02 22:36:48179 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable.
[email protected]c2932f5e2010-11-03 03:22:33180 local_get_interface_(local_get_interface),
[email protected]709a847e2010-11-10 01:16:11181 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
[email protected]c2932f5e2010-11-03 03:22:33182}
183
184Dispatcher::~Dispatcher() {
185}
186
[email protected]a95986a82010-12-24 06:19:28187bool Dispatcher::OnMessageReceived(const IPC::Message& msg) {
[email protected]c2932f5e2010-11-03 03:22:33188 // Control messages.
189 if (msg.routing_id() == MSG_ROUTING_CONTROL) {
[email protected]a95986a82010-12-24 06:19:28190 bool handled = true;
[email protected]c2932f5e2010-11-03 03:22:33191 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg)
[email protected]c2932f5e2010-11-03 03:22:33192 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_,
193 CallbackTracker::ReceiveExecuteSerializedCallback)
[email protected]a95986a82010-12-24 06:19:28194 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]c2932f5e2010-11-03 03:22:33195 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28196 return handled;
[email protected]c2932f5e2010-11-03 03:22:33197 }
[email protected]a95986a82010-12-24 06:19:28198 return false;
[email protected]c2932f5e2010-11-03 03:22:33199}
200
[email protected]465faa22011-02-08 16:31:46201// static
202const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(
203 const std::string& name) {
204 const InterfaceList* list = InterfaceList::GetInstance();
205 InterfaceList::NameToInfo::const_iterator found =
206 list->name_to_browser_info_.find(name);
207 if (found == list->name_to_browser_info_.end())
208 return NULL;
209 return found->second;
210}
211
212// static
213const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(InterfaceID id) {
214 if (id <= 0 || id >= INTERFACE_ID_COUNT)
215 return NULL;
216 const InterfaceList* list = InterfaceList::GetInstance();
217 return list->id_to_browser_info_[id];
218}
219
220// static
221const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo(
222 const std::string& name) {
223 const InterfaceList* list = InterfaceList::GetInstance();
224 InterfaceList::NameToInfo::const_iterator found =
225 list->name_to_plugin_info_.find(name);
226 if (found == list->name_to_plugin_info_.end())
227 return NULL;
228 return found->second;
229}
230
231// static
232const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo(InterfaceID id) {
233 if (id <= 0 || id >= INTERFACE_ID_COUNT)
234 return NULL;
235 const InterfaceList* list = InterfaceList::GetInstance();
236 return list->id_to_plugin_info_[id];
237}
238
[email protected]c2932f5e2010-11-03 03:22:33239void Dispatcher::SetSerializationRules(
240 VarSerializationRules* var_serialization_rules) {
241 serialization_rules_.reset(var_serialization_rules);
242}
243
[email protected]84396dbc2011-04-14 06:33:42244const void* Dispatcher::GetLocalInterface(const char* interface_name) {
245 return local_get_interface_(interface_name);
[email protected]c2932f5e2010-11-03 03:22:33246}
247
[email protected]1609d0d2011-04-15 22:06:21248MessageLoop* Dispatcher::GetIPCMessageLoop() {
[email protected]e2614c62011-04-16 22:12:45249 return delegate()->GetIPCMessageLoop();
[email protected]1609d0d2011-04-15 22:06:21250}
251
252void Dispatcher::AddIOThreadMessageFilter(
253 IPC::ChannelProxy::MessageFilter* filter) {
[email protected]e2614c62011-04-16 22:12:45254 channel()->AddFilter(filter);
[email protected]c2932f5e2010-11-03 03:22:33255}
256
[email protected]c2932f5e2010-11-03 03:22:33257} // namespace proxy
258} // namespace pp