diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 16:53:06 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 16:53:06 +0000 |
commit | e0ba93971402fee8e7b7cb1cbd2259a37d338760 (patch) | |
tree | 4af1d741d0b1b89f27f4c9225d4df6568ffd6b85 /chrome/renderer/pepper_plugin_delegate_impl.cc | |
parent | 8b21080ae97787dfe73068014bce3c9e0343eb36 (diff) | |
download | chromium_src-e0ba93971402fee8e7b7cb1cbd2259a37d338760.zip chromium_src-e0ba93971402fee8e7b7cb1cbd2259a37d338760.tar.gz chromium_src-e0ba93971402fee8e7b7cb1cbd2259a37d338760.tar.bz2 |
Make webkit/glue/plugins no longer depend on ppapi/proxy directly. This causes
things that use webkit but otherwise don't need IPC to include the IPC
directory.
This patch moves the set-up of the proxy into the renderer. I also did a lot
of clean-up of the initialization and it seems much nicer now.
BUG=63684
TEST=manual PPAPI proxy testing
Review URL: http://codereview.chromium.org/5592005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/pepper_plugin_delegate_impl.cc')
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 88 |
1 files changed, 79 insertions, 9 deletions
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index c3a85d9..a949ffb8 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <cmath> - #include "chrome/renderer/pepper_plugin_delegate_impl.h" +#include <cmath> + #include "app/l10n_util.h" #include "app/surface/transport_dib.h" #include "base/callback.h" @@ -18,6 +18,7 @@ #include "base/utf_string_conversions.h" #include "chrome/common/child_thread.h" #include "chrome/common/file_system/file_system_dispatcher.h" +#include "chrome/common/pepper_plugin_registry.h" #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "chrome/renderer/audio_message_filter.h" @@ -32,6 +33,7 @@ #include "grit/locale_settings.h" #include "ipc/ipc_channel_handle.h" #include "ppapi/c/dev/pp_video_dev.h" +#include "ppapi/proxy/host_dispatcher.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserCompletion.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" @@ -47,6 +49,10 @@ #include "chrome/renderer/render_thread.h" #endif +#if defined(OS_POSIX) +#include "ipc/ipc_channel_posix.h" +#endif + using WebKit::WebView; namespace { @@ -413,6 +419,60 @@ class PlatformVideoDecoderImpl DISALLOW_COPY_AND_ASSIGN(PlatformVideoDecoderImpl); }; +class DispatcherWrapper : public pepper::PluginDelegate::OutOfProcessProxy { + public: + DispatcherWrapper() {} + virtual ~DispatcherWrapper() {} + + bool Init(base::ProcessHandle plugin_process_handle, + IPC::ChannelHandle channel_handle, + PP_Module pp_module, + pp::proxy::Dispatcher::GetInterfaceFunc local_get_interface); + + // OutOfProcessProxy implementation. + virtual const void* GetProxiedInterface(const char* name) { + return dispatcher_->GetProxiedInterface(name); + } + virtual void AddInstance(PP_Instance instance) { + pp::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); + } + virtual void RemoveInstance(PP_Instance instance) { + pp::proxy::HostDispatcher::RemoveForInstance(instance); + } + + private: + scoped_ptr<pp::proxy::HostDispatcher> dispatcher_; +}; + +bool DispatcherWrapper::Init( + base::ProcessHandle plugin_process_handle, + IPC::ChannelHandle channel_handle, + PP_Module pp_module, + pp::proxy::Dispatcher::GetInterfaceFunc local_get_interface) { + dispatcher_.reset(new pp::proxy::HostDispatcher( + plugin_process_handle, pp_module, local_get_interface)); + +#if defined(OS_POSIX) + // If we received a ChannelHandle, register it now. + if (channel_handle.socket.fd >= 0) + IPC::AddChannelSocket(channel_handle.name, channel_handle.socket.fd); +#endif + + if (!dispatcher_->InitWithChannel( + ChildProcess::current()->io_message_loop(), channel_handle.name, + true, ChildProcess::current()->GetShutDownEvent())) { + dispatcher_.reset(); + return false; + } + + if (!dispatcher_->InitializeModule()) { + // TODO(brettw) does the module get unloaded in this case? + dispatcher_.reset(); + return false; + } + return true; +} + } // namespace PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) @@ -424,19 +484,29 @@ PepperPluginDelegateImpl::~PepperPluginDelegateImpl() { } scoped_refptr<pepper::PluginModule> -PepperPluginDelegateImpl::CreateOutOfProcessPepperPlugin( - const FilePath& path) { +PepperPluginDelegateImpl::CreatePepperPlugin(const FilePath& path) { + // Easy case is in-process plugins. + if (!PepperPluginRegistry::GetInstance()->RunOutOfProcessForPlugin(path)) + return PepperPluginRegistry::GetInstance()->GetModule(path); + + // Out of process: have the browser start the plugin process for us. base::ProcessHandle plugin_process_handle = NULL; IPC::ChannelHandle channel_handle; render_view_->Send(new ViewHostMsg_OpenChannelToPepperPlugin( path, &plugin_process_handle, &channel_handle)); if (channel_handle.name.empty()) return scoped_refptr<pepper::PluginModule>(); // Couldn't be initialized. - return pepper::PluginModule::CreateOutOfProcessModule( - ChildProcess::current()->io_message_loop(), - plugin_process_handle, - channel_handle, - ChildProcess::current()->GetShutDownEvent()); + + // Create a new HostDispatcher for the proxying, and hook it to a new + // PluginModule. + scoped_refptr<pepper::PluginModule> module(new pepper::PluginModule); + scoped_ptr<DispatcherWrapper> dispatcher(new DispatcherWrapper); + if (!dispatcher->Init(plugin_process_handle, channel_handle, + module->pp_module(), + pepper::PluginModule::GetLocalGetInterfaceFunc())) + return scoped_refptr<pepper::PluginModule>(); + module->InitAsProxied(dispatcher.release()); + return module; } void PepperPluginDelegateImpl::ViewInitiatedPaint() { |