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/channel_info.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pepper_permission_util.h"
14 #include "components/version_info/version_info.h"
15 #include "content/public/browser/render_process_host.h"
16 #include "ppapi/host/ppapi_host.h"
17 #include "ppapi/shared_impl/ppapi_switches.h"
19 #if defined(ENABLE_EXTENSIONS)
20 #include "chrome/browser/extensions/extension_service.h"
21 #include "extensions/browser/extension_registry.h"
22 #include "extensions/common/constants.h"
23 #include "extensions/common/permissions/permissions_data.h"
24 #include "extensions/common/permissions/socket_permission.h"
29 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() {
32 ChromeContentBrowserClientPluginsPart::
33 ~ChromeContentBrowserClientPluginsPart() {
36 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch(
37 content::RenderProcessHost
* host
) {
38 Profile
* profile
= Profile::FromBrowserContext(host
->GetBrowserContext());
39 host
->AddFilter(new PluginInfoMessageFilter(host
->GetID(), profile
));
42 bool ChromeContentBrowserClientPluginsPart::
43 IsPluginAllowedToCallRequestOSFileHandle(
44 content::BrowserContext
* browser_context
,
46 const std::set
<std::string
>& allowed_file_handle_origins
) {
47 #if defined(ENABLE_EXTENSIONS)
48 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
49 const extensions::ExtensionSet
* extension_set
= NULL
;
52 &extensions::ExtensionRegistry::Get(profile
)->enabled_extensions();
55 return chrome::IsExtensionOrSharedModuleWhitelisted(
56 url
, extension_set
, allowed_file_handle_origins
) ||
57 chrome::IsHostAllowedByCommandLine(
58 url
, extension_set
, ::switches::kAllowNaClFileHandleAPI
);
64 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
65 content::BrowserContext
* browser_context
,
68 const content::SocketPermissionRequest
* params
,
69 const std::set
<std::string
>& allowed_socket_origin
) {
70 #if defined(ENABLE_EXTENSIONS)
71 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
72 const extensions::ExtensionSet
* extension_set
= NULL
;
75 &extensions::ExtensionRegistry::Get(profile
)->enabled_extensions();
79 // Access to private socket APIs is controlled by the whitelist.
80 if (chrome::IsExtensionOrSharedModuleWhitelisted(url
, extension_set
,
81 allowed_socket_origin
)) {
85 // Access to public socket APIs is controlled by extension permissions.
86 if (url
.is_valid() && url
.SchemeIs(extensions::kExtensionScheme
) &&
88 const extensions::Extension
* extension
=
89 extension_set
->GetByID(url
.host());
91 const extensions::PermissionsData
* permissions_data
=
92 extension
->permissions_data();
94 extensions::SocketPermission::CheckParam
check_params(
95 params
->type
, params
->host
, params
->port
);
96 if (permissions_data
->CheckAPIPermissionWithParam(
97 extensions::APIPermission::kSocket
, &check_params
)) {
100 } else if (permissions_data
->HasAPIPermission(
101 extensions::APIPermission::kSocket
)) {
108 // Allow both public and private APIs if the command line says so.
109 return chrome::IsHostAllowedByCommandLine(url
, extension_set
,
110 ::switches::kAllowNaClSocketAPI
);
116 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs(
117 content::BrowserContext
* browser_context
,
119 const std::set
<std::string
>& allowed_dev_channel_origins
) {
120 // Allow access for tests.
121 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
122 switches::kEnablePepperTesting
)) {
126 #if defined(ENABLE_EXTENSIONS)
127 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
128 const extensions::ExtensionSet
* extension_set
= NULL
;
131 &extensions::ExtensionRegistry::Get(profile
)->enabled_extensions();
134 // Allow access for whitelisted applications.
135 if (chrome::IsExtensionOrSharedModuleWhitelisted(
136 url
, extension_set
, allowed_dev_channel_origins
)) {
140 version_info::Channel channel
= chrome::GetChannel();
141 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
142 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
143 // Chromium builds as well.
144 return channel
<= version_info::Channel::DEV
;
147 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(
148 content::BrowserPpapiHost
* browser_host
) {
149 browser_host
->GetPpapiHost()->AddHostFactoryFilter(
150 scoped_ptr
<ppapi::host::HostFactory
>(
151 new chrome::ChromeBrowserPepperHostFactory(browser_host
)));
154 } // namespace plugins