| 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_webkit_thread.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/ppp.h" | 24 #include "ppapi/c/ppp.h" |
| 25 #include "ppapi/proxy/plugin_globals.h" | 25 #include "ppapi/proxy/plugin_globals.h" |
| 26 #include "ppapi/proxy/ppapi_messages.h" | 26 #include "ppapi/proxy/ppapi_messages.h" |
| 27 #include "ppapi/proxy/interface_list.h" | 27 #include "ppapi/proxy/interface_list.h" |
| 28 #include "webkit/plugins/ppapi/webkit_forwarding_impl.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 29 | 29 |
| 30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 31 #include "sandbox/src/sandbox.h" | 31 #include "sandbox/src/sandbox.h" |
| 32 #elif defined(OS_MACOSX) | 32 #elif defined(OS_MACOSX) |
| 33 #include "content/common/sandbox_init_mac.h" | 33 #include "content/common/sandbox_init_mac.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 37 extern sandbox::TargetServices* g_target_services; | 37 extern sandbox::TargetServices* g_target_services; |
| 38 #else | 38 #else |
| 39 extern void* g_target_services; | 39 extern void* g_target_services; |
| 40 #endif | 40 #endif |
| 41 | 41 |
| 42 typedef int32_t (*InitializeBrokerFunc) | 42 typedef int32_t (*InitializeBrokerFunc) |
| 43 (PP_ConnectInstance_Func* connect_instance_func); | 43 (PP_ConnectInstance_Func* connect_instance_func); |
| 44 | 44 |
| 45 PpapiThread::PpapiThread(bool is_broker) | 45 PpapiThread::PpapiThread(bool is_broker) |
| 46 : is_broker_(is_broker), | 46 : is_broker_(is_broker), |
| 47 get_plugin_interface_(NULL), | 47 get_plugin_interface_(NULL), |
| 48 connect_instance_func_(NULL), | 48 connect_instance_func_(NULL), |
| 49 local_pp_module_( | 49 local_pp_module_( |
| 50 base::RandInt(0, std::numeric_limits<PP_Module>::max())), | 50 base::RandInt(0, std::numeric_limits<PP_Module>::max())), |
| 51 next_plugin_dispatcher_id_(1) { | 51 next_plugin_dispatcher_id_(1) { |
| 52 ppapi::proxy::PluginGlobals::Get()->set_plugin_proxy_delegate(this); | 52 ppapi::proxy::PluginGlobals::Get()->set_plugin_proxy_delegate(this); |
| 53 webkit_platform_support_.reset(new PpapiWebKitPlatformSupportImpl); |
| 54 WebKit::initialize(webkit_platform_support_.get()); |
| 53 } | 55 } |
| 54 | 56 |
| 55 PpapiThread::~PpapiThread() { | 57 PpapiThread::~PpapiThread() { |
| 56 ppapi::proxy::PluginGlobals::Get()->set_plugin_proxy_delegate(NULL); | 58 ppapi::proxy::PluginGlobals::Get()->set_plugin_proxy_delegate(NULL); |
| 57 | 59 |
| 58 if (!library_.is_valid()) | 60 if (!library_.is_valid()) |
| 59 return; | 61 return; |
| 60 | 62 |
| 61 // The ShutdownModule/ShutdownBroker function is optional. | 63 // The ShutdownModule/ShutdownBroker function is optional. |
| 62 ppapi::proxy::ProxyChannel::ShutdownModuleFunc shutdown_function = | 64 ppapi::proxy::ProxyChannel::ShutdownModuleFunc shutdown_function = |
| 63 is_broker_ ? | 65 is_broker_ ? |
| 64 reinterpret_cast<ppapi::proxy::ProxyChannel::ShutdownModuleFunc>( | 66 reinterpret_cast<ppapi::proxy::ProxyChannel::ShutdownModuleFunc>( |
| 65 library_.GetFunctionPointer("PPP_ShutdownBroker")) : | 67 library_.GetFunctionPointer("PPP_ShutdownBroker")) : |
| 66 reinterpret_cast<ppapi::proxy::ProxyChannel::ShutdownModuleFunc>( | 68 reinterpret_cast<ppapi::proxy::ProxyChannel::ShutdownModuleFunc>( |
| 67 library_.GetFunctionPointer("PPP_ShutdownModule")); | 69 library_.GetFunctionPointer("PPP_ShutdownModule")); |
| 68 if (shutdown_function) | 70 if (shutdown_function) |
| 69 shutdown_function(); | 71 shutdown_function(); |
| 72 WebKit::shutdown(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 // The "regular" ChildThread implements this function and does some standard | 75 // The "regular" ChildThread implements this function and does some standard |
| 73 // dispatching, then uses the message router. We don't actually need any of | 76 // dispatching, then uses the message router. We don't actually need any of |
| 74 // this so this function just overrides that one. | 77 // this so this function just overrides that one. |
| 75 // | 78 // |
| 76 // Note that this function is called only for messages from the channel to the | 79 // Note that this function is called only for messages from the channel to the |
| 77 // browser process. Messages from the renderer process are sent via a different | 80 // browser process. Messages from the renderer process are sent via a different |
| 78 // channel that ends up at Dispatcher::OnMessageReceived. | 81 // channel that ends up at Dispatcher::OnMessageReceived. |
| 79 bool PpapiThread::OnMessageReceived(const IPC::Message& msg) { | 82 bool PpapiThread::OnMessageReceived(const IPC::Message& msg) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 104 } | 107 } |
| 105 | 108 |
| 106 base::WaitableEvent* PpapiThread::GetShutdownEvent() { | 109 base::WaitableEvent* PpapiThread::GetShutdownEvent() { |
| 107 return ChildProcess::current()->GetShutDownEvent(); | 110 return ChildProcess::current()->GetShutDownEvent(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { | 113 std::set<PP_Instance>* PpapiThread::GetGloballySeenInstanceIDSet() { |
| 111 return &globally_seen_instance_ids_; | 114 return &globally_seen_instance_ids_; |
| 112 } | 115 } |
| 113 | 116 |
| 114 ppapi::WebKitForwarding* PpapiThread::GetWebKitForwarding() { | |
| 115 if (!webkit_forwarding_.get()) | |
| 116 webkit_forwarding_.reset(new webkit::ppapi::WebKitForwardingImpl); | |
| 117 return webkit_forwarding_.get(); | |
| 118 } | |
| 119 | |
| 120 void PpapiThread::PostToWebKitThread(const tracked_objects::Location& from_here, | |
| 121 const base::Closure& task) { | |
| 122 if (!webkit_thread_.get()) | |
| 123 webkit_thread_.reset(new PpapiWebKitThread); | |
| 124 webkit_thread_->PostTask(from_here, task); | |
| 125 } | |
| 126 | |
| 127 bool PpapiThread::SendToBrowser(IPC::Message* msg) { | 117 bool PpapiThread::SendToBrowser(IPC::Message* msg) { |
| 128 return Send(msg); | 118 return Send(msg); |
| 129 } | 119 } |
| 130 | 120 |
| 131 void PpapiThread::PreCacheFont(const void* logfontw) { | 121 void PpapiThread::PreCacheFont(const void* logfontw) { |
| 132 #if defined(OS_WIN) | 122 #if defined(OS_WIN) |
| 133 Send(new ChildProcessHostMsg_PreCacheFont( | 123 Send(new ChildProcessHostMsg_PreCacheFont( |
| 134 *static_cast<const LOGFONTW*>(logfontw))); | 124 *static_cast<const LOGFONTW*>(logfontw))); |
| 135 #endif | 125 #endif |
| 136 } | 126 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // See for details: crbug.com/103957. | 312 // See for details: crbug.com/103957. |
| 323 CHECK_NE(-1, handle->socket.fd); | 313 CHECK_NE(-1, handle->socket.fd); |
| 324 if (handle->socket.fd == -1) | 314 if (handle->socket.fd == -1) |
| 325 return false; | 315 return false; |
| 326 #endif | 316 #endif |
| 327 | 317 |
| 328 // From here, the dispatcher will manage its own lifetime according to the | 318 // From here, the dispatcher will manage its own lifetime according to the |
| 329 // lifetime of the attached channel. | 319 // lifetime of the attached channel. |
| 330 return true; | 320 return true; |
| 331 } | 321 } |
| OLD | NEW |