blob: 88d567a5cdb77d89db20998549ce965ca0e6c96b [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
avi1023d012015-12-25 02:39:147#include "build/build_config.h"
avi270d4222015-09-04 22:37:198#include "content/common/frame_messages.h"
raymes568fbca2015-05-14 19:24:219#include "content/public/common/origin_util.h"
[email protected]35099ad2013-07-26 22:06:3910#include "content/renderer/pepper/pepper_hung_plugin_filter.h"
11#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
12#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
13#include "content/renderer/pepper/plugin_module.h"
14#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
15#include "content/renderer/pepper/renderer_restrict_dispatch_group.h"
[email protected]6dd625e2013-12-20 17:03:0716#include "content/renderer/render_frame_impl.h"
raymes568fbca2015-05-14 19:24:2117#include "third_party/WebKit/public/web/WebDocument.h"
raymes568fbca2015-05-14 19:24:2118#include "third_party/WebKit/public/web/WebPluginContainer.h"
[email protected]35099ad2013-07-26 22:06:3919
20namespace content {
21
22HostDispatcherWrapper::HostDispatcherWrapper(
23 PluginModule* module,
24 base::ProcessId peer_pid,
25 int plugin_child_id,
26 const ppapi::PpapiPermissions& perms,
27 bool is_external)
28 : module_(module),
29 peer_pid_(peer_pid),
30 plugin_child_id_(plugin_child_id),
31 permissions_(perms),
[email protected]ad63b5c2014-04-11 21:12:3632 is_external_(is_external) {}
[email protected]35099ad2013-07-26 22:06:3933
[email protected]ad63b5c2014-04-11 21:12:3634HostDispatcherWrapper::~HostDispatcherWrapper() {}
[email protected]35099ad2013-07-26 22:06:3935
36bool HostDispatcherWrapper::Init(const IPC::ChannelHandle& channel_handle,
37 PP_GetInterface_Func local_get_interface,
38 const ppapi::Preferences& preferences,
dmichael6b328f3d2014-09-29 23:49:0239 scoped_refptr<PepperHungPluginFilter> filter) {
[email protected]35099ad2013-07-26 22:06:3940 if (channel_handle.name.empty())
41 return false;
42
43#if defined(OS_POSIX)
44 DCHECK_NE(-1, channel_handle.socket.fd);
45 if (channel_handle.socket.fd == -1)
46 return false;
47#endif
48
49 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
50 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
dmichael6b328f3d2014-09-29 23:49:0251 module_->pp_module(), local_get_interface, permissions_));
52 // The HungPluginFilter needs to know when we are blocked on a sync message
53 // to the plugin. Note the filter outlives the dispatcher, so there is no
54 // need to remove it as an observer.
55 dispatcher_->AddSyncMessageStatusObserver(filter.get());
56 // Guarantee the hung_plugin_filter_ outlives |dispatcher_|.
57 hung_plugin_filter_ = filter;
[email protected]35099ad2013-07-26 22:06:3958
59 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
60 peer_pid_,
61 channel_handle,
62 true, // Client.
63 preferences)) {
64 dispatcher_.reset();
65 dispatcher_delegate_.reset();
66 return false;
67 }
dmichael6b328f3d2014-09-29 23:49:0268 // HungPluginFilter needs to listen for some messages on the IO thread.
69 dispatcher_->AddIOThreadMessageFilter(filter);
70
[email protected]35099ad2013-07-26 22:06:3971 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
72 kRendererRestrictDispatchGroup_Pepper);
73 return true;
74}
75
76const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) {
77 return dispatcher_->GetProxiedInterface(name);
78}
79
80void HostDispatcherWrapper::AddInstance(PP_Instance instance) {
81 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
82
83 RendererPpapiHostImpl* host =
84 RendererPpapiHostImpl::GetForPPInstance(instance);
85 // TODO(brettw) remove this null check when the old-style pepper-based
86 // browser tag is removed from this file. Getting this notification should
87 // always give us an instance we can find in the map otherwise, but that
88 // isn't true for browser tag support.
89 if (host) {
[email protected]6dd625e2013-12-20 17:03:0790 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
[email protected]35099ad2013-07-26 22:06:3991 PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance);
raymes568fbca2015-05-14 19:24:2192 blink::WebString unused;
93 bool is_privileged_context =
94 plugin_instance->GetContainer()
esprehnd88a9032016-05-05 15:46:4295 ->document()
mkwstfd67eed2015-09-29 12:05:3796 .isSecureContext(unused) &&
raymes568fbca2015-05-14 19:24:2197 content::IsOriginSecure(plugin_instance->GetPluginURL());
avi270d4222015-09-04 22:37:1998 render_frame->Send(new FrameHostMsg_DidCreateOutOfProcessPepperInstance(
raymes568fbca2015-05-14 19:24:2199 plugin_child_id_, instance,
[email protected]35099ad2013-07-26 22:06:39100 PepperRendererInstanceData(
101 0, // The render process id will be supplied in the browser.
raymes568fbca2015-05-14 19:24:21102 render_frame->GetRoutingID(), host->GetDocumentURL(instance),
103 plugin_instance->GetPluginURL(), is_privileged_context),
[email protected]35099ad2013-07-26 22:06:39104 is_external_));
105 }
106}
107
108void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) {
109 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
110
111 RendererPpapiHostImpl* host =
112 RendererPpapiHostImpl::GetForPPInstance(instance);
113 // TODO(brettw) remove null check as described in AddInstance.
114 if (host) {
[email protected]6dd625e2013-12-20 17:03:07115 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
[email protected]e3c8c992014-02-12 16:18:00116 if (render_frame) {
avi270d4222015-09-04 22:37:19117 render_frame->Send(new FrameHostMsg_DidDeleteOutOfProcessPepperInstance(
[email protected]ad63b5c2014-04-11 21:12:36118 plugin_child_id_, instance, is_external_));
[email protected]e3c8c992014-02-12 16:18:00119 }
[email protected]35099ad2013-07-26 22:06:39120 }
121}
122
123} // namespace content