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_opengles_dev.h" | |
22 #include "ppapi/c/dev/ppb_surface_3d_dev.h" | |
23 #include "ppapi/c/dev/ppb_testing_dev.h" | |
24 #include "ppapi/c/dev/ppb_url_util_dev.h" | |
25 #include "ppapi/c/dev/ppb_var_deprecated.h" | |
26 #include "ppapi/c/pp_errors.h" | |
27 #include "ppapi/c/ppb_audio.h" | |
28 #include "ppapi/c/ppb_audio_config.h" | |
29 #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" | |
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_video_decoder_proxy.h" | |
92 #include "ppapi/proxy/var_serialization_rules.h" | 15 #include "ppapi/proxy/var_serialization_rules.h" |
93 | 16 |
94 namespace ppapi { | 17 namespace ppapi { |
95 namespace proxy { | 18 namespace proxy { |
96 | 19 |
97 namespace { | |
98 | |
99 struct InterfaceList { | |
100 InterfaceList(); | |
101 | |
102 static InterfaceList* GetInstance(); | |
103 | |
104 void AddPPP(const InterfaceProxy::Info* info); | |
105 void AddPPB(const InterfaceProxy::Info* info); | |
106 | |
107 typedef std::map<std::string, const InterfaceProxy::Info*> NameToInfo; | |
108 NameToInfo name_to_plugin_info_; | |
109 NameToInfo name_to_browser_info_; | |
110 | |
111 // Note that there can be multiple interface names mapping to the same ID. | |
112 // In this case, the ID will map to one of them. This is temporary while | |
113 // we're converting to the thunk system, when that is complete, we need to | |
114 // have a better way of handling multiple interface implemented by one | |
115 // proxy object. | |
116 const InterfaceProxy::Info* id_to_browser_info_[INTERFACE_ID_COUNT]; | |
117 }; | |
118 | |
119 InterfaceList::InterfaceList() { | |
120 memset(id_to_browser_info_, 0, sizeof(id_to_browser_info_)); | |
121 | |
122 // PPB (browser) interfaces. | |
123 AddPPB(PPB_AudioConfig_Proxy::GetInfo()); | |
124 AddPPB(PPB_Audio_Proxy::GetInfo()); | |
125 AddPPB(PPB_Broker_Proxy::GetInfo()); | |
126 AddPPB(PPB_Buffer_Proxy::GetInfo()); | |
127 AddPPB(PPB_CharSet_Proxy::GetInfo()); | |
128 AddPPB(PPB_Console_Proxy::GetInfo()); | |
129 AddPPB(PPB_Context3D_Proxy::GetInfo()); | |
130 AddPPB(PPB_Context3D_Proxy::GetTextureMappingInfo()); | |
131 AddPPB(PPB_Core_Proxy::GetInfo()); | |
132 AddPPB(PPB_Crypto_Proxy::GetInfo()); | |
133 AddPPB(PPB_CursorControl_Proxy::GetInfo()); | |
134 AddPPB(PPB_FileChooser_Proxy::GetInfo()); | |
135 AddPPB(PPB_FileChooser_Proxy::GetInfo0_4()); | |
136 AddPPB(PPB_FileRef_Proxy::GetInfo()); | |
137 AddPPB(PPB_FileSystem_Proxy::GetInfo()); | |
138 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); | |
139 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); | |
140 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); | |
141 AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); | |
142 AddPPB(PPB_Flash_Proxy::GetInfo()); | |
143 AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); | |
144 AddPPB(PPB_Font_Proxy::GetInfo()); | |
145 AddPPB(PPB_Graphics2D_Proxy::GetInfo()); | |
146 AddPPB(PPB_Graphics3D_Proxy::GetInfo()); | |
147 AddPPB(PPB_ImageData_Proxy::GetInfo()); | |
148 AddPPB(PPB_InputEvent_Proxy::GetInputEventInfo()); | |
149 AddPPB(PPB_InputEvent_Proxy::GetKeyboardInputEventInfo()); | |
150 AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo1_0()); | |
151 AddPPB(PPB_InputEvent_Proxy::GetMouseInputEventInfo1_1()); | |
152 AddPPB(PPB_InputEvent_Proxy::GetWheelInputEventInfo()); | |
153 AddPPB(PPB_Instance_Proxy::GetInfo0_5()); | |
154 AddPPB(PPB_Instance_Proxy::GetInfo1_0()); | |
155 AddPPB(PPB_Instance_Proxy::GetInfoFullscreen()); | |
156 AddPPB(PPB_Instance_Proxy::GetInfoMessaging()); | |
157 AddPPB(PPB_Instance_Proxy::GetInfoPrivate()); | |
158 AddPPB(PPB_Memory_Proxy::GetInfo()); | |
159 AddPPB(PPB_OpenGLES2_Proxy::GetInfo()); | |
160 AddPPB(PPB_PDF_Proxy::GetInfo()); | |
161 AddPPB(PPB_Surface3D_Proxy::GetInfo()); | |
162 AddPPB(PPB_Testing_Proxy::GetInfo()); | |
163 AddPPB(PPB_URLLoader_Proxy::GetInfo()); | |
164 AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); | |
165 AddPPB(PPB_URLRequestInfo_Proxy::GetInfo()); | |
166 AddPPB(PPB_URLResponseInfo_Proxy::GetInfo()); | |
167 AddPPB(PPB_URLUtil_Proxy::GetInfo()); | |
168 AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); | |
169 AddPPB(PPB_Var_Proxy::GetInfo()); | |
170 AddPPB(PPB_VideoCapture_Proxy::GetInfo()); | |
171 AddPPB(PPB_VideoDecoder_Proxy::GetInfo()); | |
172 | |
173 #ifdef ENABLE_FLAPPER_HACKS | |
174 AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo()); | |
175 #endif | |
176 | |
177 // PPP (plugin) interfaces. | |
178 AddPPP(PPP_Graphics3D_Proxy::GetInfo()); | |
179 AddPPP(PPP_InputEvent_Proxy::GetInfo()); | |
180 AddPPP(PPP_Instance_Private_Proxy::GetInfo()); | |
181 AddPPP(PPP_Instance_Proxy::GetInfo1_0()); | |
182 AddPPP(PPP_Messaging_Proxy::GetInfo()); | |
183 AddPPP(PPP_VideoCapture_Proxy::GetInfo()); | |
184 AddPPP(PPP_VideoDecoder_Proxy::GetInfo()); | |
185 } | |
186 | |
187 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { | |
188 DCHECK(name_to_plugin_info_.find(info->name) == | |
189 name_to_plugin_info_.end()); | |
190 DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT); | |
191 | |
192 name_to_plugin_info_[info->name] = info; | |
193 } | |
194 | |
195 void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { | |
196 DCHECK(name_to_browser_info_.find(info->name) == | |
197 name_to_browser_info_.end()); | |
198 DCHECK(info->id >= INTERFACE_ID_NONE && info->id < INTERFACE_ID_COUNT); | |
199 DCHECK(info->id == INTERFACE_ID_NONE || | |
200 id_to_browser_info_[info->id] == NULL); | |
201 | |
202 name_to_browser_info_[std::string(info->name)] = info; | |
203 if (info->id != INTERFACE_ID_NONE) | |
204 id_to_browser_info_[info->id] = info; | |
205 } | |
206 | |
207 // static | |
208 InterfaceList* InterfaceList::GetInstance() { | |
209 return Singleton<InterfaceList>::get(); | |
210 } | |
211 | |
212 } // namespace | |
213 | |
214 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, | 20 Dispatcher::Dispatcher(base::ProcessHandle remote_process_handle, |
215 GetInterfaceFunc local_get_interface) | 21 GetInterfaceFunc local_get_interface) |
216 : ProxyChannel(remote_process_handle), | 22 : ProxyChannel(remote_process_handle), |
217 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. | 23 disallow_trusted_interfaces_(false), // TODO(brettw) make this settable. |
218 local_get_interface_(local_get_interface), | 24 local_get_interface_(local_get_interface), |
219 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 25 callback_tracker_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
220 } | 26 } |
221 | 27 |
222 Dispatcher::~Dispatcher() { | 28 Dispatcher::~Dispatcher() { |
223 } | 29 } |
224 | 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 | |
225 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { | 57 bool Dispatcher::OnMessageReceived(const IPC::Message& msg) { |
226 // Control messages. | 58 // Control messages. |
227 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 59 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
228 bool handled = true; | 60 bool handled = true; |
229 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) | 61 IPC_BEGIN_MESSAGE_MAP(Dispatcher, msg) |
230 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, | 62 IPC_MESSAGE_FORWARD(PpapiMsg_ExecuteCallback, &callback_tracker_, |
231 CallbackTracker::ReceiveExecuteSerializedCallback) | 63 CallbackTracker::ReceiveExecuteSerializedCallback) |
232 IPC_MESSAGE_UNHANDLED(handled = false) | 64 IPC_MESSAGE_UNHANDLED(handled = false) |
233 IPC_END_MESSAGE_MAP() | 65 IPC_END_MESSAGE_MAP() |
234 return handled; | 66 return handled; |
235 } | 67 } |
236 return false; | |
237 } | |
238 | 68 |
239 // static | 69 if (msg.routing_id() <= 0 || msg.routing_id() >= INTERFACE_ID_COUNT) { |
noelallen_use_chromium
2011/09/07 21:16:57
What is guaranteeing that Chrome and the Plugin th
brettw
2011/09/08 05:34:29
Just the fact that this is all compiled at the sam
noelallen_use_chromium
2011/09/08 19:49:16
Sure for our current uses. I just wasn't sure if
| |
240 const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo( | 70 OnInvalidMessageReceived(); |
241 const std::string& name) { | 71 return true; |
242 const InterfaceList* list = InterfaceList::GetInstance(); | 72 } |
243 InterfaceList::NameToInfo::const_iterator found = | |
244 list->name_to_browser_info_.find(name); | |
245 if (found == list->name_to_browser_info_.end()) | |
246 return NULL; | |
247 return found->second; | |
248 } | |
249 | 73 |
250 // static | 74 InterfaceProxy* proxy = GetInterfaceProxy( |
251 const InterfaceProxy::Info* Dispatcher::GetPPBInterfaceInfo(InterfaceID id) { | 75 static_cast<InterfaceID>(msg.routing_id())); |
252 if (id <= 0 || id >= INTERFACE_ID_COUNT) | 76 if (!proxy) { |
253 return NULL; | 77 NOTREACHED(); |
254 const InterfaceList* list = InterfaceList::GetInstance(); | 78 return true; |
255 return list->id_to_browser_info_[id]; | 79 } |
256 } | 80 return proxy->OnMessageReceived(msg); |
257 | |
258 // static | |
259 const InterfaceProxy::Info* Dispatcher::GetPPPInterfaceInfo( | |
260 const std::string& name) { | |
261 const InterfaceList* list = InterfaceList::GetInstance(); | |
262 InterfaceList::NameToInfo::const_iterator found = | |
263 list->name_to_plugin_info_.find(name); | |
264 if (found == list->name_to_plugin_info_.end()) | |
265 return NULL; | |
266 return found->second; | |
267 } | 81 } |
268 | 82 |
269 void Dispatcher::SetSerializationRules( | 83 void Dispatcher::SetSerializationRules( |
270 VarSerializationRules* var_serialization_rules) { | 84 VarSerializationRules* var_serialization_rules) { |
271 serialization_rules_.reset(var_serialization_rules); | 85 serialization_rules_.reset(var_serialization_rules); |
272 } | 86 } |
273 | 87 |
274 const void* Dispatcher::GetLocalInterface(const char* interface_name) { | 88 void Dispatcher::OnInvalidMessageReceived() { |
275 return local_get_interface_(interface_name); | |
276 } | |
277 | |
278 base::MessageLoopProxy* Dispatcher::GetIPCMessageLoop() { | |
279 return delegate()->GetIPCMessageLoop(); | |
280 } | |
281 | |
282 void Dispatcher::AddIOThreadMessageFilter( | |
283 IPC::ChannelProxy::MessageFilter* filter) { | |
284 channel()->AddFilter(filter); | |
285 } | 89 } |
286 | 90 |
287 } // namespace proxy | 91 } // namespace proxy |
288 } // namespace ppapi | 92 } // namespace ppapi |
OLD | NEW |