Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / renderer / pepper / host_dispatcher_wrapper.cc
blobb14a8a01043184c3ee9fa46596f139077c398e03
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.
5 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
7 #include "content/common/view_messages.h"
8 #include "content/public/common/origin_util.h"
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"
15 #include "content/renderer/render_frame_impl.h"
16 #include "third_party/WebKit/public/web/WebDocument.h"
17 #include "third_party/WebKit/public/web/WebElement.h"
18 #include "third_party/WebKit/public/web/WebPluginContainer.h"
20 namespace content {
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),
32 is_external_(is_external) {}
34 HostDispatcherWrapper::~HostDispatcherWrapper() {}
36 bool HostDispatcherWrapper::Init(const IPC::ChannelHandle& channel_handle,
37 PP_GetInterface_Func local_get_interface,
38 const ppapi::Preferences& preferences,
39 scoped_refptr<PepperHungPluginFilter> filter) {
40 if (channel_handle.name.empty())
41 return false;
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
49 dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
50 dispatcher_.reset(new ppapi::proxy::HostDispatcher(
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;
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;
68 // HungPluginFilter needs to listen for some messages on the IO thread.
69 dispatcher_->AddIOThreadMessageFilter(filter);
71 dispatcher_->channel()->SetRestrictDispatchChannelGroup(
72 kRendererRestrictDispatchGroup_Pepper);
73 return true;
76 const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) {
77 return dispatcher_->GetProxiedInterface(name);
80 void HostDispatcherWrapper::AddInstance(PP_Instance instance) {
81 ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
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) {
90 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
91 PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance);
92 blink::WebString unused;
93 bool is_privileged_context =
94 plugin_instance->GetContainer()
95 ->element()
96 .document()
97 .isPrivilegedContext(unused) &&
98 content::IsOriginSecure(plugin_instance->GetPluginURL());
99 render_frame->Send(new ViewHostMsg_DidCreateOutOfProcessPepperInstance(
100 plugin_child_id_, instance,
101 PepperRendererInstanceData(
102 0, // The render process id will be supplied in the browser.
103 render_frame->GetRoutingID(), host->GetDocumentURL(instance),
104 plugin_instance->GetPluginURL(), is_privileged_context),
105 is_external_));
109 void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) {
110 ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
112 RendererPpapiHostImpl* host =
113 RendererPpapiHostImpl::GetForPPInstance(instance);
114 // TODO(brettw) remove null check as described in AddInstance.
115 if (host) {
116 RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
117 if (render_frame) {
118 render_frame->Send(new ViewHostMsg_DidDeleteOutOfProcessPepperInstance(
119 plugin_child_id_, instance, is_external_));
124 } // namespace content