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_flash_browser_host.h"
10 #include "chrome/browser/renderer_host/pepper/pepper_flash_clipboard_message_filter.h"
11 #include "chrome/browser/renderer_host/pepper/pepper_flash_drm_host.h"
12 #include "chrome/browser/renderer_host/pepper/pepper_isolated_file_system_message_filter.h"
13 #include "chrome/browser/renderer_host/pepper/pepper_output_protection_message_filter.h"
14 #include "chrome/browser/renderer_host/pepper/pepper_platform_verification_message_filter.h"
15 #include "content/public/browser/browser_ppapi_host.h"
16 #include "ppapi/host/message_filter_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/shared_impl/ppapi_permissions.h"
22 using ppapi::host::MessageFilterHost
;
23 using ppapi::host::ResourceHost
;
24 using ppapi::host::ResourceMessageFilter
;
26 ChromeBrowserPepperHostFactory::ChromeBrowserPepperHostFactory(
27 content::BrowserPpapiHost
* host
)
30 ChromeBrowserPepperHostFactory::~ChromeBrowserPepperHostFactory() {}
32 scoped_ptr
<ResourceHost
> ChromeBrowserPepperHostFactory::CreateResourceHost(
33 ppapi::host::PpapiHost
* host
,
36 const IPC::Message
& message
) {
37 DCHECK(host
== host_
->GetPpapiHost());
39 // Make sure the plugin is giving us a valid instance for this resource.
40 if (!host_
->IsValidInstance(instance
))
41 return scoped_ptr
<ResourceHost
>();
43 // Private interfaces.
44 if (host_
->GetPpapiHost()->permissions().HasPermission(
45 ppapi::PERMISSION_PRIVATE
)) {
46 switch (message
.type()) {
47 case PpapiHostMsg_Broker_Create::ID
: {
48 scoped_refptr
<ResourceMessageFilter
> broker_filter(
49 new chrome::PepperBrokerMessageFilter(instance
, host_
));
50 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
51 host_
->GetPpapiHost(), instance
, resource
, broker_filter
));
53 #if defined(OS_CHROMEOS)
54 case PpapiHostMsg_PlatformVerification_Create::ID
: {
55 scoped_refptr
<ResourceMessageFilter
> pv_filter(
56 new chrome::PepperPlatformVerificationMessageFilter(host_
,
58 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
59 host_
->GetPpapiHost(), instance
, resource
, pv_filter
));
62 #if defined(OS_CHROMEOS)
63 case PpapiHostMsg_OutputProtection_Create::ID
: {
64 scoped_refptr
<ResourceMessageFilter
> output_protection_filter(
65 new chrome::PepperOutputProtectionMessageFilter(host_
, instance
));
66 return scoped_ptr
<ResourceHost
>(
67 new MessageFilterHost(host_
->GetPpapiHost(), instance
, resource
,
68 output_protection_filter
));
75 if (host_
->GetPpapiHost()->permissions().HasPermission(
76 ppapi::PERMISSION_FLASH
)) {
77 switch (message
.type()) {
78 case PpapiHostMsg_Flash_Create::ID
:
79 return scoped_ptr
<ResourceHost
>(
80 new chrome::PepperFlashBrowserHost(host_
, instance
, resource
));
81 case PpapiHostMsg_FlashClipboard_Create::ID
: {
82 scoped_refptr
<ResourceMessageFilter
> clipboard_filter(
83 new chrome::PepperFlashClipboardMessageFilter
);
84 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
85 host_
->GetPpapiHost(), instance
, resource
, clipboard_filter
));
87 case PpapiHostMsg_FlashDRM_Create::ID
:
88 return scoped_ptr
<ResourceHost
>(
89 new chrome::PepperFlashDRMHost(host_
, instance
, resource
));
93 // Permissions for the following interfaces will be checked at the
94 // time of the corresponding instance's methods calls (because
95 // permission check can be performed only on the UI
96 // thread). Currently these interfaces are available only for
97 // whitelisted apps which may not have access to the other private
99 if (message
.type() == PpapiHostMsg_IsolatedFileSystem_Create::ID
) {
100 chrome::PepperIsolatedFileSystemMessageFilter
* isolated_fs_filter
=
101 chrome::PepperIsolatedFileSystemMessageFilter::Create(instance
, host_
);
102 if (!isolated_fs_filter
)
103 return scoped_ptr
<ResourceHost
>();
104 return scoped_ptr
<ResourceHost
>(
105 new MessageFilterHost(host
, instance
, resource
, isolated_fs_filter
));
108 return scoped_ptr
<ResourceHost
>();