OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" | 5 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/plugins/plugin_info_message_filter.h" | 8 #include "chrome/browser/plugins/plugin_info_message_filter.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory
.h" | 10 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory
.h" |
11 #include "chrome/common/channel_info.h" | 11 #include "chrome/common/channel_info.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pepper_permission_util.h" | 13 #include "chrome/common/pepper_permission_util.h" |
14 #include "components/version_info/version_info.h" | 14 #include "components/version_info/version_info.h" |
15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 16 #include "extensions/features/features.h" |
16 #include "ppapi/host/ppapi_host.h" | 17 #include "ppapi/host/ppapi_host.h" |
17 #include "ppapi/shared_impl/ppapi_switches.h" | 18 #include "ppapi/shared_impl/ppapi_switches.h" |
18 | 19 |
19 #if defined(ENABLE_EXTENSIONS) | 20 #if BUILDFLAG(ENABLE_EXTENSIONS) |
20 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
21 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
22 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
23 #include "extensions/common/permissions/permissions_data.h" | 24 #include "extensions/common/permissions/permissions_data.h" |
24 #include "extensions/common/permissions/socket_permission.h" | 25 #include "extensions/common/permissions/socket_permission.h" |
25 #endif | 26 #endif |
26 | 27 |
27 namespace plugins { | 28 namespace plugins { |
28 | 29 |
29 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() { | 30 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() { |
30 } | 31 } |
31 | 32 |
32 ChromeContentBrowserClientPluginsPart:: | 33 ChromeContentBrowserClientPluginsPart:: |
33 ~ChromeContentBrowserClientPluginsPart() { | 34 ~ChromeContentBrowserClientPluginsPart() { |
34 } | 35 } |
35 | 36 |
36 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch( | 37 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch( |
37 content::RenderProcessHost* host) { | 38 content::RenderProcessHost* host) { |
38 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); | 39 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
39 host->AddFilter(new PluginInfoMessageFilter(host->GetID(), profile)); | 40 host->AddFilter(new PluginInfoMessageFilter(host->GetID(), profile)); |
40 } | 41 } |
41 | 42 |
42 bool ChromeContentBrowserClientPluginsPart:: | 43 bool ChromeContentBrowserClientPluginsPart:: |
43 IsPluginAllowedToCallRequestOSFileHandle( | 44 IsPluginAllowedToCallRequestOSFileHandle( |
44 content::BrowserContext* browser_context, | 45 content::BrowserContext* browser_context, |
45 const GURL& url, | 46 const GURL& url, |
46 const std::set<std::string>& allowed_file_handle_origins) { | 47 const std::set<std::string>& allowed_file_handle_origins) { |
47 #if defined(ENABLE_EXTENSIONS) | 48 #if BUILDFLAG(ENABLE_EXTENSIONS) |
48 Profile* profile = Profile::FromBrowserContext(browser_context); | 49 Profile* profile = Profile::FromBrowserContext(browser_context); |
49 const extensions::ExtensionSet* extension_set = NULL; | 50 const extensions::ExtensionSet* extension_set = NULL; |
50 if (profile) { | 51 if (profile) { |
51 extension_set = | 52 extension_set = |
52 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 53 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
53 } | 54 } |
54 | 55 |
55 return chrome::IsExtensionOrSharedModuleWhitelisted( | 56 return chrome::IsExtensionOrSharedModuleWhitelisted( |
56 url, extension_set, allowed_file_handle_origins) || | 57 url, extension_set, allowed_file_handle_origins) || |
57 chrome::IsHostAllowedByCommandLine( | 58 chrome::IsHostAllowedByCommandLine( |
58 url, extension_set, ::switches::kAllowNaClFileHandleAPI); | 59 url, extension_set, ::switches::kAllowNaClFileHandleAPI); |
59 #else | 60 #else |
60 return false; | 61 return false; |
61 #endif | 62 #endif |
62 } | 63 } |
63 | 64 |
64 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( | 65 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
65 content::BrowserContext* browser_context, | 66 content::BrowserContext* browser_context, |
66 const GURL& url, | 67 const GURL& url, |
67 bool private_api, | 68 bool private_api, |
68 const content::SocketPermissionRequest* params, | 69 const content::SocketPermissionRequest* params, |
69 const std::set<std::string>& allowed_socket_origin) { | 70 const std::set<std::string>& allowed_socket_origin) { |
70 #if defined(ENABLE_EXTENSIONS) | 71 #if BUILDFLAG(ENABLE_EXTENSIONS) |
71 Profile* profile = Profile::FromBrowserContext(browser_context); | 72 Profile* profile = Profile::FromBrowserContext(browser_context); |
72 const extensions::ExtensionSet* extension_set = NULL; | 73 const extensions::ExtensionSet* extension_set = NULL; |
73 if (profile) { | 74 if (profile) { |
74 extension_set = | 75 extension_set = |
75 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 76 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
76 } | 77 } |
77 | 78 |
78 if (private_api) { | 79 if (private_api) { |
79 // Access to private socket APIs is controlled by the whitelist. | 80 // Access to private socket APIs is controlled by the whitelist. |
80 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set, | 81 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set, |
(...skipping 28 matching lines...) Expand all Loading... |
109 return chrome::IsHostAllowedByCommandLine(url, extension_set, | 110 return chrome::IsHostAllowedByCommandLine(url, extension_set, |
110 ::switches::kAllowNaClSocketAPI); | 111 ::switches::kAllowNaClSocketAPI); |
111 #else | 112 #else |
112 return false; | 113 return false; |
113 #endif | 114 #endif |
114 } | 115 } |
115 | 116 |
116 bool ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( | 117 bool ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
117 content::BrowserContext* browser_context, | 118 content::BrowserContext* browser_context, |
118 const GURL& url) { | 119 const GURL& url) { |
119 #if defined(ENABLE_EXTENSIONS) | 120 #if BUILDFLAG(ENABLE_EXTENSIONS) |
120 Profile* profile = Profile::FromBrowserContext(browser_context); | 121 Profile* profile = Profile::FromBrowserContext(browser_context); |
121 if (!profile) | 122 if (!profile) |
122 return false; | 123 return false; |
123 | 124 |
124 const extensions::ExtensionSet* extension_set = | 125 const extensions::ExtensionSet* extension_set = |
125 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 126 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
126 if (!extension_set) | 127 if (!extension_set) |
127 return false; | 128 return false; |
128 | 129 |
129 // Access to the vpnProvider API is controlled by extension permissions. | 130 // Access to the vpnProvider API is controlled by extension permissions. |
(...skipping 14 matching lines...) Expand all Loading... |
144 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs( | 145 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs( |
145 content::BrowserContext* browser_context, | 146 content::BrowserContext* browser_context, |
146 const GURL& url, | 147 const GURL& url, |
147 const std::set<std::string>& allowed_dev_channel_origins) { | 148 const std::set<std::string>& allowed_dev_channel_origins) { |
148 // Allow access for tests. | 149 // Allow access for tests. |
149 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 150 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
150 switches::kEnablePepperTesting)) { | 151 switches::kEnablePepperTesting)) { |
151 return true; | 152 return true; |
152 } | 153 } |
153 | 154 |
154 #if defined(ENABLE_EXTENSIONS) | 155 #if BUILDFLAG(ENABLE_EXTENSIONS) |
155 Profile* profile = Profile::FromBrowserContext(browser_context); | 156 Profile* profile = Profile::FromBrowserContext(browser_context); |
156 const extensions::ExtensionSet* extension_set = NULL; | 157 const extensions::ExtensionSet* extension_set = NULL; |
157 if (profile) { | 158 if (profile) { |
158 extension_set = | 159 extension_set = |
159 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); | 160 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions(); |
160 } | 161 } |
161 | 162 |
162 // Allow access for whitelisted applications. | 163 // Allow access for whitelisted applications. |
163 if (chrome::IsExtensionOrSharedModuleWhitelisted( | 164 if (chrome::IsExtensionOrSharedModuleWhitelisted( |
164 url, extension_set, allowed_dev_channel_origins)) { | 165 url, extension_set, allowed_dev_channel_origins)) { |
165 return true; | 166 return true; |
166 } | 167 } |
167 #endif | 168 #endif |
168 version_info::Channel channel = chrome::GetChannel(); | 169 version_info::Channel channel = chrome::GetChannel(); |
169 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" | 170 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown" |
170 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on | 171 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on |
171 // Chromium builds as well. | 172 // Chromium builds as well. |
172 return channel <= version_info::Channel::DEV; | 173 return channel <= version_info::Channel::DEV; |
173 } | 174 } |
174 | 175 |
175 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin( | 176 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin( |
176 content::BrowserPpapiHost* browser_host) { | 177 content::BrowserPpapiHost* browser_host) { |
177 browser_host->GetPpapiHost()->AddHostFactoryFilter( | 178 browser_host->GetPpapiHost()->AddHostFactoryFilter( |
178 std::unique_ptr<ppapi::host::HostFactory>( | 179 std::unique_ptr<ppapi::host::HostFactory>( |
179 new ChromeBrowserPepperHostFactory(browser_host))); | 180 new ChromeBrowserPepperHostFactory(browser_host))); |
180 } | 181 } |
181 | 182 |
182 } // namespace plugins | 183 } // namespace plugins |
OLD | NEW |