| 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/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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 namespace { | 100 namespace { |
| 101 | 101 |
| 102 // This class wraps a dispatcher and has the same lifetime. A dispatcher has | 102 // This class wraps a dispatcher and has the same lifetime. A dispatcher has |
| 103 // the same lifetime as a plugin module, which is longer than any particular | 103 // the same lifetime as a plugin module, which is longer than any particular |
| 104 // RenderView or plugin instance. | 104 // RenderView or plugin instance. |
| 105 class HostDispatcherWrapper | 105 class HostDispatcherWrapper |
| 106 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy { | 106 : public webkit::ppapi::PluginDelegate::OutOfProcessProxy { |
| 107 public: | 107 public: |
| 108 HostDispatcherWrapper(webkit::ppapi::PluginModule* module, | 108 HostDispatcherWrapper(webkit::ppapi::PluginModule* module, |
| 109 int plugin_child_id, | 109 int plugin_child_id, |
| 110 const ppapi::PpapiPermissions& perms) | 110 const ppapi::PpapiPermissions& perms, |
| 111 bool is_external) |
| 111 : module_(module), | 112 : module_(module), |
| 112 plugin_child_id_(plugin_child_id), | 113 plugin_child_id_(plugin_child_id), |
| 113 permissions_(perms) { | 114 permissions_(perms), |
| 115 is_external_(is_external) { |
| 114 } | 116 } |
| 115 virtual ~HostDispatcherWrapper() {} | 117 virtual ~HostDispatcherWrapper() {} |
| 116 | 118 |
| 117 bool Init(const IPC::ChannelHandle& channel_handle, | 119 bool Init(const IPC::ChannelHandle& channel_handle, |
| 118 PP_GetInterface_Func local_get_interface, | 120 PP_GetInterface_Func local_get_interface, |
| 119 const ppapi::Preferences& preferences, | 121 const ppapi::Preferences& preferences, |
| 120 const ppapi::PpapiPermissions& permissions, | |
| 121 PepperHungPluginFilter* filter) { | 122 PepperHungPluginFilter* filter) { |
| 122 if (channel_handle.name.empty()) | 123 if (channel_handle.name.empty()) |
| 123 return false; | 124 return false; |
| 124 | 125 |
| 125 #if defined(OS_POSIX) | 126 #if defined(OS_POSIX) |
| 126 DCHECK_NE(-1, channel_handle.socket.fd); | 127 DCHECK_NE(-1, channel_handle.socket.fd); |
| 127 if (channel_handle.socket.fd == -1) | 128 if (channel_handle.socket.fd == -1) |
| 128 return false; | 129 return false; |
| 129 #endif | 130 #endif |
| 130 | 131 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 156 RendererPpapiHostImpl::GetForPPInstance(instance); | 157 RendererPpapiHostImpl::GetForPPInstance(instance); |
| 157 // TODO(brettw) remove this null check when the old-style pepper-based | 158 // TODO(brettw) remove this null check when the old-style pepper-based |
| 158 // browser tag is removed from this file. Getting this notification should | 159 // browser tag is removed from this file. Getting this notification should |
| 159 // always give us an instance we can find in the map otherwise, but that | 160 // always give us an instance we can find in the map otherwise, but that |
| 160 // isn't true for browser tag support. | 161 // isn't true for browser tag support. |
| 161 if (host) { | 162 if (host) { |
| 162 RenderView* render_view = host->GetRenderViewForInstance(instance); | 163 RenderView* render_view = host->GetRenderViewForInstance(instance); |
| 163 render_view->Send(new ViewHostMsg_DidCreateOutOfProcessPepperInstance( | 164 render_view->Send(new ViewHostMsg_DidCreateOutOfProcessPepperInstance( |
| 164 plugin_child_id_, | 165 plugin_child_id_, |
| 165 instance, | 166 instance, |
| 166 render_view->GetRoutingID())); | 167 render_view->GetRoutingID(), |
| 168 is_external_)); |
| 167 } | 169 } |
| 168 } | 170 } |
| 169 virtual void RemoveInstance(PP_Instance instance) { | 171 virtual void RemoveInstance(PP_Instance instance) { |
| 170 ppapi::proxy::HostDispatcher::RemoveForInstance(instance); | 172 ppapi::proxy::HostDispatcher::RemoveForInstance(instance); |
| 171 | 173 |
| 172 RendererPpapiHostImpl* host = | 174 RendererPpapiHostImpl* host = |
| 173 RendererPpapiHostImpl::GetForPPInstance(instance); | 175 RendererPpapiHostImpl::GetForPPInstance(instance); |
| 174 // TODO(brettw) remove null check as described in AddInstance. | 176 // TODO(brettw) remove null check as described in AddInstance. |
| 175 if (host) { | 177 if (host) { |
| 176 RenderView* render_view = host->GetRenderViewForInstance(instance); | 178 RenderView* render_view = host->GetRenderViewForInstance(instance); |
| 177 render_view->Send(new ViewHostMsg_DidDeleteOutOfProcessPepperInstance( | 179 render_view->Send(new ViewHostMsg_DidDeleteOutOfProcessPepperInstance( |
| 178 plugin_child_id_, | 180 plugin_child_id_, |
| 179 instance)); | 181 instance, |
| 182 is_external_)); |
| 180 } | 183 } |
| 181 } | 184 } |
| 182 | 185 |
| 183 ppapi::proxy::HostDispatcher* dispatcher() { return dispatcher_.get(); } | 186 ppapi::proxy::HostDispatcher* dispatcher() { return dispatcher_.get(); } |
| 184 | 187 |
| 185 private: | 188 private: |
| 186 webkit::ppapi::PluginModule* module_; | 189 webkit::ppapi::PluginModule* module_; |
| 187 | 190 |
| 188 // ID that the browser process uses to idetify the child process for the | 191 // ID that the browser process uses to idetify the child process for the |
| 189 // plugin. This isn't directly useful from our process (the renderer) except | 192 // plugin. This isn't directly useful from our process (the renderer) except |
| 190 // in messages to the browser to disambiguate plugins. | 193 // in messages to the browser to disambiguate plugins. |
| 191 int plugin_child_id_; | 194 int plugin_child_id_; |
| 192 | 195 |
| 193 ppapi::PpapiPermissions permissions_; | 196 ppapi::PpapiPermissions permissions_; |
| 197 bool is_external_; |
| 194 | 198 |
| 195 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_; | 199 scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_; |
| 196 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_; | 200 scoped_ptr<ppapi::proxy::ProxyChannel::Delegate> dispatcher_delegate_; |
| 197 }; | 201 }; |
| 198 | 202 |
| 199 class QuotaCallbackTranslator : public QuotaDispatcher::Callback { | 203 class QuotaCallbackTranslator : public QuotaDispatcher::Callback { |
| 200 public: | 204 public: |
| 201 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback; | 205 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback; |
| 202 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {} | 206 explicit QuotaCallbackTranslator(const PluginCallback& cb) : callback_(cb) {} |
| 203 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { | 207 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 389 } |
| 386 | 390 |
| 387 // AddLiveModule must be called before any early returns since the | 391 // AddLiveModule must be called before any early returns since the |
| 388 // module's destructor will remove itself. | 392 // module's destructor will remove itself. |
| 389 module = new webkit::ppapi::PluginModule( | 393 module = new webkit::ppapi::PluginModule( |
| 390 info->name, path, | 394 info->name, path, |
| 391 PepperPluginRegistry::GetInstance(), | 395 PepperPluginRegistry::GetInstance(), |
| 392 permissions); | 396 permissions); |
| 393 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); | 397 PepperPluginRegistry::GetInstance()->AddLiveModule(path, module); |
| 394 | 398 |
| 395 if (!CreateOutOfProcessModule( | 399 if (!CreateOutOfProcessModule(module, |
| 396 module, path, permissions, channel_handle, plugin_child_id)) { | 400 path, |
| 401 permissions, |
| 402 channel_handle, |
| 403 plugin_child_id, |
| 404 false)) // is_external = false |
| 397 return scoped_refptr<webkit::ppapi::PluginModule>(); | 405 return scoped_refptr<webkit::ppapi::PluginModule>(); |
| 398 } | 406 |
| 399 return module; | 407 return module; |
| 400 } | 408 } |
| 401 | 409 |
| 402 RendererPpapiHost* PepperPluginDelegateImpl::CreateExternalPluginModule( | 410 RendererPpapiHost* PepperPluginDelegateImpl::CreateExternalPluginModule( |
| 403 scoped_refptr<webkit::ppapi::PluginModule> module, | 411 scoped_refptr<webkit::ppapi::PluginModule> module, |
| 404 const FilePath& path, | 412 const FilePath& path, |
| 405 ppapi::PpapiPermissions permissions, | 413 ppapi::PpapiPermissions permissions, |
| 406 const IPC::ChannelHandle& channel_handle, | 414 const IPC::ChannelHandle& channel_handle, |
| 407 int plugin_child_id) { | 415 int plugin_child_id) { |
| 408 // We don't call PepperPluginRegistry::AddLiveModule, as this module is | 416 // We don't call PepperPluginRegistry::AddLiveModule, as this module is |
| 409 // managed externally. | 417 // managed externally. |
| 410 // TODO(bbudge) pass plugin_child_id when PpapiPluginProcessHost receives | 418 return CreateOutOfProcessModule(module, |
| 411 // a message notifying it that the external plugin process has been created. | 419 path, |
| 412 return CreateOutOfProcessModule( | 420 permissions, |
| 413 module, path, permissions, channel_handle, 0); | 421 channel_handle, |
| 422 plugin_child_id, |
| 423 true); // is_external = true |
| 414 } | 424 } |
| 415 | 425 |
| 416 scoped_refptr<PepperBrokerImpl> PepperPluginDelegateImpl::CreateBroker( | 426 scoped_refptr<PepperBrokerImpl> PepperPluginDelegateImpl::CreateBroker( |
| 417 webkit::ppapi::PluginModule* plugin_module) { | 427 webkit::ppapi::PluginModule* plugin_module) { |
| 418 DCHECK(plugin_module); | 428 DCHECK(plugin_module); |
| 419 DCHECK(!plugin_module->GetBroker()); | 429 DCHECK(!plugin_module->GetBroker()); |
| 420 | 430 |
| 421 // The broker path is the same as the plugin. | 431 // The broker path is the same as the plugin. |
| 422 const FilePath& broker_path = plugin_module->path(); | 432 const FilePath& broker_path = plugin_module->path(); |
| 423 | 433 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 438 } | 448 } |
| 439 | 449 |
| 440 return broker; | 450 return broker; |
| 441 } | 451 } |
| 442 | 452 |
| 443 RendererPpapiHost* PepperPluginDelegateImpl::CreateOutOfProcessModule( | 453 RendererPpapiHost* PepperPluginDelegateImpl::CreateOutOfProcessModule( |
| 444 webkit::ppapi::PluginModule* module, | 454 webkit::ppapi::PluginModule* module, |
| 445 const FilePath& path, | 455 const FilePath& path, |
| 446 ppapi::PpapiPermissions permissions, | 456 ppapi::PpapiPermissions permissions, |
| 447 const IPC::ChannelHandle& channel_handle, | 457 const IPC::ChannelHandle& channel_handle, |
| 448 int plugin_child_id) { | 458 int plugin_child_id, |
| 459 bool is_external) { |
| 449 scoped_refptr<PepperHungPluginFilter> hung_filter( | 460 scoped_refptr<PepperHungPluginFilter> hung_filter( |
| 450 new PepperHungPluginFilter(path, | 461 new PepperHungPluginFilter(path, |
| 451 render_view_->routing_id(), | 462 render_view_->routing_id(), |
| 452 plugin_child_id)); | 463 plugin_child_id)); |
| 453 scoped_ptr<HostDispatcherWrapper> dispatcher( | 464 scoped_ptr<HostDispatcherWrapper> dispatcher( |
| 454 new HostDispatcherWrapper(module, plugin_child_id, permissions)); | 465 new HostDispatcherWrapper(module, |
| 466 plugin_child_id, |
| 467 permissions, |
| 468 is_external)); |
| 455 if (!dispatcher->Init( | 469 if (!dispatcher->Init( |
| 456 channel_handle, | 470 channel_handle, |
| 457 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), | 471 webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), |
| 458 GetPreferences(), | 472 GetPreferences(), |
| 459 permissions, | |
| 460 hung_filter.get())) | 473 hung_filter.get())) |
| 461 return NULL; | 474 return NULL; |
| 462 | 475 |
| 463 RendererPpapiHostImpl* host_impl = | 476 RendererPpapiHostImpl* host_impl = |
| 464 RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( | 477 RendererPpapiHostImpl::CreateOnModuleForOutOfProcess( |
| 465 module, dispatcher->dispatcher(), permissions); | 478 module, dispatcher->dispatcher(), permissions); |
| 466 render_view_->PpapiPluginCreated(host_impl); | 479 render_view_->PpapiPluginCreated(host_impl); |
| 467 | 480 |
| 468 module->InitAsProxied(dispatcher.release()); | 481 module->InitAsProxied(dispatcher.release()); |
| 469 return host_impl; | 482 return host_impl; |
| (...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 RenderWidgetFullscreenPepper* container = | 1871 RenderWidgetFullscreenPepper* container = |
| 1859 static_cast<RenderWidgetFullscreenPepper*>( | 1872 static_cast<RenderWidgetFullscreenPepper*>( |
| 1860 instance->fullscreen_container()); | 1873 instance->fullscreen_container()); |
| 1861 return container->mouse_lock_dispatcher(); | 1874 return container->mouse_lock_dispatcher(); |
| 1862 } else { | 1875 } else { |
| 1863 return render_view_->mouse_lock_dispatcher(); | 1876 return render_view_->mouse_lock_dispatcher(); |
| 1864 } | 1877 } |
| 1865 } | 1878 } |
| 1866 | 1879 |
| 1867 } // namespace content | 1880 } // namespace content |
| OLD | NEW |