This source file includes following definitions.
- AddPendingResourceHost
- render_process_id_
- GetHostForChildProcess
- OnMessageReceived
- OnMsgCreateResourceHostsFromHost
- OnMsgDidCreateInProcessInstance
- OnMsgDidDeleteInProcessInstance
#include "content/browser/renderer_host/pepper/pepper_renderer_connection.h"
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/ppapi_plugin_process_host.h"
#include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h"
#include "content/common/pepper_renderer_instance_data.h"
#include "content/common/view_messages.h"
#include "content/browser/renderer_host/pepper/pepper_file_ref_host.h"
#include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "ipc/ipc_message_macros.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/ppapi_message_utils.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppapi_message_utils.h"
#include "ppapi/proxy/resource_message_params.h"
namespace content {
namespace {
const uint32 kFilteredMessageClasses[] = {
PpapiMsgStart,
ViewMsgStart,
};
class PendingHostCreator
: public base::RefCounted<PendingHostCreator> {
public:
PendingHostCreator(BrowserPpapiHostImpl* host,
BrowserMessageFilter* connection,
int routing_id,
int sequence_id,
size_t nested_msgs_size);
void AddPendingResourceHost(
size_t index,
scoped_ptr<ppapi::host::ResourceHost> resource_host);
private:
friend class base::RefCounted<PendingHostCreator>;
~PendingHostCreator();
BrowserPpapiHostImpl* host_;
BrowserMessageFilter* connection_;
int routing_id_;
int sequence_id_;
std::vector<int> pending_resource_host_ids_;
};
PendingHostCreator::PendingHostCreator(BrowserPpapiHostImpl* host,
BrowserMessageFilter* connection,
int routing_id,
int sequence_id,
size_t nested_msgs_size)
: host_(host),
connection_(connection),
routing_id_(routing_id),
sequence_id_(sequence_id),
pending_resource_host_ids_(nested_msgs_size, 0) {}
void PendingHostCreator::AddPendingResourceHost(
size_t index,
scoped_ptr<ppapi::host::ResourceHost> resource_host) {
pending_resource_host_ids_[index] =
host_->GetPpapiHost()->AddPendingResourceHost(resource_host.Pass());
}
PendingHostCreator::~PendingHostCreator() {
connection_->Send(new PpapiHostMsg_CreateResourceHostsFromHostReply(
routing_id_, sequence_id_, pending_resource_host_ids_));
}
}
PepperRendererConnection::PepperRendererConnection(int render_process_id)
: BrowserMessageFilter(
kFilteredMessageClasses, arraysize(kFilteredMessageClasses)),
render_process_id_(render_process_id) {
in_process_host_.reset(new BrowserPpapiHostImpl(this,
ppapi::PpapiPermissions(),
"",
base::FilePath(),
base::FilePath(),
true ,
false ));
}
PepperRendererConnection::~PepperRendererConnection() {
}
BrowserPpapiHostImpl* PepperRendererConnection::GetHostForChildProcess(
int child_process_id) const {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
BrowserPpapiHostImpl* host = static_cast<BrowserPpapiHostImpl*>(
GetContentClient()->browser()->GetExternalBrowserPpapiHost(
child_process_id));
if (!host) {
for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) {
if (iter->process() &&
iter->process()->GetData().id == child_process_id) {
host = iter->host_impl();
break;
}
}
}
if (!host && child_process_id == 0) {
host = in_process_host_.get();
}
return host;
}
bool PepperRendererConnection::OnMessageReceived(const IPC::Message& msg,
bool* message_was_ok) {
if (in_process_host_->GetPpapiHost()->OnMessageReceived(msg))
return true;
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(PepperRendererConnection, msg, *message_was_ok)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostsFromHost,
OnMsgCreateResourceHostsFromHost)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidCreateInProcessInstance,
OnMsgDidCreateInProcessInstance)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidDeleteInProcessInstance,
OnMsgDidDeleteInProcessInstance)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
return handled;
}
void PepperRendererConnection::OnMsgCreateResourceHostsFromHost(
int routing_id,
int child_process_id,
const ppapi::proxy::ResourceMessageCallParams& params,
PP_Instance instance,
const std::vector<IPC::Message>& nested_msgs) {
BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id);
if (!host) {
DLOG(ERROR) << "Invalid plugin process ID.";
return;
}
scoped_refptr<PendingHostCreator> creator = new PendingHostCreator(
host, this, routing_id, params.sequence(), nested_msgs.size());
for (size_t i = 0; i < nested_msgs.size(); ++i) {
const IPC::Message& nested_msg = nested_msgs[i];
scoped_ptr<ppapi::host::ResourceHost> resource_host;
if (host->IsValidInstance(instance)) {
if (nested_msg.type() == PpapiHostMsg_FileRef_CreateExternal::ID) {
base::FilePath external_path;
if (ppapi::UnpackMessage<PpapiHostMsg_FileRef_CreateExternal>(
nested_msg, &external_path)) {
resource_host.reset(new PepperFileRefHost(
host, instance, params.pp_resource(), external_path));
}
} else if (nested_msg.type() ==
PpapiHostMsg_FileSystem_CreateFromRenderer::ID) {
std::string root_url;
PP_FileSystemType file_system_type;
if (ppapi::UnpackMessage<PpapiHostMsg_FileSystem_CreateFromRenderer>(
nested_msg, &root_url, &file_system_type)) {
PepperFileSystemBrowserHost* browser_host =
new PepperFileSystemBrowserHost(host,
instance,
params.pp_resource(),
file_system_type);
resource_host.reset(browser_host);
browser_host->OpenExisting(
GURL(root_url),
base::Bind(
&PendingHostCreator::AddPendingResourceHost,
creator,
i,
base::Passed(&resource_host)));
continue;
}
}
}
if (!resource_host.get()) {
resource_host = host->GetPpapiHost()->CreateResourceHost(
params, instance, nested_msg);
}
if (resource_host.get())
creator->AddPendingResourceHost(i, resource_host.Pass());
}
}
void PepperRendererConnection::OnMsgDidCreateInProcessInstance(
PP_Instance instance,
const PepperRendererInstanceData& instance_data) {
PepperRendererInstanceData data = instance_data;
data.render_process_id = render_process_id_;
in_process_host_->AddInstance(instance, data);
}
void PepperRendererConnection::OnMsgDidDeleteInProcessInstance(
PP_Instance instance) {
in_process_host_->DeleteInstance(instance);
}
}