Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: content/renderer/pepper/pepper_plugin_delegate_impl.cc

Issue 10378057: Broker out PPAPI handle duplication (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/renderer/pepper/pepper_plugin_delegate_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 namespace content { 95 namespace content {
96 96
97 namespace { 97 namespace {
98 98
99 class HostDispatcherWrapper 99 class HostDispatcherWrapper
100 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy { 100 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy {
101 public: 101 public:
102 HostDispatcherWrapper() {} 102 HostDispatcherWrapper() {}
103 virtual ~HostDispatcherWrapper() {} 103 virtual ~HostDispatcherWrapper() {}
104 104
105 bool Init(base::ProcessHandle plugin_process_handle, 105 bool Init(const IPC::ChannelHandle& channel_handle,
106 const IPC::ChannelHandle& channel_handle,
107 PP_Module pp_module, 106 PP_Module pp_module,
108 PP_GetInterface_Func local_get_interface, 107 PP_GetInterface_Func local_get_interface,
109 const ppapi::Preferences& preferences, 108 const ppapi::Preferences& preferences,
110 PepperHungPluginFilter* filter) { 109 PepperHungPluginFilter* filter) {
111 if (channel_handle.name.empty()) 110 if (channel_handle.name.empty())
112 return false; 111 return false;
113 112
114 #if defined(OS_POSIX) 113 #if defined(OS_POSIX)
115 DCHECK_NE(-1, channel_handle.socket.fd); 114 DCHECK_NE(-1, channel_handle.socket.fd);
116 if (channel_handle.socket.fd == -1) 115 if (channel_handle.socket.fd == -1)
117 return false; 116 return false;
118 #endif 117 #endif
119 118
120 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl); 119 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
121 dispatcher_.reset(new ppapi::proxy::HostDispatcher( 120 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
122 plugin_process_handle, pp_module, local_get_interface, filter)); 121 pp_module, local_get_interface, filter));
123 122
124 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), 123 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
125 channel_handle, 124 channel_handle,
126 true, // Client. 125 true, // Client.
127 preferences)) { 126 preferences)) {
128 dispatcher_.reset(); 127 dispatcher_.reset();
129 dispatcher_delegate_.reset(); 128 dispatcher_delegate_.reset();
130 return false; 129 return false;
131 } 130 }
132 dispatcher_->channel()->SetRestrictDispatchChannelGroup( 131 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); 226 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info);
228 if (!info) { 227 if (!info) {
229 *pepper_plugin_was_registered = false; 228 *pepper_plugin_was_registered = false;
230 return scoped_refptr<webkit::ppapi::PluginModule>(); 229 return scoped_refptr<webkit::ppapi::PluginModule>();
231 } else if (!info->is_out_of_process) { 230 } else if (!info->is_out_of_process) {
232 // In-process plugin not preloaded, it probably couldn't be initialized. 231 // In-process plugin not preloaded, it probably couldn't be initialized.
233 return scoped_refptr<webkit::ppapi::PluginModule>(); 232 return scoped_refptr<webkit::ppapi::PluginModule>();
234 } 233 }
235 234
236 // Out of process: have the browser start the plugin process for us. 235 // Out of process: have the browser start the plugin process for us.
237 base::ProcessHandle plugin_process_handle = base::kNullProcessHandle;
238 IPC::ChannelHandle channel_handle; 236 IPC::ChannelHandle channel_handle;
239 int plugin_child_id = 0; 237 int plugin_child_id = 0;
240 render_view_->Send(new ViewHostMsg_OpenChannelToPepperPlugin( 238 render_view_->Send(new ViewHostMsg_OpenChannelToPepperPlugin(
241 path, &plugin_process_handle, &channel_handle, &plugin_child_id)); 239 path, &channel_handle, &plugin_child_id));
242 if (channel_handle.name.empty()) { 240 if (channel_handle.name.empty()) {
243 // Couldn't be initialized. 241 // Couldn't be initialized.
244 return scoped_refptr<webkit::ppapi::PluginModule>(); 242 return scoped_refptr<webkit::ppapi::PluginModule>();
245 } 243 }
246 244
247 scoped_refptr<PepperHungPluginFilter> hung_filter( 245 scoped_refptr<PepperHungPluginFilter> hung_filter(
248 new PepperHungPluginFilter(path, render_view_->routing_id(), 246 new PepperHungPluginFilter(path, render_view_->routing_id(),
249 plugin_child_id)); 247 plugin_child_id));
250 248
251 // Create a new HostDispatcher for the proxying, and hook it to a new 249 // Create a new HostDispatcher for the proxying, and hook it to a new
252 // PluginModule. Note that AddLiveModule must be called before any early 250 // PluginModule. Note that AddLiveModule must be called before any early
253 // returns since the module's destructor will remove itself. 251 // returns since the module's destructor will remove itself.
254 module = new webkit::ppapi::PluginModule(info->name, path, 252 module = new webkit::ppapi::PluginModule(info->name, path,
255 PepperPluginRegistry::GetInstance()); 253 PepperPluginRegistry::GetInstance());
256 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); 254 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module);
257 scoped_ptr<HostDispatcherWrapper> dispatcher(new HostDispatcherWrapper); 255 scoped_ptr<HostDispatcherWrapper> dispatcher(new HostDispatcherWrapper);
258 if (!dispatcher->Init( 256 if (!dispatcher->Init(
259 plugin_process_handle,
260 channel_handle, 257 channel_handle,
261 module->pp_module(), 258 module->pp_module(),
262 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), 259 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(),
263 GetPreferences(), 260 GetPreferences(),
264 hung_filter.get())) 261 hung_filter.get()))
265 return scoped_refptr<webkit::ppapi::PluginModule>(); 262 return scoped_refptr<webkit::ppapi::PluginModule>();
266 module->InitAsProxied(dispatcher.release()); 263 module->InitAsProxied(dispatcher.release());
267 return module; 264 return module;
268 } 265 }
269 266
(...skipping 19 matching lines...) Expand all
289 if (!render_view_->Send(msg)) { 286 if (!render_view_->Send(msg)) {
290 pending_connect_broker_.Remove(request_id); 287 pending_connect_broker_.Remove(request_id);
291 return scoped_refptr<PepperBrokerImpl>(); 288 return scoped_refptr<PepperBrokerImpl>();
292 } 289 }
293 290
294 return broker; 291 return broker;
295 } 292 }
296 293
297 void PepperPluginDelegateImpl::OnPpapiBrokerChannelCreated( 294 void PepperPluginDelegateImpl::OnPpapiBrokerChannelCreated(
298 int request_id, 295 int request_id,
299 base::ProcessHandle broker_process_handle,
300 const IPC::ChannelHandle& handle) { 296 const IPC::ChannelHandle& handle) {
301 scoped_refptr<PepperBrokerImpl>* broker_ptr = 297 scoped_refptr<PepperBrokerImpl>* broker_ptr =
302 pending_connect_broker_.Lookup(request_id); 298 pending_connect_broker_.Lookup(request_id);
303 if (broker_ptr) { 299 if (broker_ptr) {
304 scoped_refptr<PepperBrokerImpl> broker = *broker_ptr; 300 scoped_refptr<PepperBrokerImpl> broker = *broker_ptr;
305 pending_connect_broker_.Remove(request_id); 301 pending_connect_broker_.Remove(request_id);
306 broker->OnBrokerChannelConnected(broker_process_handle, handle); 302 broker->OnBrokerChannelConnected(handle);
307 } else { 303 } else {
308 // There is no broker waiting for this channel. Close it so the broker can 304 // There is no broker waiting for this channel. Close it so the broker can
309 // clean up and possibly exit. 305 // clean up and possibly exit.
310 // The easiest way to clean it up is to just put it in an object 306 // The easiest way to clean it up is to just put it in an object
311 // and then close them. This failure case is not performance critical. 307 // and then close them. This failure case is not performance critical.
312 PepperBrokerDispatcherWrapper temp_dispatcher; 308 PepperBrokerDispatcherWrapper temp_dispatcher;
313 temp_dispatcher.Init(broker_process_handle, handle); 309 temp_dispatcher.Init(handle);
314 } 310 }
315 } 311 }
316 312
317 // Iterates through pending_connect_broker_ to find the broker. 313 // Iterates through pending_connect_broker_ to find the broker.
318 // Cannot use Lookup() directly because pending_connect_broker_ does not store 314 // Cannot use Lookup() directly because pending_connect_broker_ does not store
319 // the raw pointer to the broker. Assumes maximum of one copy of broker exists. 315 // the raw pointer to the broker. Assumes maximum of one copy of broker exists.
320 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection( 316 bool PepperPluginDelegateImpl::StopWaitingForBrokerConnection(
321 PepperBrokerImpl* broker) { 317 PepperBrokerImpl* broker) {
322 for (BrokerMap::iterator i(&pending_connect_broker_); 318 for (BrokerMap::iterator i(&pending_connect_broker_);
323 !i.IsAtEnd(); i.Advance()) { 319 !i.IsAtEnd(); i.Advance()) {
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 virtual void DidFail(base::PlatformFileError error_code) { 826 virtual void DidFail(base::PlatformFileError error_code) {
831 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; 827 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue;
832 callback_.Run(error_code, base::PassPlatformFile(&invalid_file)); 828 callback_.Run(error_code, base::PassPlatformFile(&invalid_file));
833 } 829 }
834 830
835 virtual void DidWrite(int64 bytes, bool complete) { 831 virtual void DidWrite(int64 bytes, bool complete) {
836 NOTREACHED(); 832 NOTREACHED();
837 } 833 }
838 834
839 virtual void DidOpenFile( 835 virtual void DidOpenFile(
840 base::PlatformFile file, 836 base::PlatformFile file) {
841 base::ProcessHandle unused) {
842 callback_.Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file)); 837 callback_.Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file));
843 // Make sure we won't leak file handle if the requester has died. 838 // Make sure we won't leak file handle if the requester has died.
844 if (file != base::kInvalidPlatformFileValue) { 839 if (file != base::kInvalidPlatformFileValue) {
845 base::FileUtilProxy::Close( 840 base::FileUtilProxy::Close(
846 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, 841 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file,
847 base::FileUtilProxy::StatusCallback()); 842 base::FileUtilProxy::StatusCallback());
848 } 843 }
849 } 844 }
850 845
851 private: // TODO(ericu): Delete this? 846 private: // TODO(ericu): Delete this?
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 mouse_lock_instances_.erase(it); 1623 mouse_lock_instances_.erase(it);
1629 } 1624 }
1630 } 1625 }
1631 1626
1632 webkit_glue::ClipboardClient* 1627 webkit_glue::ClipboardClient*
1633 PepperPluginDelegateImpl::CreateClipboardClient() const { 1628 PepperPluginDelegateImpl::CreateClipboardClient() const {
1634 return new RendererClipboardClient; 1629 return new RendererClipboardClient;
1635 } 1630 }
1636 1631
1637 } // namespace content 1632 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_delegate_impl.h ('k') | content/renderer/pepper/pepper_proxy_channel_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698