No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / plugins / chrome_content_browser_client_plugins_part.cc
blob5491372a2a477a732c3b19489124fdfa42ed9b75
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"
24 #endif
26 namespace plugins {
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,
44 const GURL& url,
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;
49 if (profile) {
50 extension_set =
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);
58 #else
59 return false;
60 #endif
63 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
64 content::BrowserContext* browser_context,
65 const GURL& url,
66 bool private_api,
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;
72 if (profile) {
73 extension_set =
74 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
77 if (private_api) {
78 // Access to private socket APIs is controlled by the whitelist.
79 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set,
80 allowed_socket_origin)) {
81 return true;
83 } else {
84 // Access to public socket APIs is controlled by extension permissions.
85 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
86 extension_set) {
87 const extensions::Extension* extension =
88 extension_set->GetByID(url.host());
89 if (extension) {
90 const extensions::PermissionsData* permissions_data =
91 extension->permissions_data();
92 if (params) {
93 extensions::SocketPermission::CheckParam check_params(
94 params->type, params->host, params->port);
95 if (permissions_data->CheckAPIPermissionWithParam(
96 extensions::APIPermission::kSocket, &check_params)) {
97 return true;
99 } else if (permissions_data->HasAPIPermission(
100 extensions::APIPermission::kSocket)) {
101 return true;
107 // Allow both public and private APIs if the command line says so.
108 return chrome::IsHostAllowedByCommandLine(url, extension_set,
109 ::switches::kAllowNaClSocketAPI);
110 #else
111 return false;
112 #endif
115 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs(
116 content::BrowserContext* browser_context,
117 const GURL& url,
118 const std::set<std::string>& allowed_dev_channel_origins) {
119 // Allow access for tests.
120 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
121 switches::kEnablePepperTesting)) {
122 return true;
125 #if defined(ENABLE_EXTENSIONS)
126 Profile* profile = Profile::FromBrowserContext(browser_context);
127 const extensions::ExtensionSet* extension_set = NULL;
128 if (profile) {
129 extension_set =
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)) {
136 return true;
138 #endif
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