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 "chrome/browser/renderer_host/pepper/pepper_talk_host.h"
16 #include "content/public/browser/browser_ppapi_host.h"
17 #include "ppapi/host/message_filter_host.h"
18 #include "ppapi/host/ppapi_host.h"
19 #include "ppapi/host/resource_host.h"
20 #include "ppapi/proxy/ppapi_messages.h"
21 #include "ppapi/shared_impl/ppapi_permissions.h"
23 using ppapi::host::MessageFilterHost
;
24 using ppapi::host::ResourceHost
;
25 using ppapi::host::ResourceMessageFilter
;
29 ChromeBrowserPepperHostFactory::ChromeBrowserPepperHostFactory(
30 content::BrowserPpapiHost
* host
)
33 ChromeBrowserPepperHostFactory::~ChromeBrowserPepperHostFactory() {}
35 scoped_ptr
<ResourceHost
> ChromeBrowserPepperHostFactory::CreateResourceHost(
36 ppapi::host::PpapiHost
* host
,
39 const IPC::Message
& message
) {
40 DCHECK(host
== host_
->GetPpapiHost());
42 // Make sure the plugin is giving us a valid instance for this resource.
43 if (!host_
->IsValidInstance(instance
))
44 return scoped_ptr
<ResourceHost
>();
46 // Private interfaces.
47 if (host_
->GetPpapiHost()->permissions().HasPermission(
48 ppapi::PERMISSION_PRIVATE
)) {
49 switch (message
.type()) {
50 case PpapiHostMsg_Broker_Create::ID
: {
51 scoped_refptr
<ResourceMessageFilter
> broker_filter(
52 new PepperBrokerMessageFilter(instance
, host_
));
53 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
54 host_
->GetPpapiHost(), instance
, resource
, broker_filter
));
56 #if defined(OS_CHROMEOS)
57 case PpapiHostMsg_PlatformVerification_Create::ID
: {
58 scoped_refptr
<ResourceMessageFilter
> pv_filter(
59 new PepperPlatformVerificationMessageFilter(host_
, instance
));
60 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
61 host_
->GetPpapiHost(), instance
, resource
, pv_filter
));
64 case PpapiHostMsg_Talk_Create::ID
:
65 return scoped_ptr
<ResourceHost
>(
66 new PepperTalkHost(host_
, instance
, resource
));
67 #if defined(OS_CHROMEOS)
68 case PpapiHostMsg_OutputProtection_Create::ID
: {
69 scoped_refptr
<ResourceMessageFilter
> output_protection_filter(
70 new PepperOutputProtectionMessageFilter(host_
, instance
));
71 return scoped_ptr
<ResourceHost
>(
72 new MessageFilterHost(host_
->GetPpapiHost(), instance
, resource
,
73 output_protection_filter
));
80 if (host_
->GetPpapiHost()->permissions().HasPermission(
81 ppapi::PERMISSION_FLASH
)) {
82 switch (message
.type()) {
83 case PpapiHostMsg_Flash_Create::ID
:
84 return scoped_ptr
<ResourceHost
>(
85 new PepperFlashBrowserHost(host_
, instance
, resource
));
86 case PpapiHostMsg_FlashClipboard_Create::ID
: {
87 scoped_refptr
<ResourceMessageFilter
> clipboard_filter(
88 new PepperFlashClipboardMessageFilter
);
89 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
90 host_
->GetPpapiHost(), instance
, resource
, clipboard_filter
));
92 case PpapiHostMsg_FlashDRM_Create::ID
:
93 return scoped_ptr
<ResourceHost
>(
94 new PepperFlashDRMHost(host_
, instance
, resource
));
98 // Permissions for the following interfaces will be checked at the
99 // time of the corresponding instance's methods calls (because
100 // permission check can be performed only on the UI
101 // thread). Currently these interfaces are available only for
102 // whitelisted apps which may not have access to the other private
104 if (message
.type() == PpapiHostMsg_IsolatedFileSystem_Create::ID
) {
105 PepperIsolatedFileSystemMessageFilter
* isolated_fs_filter
=
106 PepperIsolatedFileSystemMessageFilter::Create(instance
, host_
);
107 if (!isolated_fs_filter
)
108 return scoped_ptr
<ResourceHost
>();
109 return scoped_ptr
<ResourceHost
>(
110 new MessageFilterHost(host
, instance
, resource
, isolated_fs_filter
));
113 return scoped_ptr
<ResourceHost
>();
116 } // namespace chrome