diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 19:05:03 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-07 19:05:03 +0000 |
commit | 0c719374f8228f5615005cdd9fa4fc7cbc7554f2 (patch) | |
tree | de64ef9fe5e711ba6553935e933d3015adc3fafd /content/browser/renderer_host/pepper | |
parent | c24c9e0439b57dc1f6b785255bbac78aaa31fd2d (diff) | |
download | chromium_src-0c719374f8228f5615005cdd9fa4fc7cbc7554f2.zip chromium_src-0c719374f8228f5615005cdd9fa4fc7cbc7554f2.tar.gz chromium_src-0c719374f8228f5615005cdd9fa4fc7cbc7554f2.tar.bz2 |
Add support for external out-of-process PPAPI plugins in the browser.
- Modifies content::BrowserPpapiHostImpl so it's not ref-counted.
- Adds a public content API method, BrowserPpapiHost::CreateExternalPluginProcess
which allows the embedder to associate a browser ppapi host with a plugin process.
- Adds a public content API method, ContentBrowserClient::GetExternalBrowserPpapiHost,
so content can track instance creation and deletion for external plugins (e.g. NaCl)
- Removes the content API method EnablePepperSupportForChannel. This is now done
when creating the BrowserPpapiHost.
BUG=116317
TEST=none
Review URL: https://chromiumcodereview.appspot.com/11368019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/pepper')
4 files changed, 79 insertions, 29 deletions
diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc index dedd51e..2cb3522 100644 --- a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc +++ b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" +#include "content/browser/renderer_host/pepper/pepper_message_filter.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_view_host.h" @@ -10,28 +11,41 @@ namespace content { +// static +BrowserPpapiHost* BrowserPpapiHost::CreateExternalPluginProcess( + IPC::Sender* sender, + ppapi::PpapiPermissions permissions, + base::ProcessHandle plugin_child_process, + IPC::ChannelProxy* channel, + net::HostResolver* host_resolver, + int render_process_id, + int render_view_id) { + BrowserPpapiHostImpl* browser_ppapi_host = + new BrowserPpapiHostImpl(sender, permissions); + browser_ppapi_host->set_plugin_process_handle(plugin_child_process); + + channel->AddFilter( + new PepperMessageFilter(PepperMessageFilter::NACL, + host_resolver, + render_process_id, + render_view_id)); + + return browser_ppapi_host; +} + BrowserPpapiHostImpl::BrowserPpapiHostImpl( IPC::Sender* sender, const ppapi::PpapiPermissions& permissions) : ppapi_host_(sender, permissions), plugin_process_handle_(base::kNullProcessHandle) { + message_filter_ = new HostMessageFilter(&ppapi_host_); ppapi_host_.AddHostFactoryFilter(scoped_ptr<ppapi::host::HostFactory>( new ContentBrowserPepperHostFactory(this))); } BrowserPpapiHostImpl::~BrowserPpapiHostImpl() { -} - -bool BrowserPpapiHostImpl::OnMessageReceived(const IPC::Message& msg) { - /* TODO(brettw) when we add messages, here, the code should look like this: - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) - // Add necessary message handlers here. - IPC_MESSAGE_UNHANDLED(handled = ppapi_host_.OnMessageReceived(msg)) - IPC_END_MESSAGE_MAP(); - return handled; - */ - return ppapi_host_.OnMessageReceived(msg); + // Notify the filter so it won't foward messages to us. + message_filter_->OnHostDestroyed(); } ppapi::host::PpapiHost* BrowserPpapiHostImpl::GetPpapiHost() { @@ -84,4 +98,26 @@ void BrowserPpapiHostImpl::DeleteInstanceForView(PP_Instance instance) { instance_to_view_.erase(found); } +bool BrowserPpapiHostImpl::HostMessageFilter::OnMessageReceived( + const IPC::Message& msg) { + // Don't forward messages if our owner object has been destroyed. + if (!ppapi_host_) + return false; + + /* TODO(brettw) when we add messages, here, the code should look like this: + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(BrowserPpapiHostImpl, msg) + // Add necessary message handlers here. + IPC_MESSAGE_UNHANDLED(handled = ppapi_host_->OnMessageReceived(msg)) + IPC_END_MESSAGE_MAP(); + return handled; + */ + return ppapi_host_->OnMessageReceived(msg); +} + +void BrowserPpapiHostImpl::HostMessageFilter::OnHostDestroyed() { + DCHECK(ppapi_host_); + ppapi_host_ = NULL; +} + } // namespace content diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h index d743d15..bee35a6 100644 --- a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h +++ b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h @@ -15,24 +15,16 @@ #include "ipc/ipc_channel_proxy.h" #include "ppapi/host/ppapi_host.h" -namespace IPC { -class Sender; -} - namespace content { -class CONTENT_EXPORT BrowserPpapiHostImpl - : public BrowserPpapiHost, - public IPC::ChannelProxy::MessageFilter { +class CONTENT_EXPORT BrowserPpapiHostImpl : public BrowserPpapiHost { public: // The creator is responsible for calling set_plugin_process_handle as soon // as it is known (we start the process asynchronously so it won't be known // when this object is created). BrowserPpapiHostImpl(IPC::Sender* sender, const ppapi::PpapiPermissions& permissions); - - // IPC::ChannelProxy::MessageFilter. - virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + virtual ~BrowserPpapiHostImpl(); // BrowserPpapiHost. virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE; @@ -54,6 +46,10 @@ class CONTENT_EXPORT BrowserPpapiHostImpl int render_view_id); void DeleteInstanceForView(PP_Instance instance); + scoped_refptr<IPC::ChannelProxy::MessageFilter> message_filter() { + return message_filter_; + } + private: friend class BrowserPpapiHostTest; @@ -63,7 +59,23 @@ class CONTENT_EXPORT BrowserPpapiHostImpl }; typedef std::map<PP_Instance, RenderViewIDs> InstanceToViewMap; - virtual ~BrowserPpapiHostImpl(); + // Implementing MessageFilter on BrowserPpapiHostImpl makes it ref-counted, + // preventing us from returning these to embedders without holding a + // reference. To avoid that, define a message filter object. + class HostMessageFilter : public IPC::ChannelProxy::MessageFilter { + public: + explicit HostMessageFilter(ppapi::host::PpapiHost* ppapi_host) + : ppapi_host_(ppapi_host) {} + // IPC::ChannelProxy::MessageFilter. + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + + void OnHostDestroyed(); + + private: + virtual ~HostMessageFilter() {} + + ppapi::host::PpapiHost* ppapi_host_; + }; ppapi::host::PpapiHost ppapi_host_; base::ProcessHandle plugin_process_handle_; @@ -72,6 +84,8 @@ class CONTENT_EXPORT BrowserPpapiHostImpl // RenderProcess/RenderView IDs. InstanceToViewMap instance_to_view_; + scoped_refptr<HostMessageFilter> message_filter_; + DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostImpl); }; diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_test.cc b/content/browser/renderer_host/pepper/browser_ppapi_host_test.cc index 42fc6c0..941782c 100644 --- a/content/browser/renderer_host/pepper/browser_ppapi_host_test.cc +++ b/content/browser/renderer_host/pepper/browser_ppapi_host_test.cc @@ -10,10 +10,10 @@ namespace content { BrowserPpapiHostTest::BrowserPpapiHostTest() - : sink_(), - ppapi_host_(new BrowserPpapiHostImpl( - &sink_, - ppapi::PpapiPermissions::AllPermissions())) { + : sink_() { + ppapi_host_.reset(new BrowserPpapiHostImpl( + &sink_, + ppapi::PpapiPermissions::AllPermissions())); ppapi_host_->set_plugin_process_handle(base::GetCurrentProcessHandle()); } @@ -21,7 +21,7 @@ BrowserPpapiHostTest::~BrowserPpapiHostTest() { } BrowserPpapiHost* BrowserPpapiHostTest::GetBrowserPpapiHost() { - return ppapi_host_; + return ppapi_host_.get(); } } // namespace content diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_test.h b/content/browser/renderer_host/pepper/browser_ppapi_host_test.h index d9e73a1..3f375ee 100644 --- a/content/browser/renderer_host/pepper/browser_ppapi_host_test.h +++ b/content/browser/renderer_host/pepper/browser_ppapi_host_test.h @@ -27,7 +27,7 @@ class BrowserPpapiHostTest { private: ppapi::proxy::ResourceMessageTestSink sink_; - scoped_refptr<BrowserPpapiHostImpl> ppapi_host_; + scoped_ptr<BrowserPpapiHostImpl> ppapi_host_; DISALLOW_COPY_AND_ASSIGN(BrowserPpapiHostTest); }; |