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

Side by Side Diff: chrome/browser/extensions/chrome_content_browser_client_extensions_part.cc

Issue 2851763003: Hosted apps VS --site-per-process.
Patch Set: Created 3 years, 7 months 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
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/extensions/chrome_content_browser_client_extensions_par t.h" 5 #include "chrome/browser/extensions/chrome_content_browser_client_extensions_par t.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 namespace extensions { 81 namespace extensions {
82 82
83 namespace { 83 namespace {
84 84
85 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 85 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
86 // below. Extension, and isolated apps require different privileges to be 86 // below. Extension, and isolated apps require different privileges to be
87 // granted to their RenderProcessHosts. This classification allows us to make 87 // granted to their RenderProcessHosts. This classification allows us to make
88 // sure URLs are served by hosts with the right set of privileges. 88 // sure URLs are served by hosts with the right set of privileges.
89 enum RenderProcessHostPrivilege { 89 enum RenderProcessHostPrivilege {
90 PRIV_NORMAL, 90 PRIV_NORMAL,
91 PRIV_HOSTED,
92 PRIV_ISOLATED, 91 PRIV_ISOLATED,
93 PRIV_EXTENSION, 92 PRIV_EXTENSION,
94 }; 93 };
95 94
96 // Specifies the scheme of the SiteInstance responsible for a failed 95 // Specifies the scheme of the SiteInstance responsible for a failed
97 // web-accessible resource check in ShouldAllowOpenURL. 96 // web-accessible resource check in ShouldAllowOpenURL.
98 // 97 //
99 // This enum backs an UMA histogram. The order of existing values 98 // This enum backs an UMA histogram. The order of existing values
100 // should not be changed. Add any new values before SCHEME_LAST, and also run 99 // should not be changed. Add any new values before SCHEME_LAST, and also run
101 // update_should_allow_open_url_histograms.py to update the corresponding enum 100 // update_should_allow_open_url_histograms.py to update the corresponding enum
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 return PRIV_NORMAL; 139 return PRIV_NORMAL;
141 140
142 if (!url.SchemeIs(kExtensionScheme)) 141 if (!url.SchemeIs(kExtensionScheme))
143 return PRIV_NORMAL; 142 return PRIV_NORMAL;
144 143
145 const Extension* extension = 144 const Extension* extension =
146 registry->enabled_extensions().GetByID(url.host()); 145 registry->enabled_extensions().GetByID(url.host());
147 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) 146 if (extension && AppIsolationInfo::HasIsolatedStorage(extension))
148 return PRIV_ISOLATED; 147 return PRIV_ISOLATED;
149 if (extension && extension->is_hosted_app()) 148 if (extension && extension->is_hosted_app())
150 return PRIV_HOSTED; 149 return PRIV_NORMAL;
151 return PRIV_EXTENSION; 150 return PRIV_EXTENSION;
152 } 151 }
153 152
154 RenderProcessHostPrivilege GetProcessPrivilege( 153 RenderProcessHostPrivilege GetProcessPrivilege(
155 content::RenderProcessHost* process_host, 154 content::RenderProcessHost* process_host,
156 ProcessMap* process_map, 155 ProcessMap* process_map,
157 ExtensionRegistry* registry) { 156 ExtensionRegistry* registry) {
158 std::set<std::string> extension_ids = 157 std::set<std::string> extension_ids =
159 process_map->GetExtensionsInProcess(process_host->GetID()); 158 process_map->GetExtensionsInProcess(process_host->GetID());
160 if (extension_ids.empty()) 159 if (extension_ids.empty())
161 return PRIV_NORMAL; 160 return PRIV_NORMAL;
162 161
163 for (const std::string& extension_id : extension_ids) { 162 for (const std::string& extension_id : extension_ids) {
164 const Extension* extension = 163 const Extension* extension =
165 registry->enabled_extensions().GetByID(extension_id); 164 registry->enabled_extensions().GetByID(extension_id);
166 if (extension && AppIsolationInfo::HasIsolatedStorage(extension)) 165 if (extension && AppIsolationInfo::HasIsolatedStorage(extension))
167 return PRIV_ISOLATED; 166 return PRIV_ISOLATED;
168 if (extension && extension->is_hosted_app()) 167 if (extension && extension->is_hosted_app())
169 return PRIV_HOSTED; 168 return PRIV_NORMAL;
170 } 169 }
171 170
172 return PRIV_EXTENSION; 171 return PRIV_EXTENSION;
173 } 172 }
174 173
175 // Determines whether the extension |origin| is legal to use in an Origin header 174 // Determines whether the extension |origin| is legal to use in an Origin header
176 // from the process identified by |child_id|. Returns CONTINUE if so, FAIL if 175 // from the process identified by |child_id|. Returns CONTINUE if so, FAIL if
177 // the extension is not recognized (and may recently have been uninstalled), and 176 // the extension is not recognized (and may recently have been uninstalled), and
178 // KILL if the origin is from a platform app but the request does not come from 177 // KILL if the origin is from a platform app but the request does not come from
179 // that app. 178 // that app.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 254
256 ChromeContentBrowserClientExtensionsPart:: 255 ChromeContentBrowserClientExtensionsPart::
257 ChromeContentBrowserClientExtensionsPart() { 256 ChromeContentBrowserClientExtensionsPart() {
258 } 257 }
259 258
260 ChromeContentBrowserClientExtensionsPart:: 259 ChromeContentBrowserClientExtensionsPart::
261 ~ChromeContentBrowserClientExtensionsPart() { 260 ~ChromeContentBrowserClientExtensionsPart() {
262 } 261 }
263 262
264 // static 263 // static
265 GURL ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(
266 Profile* profile, const GURL& url) {
267 // If the input |url| is part of an installed app, the effective URL is an
268 // extension URL with the ID of that extension as the host. This has the
269 // effect of grouping apps together in a common SiteInstance.
270 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
271 if (!registry)
272 return url;
273
274 const Extension* extension =
275 registry->enabled_extensions().GetHostedAppByURL(url);
276 if (!extension)
277 return url;
278
279 // Bookmark apps do not use the hosted app process model, and should be
280 // treated as normal URLs.
281 if (extension->from_bookmark())
282 return url;
283
284 // If the URL is part of an extension's web extent, convert it to an
285 // extension URL.
286 return extension->GetResourceURL(url.path());
287 }
288
289 // static
290 bool ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( 264 bool ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite(
291 Profile* profile, const GURL& effective_url) { 265 Profile* profile, const GURL& effective_url) {
292 if (!effective_url.SchemeIs(kExtensionScheme)) 266 if (!effective_url.SchemeIs(kExtensionScheme))
293 return false; 267 return false;
294 268
295 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); 269 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
296 if (!registry) 270 if (!registry)
297 return false; 271 return false;
298 272
299 const Extension* extension = 273 const Extension* extension =
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 384
411 // These may be NULL during tests. In that case, just assume any site can 385 // These may be NULL during tests. In that case, just assume any site can
412 // share any host. 386 // share any host.
413 if (!registry || !process_map) 387 if (!registry || !process_map)
414 return true; 388 return true;
415 389
416 // Otherwise, just make sure the process privilege matches the privilege 390 // Otherwise, just make sure the process privilege matches the privilege
417 // required by the site. 391 // required by the site.
418 RenderProcessHostPrivilege privilege_required = 392 RenderProcessHostPrivilege privilege_required =
419 GetPrivilegeRequiredByUrl(site_url, registry); 393 GetPrivilegeRequiredByUrl(site_url, registry);
420 return GetProcessPrivilege(process_host, process_map, registry) == 394 RenderProcessHostPrivilege privilege_of_process =
421 privilege_required; 395 GetProcessPrivilege(process_host, process_map, registry);
396 return privilege_of_process == privilege_required;
422 } 397 }
423 398
424 // static 399 // static
425 bool 400 bool
426 ChromeContentBrowserClientExtensionsPart::ShouldTryToUseExistingProcessHost( 401 ChromeContentBrowserClientExtensionsPart::ShouldTryToUseExistingProcessHost(
427 Profile* profile, const GURL& url) { 402 Profile* profile, const GURL& url) {
428 // This function is trying to limit the amount of processes used by extensions 403 // This function is trying to limit the amount of processes used by extensions
429 // with background pages. It uses a globally set percentage of processes to 404 // with background pages. It uses a globally set percentage of processes to
430 // run such extensions and if the limit is exceeded, it returns true, to 405 // run such extensions and if the limit is exceeded, it returns true, to
431 // indicate to the content module to group extensions together. 406 // indicate to the content module to group extensions together.
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 command_line->AppendSwitch(switches::kExtensionProcess); 859 command_line->AppendSwitch(switches::kExtensionProcess);
885 } 860 }
886 } 861 }
887 862
888 void ChromeContentBrowserClientExtensionsPart::ResourceDispatcherHostCreated() { 863 void ChromeContentBrowserClientExtensionsPart::ResourceDispatcherHostCreated() {
889 content::ResourceDispatcherHost::Get()->RegisterInterceptor( 864 content::ResourceDispatcherHost::Get()->RegisterInterceptor(
890 "Origin", kExtensionScheme, base::Bind(&OnHttpHeaderReceived)); 865 "Origin", kExtensionScheme, base::Bind(&OnHttpHeaderReceived));
891 } 866 }
892 867
893 } // namespace extensions 868 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698