[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" |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 9 | #include "content/public/common/origin_util.h" |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 10 | #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] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 16 | #include "content/renderer/render_frame_impl.h" |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 17 | #include "third_party/WebKit/public/web/WebDocument.h" |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 18 | #include "third_party/WebKit/public/web/WebPluginContainer.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 | |
| 36 | bool HostDispatcherWrapper::Init(const IPC::ChannelHandle& channel_handle, |
| 37 | PP_GetInterface_Func local_get_interface, |
| 38 | const ppapi::Preferences& preferences, |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 39 | scoped_refptr<PepperHungPluginFilter> filter) { |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 40 | 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( |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 51 | 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] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 58 | |
| 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 | } |
dmichael | 6b328f3d | 2014-09-29 23:49:02 | [diff] [blame] | 68 | // HungPluginFilter needs to listen for some messages on the IO thread. |
| 69 | dispatcher_->AddIOThreadMessageFilter(filter); |
| 70 | |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 71 | dispatcher_->channel()->SetRestrictDispatchChannelGroup( |
| 72 | kRendererRestrictDispatchGroup_Pepper); |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) { |
| 77 | return dispatcher_->GetProxiedInterface(name); |
| 78 | } |
| 79 | |
| 80 | void 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] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 90 | RenderFrame* render_frame = host->GetRenderFrameForInstance(instance); |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 91 | PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance); |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 92 | blink::WebString unused; |
| 93 | bool is_privileged_context = |
| 94 | plugin_instance->GetContainer() |
esprehn | d88a903 | 2016-05-05 15:46:42 | [diff] [blame] | 95 | ->document() |
mkwst | fd67eed | 2015-09-29 12:05:37 | [diff] [blame] | 96 | .isSecureContext(unused) && |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 97 | content::IsOriginSecure(plugin_instance->GetPluginURL()); |
avi | 270d422 | 2015-09-04 22:37:19 | [diff] [blame] | 98 | render_frame->Send(new FrameHostMsg_DidCreateOutOfProcessPepperInstance( |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 99 | plugin_child_id_, instance, |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 100 | PepperRendererInstanceData( |
| 101 | 0, // The render process id will be supplied in the browser. |
raymes | 568fbca | 2015-05-14 19:24:21 | [diff] [blame] | 102 | render_frame->GetRoutingID(), host->GetDocumentURL(instance), |
| 103 | plugin_instance->GetPluginURL(), is_privileged_context), |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 104 | is_external_)); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void 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] | 6dd625e | 2013-12-20 17:03:07 | [diff] [blame] | 115 | RenderFrame* render_frame = host->GetRenderFrameForInstance(instance); |
[email protected] | e3c8c99 | 2014-02-12 16:18:00 | [diff] [blame] | 116 | if (render_frame) { |
avi | 270d422 | 2015-09-04 22:37:19 | [diff] [blame] | 117 | render_frame->Send(new FrameHostMsg_DidDeleteOutOfProcessPepperInstance( |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 118 | plugin_child_id_, instance, is_external_)); |
[email protected] | e3c8c99 | 2014-02-12 16:18:00 | [diff] [blame] | 119 | } |
[email protected] | 35099ad | 2013-07-26 22:06:39 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
| 123 | } // namespace content |