blob: 4c48a5ba97d7ad57816037d1ff048e5d21d5eb0e [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"
Dave Tapuskab9fc3ef62021-01-15 17:25:109#include "content/renderer/pepper/pepper_browser_connection.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"
Frédéric Wang073e74a2020-12-16 17:43:3217#include "services/network/public/cpp/is_potentially_trustworthy.h"
Blink Reformata30d4232018-04-07 15:31:0618#include "third_party/blink/public/web/web_document.h"
19#include "third_party/blink/public/web/web_plugin_container.h"
[email protected]35099ad2013-07-26 22:06:3920
21namespace content {
22
23HostDispatcherWrapper::HostDispatcherWrapper(
24 PluginModule* module,
25 base::ProcessId peer_pid,
26 int plugin_child_id,
27 const ppapi::PpapiPermissions& perms,
28 bool is_external)
29 : module_(module),
30 peer_pid_(peer_pid),
31 plugin_child_id_(plugin_child_id),
32 permissions_(perms),
[email protected]ad63b5c2014-04-11 21:12:3633 is_external_(is_external) {}
[email protected]35099ad2013-07-26 22:06:3934
[email protected]ad63b5c2014-04-11 21:12:3635HostDispatcherWrapper::~HostDispatcherWrapper() {}
[email protected]35099ad2013-07-26 22:06:3936
Hajime Hoshi5959c54f2019-01-09 01:42:1237bool HostDispatcherWrapper::Init(
38 const IPC::ChannelHandle& channel_handle,
39 PP_GetInterface_Func local_get_interface,
40 const ppapi::Preferences& preferences,
41 scoped_refptr<PepperHungPluginFilter> filter,
42 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
sammc414873fd2016-10-18 06:00:4743 if (!channel_handle.is_mojo_channel_handle())
[email protected]35099ad2013-07-26 22:06:3944 return false;
45
[email protected]35099ad2013-07-26 22:06:3946 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
47 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
dmichael6b328f3d2014-09-29 23:49:0248 module_->pp_module(), local_get_interface, permissions_));
49 // The HungPluginFilter needs to know when we are blocked on a sync message
50 // to the plugin. Note the filter outlives the dispatcher, so there is no
51 // need to remove it as an observer.
52 dispatcher_->AddSyncMessageStatusObserver(filter.get());
53 // Guarantee the hung_plugin_filter_ outlives |dispatcher_|.
54 hung_plugin_filter_ = filter;
[email protected]35099ad2013-07-26 22:06:3955
Hajime Hoshi5959c54f2019-01-09 01:42:1256 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), peer_pid_,
[email protected]35099ad2013-07-26 22:06:3957 channel_handle,
58 true, // Client.
Hajime Hoshi5959c54f2019-01-09 01:42:1259 preferences, task_runner)) {
[email protected]35099ad2013-07-26 22:06:3960 dispatcher_.reset();
61 dispatcher_delegate_.reset();
62 return false;
63 }
dmichael6b328f3d2014-09-29 23:49:0264 // HungPluginFilter needs to listen for some messages on the IO thread.
65 dispatcher_->AddIOThreadMessageFilter(filter);
66
[email protected]35099ad2013-07-26 22:06:3967 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
68 kRendererRestrictDispatchGroup_Pepper);
69 return true;
70}
71
72const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) {
73 return dispatcher_->GetProxiedInterface(name);
74}
75
76void HostDispatcherWrapper::AddInstance(PP_Instance instance) {
77 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
78
79 RendererPpapiHostImpl* host =
80 RendererPpapiHostImpl::GetForPPInstance(instance);
81 // TODO(brettw) remove this null check when the old-style pepper-based
82 // browser tag is removed from this file. Getting this notification should
83 // always give us an instance we can find in the map otherwise, but that
84 // isn't true for browser tag support.
85 if (host) {
[email protected]6dd625e2013-12-20 17:03:0786 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
[email protected]35099ad2013-07-26 22:06:3987 PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance);
raymes568fbca2015-05-14 19:24:2188 bool is_privileged_context =
Blink Reformat1c4d759e2017-04-09 16:34:5489 plugin_instance->GetContainer()->GetDocument().IsSecureContext() &&
Frédéric Wang073e74a2020-12-16 17:43:3290 network::IsUrlPotentiallyTrustworthy(plugin_instance->GetPluginURL());
Dave Tapuskab9fc3ef62021-01-15 17:25:1091 PepperBrowserConnection::Get(render_frame)
92 ->DidCreateOutOfProcessPepperInstance(
93 plugin_child_id_, instance, is_external_,
raymes568fbca2015-05-14 19:24:2194 render_frame->GetRoutingID(), host->GetDocumentURL(instance),
Dave Tapuskab9fc3ef62021-01-15 17:25:1095 plugin_instance->GetPluginURL(), is_privileged_context);
[email protected]35099ad2013-07-26 22:06:3996 }
97}
98
99void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) {
100 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
101
102 RendererPpapiHostImpl* host =
103 RendererPpapiHostImpl::GetForPPInstance(instance);
104 // TODO(brettw) remove null check as described in AddInstance.
105 if (host) {
[email protected]6dd625e2013-12-20 17:03:07106 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
[email protected]e3c8c992014-02-12 16:18:00107 if (render_frame) {
Dave Tapuskab9fc3ef62021-01-15 17:25:10108 PepperBrowserConnection::Get(render_frame)
109 ->DidDeleteOutOfProcessPepperInstance(plugin_child_id_, instance,
110 is_external_);
[email protected]e3c8c992014-02-12 16:18:00111 }
[email protected]35099ad2013-07-26 22:06:39112 }
113}
114
115} // namespace content