summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-27 22:49:36 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-27 22:49:36 +0000
commit236bf85d455cd3aa4f66d16279756b96f57d762f (patch)
tree4bf1ce8869093c5c6c13863b7105986e9d96aabc
parent951ef0bdf8d1c272afb3bdce4dd3c39ffaab2fee (diff)
downloadchromium_src-236bf85d455cd3aa4f66d16279756b96f57d762f.zip
chromium_src-236bf85d455cd3aa4f66d16279756b96f57d762f.tar.gz
chromium_src-236bf85d455cd3aa4f66d16279756b96f57d762f.tar.bz2
Hook up the PPB_Flash_Print interface to new host system.
This adds the ability to implement "instance" messages (as opposed to resource messages) to PpapiHost via a message filter interface. The ownership model for these filters works just like RenderViewObserver. All non-resource messages are sent through this list of filters. This adds the ability to add such filters in the Chrome layer (as opposed to just content) by plumbing through some notifications. This patch responds to the trivial "Flash print" interface by calling the existing function in the renderer. This doesn't change the in-process case. Making this code path work in process will require that the "core" instance interface be done first or at the same time. As a result, the old in-process implementation is kept (it forwards to the same function in the end). This patch adds a HostResourceFactory for Chrome but doesn't hook it up yet. There is a TODO for this. I need to conver the host factories to a filter-like system to allow dynamic adding of filters from the Chrome layer. I'll do this in a follow-up patch. TEST=manual BUG=none Review URL: https://chromiumcodereview.appspot.com/10803050 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148840 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/chrome_renderer.gypi7
-rw-r--r--chrome/renderer/chrome_content_renderer_client.cc3
-rw-r--r--chrome/renderer/pepper/DEPS3
-rw-r--r--chrome/renderer/pepper/chrome_renderer_pepper_host_factory.cc30
-rw-r--r--chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h34
-rw-r--r--chrome/renderer/pepper/pepper_flash_renderer_message_filter.cc36
-rw-r--r--chrome/renderer/pepper/pepper_flash_renderer_message_filter.h36
-rw-r--r--chrome/renderer/pepper/pepper_helper.cc29
-rw-r--r--chrome/renderer/pepper/pepper_helper.h29
-rw-r--r--content/public/renderer/render_view_observer.h7
-rw-r--r--content/renderer/pepper/pepper_in_process_resource_creation.cc4
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.cc5
-rw-r--r--content/renderer/render_view_impl.cc5
-rw-r--r--content/renderer/render_view_impl.h3
-rw-r--r--ppapi/host/instance_message_filter.cc19
-rw-r--r--ppapi/host/instance_message_filter.h41
-rw-r--r--ppapi/host/ppapi_host.cc24
-rw-r--r--ppapi/host/ppapi_host.h16
-rw-r--r--ppapi/ppapi_host.gypi2
19 files changed, 330 insertions, 3 deletions
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi
index 0236adf6..e19827b 100644
--- a/chrome/chrome_renderer.gypi
+++ b/chrome/chrome_renderer.gypi
@@ -16,6 +16,7 @@
'safe_browsing_proto',
'../content/content.gyp:content_renderer',
'../net/net.gyp:net',
+ '../ppapi/ppapi_internal.gyp:ppapi_host',
'../ppapi/ppapi_internal.gyp:ppapi_proxy',
'../ppapi/ppapi_internal.gyp:ppapi_shared',
'../printing/printing.gyp:printing',
@@ -200,6 +201,12 @@
'renderer/page_load_histograms.h',
'renderer/pepper/chrome_ppapi_interfaces.cc',
'renderer/pepper/chrome_ppapi_interfaces.h',
+ 'renderer/pepper/chrome_renderer_pepper_host_factory.cc',
+ 'renderer/pepper/chrome_renderer_pepper_host_factory.h',
+ 'renderer/pepper/pepper_flash_renderer_message_filter.cc',
+ 'renderer/pepper/pepper_flash_renderer_message_filter.h',
+ 'renderer/pepper/pepper_helper.cc',
+ 'renderer/pepper/pepper_helper.h',
'renderer/pepper/ppb_flash_print_impl.cc',
'renderer/pepper/ppb_flash_print_impl.h',
'renderer/pepper/ppb_nacl_private_impl.cc',
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 04aff28..3ca868a 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -47,6 +47,7 @@
#include "chrome/renderer/page_click_tracker.h"
#include "chrome/renderer/page_load_histograms.h"
#include "chrome/renderer/pepper/chrome_ppapi_interfaces.h"
+#include "chrome/renderer/pepper/pepper_helper.h"
#include "chrome/renderer/playback_extension.h"
#include "chrome/renderer/plugins/plugin_placeholder.h"
#include "chrome/renderer/plugins/plugin_uma.h"
@@ -281,6 +282,8 @@ void ChromeContentRendererClient::RenderViewCreated(
render_view, content_settings, chrome_observer_.get(),
extension_dispatcher_.get(), translate);
+ new PepperHelper(render_view);
+
// Used only for testing/automation.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDomAutomationController)) {
diff --git a/chrome/renderer/pepper/DEPS b/chrome/renderer/pepper/DEPS
new file mode 100644
index 0000000..e1f8fae
--- /dev/null
+++ b/chrome/renderer/pepper/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+ppapi/host",
+]
diff --git a/chrome/renderer/pepper/chrome_renderer_pepper_host_factory.cc b/chrome/renderer/pepper/chrome_renderer_pepper_host_factory.cc
new file mode 100644
index 0000000..ebdf6ba
--- /dev/null
+++ b/chrome/renderer/pepper/chrome_renderer_pepper_host_factory.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
+
+#include "ppapi/host/resource_host.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+using ppapi::host::ResourceHost;
+
+namespace chrome {
+
+ChromeRendererPepperHostFactory::ChromeRendererPepperHostFactory() {
+}
+
+ChromeRendererPepperHostFactory::~ChromeRendererPepperHostFactory() {
+}
+
+scoped_ptr<ResourceHost>
+ChromeRendererPepperHostFactory::CreateResourceHost(
+ ppapi::host::PpapiHost* host,
+ const ppapi::proxy::ResourceMessageCallParams& params,
+ PP_Instance instance,
+ const IPC::Message& message) {
+ // There are no Chrome-side implementations of resources.
+ return scoped_ptr<ResourceHost>();
+}
+
+} // namespace chrome
diff --git a/chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h b/chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h
new file mode 100644
index 0000000..18d609c
--- /dev/null
+++ b/chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_PEPPER_CHROME_RENDERER_PEPPER_HOST_FACTORY_H_
+#define CHROME_RENDERER_PEPPER_CHROME_RENDERER_PEPPER_HOST_FACTORY_H_
+
+#include "base/compiler_specific.h"
+#include "ppapi/host/host_factory.h"
+#include "ppapi/shared_impl/ppapi_permissions.h"
+
+namespace chrome {
+
+class PepperInstanceStateAccessor;
+
+class ChromeRendererPepperHostFactory : public ppapi::host::HostFactory {
+ public:
+ ChromeRendererPepperHostFactory();
+ virtual ~ChromeRendererPepperHostFactory();
+
+ // HostFactory.
+ virtual scoped_ptr<ppapi::host::ResourceHost> CreateResourceHost(
+ ppapi::host::PpapiHost* host,
+ const ppapi::proxy::ResourceMessageCallParams& params,
+ PP_Instance instance,
+ const IPC::Message& message) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChromeRendererPepperHostFactory);
+};
+
+} // namespace chrome
+
+#endif // CHROME_RENDERER_PEPPER_CHROME_RENDERER_PEPPER_HOST_FACTORY_H_
diff --git a/chrome/renderer/pepper/pepper_flash_renderer_message_filter.cc b/chrome/renderer/pepper/pepper_flash_renderer_message_filter.cc
new file mode 100644
index 0000000..c556ae0
--- /dev/null
+++ b/chrome/renderer/pepper/pepper_flash_renderer_message_filter.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/pepper/pepper_flash_renderer_message_filter.h"
+
+#include "chrome/renderer/pepper/ppb_pdf_impl.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace chrome {
+
+PepperFlashRendererMessageFilter::PepperFlashRendererMessageFilter(
+ ppapi::host::PpapiHost* host)
+ : InstanceMessageFilter(host) {
+}
+
+PepperFlashRendererMessageFilter::~PepperFlashRendererMessageFilter() {
+}
+
+bool PepperFlashRendererMessageFilter::OnInstanceMessageReceived(
+ const IPC::Message& msg) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(PepperFlashRendererMessageFilter, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting,
+ OnHostMsgInvokePrinting)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void PepperFlashRendererMessageFilter::OnHostMsgInvokePrinting(
+ PP_Instance instance) {
+ PPB_PDF_Impl::InvokePrintingForInstance(instance);
+}
+
+} // namespace chrome
diff --git a/chrome/renderer/pepper/pepper_flash_renderer_message_filter.h b/chrome/renderer/pepper/pepper_flash_renderer_message_filter.h
new file mode 100644
index 0000000..3a39ae6
--- /dev/null
+++ b/chrome/renderer/pepper/pepper_flash_renderer_message_filter.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_PEPPER_PEPPER_FLASH_RENDERER_MESSAGE_FILTER_H_
+#define CHROME_RENDERER_PEPPER_PEPPER_FLASH_RENDERER_MESSAGE_FILTER_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ppapi/c/pp_instance.h"
+#include "ppapi/host/instance_message_filter.h"
+
+namespace chrome {
+
+// Implements the backend for Flash-specific messages from a plugin process.
+class PepperFlashRendererMessageFilter
+ : public ppapi::host::InstanceMessageFilter {
+ public:
+ // This class is designed to be heap-allocated. It will attach itself to the
+ // given host and delete itself when the host is destroyed.
+ explicit PepperFlashRendererMessageFilter(ppapi::host::PpapiHost* host);
+ virtual ~PepperFlashRendererMessageFilter();
+
+ // InstanceMessageFilter:
+ virtual bool OnInstanceMessageReceived(const IPC::Message& msg) OVERRIDE;
+
+ private:
+ // Message handlers.
+ void OnHostMsgInvokePrinting(PP_Instance instance);
+
+ DISALLOW_COPY_AND_ASSIGN(PepperFlashRendererMessageFilter);
+};
+
+} // namespace chrome
+
+#endif // CHROME_RENDERER_PEPPER_PEPPER_FLASH_RENDERER_MESSAGE_FILTER_H_
diff --git a/chrome/renderer/pepper/pepper_helper.cc b/chrome/renderer/pepper/pepper_helper.cc
new file mode 100644
index 0000000..4cd5c4d
--- /dev/null
+++ b/chrome/renderer/pepper/pepper_helper.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/renderer/pepper/pepper_helper.h"
+
+#include "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
+#include "chrome/renderer/pepper/pepper_flash_renderer_message_filter.h"
+#include "ppapi/host/ppapi_host.h"
+
+namespace chrome {
+
+PepperHelper::PepperHelper(content::RenderView* render_view)
+ : RenderViewObserver(render_view) {
+}
+
+PepperHelper::~PepperHelper() {
+}
+
+void PepperHelper::DidCreatePepperPlugin(ppapi::host::PpapiHost* host) {
+ // TODO(brettw) figure out how to hook up the host factory. It needs some
+ // kind of filter-like system to allow dynamic additions.
+ // new ChromeRendererPepperHostFactory(host);
+ host->AddInstanceMessageFilter(
+ scoped_ptr<ppapi::host::InstanceMessageFilter>(
+ new PepperFlashRendererMessageFilter(host)));
+}
+
+} // namespace chrome
diff --git a/chrome/renderer/pepper/pepper_helper.h b/chrome/renderer/pepper/pepper_helper.h
new file mode 100644
index 0000000..969a80e
--- /dev/null
+++ b/chrome/renderer/pepper/pepper_helper.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_PEPPER_PEPPER_HELPER_H_
+#define CHROME_RENDERER_PEPPER_PEPPER_HELPER_H_
+
+#include "base/compiler_specific.h"
+#include "content/public/renderer/render_view_observer.h"
+
+namespace chrome {
+
+// This class listens for Pepper creation events from the RenderView and
+// attaches the parts required for Chrome-specific plugin support.
+class PepperHelper : public content::RenderViewObserver {
+ public:
+ explicit PepperHelper(content::RenderView* render_view);
+ virtual ~PepperHelper();
+
+ // RenderViewObserver.
+ virtual void DidCreatePepperPlugin(ppapi::host::PpapiHost* host) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PepperHelper);
+};
+
+} // namespace chrome
+
+#endif // CHROME_RENDERER_PEPPER_PEPPER_HELPER_H_
diff --git a/content/public/renderer/render_view_observer.h b/content/public/renderer/render_view_observer.h
index 0cdc0b0..b6eb317 100644
--- a/content/public/renderer/render_view_observer.h
+++ b/content/public/renderer/render_view_observer.h
@@ -14,6 +14,12 @@
class RenderViewImpl;
+namespace ppapi {
+namespace host {
+class PpapiHost;
+}
+}
+
namespace WebKit {
class WebDataSource;
class WebFrame;
@@ -77,6 +83,7 @@ class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
// These match the RenderView methods.
virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) {}
virtual void DidHandleTouchEvent(const WebKit::WebTouchEvent& event) {}
+ virtual void DidCreatePepperPlugin(ppapi::host::PpapiHost* host) {}
// These match incoming IPCs.
virtual void ContextMenuAction(unsigned id) {}
diff --git a/content/renderer/pepper/pepper_in_process_resource_creation.cc b/content/renderer/pepper/pepper_in_process_resource_creation.cc
index af3e0e7..19eac81 100644
--- a/content/renderer/pepper/pepper_in_process_resource_creation.cc
+++ b/content/renderer/pepper/pepper_in_process_resource_creation.cc
@@ -8,6 +8,7 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "content/renderer/pepper/content_renderer_pepper_host_factory.h"
+#include "content/renderer/render_view_impl.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "ppapi/host/ppapi_host.h"
@@ -33,6 +34,8 @@ class PepperInProcessResourceCreation::PluginToHostRouter
const ppapi::PpapiPermissions& perms);
virtual ~PluginToHostRouter() {}
+ ppapi::host::PpapiHost& host() { return host_; }
+
// Sender implementation.
virtual bool Send(IPC::Message* msg) OVERRIDE;
@@ -146,6 +149,7 @@ PepperInProcessResourceCreation::PepperInProcessResourceCreation(
new PluginToHostRouter(render_view, &instance_state_,
host_to_plugin_router_.get(),
perms)) {
+ render_view->PpapiPluginCreated(&plugin_to_host_router_->host());
}
PepperInProcessResourceCreation::~PepperInProcessResourceCreation() {
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
index 75a5236..c53be6a 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
@@ -111,7 +111,8 @@ class HostDispatcherWrapper
const ppapi::PpapiPermissions& perms)
: module_(module),
instance_state_(module),
- host_factory_(rv, perms, &instance_state_) {
+ host_factory_(rv, perms, &instance_state_),
+ render_view_(rv) {
}
virtual ~HostDispatcherWrapper() {}
@@ -147,6 +148,7 @@ class HostDispatcherWrapper
}
dispatcher_->channel()->SetRestrictDispatchChannelGroup(
content::kRendererRestrictDispatchGroup_Pepper);
+ render_view_->PpapiPluginCreated(host_.get());
return true;
}
@@ -166,6 +168,7 @@ class HostDispatcherWrapper
PepperInstanceStateAccessorImpl instance_state_;
ContentRendererPepperHostFactory host_factory_;
+ RenderViewImpl* render_view_;
scoped_ptr<ppapi::host::PpapiHost> host_;
scoped_ptr<ppapi::proxy::HostDispatcher> dispatcher_;
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index de604b1e..d88f508 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -5307,6 +5307,11 @@ void RenderViewImpl::PpapiPluginSelectionChanged() {
SyncSelectionIfRequired();
}
+void RenderViewImpl::PpapiPluginCreated(ppapi::host::PpapiHost* host) {
+ FOR_EACH_OBSERVER(RenderViewObserver, observers_,
+ DidCreatePepperPlugin(host));
+}
+
void RenderViewImpl::OnImeSetComposition(
const string16& text,
const std::vector<WebKit::WebCompositionUnderline>& underlines,
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index 0dc2bed..1c21cd6 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -329,6 +329,9 @@ class RenderViewImpl : public RenderWidget,
// Informs the render view that a PPAPI plugin has changed selection.
void PpapiPluginSelectionChanged();
+ // Notification that a PPAPI plugin has been created.
+ void PpapiPluginCreated(ppapi::host::PpapiHost* host);
+
// Retrieves the current caret position if a PPAPI plugin has focus.
bool GetPpapiPluginCaretBounds(gfx::Rect* rect);
diff --git a/ppapi/host/instance_message_filter.cc b/ppapi/host/instance_message_filter.cc
new file mode 100644
index 0000000..229235f
--- /dev/null
+++ b/ppapi/host/instance_message_filter.cc
@@ -0,0 +1,19 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/host/instance_message_filter.h"
+
+#include "ppapi/host/ppapi_host.h"
+
+namespace ppapi {
+namespace host {
+
+InstanceMessageFilter::InstanceMessageFilter(PpapiHost* host) : host_(host) {
+}
+
+InstanceMessageFilter::~InstanceMessageFilter() {
+}
+
+} // namespace host
+} // namespace ppapi
diff --git a/ppapi/host/instance_message_filter.h b/ppapi/host/instance_message_filter.h
new file mode 100644
index 0000000..2b072e9
--- /dev/null
+++ b/ppapi/host/instance_message_filter.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_HOST_INSTANCE_MESSAGE_FILTER_H_
+#define PPAPI_HOST_INSTANCE_MESSAGE_FILTER_H_
+
+#include "base/basictypes.h"
+#include "ppapi/host/ppapi_host_export.h"
+
+namespace IPC {
+class Message;
+}
+
+namespace ppapi {
+namespace host {
+
+class PpapiHost;
+
+class PPAPI_HOST_EXPORT InstanceMessageFilter {
+ public:
+ explicit InstanceMessageFilter(PpapiHost* host);
+ virtual ~InstanceMessageFilter();
+
+ // Processes an instance message from the plugin process. Returns true if the
+ // message was handled. On false, the PpapiHost will forward the message to
+ // the next filter.
+ virtual bool OnInstanceMessageReceived(const IPC::Message& msg) = 0;
+
+ PpapiHost* host() { return host_; }
+
+ private:
+ PpapiHost* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(InstanceMessageFilter);
+};
+
+} // namespace host
+} // namespace ppapi
+
+#endif // PPAPI_HOST_INSTANCE_MESSAGE_FILTER_H_
diff --git a/ppapi/host/ppapi_host.cc b/ppapi/host/ppapi_host.cc
index 8754501..14a3a4f 100644
--- a/ppapi/host/ppapi_host.cc
+++ b/ppapi/host/ppapi_host.cc
@@ -8,6 +8,7 @@
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/host_factory.h"
#include "ppapi/host/host_message_context.h"
+#include "ppapi/host/instance_message_filter.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/resource_message_params.h"
@@ -33,6 +34,10 @@ PpapiHost::PpapiHost(IPC::Sender* sender,
}
PpapiHost::~PpapiHost() {
+ // Delete these explicitly before destruction since then the host is still
+ // technically alive in case one of the filters accesses us from the
+ // destructor.
+ instance_message_filters_.clear();
}
bool PpapiHost::Send(IPC::Message* msg) {
@@ -50,6 +55,16 @@ bool PpapiHost::OnMessageReceived(const IPC::Message& msg) {
OnHostMsgResourceDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
+
+ if (!handled) {
+ for (size_t i = 0; i < instance_message_filters_.size(); i++) {
+ if (instance_message_filters_[i]->OnInstanceMessageReceived(msg)) {
+ handled = true;
+ break;
+ }
+ }
+ }
+
return handled;
}
@@ -58,6 +73,12 @@ void PpapiHost::SendReply(const proxy::ResourceMessageReplyParams& params,
Send(new PpapiPluginMsg_ResourceReply(params, msg));
}
+
+void PpapiHost::AddInstanceMessageFilter(
+ scoped_ptr<InstanceMessageFilter> filter) {
+ instance_message_filters_.push_back(filter.release());
+}
+
void PpapiHost::OnHostMsgResourceCall(
const proxy::ResourceMessageCallParams& params,
const IPC::Message& nested_msg) {
@@ -100,8 +121,7 @@ void PpapiHost::OnHostMsgResourceCreated(
return;
scoped_ptr<ResourceHost> resource_host(
- host_factory_->CreateResourceHost(this, params, instance,
- nested_msg));
+ host_factory_->CreateResourceHost(this, params, instance, nested_msg));
if (!resource_host.get()) {
NOTREACHED();
return;
diff --git a/ppapi/host/ppapi_host.h b/ppapi/host/ppapi_host.h
index 7a20c1f..5bc284c 100644
--- a/ppapi/host/ppapi_host.h
+++ b/ppapi/host/ppapi_host.h
@@ -9,6 +9,9 @@
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
+#include "base/memory/scoped_vector.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
#include "ppapi/c/pp_instance.h"
@@ -26,6 +29,7 @@ class ResourceMessageReplyParams;
namespace host {
class HostFactory;
+class InstanceMessageFilter;
class ResourceHost;
// The host provides routing and tracking for resource message calls that
@@ -53,7 +57,13 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
void SendReply(const proxy::ResourceMessageReplyParams& params,
const IPC::Message& msg);
+ // Adds the given message filter to the host. The PpapiHost will take
+ // ownership of the pointer.
+ void AddInstanceMessageFilter(scoped_ptr<InstanceMessageFilter> filter);
+
private:
+ friend class InstanceMessageFilter;
+
// Message handlers.
void OnHostMsgResourceCall(const proxy::ResourceMessageCallParams& params,
const IPC::Message& nested_msg);
@@ -73,6 +83,12 @@ class PPAPI_HOST_EXPORT PpapiHost : public IPC::Sender, public IPC::Listener {
PpapiPermissions permissions_;
+ // Filters for instance messages. Note that since we don't support deleting
+ // these dynamically we don't need to worry about modifications during
+ // iteration. If we add that capability, this should be replaced with an
+ // ObserverList.
+ ScopedVector<InstanceMessageFilter> instance_message_filters_;
+
typedef std::map<PP_Resource, linked_ptr<ResourceHost> > ResourceMap;
ResourceMap resources_;
diff --git a/ppapi/ppapi_host.gypi b/ppapi/ppapi_host.gypi
index c2f9ff8..c0cdfa0 100644
--- a/ppapi/ppapi_host.gypi
+++ b/ppapi/ppapi_host.gypi
@@ -22,6 +22,8 @@
'host/dispatch_host_message.h',
'host/host_factory.h',
'host/host_message_context.h',
+ 'host/instance_message_filter.cc',
+ 'host/instance_message_filter.h',
'host/ppapi_host.cc',
'host/ppapi_host.h',
'host/ppapi_host_export.h',