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

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: fix review comment 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"
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 "extensions/browser/extension_registry.h"
17 #include "extensions/common/constants.h"
18 #include "extensions/common/permissions/permissions_data.h"
19 #include "extensions/common/permissions/socket_permission.h"
20 #include "ppapi/host/ppapi_host.h"
21 #include "ppapi/shared_impl/ppapi_switches.h"
22
23 namespace plugins {
24
25 ChromeContentBrowserClientPluginsPart::ChromeContentBrowserClientPluginsPart() {
26 }
27
28 ChromeContentBrowserClientPluginsPart::
29 ~ChromeContentBrowserClientPluginsPart() {
30 }
31
32 void ChromeContentBrowserClientPluginsPart::RenderProcessWillLaunch(
33 content::RenderProcessHost* host) {
34 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
35 host->AddFilter(new PluginInfoMessageFilter(host->GetID(), profile));
36 }
37
38 bool ChromeContentBrowserClientPluginsPart::
39 IsPluginAllowedToCallRequestOSFileHandle(
40 content::BrowserContext* browser_context,
41 const GURL& url,
42 const std::set<std::string>& allowed_file_handle_origins) {
43 #if defined(ENABLE_EXTENSIONS)
44 Profile* profile = Profile::FromBrowserContext(browser_context);
45 const extensions::ExtensionSet* extension_set = NULL;
46 if (profile) {
47 extension_set =
48 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
49 }
50
51 return chrome::IsExtensionOrSharedModuleWhitelisted(
52 url, extension_set, allowed_file_handle_origins) ||
53 chrome::IsHostAllowedByCommandLine(
54 url, extension_set, ::switches::kAllowNaClFileHandleAPI);
55 #endif
Lei Zhang 2014/12/05 05:45:47 #else return false; #endif Otherwise I worry th
56 return false;
57 }
58
59 bool ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI(
60 content::BrowserContext* browser_context,
61 const GURL& url,
62 bool private_api,
63 const content::SocketPermissionRequest* params,
64 const std::set<std::string>& allowed_socket_origin) {
65 Profile* profile = Profile::FromBrowserContext(browser_context);
66 const extensions::ExtensionSet* extension_set = NULL;
67 if (profile) {
68 extension_set =
69 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
70 }
71
72 if (private_api) {
73 // Access to private socket APIs is controlled by the whitelist.
74 if (chrome::IsExtensionOrSharedModuleWhitelisted(url, extension_set,
75 allowed_socket_origin)) {
76 return true;
77 }
78 } else {
79 // Access to public socket APIs is controlled by extension permissions.
80 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
81 extension_set) {
82 const extensions::Extension* extension =
83 extension_set->GetByID(url.host());
84 if (extension) {
85 const extensions::PermissionsData* permissions_data =
86 extension->permissions_data();
87 if (params) {
88 extensions::SocketPermission::CheckParam check_params(
89 params->type, params->host, params->port);
90 if (permissions_data->CheckAPIPermissionWithParam(
91 extensions::APIPermission::kSocket, &check_params)) {
92 return true;
93 }
94 } else if (permissions_data->HasAPIPermission(
95 extensions::APIPermission::kSocket)) {
96 return true;
97 }
98 }
99 }
100 }
101
102 // Allow both public and private APIs if the command line says so.
103 return chrome::IsHostAllowedByCommandLine(url, extension_set,
104 ::switches::kAllowNaClSocketAPI);
105 }
106
107 bool ChromeContentBrowserClientPluginsPart::IsPluginAllowedToUseDevChannelAPIs(
108 content::BrowserContext* browser_context,
109 const GURL& url,
110 const std::set<std::string>& allowed_dev_channel_origins) {
111 // Allow access for tests.
112 if (CommandLine::ForCurrentProcess()->HasSwitch(
113 switches::kEnablePepperTesting)) {
114 return true;
115 }
116
117 Profile* profile = Profile::FromBrowserContext(browser_context);
118 const extensions::ExtensionSet* extension_set = NULL;
119 if (profile) {
120 extension_set =
121 &extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
122 }
123
124 // Allow access for whitelisted applications.
125 if (chrome::IsExtensionOrSharedModuleWhitelisted(
126 url, extension_set, allowed_dev_channel_origins)) {
127 return true;
128 }
129
130 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
131 // Allow dev channel APIs to be used on "Canary", "Dev", and "Unknown"
132 // releases of Chrome. Permitting "Unknown" allows these APIs to be used on
133 // Chromium builds as well.
134 return channel <= chrome::VersionInfo::CHANNEL_DEV;
135 }
136
137 void ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(
138 content::BrowserPpapiHost* browser_host) {
139 browser_host->GetPpapiHost()->AddHostFactoryFilter(
140 scoped_ptr<ppapi::host::HostFactory>(
141 new chrome::ChromeBrowserPepperHostFactory(browser_host)));
142 }
143
144 } // 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