Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / renderer_host / pepper / chrome_browser_pepper_host_factory.cc
blobb28a2c37914507d57f3e39d8909f97e11ba825cd
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 namespace chrome {
28 ChromeBrowserPepperHostFactory::ChromeBrowserPepperHostFactory(
29 content::BrowserPpapiHost* host)
30 : host_(host) {}
32 ChromeBrowserPepperHostFactory::~ChromeBrowserPepperHostFactory() {}
34 scoped_ptr<ResourceHost> ChromeBrowserPepperHostFactory::CreateResourceHost(
35 ppapi::host::PpapiHost* host,
36 PP_Resource resource,
37 PP_Instance instance,
38 const IPC::Message& message) {
39 DCHECK(host == host_->GetPpapiHost());
41 // Make sure the plugin is giving us a valid instance for this resource.
42 if (!host_->IsValidInstance(instance))
43 return scoped_ptr<ResourceHost>();
45 // Private interfaces.
46 if (host_->GetPpapiHost()->permissions().HasPermission(
47 ppapi::PERMISSION_PRIVATE)) {
48 switch (message.type()) {
49 case PpapiHostMsg_Broker_Create::ID: {
50 scoped_refptr<ResourceMessageFilter> broker_filter(
51 new PepperBrokerMessageFilter(instance, host_));
52 return scoped_ptr<ResourceHost>(new MessageFilterHost(
53 host_->GetPpapiHost(), instance, resource, broker_filter));
55 #if defined(OS_CHROMEOS)
56 case PpapiHostMsg_PlatformVerification_Create::ID: {
57 scoped_refptr<ResourceMessageFilter> pv_filter(
58 new PepperPlatformVerificationMessageFilter(host_, instance));
59 return scoped_ptr<ResourceHost>(new MessageFilterHost(
60 host_->GetPpapiHost(), instance, resource, pv_filter));
62 #endif
63 #if defined(OS_CHROMEOS)
64 case PpapiHostMsg_OutputProtection_Create::ID: {
65 scoped_refptr<ResourceMessageFilter> output_protection_filter(
66 new PepperOutputProtectionMessageFilter(host_, instance));
67 return scoped_ptr<ResourceHost>(
68 new MessageFilterHost(host_->GetPpapiHost(), instance, resource,
69 output_protection_filter));
71 #endif
75 // Flash interfaces.
76 if (host_->GetPpapiHost()->permissions().HasPermission(
77 ppapi::PERMISSION_FLASH)) {
78 switch (message.type()) {
79 case PpapiHostMsg_Flash_Create::ID:
80 return scoped_ptr<ResourceHost>(
81 new PepperFlashBrowserHost(host_, instance, resource));
82 case PpapiHostMsg_FlashClipboard_Create::ID: {
83 scoped_refptr<ResourceMessageFilter> clipboard_filter(
84 new PepperFlashClipboardMessageFilter);
85 return scoped_ptr<ResourceHost>(new MessageFilterHost(
86 host_->GetPpapiHost(), instance, resource, clipboard_filter));
88 case PpapiHostMsg_FlashDRM_Create::ID:
89 return scoped_ptr<ResourceHost>(
90 new PepperFlashDRMHost(host_, instance, resource));
94 // Permissions for the following interfaces will be checked at the
95 // time of the corresponding instance's methods calls (because
96 // permission check can be performed only on the UI
97 // thread). Currently these interfaces are available only for
98 // whitelisted apps which may not have access to the other private
99 // interfaces.
100 if (message.type() == PpapiHostMsg_IsolatedFileSystem_Create::ID) {
101 PepperIsolatedFileSystemMessageFilter* isolated_fs_filter =
102 PepperIsolatedFileSystemMessageFilter::Create(instance, host_);
103 if (!isolated_fs_filter)
104 return scoped_ptr<ResourceHost>();
105 return scoped_ptr<ResourceHost>(
106 new MessageFilterHost(host, instance, resource, isolated_fs_filter));
109 return scoped_ptr<ResourceHost>();
112 } // namespace chrome