1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
7 #include "content/common/view_messages.h"
8 #include "content/renderer/pepper/pepper_hung_plugin_filter.h"
9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
10 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
11 #include "content/renderer/pepper/plugin_module.h"
12 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
13 #include "content/renderer/pepper/renderer_restrict_dispatch_group.h"
14 #include "content/renderer/render_frame_impl.h"
18 HostDispatcherWrapper::HostDispatcherWrapper(
20 base::ProcessId peer_pid
,
22 const ppapi::PpapiPermissions
& perms
,
26 plugin_child_id_(plugin_child_id
),
28 is_external_(is_external
) {}
30 HostDispatcherWrapper::~HostDispatcherWrapper() {}
32 bool HostDispatcherWrapper::Init(const IPC::ChannelHandle
& channel_handle
,
33 PP_GetInterface_Func local_get_interface
,
34 const ppapi::Preferences
& preferences
,
35 scoped_refptr
<PepperHungPluginFilter
> filter
) {
36 if (channel_handle
.name
.empty())
40 DCHECK_NE(-1, channel_handle
.socket
.fd
);
41 if (channel_handle
.socket
.fd
== -1)
45 dispatcher_delegate_
.reset(new PepperProxyChannelDelegateImpl
);
46 dispatcher_
.reset(new ppapi::proxy::HostDispatcher(
47 module_
->pp_module(), local_get_interface
, permissions_
));
48 // The HungPluginFilter needs to know when we are blocked on a sync message
49 // to the plugin. Note the filter outlives the dispatcher, so there is no
50 // need to remove it as an observer.
51 dispatcher_
->AddSyncMessageStatusObserver(filter
.get());
53 if (!dispatcher_
->InitHostWithChannel(dispatcher_delegate_
.get(),
59 dispatcher_delegate_
.reset();
62 // HungPluginFilter needs to listen for some messages on the IO thread.
63 dispatcher_
->AddIOThreadMessageFilter(filter
);
65 dispatcher_
->channel()->SetRestrictDispatchChannelGroup(
66 kRendererRestrictDispatchGroup_Pepper
);
70 const void* HostDispatcherWrapper::GetProxiedInterface(const char* name
) {
71 return dispatcher_
->GetProxiedInterface(name
);
74 void HostDispatcherWrapper::AddInstance(PP_Instance instance
) {
75 ppapi::proxy::HostDispatcher::SetForInstance(instance
, dispatcher_
.get());
77 RendererPpapiHostImpl
* host
=
78 RendererPpapiHostImpl::GetForPPInstance(instance
);
79 // TODO(brettw) remove this null check when the old-style pepper-based
80 // browser tag is removed from this file. Getting this notification should
81 // always give us an instance we can find in the map otherwise, but that
82 // isn't true for browser tag support.
84 RenderFrame
* render_frame
= host
->GetRenderFrameForInstance(instance
);
85 PepperPluginInstance
* plugin_instance
= host
->GetPluginInstance(instance
);
86 render_frame
->Send(new ViewHostMsg_DidCreateOutOfProcessPepperInstance(
89 PepperRendererInstanceData(
90 0, // The render process id will be supplied in the browser.
91 render_frame
->GetRoutingID(),
92 host
->GetDocumentURL(instance
),
93 plugin_instance
->GetPluginURL()),
98 void HostDispatcherWrapper::RemoveInstance(PP_Instance instance
) {
99 ppapi::proxy::HostDispatcher::RemoveForInstance(instance
);
101 RendererPpapiHostImpl
* host
=
102 RendererPpapiHostImpl::GetForPPInstance(instance
);
103 // TODO(brettw) remove null check as described in AddInstance.
105 RenderFrame
* render_frame
= host
->GetRenderFrameForInstance(instance
);
107 render_frame
->Send(new ViewHostMsg_DidDeleteOutOfProcessPepperInstance(
108 plugin_child_id_
, instance
, is_external_
));
113 } // namespace content