Commit 236bf85d authored by brettw@chromium.org's avatar brettw@chromium.org

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
parent 951ef0bd
......@@ -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',
......
......@@ -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)) {
......
include_rules = [
"+ppapi/host",
]
// 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
// 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_
// 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
// 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_
// 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
// 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_
......@@ -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) {}
......
......@@ -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() {
......
......@@ -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_;
......
......@@ -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,
......
......@@ -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);
......
// 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
// 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_
......@@ -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;
......
......@@ -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_;
......
......@@ -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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment