Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / plugins / chrome_content_browser_client_plugins_part.cc
blob59549cdcd0dbfeb297ebb4118b89a85f7799e096
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"
25 #endif
27 namespace plugins {
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,
45 const GURL& url,
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;
50 if (profile) {
51 extension_set =
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);
59 #else
60 return false;
61 #endif
64 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
65 content::BrowserContext* browser_context,
66 const GURL& url,
67 bool private_api,
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;
73 if (profile) {
74 extension_set =
75 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
78 if (private_api) {
79 // Access to private socket APIs is controlled by the whitelist.
80 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set,
81 allowed_socket_origin)) {
82 return true;
84 } else {
85 // Access to public socket APIs is controlled by extension permissions.
86 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
87 extension_set) {
88 const extensions::Extension* extension =
89 extension_set->GetByID(url.host());
90 if (extension) {
91 const extensions::PermissionsData* permissions_data =
92 extension->permissions_data();
93 if (params) {
94 extensions::SocketPermission::CheckParam check_params(
95 params->type, params->host, params->port);
96 if (permissions_data->CheckAPIPermissionWithParam(
97 extensions::APIPermission::kSocket, &check_params)) {
98 return true;
100 } else if (permissions_data->HasAPIPermission(
101 extensions::APIPermission::kSocket)) {
102 return true;
108 // Allow both public and private APIs if the command line says so.
109 return chrome::IsHostAllowedByCommandLine(url, extension_set,
110 ::switches::kAllowNaClSocketAPI);
111 #else
112 return false;
113 #endif
116 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs(
117 content::BrowserContext* browser_context,
118 const GURL& url,
119 const std::set<std::string>& allowed_dev_channel_origins) {
120 // Allow access for tests.
121 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
122 switches::kEnablePepperTesting)) {
123 return true;
126 #if defined(ENABLE_EXTENSIONS)
127 Profile* profile = Profile::FromBrowserContext(browser_context);
128 const extensions::ExtensionSet* extension_set = NULL;
129 if (profile) {
130 extension_set =
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)) {
137 return true;
139 #endif
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