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 "chrome/renderer/pepper/chrome_renderer_pepper_host_factory.h"
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 "chrome/renderer/pepper/pepper_uma_host.h"
16 #include "content/public/renderer/renderer_ppapi_host.h"
17 #include "ppapi/host/ppapi_host.h"
18 #include "ppapi/host/resource_host.h"
19 #include "ppapi/proxy/ppapi_messages.h"
20 #include "ppapi/proxy/ppapi_message_utils.h"
21 #include "ppapi/shared_impl/ppapi_permissions.h"
23 using ppapi::host::ResourceHost
;
25 ChromeRendererPepperHostFactory::ChromeRendererPepperHostFactory(
26 content::RendererPpapiHost
* host
)
29 ChromeRendererPepperHostFactory::~ChromeRendererPepperHostFactory() {}
31 scoped_ptr
<ResourceHost
> ChromeRendererPepperHostFactory::CreateResourceHost(
32 ppapi::host::PpapiHost
* host
,
33 const ppapi::proxy::ResourceMessageCallParams
& params
,
35 const IPC::Message
& message
) {
36 DCHECK(host
== host_
->GetPpapiHost());
38 // Make sure the plugin is giving us a valid instance for this resource.
39 if (!host_
->IsValidInstance(instance
))
40 return scoped_ptr
<ResourceHost
>();
43 if (host_
->GetPpapiHost()->permissions().HasPermission(
44 ppapi::PERMISSION_DEV
)) {
45 switch (message
.type()) {
46 case PpapiHostMsg_ExtensionsCommon_Create::ID
: {
47 return scoped_ptr
<ResourceHost
>(PepperExtensionsCommonHost::Create(
48 host_
, instance
, params
.pp_resource()));
53 if (host_
->GetPpapiHost()->permissions().HasPermission(
54 ppapi::PERMISSION_FLASH
)) {
55 switch (message
.type()) {
56 case PpapiHostMsg_Flash_Create::ID
: {
57 return scoped_ptr
<ResourceHost
>(
58 new PepperFlashRendererHost(host_
, instance
, params
.pp_resource()));
60 case PpapiHostMsg_FlashFullscreen_Create::ID
: {
61 return scoped_ptr
<ResourceHost
>(new PepperFlashFullscreenHost(
62 host_
, instance
, params
.pp_resource()));
64 case PpapiHostMsg_FlashMenu_Create::ID
: {
65 ppapi::proxy::SerializedFlashMenu serialized_menu
;
66 if (ppapi::UnpackMessage
<PpapiHostMsg_FlashMenu_Create
>(
67 message
, &serialized_menu
)) {
68 return scoped_ptr
<ResourceHost
>(new PepperFlashMenuHost(
69 host_
, instance
, params
.pp_resource(), serialized_menu
));
76 // TODO(raymes): PDF also needs access to the FlashFontFileHost currently.
77 // We should either rename PPB_FlashFont_File to PPB_FontFile_Private or get
78 // rid of its use in PDF if possible.
79 if (host_
->GetPpapiHost()->permissions().HasPermission(
80 ppapi::PERMISSION_FLASH
) ||
81 host_
->GetPpapiHost()->permissions().HasPermission(
82 ppapi::PERMISSION_PRIVATE
)) {
83 switch (message
.type()) {
84 case PpapiHostMsg_FlashFontFile_Create::ID
: {
85 ppapi::proxy::SerializedFontDescription description
;
86 PP_PrivateFontCharset charset
;
87 if (ppapi::UnpackMessage
<PpapiHostMsg_FlashFontFile_Create
>(
88 message
, &description
, &charset
)) {
89 return scoped_ptr
<ResourceHost
>(new PepperFlashFontFileHost(
90 host_
, instance
, params
.pp_resource(), description
, charset
));
94 case PpapiHostMsg_FlashDRM_Create::ID
:
95 return scoped_ptr
<ResourceHost
>(new PepperFlashDRMRendererHost(
96 host_
, instance
, params
.pp_resource()));
100 if (host_
->GetPpapiHost()->permissions().HasPermission(
101 ppapi::PERMISSION_PRIVATE
)) {
102 switch (message
.type()) {
103 case PpapiHostMsg_PDF_Create::ID
: {
104 return scoped_ptr
<ResourceHost
>(
105 new PepperPDFHost(host_
, instance
, params
.pp_resource()));
110 // Permissions for the following interfaces will be checked at the
111 // time of the corresponding instance's method calls. Currently these
112 // interfaces are available only for whitelisted apps which may not have
113 // access to the other private interfaces.
114 switch (message
.type()) {
115 case PpapiHostMsg_UMA_Create::ID
: {
116 return scoped_ptr
<ResourceHost
>(
117 new PepperUMAHost(host_
, instance
, params
.pp_resource()));
121 return scoped_ptr
<ResourceHost
>();