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