Home | History | Annotate | Download | only in pepper
      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 
      7 #include "content/common/view_messages.h"
      8 #include "content/renderer/pepper/pepper_hung_plugin_filter.h"
      9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
     10 #include "content/renderer/pepper/pepper_proxy_channel_delegate_impl.h"
     11 #include "content/renderer/pepper/plugin_module.h"
     12 #include "content/renderer/pepper/renderer_ppapi_host_impl.h"
     13 #include "content/renderer/pepper/renderer_restrict_dispatch_group.h"
     14 #include "content/renderer/render_frame_impl.h"
     15 
     16 namespace content {
     17 
     18 HostDispatcherWrapper::HostDispatcherWrapper(
     19     PluginModule* module,
     20     base::ProcessId peer_pid,
     21     int plugin_child_id,
     22     const ppapi::PpapiPermissions& perms,
     23     bool is_external)
     24     : module_(module),
     25       peer_pid_(peer_pid),
     26       plugin_child_id_(plugin_child_id),
     27       permissions_(perms),
     28       is_external_(is_external) {}
     29 
     30 HostDispatcherWrapper::~HostDispatcherWrapper() {}
     31 
     32 bool HostDispatcherWrapper::Init(const IPC::ChannelHandle& channel_handle,
     33                                  PP_GetInterface_Func local_get_interface,
     34                                  const ppapi::Preferences& preferences,
     35                                  PepperHungPluginFilter* filter) {
     36   if (channel_handle.name.empty())
     37     return false;
     38 
     39 #if defined(OS_POSIX)
     40   DCHECK_NE(-1, channel_handle.socket.fd);
     41   if (channel_handle.socket.fd == -1)
     42     return false;
     43 #endif
     44 
     45   dispatcher_delegate_.reset(new PepperProxyChannelDelegateImpl);
     46   dispatcher_.reset(new ppapi::proxy::HostDispatcher(
     47       module_->pp_module(), local_get_interface, filter, permissions_));
     48 
     49   if (!dispatcher_->InitHostWithChannel(dispatcher_delegate_.get(),
     50                                         peer_pid_,
     51                                         channel_handle,
     52                                         true,  // Client.
     53                                         preferences)) {
     54     dispatcher_.reset();
     55     dispatcher_delegate_.reset();
     56     return false;
     57   }
     58   dispatcher_->channel()->SetRestrictDispatchChannelGroup(
     59       kRendererRestrictDispatchGroup_Pepper);
     60   return true;
     61 }
     62 
     63 const void* HostDispatcherWrapper::GetProxiedInterface(const char* name) {
     64   return dispatcher_->GetProxiedInterface(name);
     65 }
     66 
     67 void HostDispatcherWrapper::AddInstance(PP_Instance instance) {
     68   ppapi::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
     69 
     70   RendererPpapiHostImpl* host =
     71       RendererPpapiHostImpl::GetForPPInstance(instance);
     72   // TODO(brettw) remove this null check when the old-style pepper-based
     73   // browser tag is removed from this file. Getting this notification should
     74   // always give us an instance we can find in the map otherwise, but that
     75   // isn't true for browser tag support.
     76   if (host) {
     77     RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
     78     PepperPluginInstance* plugin_instance = host->GetPluginInstance(instance);
     79     render_frame->Send(new ViewHostMsg_DidCreateOutOfProcessPepperInstance(
     80         plugin_child_id_,
     81         instance,
     82         PepperRendererInstanceData(
     83             0,  // The render process id will be supplied in the browser.
     84             render_frame->GetRoutingID(),
     85             host->GetDocumentURL(instance),
     86             plugin_instance->GetPluginURL()),
     87         is_external_));
     88   }
     89 }
     90 
     91 void HostDispatcherWrapper::RemoveInstance(PP_Instance instance) {
     92   ppapi::proxy::HostDispatcher::RemoveForInstance(instance);
     93 
     94   RendererPpapiHostImpl* host =
     95       RendererPpapiHostImpl::GetForPPInstance(instance);
     96   // TODO(brettw) remove null check as described in AddInstance.
     97   if (host) {
     98     RenderFrame* render_frame = host->GetRenderFrameForInstance(instance);
     99     if (render_frame) {
    100       render_frame->Send(new ViewHostMsg_DidDeleteOutOfProcessPepperInstance(
    101           plugin_child_id_, instance, is_external_));
    102     }
    103   }
    104 }
    105 
    106 }  // namespace content
    107