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 "chrome/browser/renderer_host/pepper/pepper_broker_message_filter.h"
8 #include "chrome/browser/renderer_host/pepper/pepper_flash_browser_host.h"
9 #include "chrome/browser/renderer_host/pepper/pepper_flash_clipboard_message_filter.h"
10 #include "chrome/browser/renderer_host/pepper/pepper_flash_device_id_host.h"
11 #include "chrome/browser/renderer_host/pepper/pepper_talk_host.h"
12 #include "content/public/browser/browser_ppapi_host.h"
13 #include "ppapi/host/message_filter_host.h"
14 #include "ppapi/host/ppapi_host.h"
15 #include "ppapi/host/resource_host.h"
16 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/ppapi_permissions.h"
19 using ppapi::host::MessageFilterHost
;
20 using ppapi::host::ResourceHost
;
21 using ppapi::host::ResourceMessageFilter
;
25 ChromeBrowserPepperHostFactory::ChromeBrowserPepperHostFactory(
26 content::BrowserPpapiHost
* host
)
30 ChromeBrowserPepperHostFactory::~ChromeBrowserPepperHostFactory() {
33 scoped_ptr
<ResourceHost
> ChromeBrowserPepperHostFactory::CreateResourceHost(
34 ppapi::host::PpapiHost
* host
,
35 const ppapi::proxy::ResourceMessageCallParams
& params
,
37 const IPC::Message
& message
) {
38 DCHECK(host
== host_
->GetPpapiHost());
40 // Make sure the plugin is giving us a valid instance for this resource.
41 if (!host_
->IsValidInstance(instance
))
42 return scoped_ptr
<ResourceHost
>();
44 // Private interfaces.
45 if (host_
->GetPpapiHost()->permissions().HasPermission(
46 ppapi::PERMISSION_PRIVATE
)) {
47 switch (message
.type()) {
48 case PpapiHostMsg_Broker_Create::ID
: {
49 scoped_refptr
<ResourceMessageFilter
> broker_filter(
50 new PepperBrokerMessageFilter(instance
, host_
));
51 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
52 host_
->GetPpapiHost(), instance
, params
.pp_resource(),
55 case PpapiHostMsg_Talk_Create::ID
:
56 return scoped_ptr
<ResourceHost
>(new PepperTalkHost(
57 host_
, instance
, params
.pp_resource()));
62 if (host_
->GetPpapiHost()->permissions().HasPermission(
63 ppapi::PERMISSION_FLASH
)) {
64 switch (message
.type()) {
65 case PpapiHostMsg_Flash_Create::ID
:
66 return scoped_ptr
<ResourceHost
>(new PepperFlashBrowserHost(
67 host_
, instance
, params
.pp_resource()));
68 case PpapiHostMsg_FlashClipboard_Create::ID
: {
69 scoped_refptr
<ResourceMessageFilter
> clipboard_filter(
70 new PepperFlashClipboardMessageFilter
);
71 return scoped_ptr
<ResourceHost
>(new MessageFilterHost(
72 host_
->GetPpapiHost(), instance
, params
.pp_resource(),
75 case PpapiHostMsg_FlashDeviceID_Create::ID
:
76 return scoped_ptr
<ResourceHost
>(new PepperFlashDeviceIDHost(
77 host_
, instance
, params
.pp_resource()));
80 return scoped_ptr
<ResourceHost
>();