[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 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 7 | #include "build/build_config.h" |
avi | 270d422 | 2015-09-04 22:37:19 | [diff] [blame] | 8 | #include "content/common/frame_messages.h" |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 9 | #include "content/renderer/pepper/pepper_hung_plugin_filter.h" |
| 10 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 11 | #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h" |
| 12 | #include "content/renderer/pepper/plugin_module.h" |
| 13 | #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 14 | #include "content/renderer/pepper/renderer_restrict_dispatch_group.h" |
[email protected] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 15 | #include "content/renderer/render_frame_impl.h" |
Frédéric Wang | 073e74a | 2020-12-16 17:43:32 | [diff] [blame^] | 16 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 17 | #include "third_party/blink/public/web/web_document.h" |
| 18 | #include "third_party/blink/public/web/web_plugin_container.h" |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 19 | |
| 20 | namespace content { |
| 21 | |
| 22 | HostDispatcherWrapper::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] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 32 | is_external_(is_external) {} |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 33 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 34 | HostDispatcherWrapper::~HostDispatcherWrapper() {} |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 35 | |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame] | 36 | bool HostDispatcherWrapper::Init( |
| 37 | const IPC::ChannelHandle& channel_handle, |
| 38 | PP_GetInterface_Func local_get_interface, |
| 39 | const ppapi::Preferences& preferences, |
| 40 | scoped_refptr<PepperHungPluginFilter> filter, |
| 41 | scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
sammc | 414873fd | 2016-10-18 06:00:47 | [diff] [blame] | 42 | if (!channel_handle.is_mojo_channel_handle()) |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 43 | return false; |
| 44 | |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 45 | dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl); |
| 46 | dispatcher_.reset(new ppapi::proxy::HostDispatcher( |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 47 | module_->pp_module(), local_get_interface, permissions_)); |
| 48 | // The HungPluginFilter needs to know when we are blocked on a sync message |
| 49 | // to the plugin. Note the filter outlives the dispatcher, so there is no |
| 50 | // need to remove it as an observer. |
| 51 | dispatcher_->AddSyncMessageStatusObserver(filter.get()); |
| 52 | // Guarantee the hung_plugin_filter_ outlives |dispatcher_|. |
| 53 | hung_plugin_filter_ = filter; |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 54 | |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame] | 55 | if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(), peer_pid_, |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 56 | channel_handle, |
| 57 | true, // Client. |
Hajime Hoshi | 5959c54f | 2019-01-09 01:42:12 | [diff] [blame] | 58 | preferences, task_runner)) { |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 59 | dispatcher_.reset(); |
| 60 | dispatcher_delegate_.reset(); |
| 61 | return false; |
| 62 | } |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 63 | // HungPluginFilter needs to listen for some messages on the IO thread. |
| 64 | dispatcher_->AddIOThreadMessageFilter(filter); |
| 65 | |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 66 | dispatcher_->channel()->SetRestrictDispatchChannelGroup( |
| 67 | kRendererRestrictDispatchGroup_Pepper); |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) { |
| 72 | return dispatcher_->GetProxiedInterface(name); |
| 73 | } |
| 74 | |
| 75 | void HostDispatcherWrapper::AddInstance(PP_Instance instance) { |
| 76 | ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); |
| 77 | |
| 78 | RendererPpapiHostImpl* host = |
| 79 | RendererPpapiHostImpl::GetForPPInstance(instance); |
| 80 | // TODO(brettw) remove this null check when the old-style pepper-based |
| 81 | // browser tag is removed from this file. Getting this notification should |
| 82 | // always give us an instance we can find in the map otherwise, but that |
| 83 | // isn't true for browser tag support. |
| 84 | if (host) { |
[email protected] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 85 | RenderFrame* render_frame = host->GetRenderFrameForInstance(instance); |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 86 | PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance); |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 87 | bool is_privileged_context = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 88 | plugin_instance->GetContainer()->GetDocument().IsSecureContext() && |
Frédéric Wang | 073e74a | 2020-12-16 17:43:32 | [diff] [blame^] | 89 | network::IsUrlPotentiallyTrustworthy(plugin_instance->GetPluginURL()); |
avi | 270d422 | 2015-09-04 22:37:19 | [diff] [blame] | 90 | render_frame->Send(new FrameHostMsg_DidCreateOutOfProcessPepperInstance( |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 91 | plugin_child_id_, instance, |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 92 | PepperRendererInstanceData( |
| 93 | 0, // The render process id will be supplied in the browser. |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 94 | render_frame->GetRoutingID(), host->GetDocumentURL(instance), |
| 95 | plugin_instance->GetPluginURL(), is_privileged_context), |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 96 | is_external_)); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) { |
| 101 | ppapi::proxy::HostDispatcher::RemoveForInstance(instance); |
| 102 | |
| 103 | RendererPpapiHostImpl* host = |
| 104 | RendererPpapiHostImpl::GetForPPInstance(instance); |
| 105 | // TODO(brettw) remove null check as described in AddInstance. |
| 106 | if (host) { |
[email protected] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 107 | RenderFrame* render_frame = host->GetRenderFrameForInstance(instance); |
[email protected] | e3c8c99 | 2014-02-12 16:18:00 | [diff] [blame] | 108 | if (render_frame) { |
avi | 270d422 | 2015-09-04 22:37:19 | [diff] [blame] | 109 | render_frame->Send(new FrameHostMsg_DidDeleteOutOfProcessPepperInstance( |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 110 | plugin_child_id_, instance, is_external_)); |
[email protected] | e3c8c99 | 2014-02-12 16:18:00 | [diff] [blame] | 111 | } |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
| 115 | } // namespace content |