blob: e55aec0afc242c557154629afcc1f08be4b4805f [file] [log] [blame]
[email protected]35099ad2013-07-26 22:06:391// 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.
4
5#include "content/renderer/pepper/host_dispatcher_wrapper.h"
6
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"
[email protected]6dd625e2013-12-20 17:03:0714#include "content/renderer/render_frame_impl.h"
[email protected]35099ad2013-07-26 22:06:3915
16namespace content {
17
18HostDispatcherWrapper::HostDispatcherWrapper(
19 PluginModule* module,
20 base::ProcessId peer_pid,
21 int plugin_child_id,
22 const ppapi::PpapiPermissions& perms,
23 bool is_external)
24 : module_(module),
25 peer_pid_(peer_pid),
26 plugin_child_id_(plugin_child_id),
27 permissions_(perms),
28 is_external_(is_external) {
29}
30
31HostDispatcherWrapper::~HostDispatcherWrapper() {
32}
33
34bool HostDispatcherWrapper::Init(const IPC::ChannelHandle& channel_handle,
35 PP_GetInterface_Func local_get_interface,
36 const ppapi::Preferences& preferences,
37 PepperHungPluginFilter* filter) {
38 if (channel_handle.name.empty())
39 return false;
40
41#if defined(OS_POSIX)
42 DCHECK_NE(-1, channel_handle.socket.fd);
43 if (channel_handle.socket.fd == -1)
44 return false;
45#endif
46
47 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
48 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
49 module_->pp_module(), local_get_interface, filter, permissions_));
50
51 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
52 peer_pid_,
53 channel_handle,
54 true, // Client.
55 preferences)) {
56 dispatcher_.reset();
57 dispatcher_delegate_.reset();
58 return false;
59 }
60 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
61 kRendererRestrictDispatchGroup_Pepper);
62 return true;
63}
64
65const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) {
66 return dispatcher_->GetProxiedInterface(name);
67}
68
69void HostDispatcherWrapper::AddInstance(PP_Instance instance) {
70 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
71
72 RendererPpapiHostImpl* host =
73 RendererPpapiHostImpl::GetForPPInstance(instance);
74 // TODO(brettw) remove this null check when the old-style pepper-based
75 // browser tag is removed from this file. Getting this notification should
76 // always give us an instance we can find in the map otherwise, but that
77 // isn't true for browser tag support.
78 if (host) {
[email protected]6dd625e2013-12-20 17:03:0779 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
[email protected]35099ad2013-07-26 22:06:3980 PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance);
[email protected]6dd625e2013-12-20 17:03:0781 render_frame->Send(new ViewHostMsg_DidCreateOutOfProcessPepperInstance(
[email protected]35099ad2013-07-26 22:06:3982 plugin_child_id_,
83 instance,
84 PepperRendererInstanceData(
85 0, // The render process id will be supplied in the browser.
[email protected]6dd625e2013-12-20 17:03:0786 render_frame->GetRoutingID(),
[email protected]83d3c0c12013-11-05 06:31:0387 host->GetDocumentURL(instance),
[email protected]35099ad2013-07-26 22:06:3988 plugin_instance->GetPluginURL()),
89 is_external_));
90 }
91}
92
93void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) {
94 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
95
96 RendererPpapiHostImpl* host =
97 RendererPpapiHostImpl::GetForPPInstance(instance);
98 // TODO(brettw) remove null check as described in AddInstance.
99 if (host) {
[email protected]6dd625e2013-12-20 17:03:07100 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
[email protected]e3c8c992014-02-12 16:18:00101 if (render_frame) {
102 render_frame->Send(new ViewHostMsg_DidDeleteOutOfProcessPepperInstance(
103 plugin_child_id_,
104 instance,
105 is_external_));
106 }
[email protected]35099ad2013-07-26 22:06:39107 }
108}
109
110} // namespace content