chrome_renderer_pepper_host_factory.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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_extensions_common_host.h" 9#include "chrome/renderer/pepper/pepper_flash_drm_renderer_host.h" 10#include "chrome/renderer/pepper/pepper_flash_font_file_host.h" 11#include "chrome/renderer/pepper/pepper_flash_fullscreen_host.h" 12#include "chrome/renderer/pepper/pepper_flash_menu_host.h" 13#include "chrome/renderer/pepper/pepper_flash_renderer_host.h" 14#include "chrome/renderer/pepper/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_messages.h" 19#include "ppapi/proxy/ppapi_message_utils.h" 20#include "ppapi/shared_impl/ppapi_permissions.h" 21 22using ppapi::host::ResourceHost; 23 24ChromeRendererPepperHostFactory::ChromeRendererPepperHostFactory( 25 content::RendererPpapiHost* host) 26 : host_(host) { 27} 28 29ChromeRendererPepperHostFactory::~ChromeRendererPepperHostFactory() { 30} 31 32scoped_ptr<ResourceHost> 33ChromeRendererPepperHostFactory::CreateResourceHost( 34 ppapi::host::PpapiHost* host, 35 const ppapi::proxy::ResourceMessageCallParams& params, 36 PP_Instance instance, 37 const IPC::Message& message) { 38 DCHECK(host == host_->GetPpapiHost()); 39 40 // Make sure the plugin is giving us a valid instance for this resource. 41 if (!host_->IsValidInstance(instance)) 42 return scoped_ptr<ResourceHost>(); 43 44 // Dev interfaces. 45 if (host_->GetPpapiHost()->permissions().HasPermission( 46 ppapi::PERMISSION_DEV)) { 47 switch (message.type()) { 48 case PpapiHostMsg_ExtensionsCommon_Create::ID: { 49 return scoped_ptr<ResourceHost>(PepperExtensionsCommonHost::Create( 50 host_, instance, params.pp_resource())); 51 } 52 } 53 } 54 55 if (host_->GetPpapiHost()->permissions().HasPermission( 56 ppapi::PERMISSION_FLASH)) { 57 switch (message.type()) { 58 case PpapiHostMsg_Flash_Create::ID: { 59 return scoped_ptr<ResourceHost>(new PepperFlashRendererHost( 60 host_, instance, params.pp_resource())); 61 } 62 case PpapiHostMsg_FlashFullscreen_Create::ID: { 63 return scoped_ptr<ResourceHost>(new PepperFlashFullscreenHost( 64 host_, instance, params.pp_resource())); 65 } 66 case PpapiHostMsg_FlashMenu_Create::ID: { 67 ppapi::proxy::SerializedFlashMenu serialized_menu; 68 if (ppapi::UnpackMessage<PpapiHostMsg_FlashMenu_Create>( 69 message, &serialized_menu)) { 70 return scoped_ptr<ResourceHost>(new PepperFlashMenuHost( 71 host_, instance, params.pp_resource(), serialized_menu)); 72 } 73 break; 74 } 75 } 76 } 77 78 // TODO(raymes): PDF also needs access to the FlashFontFileHost currently. 79 // We should either rename PPB_FlashFont_File to PPB_FontFile_Private or get 80 // rid of its use in PDF if possible. 81 if (host_->GetPpapiHost()->permissions().HasPermission( 82 ppapi::PERMISSION_FLASH) || 83 host_->GetPpapiHost()->permissions().HasPermission( 84 ppapi::PERMISSION_PRIVATE)) { 85 switch (message.type()) { 86 case PpapiHostMsg_FlashFontFile_Create::ID: { 87 ppapi::proxy::SerializedFontDescription description; 88 PP_PrivateFontCharset charset; 89 if (ppapi::UnpackMessage<PpapiHostMsg_FlashFontFile_Create>( 90 message, &description, &charset)) { 91 return scoped_ptr<ResourceHost>(new PepperFlashFontFileHost( 92 host_, instance, params.pp_resource(), description, charset)); 93 } 94 break; 95 } 96 case PpapiHostMsg_FlashDRM_Create::ID: 97 return scoped_ptr<ResourceHost>(new PepperFlashDRMRendererHost( 98 host_, instance, params.pp_resource())); 99 } 100 } 101 102 if (host_->GetPpapiHost()->permissions().HasPermission( 103 ppapi::PERMISSION_PRIVATE)) { 104 switch (message.type()) { 105 case PpapiHostMsg_PDF_Create::ID: { 106 return scoped_ptr<ResourceHost>(new PepperPDFHost( 107 host_, instance, params.pp_resource())); 108 } 109 } 110 } 111 112 return scoped_ptr<ResourceHost>(); 113} 114