Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/plugins/chrome_content_browser_client_plugins_part.cc

Issue 591063003: Split ChromeContentBrowserClient into smaller parts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved headers inside flag Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h"
6
7 #include "base/command_line.h"
8 #include "chrome/browser/extensions/extension_service.h"
Lei Zhang 2014/12/05 08:07:02 You forgot this guy
9 #include "chrome/browser/plugins/plugin_info_message_filter.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory .h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/chrome_version_info.h"
14 #include "chrome/common/pepper_permission_util.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"
18
19 #if defined(ENABLE_EXTENSIONS)
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
25
26 namespace plugins {
27
28 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() {
29 }
30
31 ChromeContentBrowserClientPluginsPart::
32 ~ChromeContentBrowserClientPluginsPart() {
33 }
34
35 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch(
36 content::RenderProcessHost* host) {
37 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
38 host->AddFilter(new PluginInfoMessageFilter(host->GetID(), profile));
39 }
40
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();
52 }
53
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
61 }
62
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 Profile* profile = Profile::FromBrowserContext(browser_context);
70 #if defined(ENABLE_EXTENSIONS)
71 const extensions::ExtensionSet* extension_set = NULL;
72 if (profile) {
73 extension_set =
74 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
75 }
76
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;
82 }
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;
98 }
99 } else if (permissions_data->HasAPIPermission(
100 extensions::APIPermission::kSocket)) {
101 return true;
102 }
103 }
104 }
105 }
106
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
113 }
114
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 (CommandLine::ForCurrentProcess()->HasSwitch(
121 switches::kEnablePepperTesting)) {
122 return true;
123 }
124
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();
131 }
132
133 // Allow access for whitelisted applications.
134 if (chrome::IsExtensionOrSharedModuleWhitelisted(
135 url, extension_set, allowed_dev_channel_origins)) {
136 return true;
137 }
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;
144 }
145
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)));
151 }
152
153 } // namespace plugins
OLDNEW
« no previous file with comments | « chrome/browser/plugins/chrome_content_browser_client_plugins_part.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698