diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 01:16:11 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-10 01:16:11 +0000 |
commit | 709a847ee12e1380df59db8cd3c972ec4f9c674e (patch) | |
tree | 48217fd87c7e1fe15afdd90db26a925f7db28a1b /webkit/glue | |
parent | f30e74751217091c0b6050080f46cd6eb4914226 (diff) | |
download | chromium_src-709a847ee12e1380df59db8cd3c972ec4f9c674e.zip chromium_src-709a847ee12e1380df59db8cd3c972ec4f9c674e.tar.gz chromium_src-709a847ee12e1380df59db8cd3c972ec4f9c674e.tar.bz2 |
Implement a new process type for running PPAPI plugins. The process itself is
quite simple and just sets up the PPAPI dispatcher and loads the library.
There is a new command line switch --ppapi-out-of-process which runs PPAPI
plugins out of process using the new code path. There is some logic in
RenderView and PepperPluginModule for setting up this connection, but it should
be straightforward.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/3915002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65614 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/plugins/pepper_graphics_2d.cc | 3 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 64 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.h | 28 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 1 |
4 files changed, 92 insertions, 4 deletions
diff --git a/webkit/glue/plugins/pepper_graphics_2d.cc b/webkit/glue/plugins/pepper_graphics_2d.cc index a8d5091..a4f9134 100644 --- a/webkit/glue/plugins/pepper_graphics_2d.cc +++ b/webkit/glue/plugins/pepper_graphics_2d.cc @@ -420,6 +420,7 @@ bool Graphics2D::ReadImageData(PP_Resource image, SkIntToScalar(image_resource->width()), SkIntToScalar(image_resource->height()) }; + ImageDataAutoMapper auto_mapper2(image_data_); if (image_resource->format() != image_data_->format()) { // Convert the image data if the format does not match. ConvertImageData(image_data_, src_irect, image_resource.get(), dest_rect); @@ -472,7 +473,7 @@ bool Graphics2D::BindToInstance(PluginInstance* new_instance) { void Graphics2D::Paint(WebKit::WebCanvas* canvas, const gfx::Rect& plugin_rect, const gfx::Rect& paint_rect) { - // We're guaranteed to have a mapped canvas since we mapped it in Init(). + ImageDataAutoMapper auto_mapper(image_data_); const SkBitmap& backing_bitmap = *image_data_->GetMappedBitmap(); #if defined(OS_MACOSX) diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc index 662055a..cf17813 100644 --- a/webkit/glue/plugins/pepper_plugin_module.cc +++ b/webkit/glue/plugins/pepper_plugin_module.cc @@ -48,6 +48,8 @@ #include "ppapi/c/ppb_var.h" #include "ppapi/c/ppp.h" #include "ppapi/c/ppp_instance.h" +#include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" #include "webkit/glue/plugins/pepper_audio.h" #include "webkit/glue/plugins/pepper_buffer.h" #include "webkit/glue/plugins/pepper_common.h" @@ -83,6 +85,10 @@ #include "webkit/glue/plugins/pepper_graphics_3d.h" #endif // ENABLE_GPU +#if defined(OS_POSIX) +#include "ipc/ipc_channel_posix.h" +#endif + namespace pepper { namespace { @@ -335,6 +341,7 @@ scoped_refptr<PluginModule> PluginModule::CreateModule( return lib; } +// static scoped_refptr<PluginModule> PluginModule::CreateInternalModule( EntryPoints entry_points) { scoped_refptr<PluginModule> lib(new PluginModule()); @@ -345,6 +352,17 @@ scoped_refptr<PluginModule> PluginModule::CreateInternalModule( } // static +scoped_refptr<PluginModule> PluginModule::CreateOutOfProcessModule( + MessageLoop* ipc_message_loop, + const IPC::ChannelHandle& handle, + base::WaitableEvent* shutdown_event) { + scoped_refptr<PluginModule> lib(new PluginModule); + if (!lib->InitForOutOfProcess(ipc_message_loop, handle, shutdown_event)) + return NULL; + return lib; +} + +// static const PPB_Core* PluginModule::GetCore() { return &core_interface; } @@ -386,10 +404,41 @@ bool PluginModule::InitFromFile(const FilePath& path) { return true; } +bool PluginModule::InitForOutOfProcess(MessageLoop* ipc_message_loop, + const IPC::ChannelHandle& handle, + base::WaitableEvent* shutdown_event) { + const PPB_Var_Deprecated* var_interface = + reinterpret_cast<const PPB_Var_Deprecated*>( + GetInterface(PPB_VAR_DEPRECATED_INTERFACE)); + dispatcher_.reset(new pp::proxy::HostDispatcher(var_interface, + pp_module(), &GetInterface)); + +#if defined(OS_POSIX) + // If we received a ChannelHandle, register it now. + if (handle.socket.fd >= 0) + IPC::AddChannelSocket(handle.name, handle.socket.fd); +#endif + + if (!dispatcher_->InitWithChannel(ipc_message_loop, handle.name, true, + shutdown_event)) { + dispatcher_.reset(); + return false; + } + + bool init_result = false; + dispatcher_->Send(new PpapiMsg_InitializeModule(pp_module(), &init_result)); + + if (!init_result) { + // TODO(brettw) does the module get unloaded in this case? + dispatcher_.reset(); + return false; + } + return true; +} + // static bool PluginModule::LoadEntryPoints(const base::NativeLibrary& library, EntryPoints* entry_points) { - entry_points->get_interface = reinterpret_cast<PPP_GetInterfaceFunc>( base::GetFunctionPointerFromNativeLibrary(library, @@ -426,7 +475,13 @@ PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) { LOG(WARNING) << "Plugin doesn't support instance interface, failing."; return NULL; } - return new PluginInstance(delegate, this, plugin_instance_interface); + PluginInstance* instance = new PluginInstance(delegate, this, + plugin_instance_interface); + if (dispatcher_.get()) { + pp::proxy::HostDispatcher::SetForInstance(instance->pp_instance(), + dispatcher_.get()); + } + return instance; } PluginInstance* PluginModule::GetSomeInstance() const { @@ -437,6 +492,10 @@ PluginInstance* PluginModule::GetSomeInstance() const { } const void* PluginModule::GetPluginInterface(const char* name) const { + if (dispatcher_.get()) + return dispatcher_->GetProxiedInterface(name); + + // In-process plugins. if (!entry_points_.get_interface) return NULL; return entry_points_.get_interface(name); @@ -447,6 +506,7 @@ void PluginModule::InstanceCreated(PluginInstance* instance) { } void PluginModule::InstanceDeleted(PluginInstance* instance) { + pp::proxy::HostDispatcher::RemoveForInstance(instance->pp_instance()); instances_.erase(instance); } diff --git a/webkit/glue/plugins/pepper_plugin_module.h b/webkit/glue/plugins/pepper_plugin_module.h index cf7defb..6ba3146 100644 --- a/webkit/glue/plugins/pepper_plugin_module.h +++ b/webkit/glue/plugins/pepper_plugin_module.h @@ -16,10 +16,25 @@ #include "ppapi/c/ppb.h" class FilePath; +class MessageLoop; typedef struct NPObject NPObject; struct PPB_Core; typedef void* NPIdentifier; +namespace base { +class WaitableEvent; +} + +namespace pp { +namespace proxy { +class HostDispatcher; +} // proxy +} // pp + +namespace IPC { +struct ChannelHandle; +} + namespace pepper { class ObjectVar; @@ -56,6 +71,10 @@ class PluginModule : public base::RefCounted<PluginModule>, static scoped_refptr<PluginModule> CreateModule(const FilePath& path); static scoped_refptr<PluginModule> CreateInternalModule( EntryPoints entry_points); + static scoped_refptr<PluginModule> CreateOutOfProcessModule( + MessageLoop* ipc_message_loop, + const IPC::ChannelHandle& handle, + base::WaitableEvent* shutdown_event); static const PPB_Core* GetCore(); @@ -101,9 +120,16 @@ class PluginModule : public base::RefCounted<PluginModule>, bool InitFromEntryPoints(const EntryPoints& entry_points); bool InitFromFile(const FilePath& path); + bool InitForOutOfProcess(MessageLoop* ipc_message_loop, + const IPC::ChannelHandle& handle, + base::WaitableEvent* shutdown_event); static bool LoadEntryPoints(const base::NativeLibrary& library, EntryPoints* entry_points); + // Dispatcher for out-of-process plugins. This will be null when the plugin + // is being run in-process. + scoped_ptr<pp::proxy::HostDispatcher> dispatcher_; + PP_Module pp_module_; bool initialized_; @@ -115,7 +141,7 @@ class PluginModule : public base::RefCounted<PluginModule>, base::NativeLibrary library_; // Contains pointers to the entry points of the actual plugin - // implementation. + // implementation. These will be NULL for out-of-process plugins. EntryPoints entry_points_; // The name of the module. diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 99fb8b8..8ed3e8b 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -147,6 +147,7 @@ '<(DEPTH)/base/base.gyp:base_i18n', '<(DEPTH)/gpu/gpu.gyp:gles2_implementation', '<(DEPTH)/net/net.gyp:net', + '<(DEPTH)/ppapi/ppapi.gyp:ppapi_proxy', '<(DEPTH)/printing/printing.gyp:printing', '<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/third_party/icu/icu.gyp:icui18n', |