| 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_clear_site_data.h" |
| 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 std::string& site, |
| 262 uint64 flags, |
| 263 uint64 max_age) { |
| 264 Send(new PpapiHostMsg_ClearSiteDataResult( |
| 265 ClearSiteData(site, flags, max_age))); |
| 266 } |
| 267 |
| 258 void PpapiThread::OnMsgSetNetworkState(bool online) { | 268 void PpapiThread::OnMsgSetNetworkState(bool online) { |
| 259 if (!get_plugin_interface_) | 269 if (!get_plugin_interface_) |
| 260 return; | 270 return; |
| 261 const PPP_NetworkState_Dev* ns = static_cast<const PPP_NetworkState_Dev*>( | 271 const PPP_NetworkState_Dev* ns = static_cast<const PPP_NetworkState_Dev*>( |
| 262 get_plugin_interface_(PPP_NETWORK_STATE_DEV_INTERFACE)); | 272 get_plugin_interface_(PPP_NETWORK_STATE_DEV_INTERFACE)); |
| 263 if (ns) | 273 if (ns) |
| 264 ns->SetOnLine(PP_FromBool(online)); | 274 ns->SetOnLine(PP_FromBool(online)); |
| 265 } | 275 } |
| 266 | 276 |
| 267 void PpapiThread::OnPluginDispatcherMessageReceived(const IPC::Message& msg) { | 277 void PpapiThread::OnPluginDispatcherMessageReceived(const IPC::Message& msg) { |
| 268 // The first parameter should be a plugin dispatcher ID. | 278 // The first parameter should be a plugin dispatcher ID. |
| 269 PickleIterator iter(msg); | 279 PickleIterator iter(msg); |
| 270 uint32 id = 0; | 280 uint32 id = 0; |
| 271 if (!msg.ReadUInt32(&iter, &id)) { | 281 if (!msg.ReadUInt32(&iter, &id)) { |
| 272 NOTREACHED(); | 282 NOTREACHED(); |
| 273 return; | 283 return; |
| 274 } | 284 } |
| 275 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = | 285 std::map<uint32, ppapi::proxy::PluginDispatcher*>::iterator dispatcher = |
| 276 plugin_dispatchers_.find(id); | 286 plugin_dispatchers_.find(id); |
| 277 if (dispatcher != plugin_dispatchers_.end()) | 287 if (dispatcher != plugin_dispatchers_.end()) |
| 278 dispatcher->second->OnMessageReceived(msg); | 288 dispatcher->second->OnMessageReceived(msg); |
| 279 } | 289 } |
| 280 | 290 |
| 291 bool PpapiThread::ClearSiteData(const std::string& site, |
| 292 uint64 flags, |
| 293 uint64 max_age) { |
| 294 if (!get_plugin_interface_) |
| 295 return false; |
| 296 const PPP_Flash_ClearSiteData_1_0* clear_interface = |
| 297 static_cast<const PPP_Flash_ClearSiteData_1_0*>( |
| 298 get_plugin_interface_(PPP_FLASH_CLEARSITEDATA_INTERFACE_1_0)); |
| 299 if (!clear_interface) |
| 300 return false; |
| 301 |
| 302 clear_interface->ClearSiteData(site.empty() ? NULL : site.c_str(), |
| 303 flags, max_age); |
| 304 return true; |
| 305 } |
| 306 |
| 281 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, | 307 bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, |
| 282 int renderer_id, | 308 int renderer_id, |
| 283 IPC::ChannelHandle* handle) { | 309 IPC::ChannelHandle* handle) { |
| 284 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); | 310 DCHECK(is_broker_ == (connect_instance_func_ != NULL)); |
| 285 DCHECK(is_broker_ == (get_plugin_interface_ == NULL)); | 311 DCHECK(is_broker_ == (get_plugin_interface_ == NULL)); |
| 286 IPC::ChannelHandle plugin_handle; | 312 IPC::ChannelHandle plugin_handle; |
| 287 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( | 313 plugin_handle.name = IPC::Channel::GenerateVerifiedChannelID( |
| 288 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); | 314 StringPrintf("%d.r%d", base::GetCurrentProcId(), renderer_id)); |
| 289 | 315 |
| 290 ppapi::proxy::ProxyChannel* dispatcher = NULL; | 316 ppapi::proxy::ProxyChannel* dispatcher = NULL; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 349 |
| 324 // From here, the dispatcher will manage its own lifetime according to the | 350 // From here, the dispatcher will manage its own lifetime according to the |
| 325 // lifetime of the attached channel. | 351 // lifetime of the attached channel. |
| 326 return true; | 352 return true; |
| 327 } | 353 } |
| 328 | 354 |
| 329 void PpapiThread::SavePluginName(const FilePath& path) { | 355 void PpapiThread::SavePluginName(const FilePath& path) { |
| 330 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( | 356 ppapi::proxy::PluginGlobals::Get()->set_plugin_name( |
| 331 path.BaseName().AsUTF8Unsafe()); | 357 path.BaseName().AsUTF8Unsafe()); |
| 332 } | 358 } |
| OLD | NEW |