blob: 4b0d3265d9a4fe06f99cb807af2295af0168c508 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]35099ad2013-07-26 22:06:392// 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
Peter Boströmdd7e40ec2021-04-05 20:40:107#include <memory>
8
Sean Mahere672a662023-01-09 21:42:289#include "base/task/single_thread_task_runner.h"
avi1023d012015-12-25 02:39:1410#include "build/build_config.h"
David Sandersbccb1d0b2022-02-25 18:02:4611#include "content/public/renderer/render_frame.h"
Dave Tapuskab9fc3ef62021-01-15 17:25:1012#include "content/renderer/pepper/pepper_browser_connection.h"
[email protected]35099ad2013-07-26 22:06:3913#include "content/renderer/pepper/pepper_hung_plugin_filter.h"
14#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
15#include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
16#include "content/renderer/pepper/plugin_module.h"
17#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
18#include "content/renderer/pepper/renderer_restrict_dispatch_group.h"
Frédéric Wang073e74a2020-12-16 17:43:3219#include "services/network/public/cpp/is_potentially_trustworthy.h"
Blink Reformata30d4232018-04-07 15:31:0620#include "third_party/blink/public/web/web_document.h"
21#include "third_party/blink/public/web/web_plugin_container.h"
[email protected]35099ad2013-07-26 22:06:3922
23namespace content {
24
25HostDispatcherWrapper::HostDispatcherWrapper(
26 PluginModule* module,
27 base::ProcessId peer_pid,
28 int plugin_child_id,
29 const ppapi::PpapiPermissions& perms,
30 bool is_external)
31 : module_(module),
32 peer_pid_(peer_pid),
33 plugin_child_id_(plugin_child_id),
34 permissions_(perms),
[email protected]ad63b5c2014-04-11 21:12:3635 is_external_(is_external) {}
[email protected]35099ad2013-07-26 22:06:3936
Dave Tapuska76343fc2021-03-01 18:50:2837HostDispatcherWrapper::~HostDispatcherWrapper() {
38 hung_plugin_filter_->HostDispatcherDestroyed();
39}
[email protected]35099ad2013-07-26 22:06:3940
Hajime Hoshi5959c54f2019-01-09 01:42:1241bool HostDispatcherWrapper::Init(
42 const IPC::ChannelHandle& channel_handle,
43 PP_GetInterface_Func local_get_interface,
44 const ppapi::Preferences& preferences,
45 scoped_refptr<PepperHungPluginFilter> filter,
46 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
sammc414873fd2016-10-18 06:00:4747 if (!channel_handle.is_mojo_channel_handle())
[email protected]35099ad2013-07-26 22:06:3948 return false;
49
Peter Boströmdd7e40ec2021-04-05 20:40:1050 dispatcher_delegate_ = std::make_unique<PepperProxyChannelDelegateImpl>();
51 dispatcher_ = std::make_unique<ppapi::proxy::HostDispatcher>(
52 module_->pp_module(), local_get_interface, permissions_);
dmichael6b328f3d2014-09-29 23:49:0253 // The HungPluginFilter needs to know when we are blocked on a sync message
54 // to the plugin. Note the filter outlives the dispatcher, so there is no
55 // need to remove it as an observer.
56 dispatcher_->AddSyncMessageStatusObserver(filter.get());
57 // Guarantee the hung_plugin_filter_ outlives |dispatcher_|.
58 hung_plugin_filter_ = filter;
[email protected]35099ad2013-07-26 22:06:3959
Hajime Hoshi5959c54f2019-01-09 01:42:1260 if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), peer_pid_,
[email protected]35099ad2013-07-26 22:06:3961 channel_handle,
62 true, // Client.
Hajime Hoshi5959c54f2019-01-09 01:42:1263 preferences, task_runner)) {
[email protected]35099ad2013-07-26 22:06:3964 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 bool is_privileged_context =
Blink Reformat1c4d759e2017-04-09 16:34:5493 plugin_instance->GetContainer()->GetDocument().IsSecureContext() &&
Frédéric Wang073e74a2020-12-16 17:43:32