1 // Copyright 2014 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/plugins/chrome_content_browser_client_plugins_part.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/plugins/plugin_info_message_filter.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/chrome_version_info.h"
13 #include "chrome/common/pepper_permission_util.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "ppapi/host/ppapi_host.h"
16 #include "ppapi/shared_impl/ppapi_switches.h"
18 #if defined(ENABLE_EXTENSIONS)
19 #include "chrome/browser/extensions/extension_service.h"
20 #include "extensions/browser/extension_registry.h"
21 #include "extensions/common/constants.h"
22 #include "extensions/common/permissions/permissions_data.h"
23 #include "extensions/common/permissions/socket_permission.h"
28 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() {
31 ChromeContentBrowserClientPluginsPart::
32 ~ChromeContentBrowserClientPluginsPart() {
35 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch(
36 content::RenderProcessHost
* host
) {
37 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
38 host
->AddFilter(new PluginInfoMessageFilter(host
->GetID(), profile
));
41 bool ChromeContentBrowserClientPluginsPart::
42 IsPluginAllowedToCallRequestOSFileHandle(
43 content::BrowserContext
* browser_context
,
45 const std::set
<std::string
>& allowed_file_handle_origins
) {
46 #if defined(ENABLE_EXTENSIONS)
47 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
48 const extensions::ExtensionSet
* extension_set
= NULL
;
51 &extensions::ExtensionRegistry::Get(profile
)->enabled_extensions();
54 return chrome::IsExtensionOrSharedModuleWhitelisted(
55 url
, extension_set
, allowed_file_handle_origins
) ||
56 chrome::IsHostAllowedByCommandLine(
57 url
, extension_set
, ::switches::kAllowNaClFileHandleAPI
);
63 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
64 content::BrowserContext
* browser_context
,
67 const content::SocketPermissionRequest
* params
,
68 const std::set
<std::string
>& allowed_socket_origin
) {
69 #if defined(ENABLE_EXTENSIONS)
70 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
71 const extensions::ExtensionSet
* extension_set
= NULL
;
74 &extensions::ExtensionRegistry::Get(profile
)->enabled_extensions();
78 // Access to private socket APIs is controlled by the whitelist.
79 if (chrome::IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
80 allowed_socket_origin
)) {
84 // Access to public socket APIs is controlled by extension permissions.
85 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
87 const extensions::Extension
* extension
=
88 extension_set
->GetByID(url
.host());
90 const extensions::PermissionsData
* permissions_data
=
91 extension
->permissions_data();
93 extensions::SocketPermission::CheckParam
check_params(
94 params
->type
, params
->host
, params
->port
);
95 if (permissions_data
->CheckAPIPermissionWithParam(
96 extensions::APIPermission::kSocket
, &check_params
)) {
99 } else if (permissions_data
->HasAPIPermission(
100 extensions::APIPermission::kSocket
)) {
107 // Allow both public and private APIs if the command line says so.
108 return chrome::IsHostAllowedByCommandLine(url
, extension_set
,
109 ::switches::kAllowNaClSocketAPI
);
115 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs(
116 content::BrowserContext
* browser_context
,
118 const std::set
<std::string
>& allowed_dev_channel_origins
) {
119 // Allow access for tests.
120 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
121 switches::kEnablePepperTesting
)) {
125 #if defined(ENABLE_EXTENSIONS)
126 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
127 const extensions::ExtensionSet
* extension_set
= NULL
;
130 &extensions::ExtensionRegistry::Get(profile
)->enabled_extensions();
133 // Allow access for whitelisted applications.
134 if (chrome::IsExtensionOrSharedModuleWhitelisted(
135 url
, extension_set
, allowed_dev_channel_origins
)) {
139 chrome::VersionInfo::Channel channel
= chrome::VersionInfo::GetChannel();
140 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
141 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
142 // Chromium builds as well.
143 return channel
<= chrome::VersionInfo::CHANNEL_DEV
;
146 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(
147 content::BrowserPpapiHost
* browser_host
) {
148 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
149 scoped_ptr
<ppapi::host::HostFactory
>(
150 new chrome::ChromeBrowserPepperHostFactory(browser_host
)));
153 } // namespace plugins