OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/ppapi_plugin/ppapi_thread.h" | 5 #include "content/ppapi_plugin/ppapi_thread.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "content/common/child_process.h" | 13 #include "content/common/child_process.h" |
14 #include "content/common/child_process_messages.h" | 14 #include "content/common/child_process_messages.h" |
15 #include "content/ppapi_plugin/broker_process_dispatcher.h" | 15 #include "content/ppapi_plugin/broker_process_dispatcher.h" |
16 #include "content/ppapi_plugin/plugin_process_dispatcher.h" | 16 #include "content/ppapi_plugin/plugin_process_dispatcher.h" |
17 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" | 17 #include "content/ppapi_plugin/ppapi_webkitplatformsupport_impl.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/public/common/sandbox_init.h" | 19 #include "content/public/common/sandbox_init.h" |
20 #include "ipc/ipc_channel_handle.h" | 20 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_sync_channel.h" | 21 #include "ipc/ipc_sync_channel.h" |
22 #include "ppapi/c/dev/ppp_network_state_dev.h" | 22 #include "ppapi/c/dev/ppp_network_state_dev.h" |
23 #include "ppapi/c/pp_errors.h" | 23 #include "ppapi/c/pp_errors.h" |
24 #include "ppapi/c/private/ppp_flash_browser_operations.h" | |
viettrungluu
2012/04/11 02:48:10
nit: alphabetical order
| |
24 #include "ppapi/c/ppp.h" | 25 #include "ppapi/c/ppp.h" |
25 #include "ppapi/proxy/plugin_globals.h" | 26 #include "ppapi/proxy/plugin_globals.h" |
26 #include "ppapi/proxy/ppapi_messages.h" | 27 #include "ppapi/proxy/ppapi_messages.h" |
27 #include "ppapi/proxy/interface_list.h" | 28 #include "ppapi/proxy/interface_list.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
29 | 30 |
30 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
31 #include "sandbox/src/sandbox.h" | 32 #include "sandbox/src/sandbox.h" |
32 #elif defined(OS_MACOSX) | 33 #elif defined(OS_MACOSX) |
33 #include "content/common/sandbox_init_mac.h" | 34 #include "content/common/sandbox_init_mac.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 // dispatching, then uses the message router. We don't actually need any of | 77 // dispatching, then uses the message router. We don't actually need any of |
77 // this so this function just overrides that one. | 78 // this so this function just overrides that one. |
78 // | 79 // |
79 // Note that this function is called only for messages from the channel to the | 80 // Note that this function is called only for messages from the channel to the |
80 // browser process. Messages from the renderer process are sent via a different | 81 // browser process. Messages from the renderer process are sent via a different |
81 // channel that ends up at Dispatcher::OnMessageReceived. | 82 // channel that ends up at Dispatcher::OnMessageReceived. |
82 bool PpapiThread::OnMessageReceived(const IPC::Message& msg) { | 83 bool PpapiThread::OnMessageReceived(const IPC::Message& msg) { |
83 IPC_BEGIN_MESSAGE_MAP(PpapiThread, msg) | 84 IPC_BEGIN_MESSAGE_MAP(PpapiThread, msg) |
84 IPC_MESSAGE_HANDLER(PpapiMsg_LoadPlugin, OnMsgLoadPlugin) | 85 IPC_MESSAGE_HANDLER(PpapiMsg_LoadPlugin, OnMsgLoadPlugin) |
85 IPC_MESSAGE_HANDLER(PpapiMsg_CreateChannel, OnMsgCreateChannel) | 86 IPC_MESSAGE_HANDLER(PpapiMsg_CreateChannel, OnMsgCreateChannel) |
87 IPC_MESSAGE_HANDLER(PpapiMsg_ClearSiteData, OnMsgClearSiteData) | |
88 | |
86 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPServerSocket_ListenACK, | 89 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPServerSocket_ListenACK, |
87 OnPluginDispatcherMessageReceived(msg)) | 90 OnPluginDispatcherMessageReceived(msg)) |
88 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPServerSocket_AcceptACK, | 91 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPServerSocket_AcceptACK, |
89 OnPluginDispatcherMessageReceived(msg)) | 92 OnPluginDispatcherMessageReceived(msg)) |
90 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPSocket_ConnectACK, | 93 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPSocket_ConnectACK, |
91 OnPluginDispatcherMessageReceived(msg)) | 94 OnPluginDispatcherMessageReceived(msg)) |
92 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, | 95 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPSocket_SSLHandshakeACK, |
93 OnPluginDispatcherMessageReceived(msg)) | 96 OnPluginDispatcherMessageReceived(msg)) |
94 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPSocket_ReadACK, | 97 IPC_MESSAGE_HANDLER_GENERIC(PpapiMsg_PPBTCPSocket_ReadACK, |
95 OnPluginDispatcherMessageReceived(msg)) | 98 OnPluginDispatcherMessageReceived(msg)) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 if (!library_.is_valid() || // Plugin couldn't be loaded. | 251 if (!library_.is_valid() || // Plugin couldn't be loaded. |
249 !SetupRendererChannel(host_process_handle, renderer_id, | 252 !SetupRendererChannel(host_process_handle, renderer_id, |
250 &channel_handle)) { | 253 &channel_handle)) { |
251 Send(new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle())); | 254 Send(new PpapiHostMsg_ChannelCreated(IPC::ChannelHandle())); |
252 return; | 255 return; |
253 } | 256 } |
254 | 257 |
255 Send(new PpapiHostMsg_ChannelCreated(channel_handle)); | 258 Send(new PpapiHostMsg_ChannelCreated(channel_handle)); |
256 } | 259 } |
257 | 260 |
261 void PpapiThread::OnMsgClearSiteData(const FilePath& profile_path, | |
262 const std::string& site, | |
263 uint64 flags, | |
264 uint64 max_age) { | |
265 Send(new PpapiHostMsg_ClearSiteDataResult( | |
266 ClearSiteData(profile_path, site, flags, max_age))); | |
267 } | |
268 | |
258 void PpapiThread::OnMsgSetNetworkState(bool online) { | 269 void PpapiThread::OnMsgSetNetworkState(bool online) { |
259 if (!get_plugin_interface_) | 270 if (!get_plugin_interface_) |
260 return; | 271 return; |
261 const PPP_NetworkState_Dev* ns = static_cast<const PPP_NetworkState_Dev*>( | 272 const PPP_NetworkState_Dev* ns = static_cast<const PPP_NetworkState_Dev*>( |
262 get_plugin_interface_(PPP_NETWORK_STATE_DEV_INTERFACE)); | 273 get_plugin_interface_(PPP_NETWORK_STATE_DEV_INTERFACE)); |
263 if (ns) | 274 if (ns) |
264 ns->SetOnLine(PP_FromBool(online)); | 275 ns->SetOnLine(PP_FromBool(online)); |
265 } | 276 } |
266 | 277 |
267 void PpapiThread::OnPluginDispatcherMessageReceived(const IPC::Message& msg) { | 278 void PpapiThread::OnPluginDispatcherMessageReceived(const IPC::Message& msg) { |
268 // The first parameter should be a plugin dispatcher ID. | 279 // The first parameter should be a plugin dispatcher ID. |
269 PickleIterator iter(msg); | 280 PickleIterator iter(msg); |
270 uint32 id = 0; | 281 uint32 id = 0; |
271 if (!msg.ReadUInt32(&iter, &id)) { | 282 if (!msg.ReadUInt32(&iter, &id)) { |
272 NOTREACHED(); | 283 NOTREACHED(); |
273 return; | 284 return; |
274 } | 285 } |
275 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 286 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
276 plugin_dispatchers_.find(id); | 287 plugin_dispatchers_.find(id); |
277 if (dispatcher != plugin_dispatchers_.end()) | 288 if (dispatcher != plugin_dispatchers_.end()) |
278 dispatcher->second->OnMessageReceived(msg); | 289 dispatcher->second->OnMessageReceived(msg); |
279 } | 290 } |
280 | 291 |
292 bool PpapiThread::ClearSiteData(const FilePath& profile_path, | |
viettrungluu
2012/04/11 02:48:10
What I said about "profile path" (in the .idl file
| |
293 const std::string& site, | |
294 uint64 flags, | |
295 uint64 max_age) { | |
296 if (!get_plugin_interface_) | |
297 return false; | |
298 const PPP_Flash_BrowserOperations_1_0* browser_interface = | |
299 static_cast<const PPP_Flash_BrowserOperations_1_0*>( | |
300 get_plugin_interface_(PPP_FLASH_BROWSEROPERATIONS_INTERFACE_1_0)); | |
301 if (!browser_interface) | |
302 return false; | |
303 | |
304 // The string is always 8-bit, convert on Windows. | |
305 #if defined(OS_WIN) | |
306 std::string profile_str = WideToUTF8(profile_path.value()); | |
307 #else | |
308 std::string profile_str = profile_path.value(); | |
309 #endif | |
310 | |
311 browser_interface->ClearSiteData(profile_str.c_str(), | |
312 site.empty() ? NULL : site.c_str(), | |
313 flags, max_age); | |
314 return true; | |
315 } | |
316 | |
281 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, | 317 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, |
282 int renderer_id, | 318 int renderer_id, |
283 IPC::ChannelHandle* handle) { | 319 IPC::ChannelHandle* handle) { |
284 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); | 320 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); |
285 DCHECK(is_broker_ == (get_plugin_interface_ == NULL)); | 321 DCHECK(is_broker_ == (get_plugin_interface_ == NULL)); |
286 IPC::ChannelHandle plugin_handle; | 322 IPC::ChannelHandle plugin_handle; |
287 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( | 323 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( |
288 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); | 324 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); |
289 | 325 |
290 ppapi::proxy::ProxyChannel* dispatcher = NULL; | 326 ppapi::proxy::ProxyChannel* dispatcher = NULL; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 359 |
324 // From here, the dispatcher will manage its own lifetime according to the | 360 // From here, the dispatcher will manage its own lifetime according to the |
325 // lifetime of the attached channel. | 361 // lifetime of the attached channel. |
326 return true; | 362 return true; |
327 } | 363 } |
328 | 364 |
329 void PpapiThread::SavePluginName(const FilePath& path) { | 365 void PpapiThread::SavePluginName(const FilePath& path) { |
330 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( | 366 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( |
331 path.BaseName().AsUTF8Unsafe()); | 367 path.BaseName().AsUTF8Unsafe()); |
332 } | 368 } |
OLD | NEW |