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/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
7 #include "build/build_config.h"
8 #include "chrome/browser/renderer_host/pepper/pepper_broker_message_filter.h"
9 #include "chrome/browser/renderer_host/pepper/pepper_extensions_common_message_filter.h"
10 #include "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h"
11 #include "chrome/browser/renderer_host/pepper/pepper_flash_clipboard_message_filter.h"
12 #include "chrome/browser/renderer_host/pepper/pepper_flash_drm_host.h"
13 #include "chrome/browser/renderer_host/pepper/pepper_isolated_file_system_message_filter.h"
14 #include "chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.h"
15 #include "chrome/browser/renderer_host/pepper/pepper_platform_verification_message_filter.h"
16 #include "chrome/browser/renderer_host/pepper/pepper_talk_host.h"
17 #include "content/public/browser/browser_ppapi_host.h"
18 #include "ppapi/host/message_filter_host.h"
19 #include "ppapi/host/ppapi_host.h"
20 #include "ppapi/host/resource_host.h"
21 #include "ppapi/proxy/ppapi_messages.h"
22 #include "ppapi/shared_impl/ppapi_permissions.h"
24 using ppapi::host::MessageFilterHost
;
25 using ppapi::host::ResourceHost
;
26 using ppapi::host::ResourceMessageFilter
;
30 ChromeBrowserPepperHostFactory::ChromeBrowserPepperHostFactory(
31 content::BrowserPpapiHost
* host
)
35 ChromeBrowserPepperHostFactory::~ChromeBrowserPepperHostFactory() {
38 scoped_ptr
<ResourceHost
> ChromeBrowserPepperHostFactory::CreateResourceHost(
39 ppapi::host::PpapiHost
* host
,
40 const ppapi::proxy::ResourceMessageCallParams
& params
,
42 const IPC::Message
& message
) {
43 DCHECK(host
== host_
->GetPpapiHost());
45 // Make sure the plugin is giving us a valid instance for this resource.
46 if (!host_
->IsValidInstance(instance
))
47 return scoped_ptr
<ResourceHost
>();
50 if (host_
->GetPpapiHost()->permissions().HasPermission(
51 ppapi::PERMISSION_DEV
)) {
52 switch (message
.type()) {
53 case PpapiHostMsg_ExtensionsCommon_Create::ID
: {
54 scoped_refptr
<ResourceMessageFilter
> extensions_common_filter(
55 PepperExtensionsCommonMessageFilter::Create(host_
, instance
));
56 if (!extensions_common_filter
.get())
57 return scoped_ptr
<ResourceHost
>();
58 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
59 host_
->GetPpapiHost(), instance
, params
.pp_resource(),
60 extensions_common_filter
));
65 // Private interfaces.
66 if (host_
->GetPpapiHost()->permissions().HasPermission(
67 ppapi::PERMISSION_PRIVATE
)) {
68 switch (message
.type()) {
69 case PpapiHostMsg_Broker_Create::ID
: {
70 scoped_refptr
<ResourceMessageFilter
> broker_filter(
71 new PepperBrokerMessageFilter(instance
, host_
));
72 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
73 host_
->GetPpapiHost(), instance
, params
.pp_resource(),
76 #if defined(OS_CHROMEOS)
77 case PpapiHostMsg_PlatformVerification_Create::ID
: {
78 scoped_refptr
<ResourceMessageFilter
> pv_filter(
79 new PepperPlatformVerificationMessageFilter(host_
, instance
));
80 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
81 host_
->GetPpapiHost(), instance
, params
.pp_resource(), pv_filter
));
84 case PpapiHostMsg_Talk_Create::ID
:
85 return scoped_ptr
<ResourceHost
>(new PepperTalkHost(
86 host_
, instance
, params
.pp_resource()));
87 #if defined(OS_CHROMEOS)
88 case PpapiHostMsg_OutputProtection_Create::ID
: {
89 scoped_refptr
<ResourceMessageFilter
> output_protection_filter(
90 new PepperOutputProtectionMessageFilter(host_
, instance
));
91 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
92 host_
->GetPpapiHost(), instance
, params
.pp_resource(),
93 output_protection_filter
));
100 if (host_
->GetPpapiHost()->permissions().HasPermission(
101 ppapi::PERMISSION_FLASH
)) {
102 switch (message
.type()) {
103 case PpapiHostMsg_Flash_Create::ID
:
104 return scoped_ptr
<ResourceHost
>(new PepperFlashBrowserHost(
105 host_
, instance
, params
.pp_resource()));
106 case PpapiHostMsg_FlashClipboard_Create::ID
: {
107 scoped_refptr
<ResourceMessageFilter
> clipboard_filter(
108 new PepperFlashClipboardMessageFilter
);
109 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
110 host_
->GetPpapiHost(), instance
, params
.pp_resource(),
116 // PepperFlashDRMHost is also used by the PPB_Flash_DeviceID interface
117 // which has private permission.
118 // TODO(xhwang): Once PPB_Flash_DeviceID is removed, remove the check
119 // for private permissions.
120 if (host_
->GetPpapiHost()->permissions().HasPermission(
121 ppapi::PERMISSION_FLASH
) ||
122 host_
->GetPpapiHost()->permissions().HasPermission(
123 ppapi::PERMISSION_PRIVATE
)) {
124 switch (message
.type()) {
125 case PpapiHostMsg_FlashDRM_Create::ID
:
126 return scoped_ptr
<ResourceHost
>(new PepperFlashDRMHost(
127 host_
, instance
, params
.pp_resource()));
131 // Permissions for the following interfaces will be checked at the
132 // time of the corresponding instance's methods calls (because
133 // permission check can be performed only on the UI
134 // thread). Currently these interfaces are available only for
135 // whitelisted apps which may not have access to the other private
137 if (message
.type() == PpapiHostMsg_IsolatedFileSystem_Create::ID
) {
138 PepperIsolatedFileSystemMessageFilter
* isolated_fs_filter
=
139 PepperIsolatedFileSystemMessageFilter::Create(instance
, host_
);
140 if (!isolated_fs_filter
)
141 return scoped_ptr
<ResourceHost
>();
142 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
143 host
, instance
, params
.pp_resource(), isolated_fs_filter
));
146 return scoped_ptr
<ResourceHost
>();
149 } // namespace chrome