diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-06 00:22:11 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-06 00:22:11 +0000 |
commit | f3a81a09155b9cb2942857007775de6b5c0a7fba (patch) | |
tree | fda02a4a481411cccaab163cd79ed4e39736b230 | |
parent | f074608f3fe830a7ba2edd347c6fc15203aa6b36 (diff) | |
download | chromium_src-f3a81a09155b9cb2942857007775de6b5c0a7fba.zip chromium_src-f3a81a09155b9cb2942857007775de6b5c0a7fba.tar.gz chromium_src-f3a81a09155b9cb2942857007775de6b5c0a7fba.tar.bz2 |
Allow the NaCl IPC proxy to support multiple instances.
Create a new PluginModule for each instance of a NaCl plugin that
uses the IPC-based PPAPI proxy. This is necessary because a NaCl plugin instance begins using in-process PPAPI, then switches to the out-of-process PPAPI proxy (when using the IPC proxy rather than the NaCl SRPC proxy.)
BUG=116317
TEST=manual
Review URL: https://chromiumcodereview.appspot.com/10912060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155068 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/pepper/ppb_nacl_private_impl.cc | 18 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 26 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.h | 9 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 16 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 11 |
5 files changed, 50 insertions, 30 deletions
diff --git a/chrome/renderer/pepper/ppb_nacl_private_impl.cc b/chrome/renderer/pepper/ppb_nacl_private_impl.cc index 7ebaba1..588cedd 100644 --- a/chrome/renderer/pepper/ppb_nacl_private_impl.cc +++ b/chrome/renderer/pepper/ppb_nacl_private_impl.cc @@ -42,6 +42,7 @@ using content::RenderView; using webkit::ppapi::HostGlobals; using webkit::ppapi::PluginInstance; using webkit::ppapi::PluginDelegate; +using webkit::ppapi::PluginModule; using WebKit::WebView; namespace { @@ -207,7 +208,7 @@ PP_Bool StartPpapiProxy(PP_Instance instance) { IPC::ChannelHandle channel_handle = it->second; map.erase(it); - webkit::ppapi::PluginInstance* plugin_instance = + PluginInstance* plugin_instance = content::GetHostGlobals()->GetInstance(instance); if (!plugin_instance) return PP_FALSE; @@ -216,18 +217,25 @@ PP_Bool StartPpapiProxy(PP_Instance instance) { plugin_instance->container()->element().document().frame()->view(); RenderView* render_view = content::RenderView::FromWebView(web_view); - webkit::ppapi::PluginModule* plugin_module = plugin_instance->module(); + PluginModule* plugin_module = plugin_instance->module(); scoped_refptr<SyncMessageStatusReceiver> status_receiver(new SyncMessageStatusReceiver()); scoped_ptr<OutOfProcessProxy> out_of_process_proxy(new OutOfProcessProxy); + // Create a new module for each instance of the NaCl plugin that is using + // the IPC based out-of-process proxy. We can't use the existing module, + // because it is configured for the in-process NaCl plugin, and we must + // keep it that way to allow the page to create other instances. + scoped_refptr<PluginModule> nacl_plugin_module( + plugin_module->CreateModuleForNaClInstance()); + if (out_of_process_proxy->Init( channel_handle, - plugin_module->pp_module(), - webkit::ppapi::PluginModule::GetLocalGetInterfaceFunc(), + nacl_plugin_module->pp_module(), + PluginModule::GetLocalGetInterfaceFunc(), ppapi::Preferences(render_view->GetWebkitPreferences()), status_receiver.get())) { - plugin_module->InitAsProxiedNaCl( + nacl_plugin_module->InitAsProxiedNaCl( out_of_process_proxy.PassAs<PluginDelegate::OutOfProcessProxy>(), instance); return PP_TRUE; diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 9257bc8..cdf8f69 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -419,8 +419,7 @@ PluginModule::PluginModule(const std::string& name, name_(name), path_(path), permissions_(perms), - reserve_instance_id_(NULL), - nacl_ipc_proxy_(false) { + reserve_instance_id_(NULL) { // Ensure the globals object is created. if (!host_globals) host_globals = new HostGlobals; @@ -503,27 +502,33 @@ void PluginModule::InitAsProxied( out_of_process_proxy_.reset(out_of_process_proxy); } +scoped_refptr<PluginModule> PluginModule::CreateModuleForNaClInstance() { + // Create a new module, but don't set the lifetime delegate. This isn't a + // plugin in the usual sense, so it isn't tracked by the browser. + scoped_refptr<PluginModule> nacl_module( + new PluginModule(name_, + path_, + NULL, // no lifetime_delegate + permissions_)); + return nacl_module; +} + void PluginModule::InitAsProxiedNaCl( scoped_ptr<PluginDelegate::OutOfProcessProxy> out_of_process_proxy, PP_Instance instance) { - // TODO(bbudge) We need to switch the mode of the PluginModule on a - // per-instance basis. Fix this so out_of_process_proxy and other - // state is stored in a map, indexed by instance. - nacl_ipc_proxy_ = true; InitAsProxied(out_of_process_proxy.release()); // InitAsProxied (for the trusted/out-of-process case) initializes only the // module, and one or more instances are added later. In this case, the // PluginInstance was already created as in-process, so we missed the proxy // AddInstance step and must do it now. out_of_process_proxy_->AddInstance(instance); - // In NaCl, we need to tell the instance to reset itself as proxied. This will // clear cached interface pointers and send DidCreate (etc) to the plugin // side of the proxy. PluginInstance* plugin_instance = host_globals->GetInstance(instance); if (!plugin_instance) return; - plugin_instance->ResetAsProxied(); + plugin_instance->ResetAsProxied(this); } // static @@ -577,11 +582,6 @@ void PluginModule::InstanceDeleted(PluginInstance* instance) { if (out_of_process_proxy_.get()) out_of_process_proxy_->RemoveInstance(instance->pp_instance()); instances_.erase(instance); - - if (nacl_ipc_proxy_) { - out_of_process_proxy_.reset(); - reserve_instance_id_ = NULL; - } } scoped_refptr< ::ppapi::CallbackTracker> PluginModule::GetCallbackTracker() { diff --git a/webkit/plugins/ppapi/plugin_module.h b/webkit/plugins/ppapi/plugin_module.h index 0f7a425..8c8e1d4 100644 --- a/webkit/plugins/ppapi/plugin_module.h +++ b/webkit/plugins/ppapi/plugin_module.h @@ -105,7 +105,12 @@ class WEBKIT_PLUGINS_EXPORT PluginModule : // ownership of the given pointer, even in the failure case. void InitAsProxied(PluginDelegate::OutOfProcessProxy* out_of_process_proxy); - // Initializes this module for the given NaCl proxy. This takes + // Creates a new module for a NaCl instance that will be using the IPC proxy. + // We can't use the existing module, or new instances of the plugin can't + // be created. + scoped_refptr<PluginModule> CreateModuleForNaClInstance(); + + // Initializes the NaCl module for the given out of process proxy. This takes // ownership of the given pointer, even in the failure case. void InitAsProxiedNaCl( scoped_ptr<PluginDelegate::OutOfProcessProxy> out_of_process_proxy, @@ -234,8 +239,6 @@ class WEBKIT_PLUGINS_EXPORT PluginModule : PP_Bool (*reserve_instance_id_)(PP_Module, PP_Instance); - bool nacl_ipc_proxy_; - DISALLOW_COPY_AND_ASSIGN(PluginModule); }; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index a2cec8f..30dc9379 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -484,6 +484,9 @@ PluginInstance::~PluginInstance() { delegate_->InstanceDeleted(this); module_->InstanceDeleted(this); + // If we switched from the NaCl plugin module, notify it too. + if (original_module_.get()) + original_module_->InstanceDeleted(this); HostGlobals::Get()->InstanceDeleted(pp_instance_); } @@ -505,8 +508,8 @@ void PluginInstance::Delete() { // If this is a NaCl plugin instance, shut down the NaCl plugin by calling // its DidDestroy. Don't call DidDestroy on the untrusted plugin instance, // since there is little that it can do at this point. - if (nacl_plugin_instance_interface_.get()) - nacl_plugin_instance_interface_->DidDestroy(pp_instance()); + if (original_instance_interface_.get()) + original_instance_interface_->DidDestroy(pp_instance()); else instance_interface_->DidDestroy(pp_instance()); @@ -2543,10 +2546,15 @@ PP_Var PluginInstance::GetPluginInstanceURL( components); } -bool PluginInstance::ResetAsProxied() { +bool PluginInstance::ResetAsProxied(scoped_refptr<PluginModule> module) { + // Save the original module and switch over to the new one now that this + // plugin is using the IPC-based proxy. + original_module_ = module_; + module_ = module; + // For NaCl instances, remember the NaCl plugin instance interface, so we // can shut it down by calling its DidDestroy in our Delete() method. - nacl_plugin_instance_interface_.reset(instance_interface_.release()); + original_instance_interface_.reset(instance_interface_.release()); base::Callback<const void*(const char*)> get_plugin_interface_func = base::Bind(&PluginModule::GetPluginInterface, module_.get()); diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 9594331..29b9129 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -469,7 +469,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // proxy and re-sends DidCreate, DidChangeView, and HandleDocumentLoad (if // necessary). // This is for use with the NaCl proxy. - bool ResetAsProxied(); + bool ResetAsProxied(scoped_refptr<PluginModule> module); private: // Implements PPB_Gamepad_API. This is just to avoid having an excessive @@ -573,10 +573,11 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : PluginDelegate* delegate_; scoped_refptr<PluginModule> module_; scoped_ptr< ::ppapi::PPP_Instance_Combined> instance_interface_; - // If this is the NaCl plugin, store its instance interface so we can shut - // it down properly when using the IPC-based PPAPI proxy. - // TODO(bbudge) Remove this when the proxy switch is complete. - scoped_ptr< ::ppapi::PPP_Instance_Combined> nacl_plugin_instance_interface_; + // If this is the NaCl plugin, we create a new module when we switch to the + // IPC-based PPAPI proxy. Store the original module and instance interface + // so we can shut down properly. + scoped_refptr<PluginModule> original_module_; + scoped_ptr< ::ppapi::PPP_Instance_Combined> original_instance_interface_; PP_Instance pp_instance_; |