[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
| 6 | |
Peter Boström | dd7e40ec | 2021-04-05 20:40:10 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 9 | #include "build/build_config.h" |
David Sanders | bccb1d0b | 2022-02-25 18:02:46 | [diff] [blame^] | 10 | #include "content/public/renderer/render_frame.h" |
Dave Tapuska | b9fc3ef6 | 2021-01-15 17:25:10 | [diff] [blame] | 11 | #include "content/renderer/pepper/pepper_browser_connection.h" |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 12 | #include "content/renderer/pepper/pepper_hung_plugin_filter.h" |
| 13 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 14 | #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" |
| 15 | #include "content/renderer/pepper/plugin_module.h" |
| 16 | #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 17 | #include "content/renderer/pepper/renderer_restrict_dispatch_group.h" |
Frédéric Wang | 073e74a | 2020-12-16 17:43:32 | [diff] [blame] | 18 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 19 | #include "third_party/blink/public/web/web_document.h" |
| 20 | #include "third_party/blink/public/web/web_plugin_container.h" |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 21 | |
| 22 | namespace content { |
| 23 | |
| 24 | HostDispatcherWrapper::HostDispatcherWrapper( |
| 25 | PluginModule* module, |
| 26 | base::ProcessId peer_pid, |
| 27 | int plugin_child_id, |
| 28 | const ppapi::PpapiPermissions& perms, |
| 29 | bool is_external) |
| 30 | : module_(module), |
| 31 | peer_pid_(peer_pid), |
| 32 | plugin_child_id_(plugin_child_id), |
| 33 | permissions_(perms), |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 34 | is_external_(is_external) {} |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 35 | |
Dave Tapuska | 76343fc | 2021-03-01 18:50:28 | [diff] [blame] | 36 | HostDispatcherWrapper::~HostDispatcherWrapper() { |
| 37 | hung_plugin_filter_->HostDispatcherDestroyed(); |
| 38 | } |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 39 | |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame] | 40 | bool HostDispatcherWrapper::Init( |
| 41 | const IPC::ChannelHandle& channel_handle, |
| 42 | PP_GetInterface_Func local_get_interface, |
| 43 | const ppapi::Preferences& preferences, |
| 44 | scoped_refptr<PepperHungPluginFilter> filter, |
| 45 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
sammc | 414873fd | 2016-10-18 06:00:47 | [diff] [blame] | 46 | if (!channel_handle.is_mojo_channel_handle()) |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 47 | return false; |
| 48 | |
Peter Boström | dd7e40ec | 2021-04-05 20:40:10 | [diff] [blame] | 49 | dispatcher_delegate_ = std::make_unique<PepperProxyChannelDelegateImpl>(); |
| 50 | dispatcher_ = std::make_unique<ppapi::proxy::HostDispatcher>( |
| 51 | module_->pp_module(), local_get_interface, permissions_); |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 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] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 58 | |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame] | 59 | if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), peer_pid_, |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 60 | channel_handle, |
| 61 | true, // Client. |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame] | 62 | preferences, task_runner)) { |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 63 | dispatcher_.reset(); |
| 64 | dispatcher_delegate_.reset(); |
| 65 | return false; |
| 66 | } |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 67 | // HungPluginFilter needs to listen for some messages on the IO thread. |
| 68 | dispatcher_->AddIOThreadMessageFilter(filter); |
| 69 | |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 70 | dispatcher_->channel()->SetRestrictDispatchChannelGroup( |
| 71 | kRendererRestrictDispatchGroup_Pepper); |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) { |
| 76 | return dispatcher_->GetProxiedInterface(name); |
| 77 | } |
| 78 | |
| 79 | void HostDispatcherWrapper::AddInstance(PP_Instance instance) { |
| 80 | ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); |
| 81 | |
| 82 | RendererPpapiHostImpl* host = |
| 83 | RendererPpapiHostImpl::GetForPPInstance(instance); |
| 84 | // TODO(brettw) remove this null check when the old-style pepper-based |
| 85 | // browser tag is removed from this file. Getting this notification should |
| 86 | // always give us an instance we can find in the map otherwise, but that |
| 87 | // isn't true for browser tag support. |
| 88 | if (host) { |
[email protected] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 89 | RenderFrame* render_frame = host->GetRenderFrameForInstance(instance); |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 90 | PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance); |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 91 | bool is_privileged_context = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 92 | plugin_instance->GetContainer()->GetDocument().IsSecureContext() && |
Frédéric Wang | 073e74a | 2020-12-16 17:43:32 | [diff] [blame] | 93 | network::IsUrlPotentiallyTrustworthy(plugin_instance->GetPluginURL()); |
Dave Tapuska | b9fc3ef6 | 2021-01-15 17:25:10 | [diff] [blame] | 94 | PepperBrowserConnection::Get(render_frame) |
| 95 | ->DidCreateOutOfProcessPepperInstance( |
| 96 | plugin_child_id_, instance, is_external_, |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 97 | render_frame->GetRoutingID(), host->GetDocumentURL(instance), |
Dave Tapuska | b9fc3ef6 | 2021-01-15 17:25:10 | [diff] [blame] | 98 | plugin_instance->GetPluginURL(), is_privileged_context); |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
| 102 | void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) { |
| 103 | ppapi::proxy::HostDispatcher::RemoveForInstance(instance); |
| 104 | |
| 105 | RendererPpapiHostImpl* host = |
| 106 | RendererPpapiHostImpl::GetForPPInstance(instance); |
| 107 | // TODO(brettw) remove null check as described in AddInstance. |
| 108 | if (host) { |
[email protected] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 109 | RenderFrame* render_frame = host->GetRenderFrameForInstance(instance); |
[email protected] | e3c8c99 | 2014-02-12 16:18:00 | [diff] [blame] | 110 | if (render_frame) { |
Dave Tapuska | b9fc3ef6 | 2021-01-15 17:25:10 | [diff] [blame] | 111 | PepperBrowserConnection::Get(render_frame) |
| 112 | ->DidDeleteOutOfProcessPepperInstance(plugin_child_id_, instance, |
| 113 | is_external_); |
[email protected] | e3c8c99 | 2014-02-12 16:18:00 | [diff] [blame] | 114 | } |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
| 118 | } // namespace content |