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 "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
      6 
      7 #include "base/logging.h"
      8 #include "chrome/renderer/pepper/pepper_flash_drm_renderer_host.h"
      9 #include "chrome/renderer/pepper/pepper_flash_font_file_host.h"
     10 #include "chrome/renderer/pepper/pepper_flash_fullscreen_host.h"
     11 #include "chrome/renderer/pepper/pepper_flash_menu_host.h"
     12 #include "chrome/renderer/pepper/pepper_flash_renderer_host.h"
     13 #include "chrome/renderer/pepper/pepper_uma_host.h"
     14 #include "components/pdf/renderer/pepper_pdf_host.h"
     15 #include "content/public/renderer/renderer_ppapi_host.h"
     16 #include "ppapi/host/ppapi_host.h"
     17 #include "ppapi/host/resource_host.h"
     18 #include "ppapi/proxy/ppapi_message_utils.h"
     19 #include "ppapi/proxy/ppapi_messages.h"
     20 #include "ppapi/shared_impl/ppapi_permissions.h"
     21 
     22 using ppapi::host::ResourceHost;
     23 
     24 ChromeRendererPepperHostFactory::ChromeRendererPepperHostFactory(
     25     content::RendererPpapiHost* host)
     26     : host_(host) {}
     27 
     28 ChromeRendererPepperHostFactory::~ChromeRendererPepperHostFactory() {}
     29 
     30 scoped_ptr<ResourceHost> ChromeRendererPepperHostFactory::CreateResourceHost(
     31     ppapi::host::PpapiHost* host,
     32     const ppapi::proxy::ResourceMessageCallParams& params,
     33     PP_Instance instance,
     34     const IPC::Message& message) {
     35   DCHECK_EQ(host_->GetPpapiHost(), host);
     36 
     37   // Make sure the plugin is giving us a valid instance for this resource.
     38   if (!host_->IsValidInstance(instance))
     39     return scoped_ptr<ResourceHost>();
     40 
     41   if (host_->GetPpapiHost()->permissions().HasPermission(
     42           ppapi::PERMISSION_FLASH)) {
     43     switch (message.type()) {
     44       case PpapiHostMsg_Flash_Create::ID: {
     45         return scoped_ptr<ResourceHost>(
     46             new PepperFlashRendererHost(host_, instance, params.pp_resource()));
     47       }
     48       case PpapiHostMsg_FlashFullscreen_Create::ID: {
     49         return scoped_ptr<ResourceHost>(new PepperFlashFullscreenHost(
     50             host_, instance, params.pp_resource()));
     51       }
     52       case PpapiHostMsg_FlashMenu_Create::ID: {
     53         ppapi::proxy::SerializedFlashMenu serialized_menu;
     54         if (ppapi::UnpackMessage<PpapiHostMsg_FlashMenu_Create>(
     55                 message, &serialized_menu)) {
     56           return scoped_ptr<ResourceHost>(new PepperFlashMenuHost(
     57               host_, instance, params.pp_resource(), serialized_menu));
     58         }
     59         break;
     60       }
     61     }
     62   }
     63 
     64   // TODO(raymes): PDF also needs access to the FlashFontFileHost currently.
     65   // We should either rename PPB_FlashFont_File to PPB_FontFile_Private or get
     66   // rid of its use in PDF if possible.
     67   if (host_->GetPpapiHost()->permissions().HasPermission(
     68           ppapi::PERMISSION_FLASH) ||
     69       host_->GetPpapiHost()->permissions().HasPermission(
     70           ppapi::PERMISSION_PRIVATE)) {
     71     switch (message.type()) {
     72       case PpapiHostMsg_FlashFontFile_Create::ID: {
     73         ppapi::proxy::SerializedFontDescription description;
     74         PP_PrivateFontCharset charset;
     75         if (ppapi::UnpackMessage<PpapiHostMsg_FlashFontFile_Create>(
     76                 message, &description, &charset)) {
     77           return scoped_ptr<ResourceHost>(new PepperFlashFontFileHost(
     78               host_, instance, params.pp_resource(), description, charset));
     79         }
     80         break;
     81       }
     82       case PpapiHostMsg_FlashDRM_Create::ID:
     83         return scoped_ptr<ResourceHost>(new PepperFlashDRMRendererHost(
     84             host_, instance, params.pp_resource()));
     85     }
     86   }
     87 
     88   if (host_->GetPpapiHost()->permissions().HasPermission(
     89           ppapi::PERMISSION_PRIVATE)) {
     90     switch (message.type()) {
     91       case PpapiHostMsg_PDF_Create::ID: {
     92         return scoped_ptr<ResourceHost>(
     93             new pdf::PepperPDFHost(host_, instance, params.pp_resource()));
     94       }
     95     }
     96   }
     97 
     98   // Permissions for the following interfaces will be checked at the
     99   // time of the corresponding instance's method calls.  Currently these
    100   // interfaces are available only for whitelisted apps which may not have
    101   // access to the other private interfaces.
    102   switch (message.type()) {
    103     case PpapiHostMsg_UMA_Create::ID: {
    104       return scoped_ptr<ResourceHost>(
    105           new PepperUMAHost(host_, instance, params.pp_resource()));
    106     }
    107   }
    108 
    109   return scoped_ptr<ResourceHost>();
    110 }
    111