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

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 8677026: Update process sharing rules for hosted and isolated apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 return true; 157 return true;
158 } 158 }
159 159
160 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions 160 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
161 // below. Extension, and isolated apps require different privileges to be 161 // below. Extension, and isolated apps require different privileges to be
162 // granted to their RenderProcessHosts. This classification allows us to make 162 // granted to their RenderProcessHosts. This classification allows us to make
163 // sure URLs are served by hosts with the right set of privileges. 163 // sure URLs are served by hosts with the right set of privileges.
164 enum RenderProcessHostPrivilege { 164 enum RenderProcessHostPrivilege {
165 PRIV_NORMAL, 165 PRIV_NORMAL,
166 PRIV_HOSTED,
167 PRIV_ISOLATED,
166 PRIV_EXTENSION, 168 PRIV_EXTENSION,
167 PRIV_ISOLATED,
168 }; 169 };
169 170
170 RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( 171 RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
171 const GURL& url, 172 const GURL& url,
172 ExtensionService* service) { 173 ExtensionService* service) {
173 // Default to a normal renderer cause it is lower privileged. This should only 174 // Default to a normal renderer cause it is lower privileged. This should only
174 // occur if the URL on a site instance is either malformed, or uninitialized. 175 // occur if the URL on a site instance is either malformed, or uninitialized.
175 // If it is malformed, then there is no need for better privileges anyways. 176 // If it is malformed, then there is no need for better privileges anyways.
176 // If it is uninitialized, but eventually settles on being an a scheme other 177 // If it is uninitialized, but eventually settles on being an a scheme other
177 // than normal webrenderer, the navigation logic will correct us out of band 178 // than normal webrenderer, the navigation logic will correct us out of band
178 // anyways. 179 // anyways.
179 if (!url.is_valid()) 180 if (!url.is_valid())
180 return PRIV_NORMAL; 181 return PRIV_NORMAL;
181 182
182 if (url.SchemeIs(chrome::kExtensionScheme)) { 183 if (url.SchemeIs(chrome::kExtensionScheme)) {
183 const Extension* extension = service->GetExtensionByURL(url); 184 const Extension* extension = service->GetExtensionByURL(url);
184 if (extension && extension->is_storage_isolated()) { 185 if (extension && extension->is_storage_isolated())
185 return PRIV_ISOLATED; 186 return PRIV_ISOLATED;
186 } 187 if (extension && extension->is_hosted_app())
188 return PRIV_HOSTED;
187 189
188 return PRIV_EXTENSION; 190 return PRIV_EXTENSION;
189 } 191 }
190 192
191 return PRIV_NORMAL; 193 return PRIV_NORMAL;
192 } 194 }
193 195
194 RenderProcessHostPrivilege GetProcessPrivilege( 196 RenderProcessHostPrivilege GetProcessPrivilege(
195 content::RenderProcessHost* process_host, 197 content::RenderProcessHost* process_host,
196 extensions::ProcessMap* process_map, 198 extensions::ProcessMap* process_map,
197 ExtensionService* service) { 199 ExtensionService* service) {
198 // TODO(aa): It seems like hosted apps should be grouped separately from
199 // extensions: crbug.com/102533.
200 std::set<std::string> extension_ids = 200 std::set<std::string> extension_ids =
201 process_map->GetExtensionsInProcess(process_host->GetID()); 201 process_map->GetExtensionsInProcess(process_host->GetID());
202 if (extension_ids.empty()) 202 if (extension_ids.empty())
203 return PRIV_NORMAL; 203 return PRIV_NORMAL;
204 204
205 for (std::set<std::string>::iterator iter = extension_ids.begin(); 205 for (std::set<std::string>::iterator iter = extension_ids.begin();
206 iter != extension_ids.end(); ++iter) { 206 iter != extension_ids.end(); ++iter) {
207 const Extension* extension = service->GetExtensionById(*iter, false); 207 const Extension* extension = service->GetExtensionById(*iter, false);
208 if (extension && extension->is_storage_isolated()) 208 if (extension && extension->is_storage_isolated())
209 return PRIV_ISOLATED; 209 return PRIV_ISOLATED;
210 if (extension && extension->is_hosted_app())
211 return PRIV_HOSTED;
210 } 212 }
211 213
212 return PRIV_EXTENSION; 214 return PRIV_EXTENSION;
213 } 215 }
214 216
217 bool IsIsolatedAppInProcess(const GURL& site_url,
218 content::RenderProcessHost* process_host,
219 extensions::ProcessMap* process_map,
220 ExtensionService* service) {
221 std::set<std::string> extension_ids =
222 process_map->GetExtensionsInProcess(process_host->GetID());
223 if (extension_ids.empty())
224 return false;
225
226 for (std::set<std::string>::iterator iter = extension_ids.begin();
227 iter != extension_ids.end(); ++iter) {
228 const Extension* extension = service->GetExtensionById(*iter, false);
229 if (extension &&
230 extension->url() == site_url &&
231 extension->is_storage_isolated())
awong 2011/11/24 00:03:49 nit: check is_storage_isolated() first. Might as
Charlie Reis 2011/11/24 00:26:45 Done.
232 return true;
233 }
234
235 return false;
236 }
237
215 } // namespace 238 } // namespace
216 239
217 namespace chrome { 240 namespace chrome {
218 241
219 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( 242 content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
220 const content::MainFunctionParams& parameters) { 243 const content::MainFunctionParams& parameters) {
221 ChromeBrowserMainParts* main_parts; 244 ChromeBrowserMainParts* main_parts;
222 // Construct the Main browser parts based on the OS type. 245 // Construct the Main browser parts based on the OS type.
223 #if defined(OS_WIN) 246 #if defined(OS_WIN)
224 main_parts = new ChromeBrowserMainPartsWin(parameters); 247 main_parts = new ChromeBrowserMainPartsWin(parameters);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // Experimental: 437 // Experimental:
415 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages 438 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
416 // to share a renderer process. (We could allow pages from the same site or 439 // to share a renderer process. (We could allow pages from the same site or
417 // extensions of the same type to share, if we knew what the given process 440 // extensions of the same type to share, if we knew what the given process
418 // was dedicated to. Allowing no sharing is simpler for now.) This may 441 // was dedicated to. Allowing no sharing is simpler for now.) This may
419 // cause resource exhaustion issues if too many sites are open at once. 442 // cause resource exhaustion issues if too many sites are open at once.
420 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 443 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
421 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) 444 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
422 return false; 445 return false;
423 446
447 // An isolated app is only allowed to share with the exact same app.
awong 2011/11/24 00:03:49 Add short sentence for why?
Charlie Reis 2011/11/24 00:26:45 Done.
448 RenderProcessHostPrivilege privilege_required =
449 GetPrivilegeRequiredByUrl(site_url, service);
450 if (privilege_required == PRIV_ISOLATED)
451 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
awong 2011/11/24 00:03:49 Sad that we have to double-iterate the extension m
Charlie Reis 2011/11/24 00:26:45 We don't, do we? We either iterate it in IsIsolat
awong 2011/11/24 00:31:28 You're right...I'm just mis-reading.
452
453 // Otherwise, just make sure the process privilege matches the privilege
454 // required by the site.
424 return GetProcessPrivilege(process_host, process_map, service) == 455 return GetProcessPrivilege(process_host, process_map, service) ==
425 GetPrivilegeRequiredByUrl(site_url, service); 456 privilege_required;
426 } 457 }
427 458
428 void ChromeContentBrowserClient::SiteInstanceGotProcess( 459 void ChromeContentBrowserClient::SiteInstanceGotProcess(
429 SiteInstance* site_instance) { 460 SiteInstance* site_instance) {
430 CHECK(site_instance->HasProcess()); 461 CHECK(site_instance->HasProcess());
431 462
432 Profile* profile = Profile::FromBrowserContext( 463 Profile* profile = Profile::FromBrowserContext(
433 site_instance->browsing_instance()->browser_context()); 464 site_instance->browsing_instance()->browser_context());
434 ExtensionService* service = profile->GetExtensionService(); 465 ExtensionService* service = profile->GetExtensionService();
435 if (!service) 466 if (!service)
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 #if defined(USE_NSS) 1144 #if defined(USE_NSS)
1114 crypto::CryptoModuleBlockingPasswordDelegate* 1145 crypto::CryptoModuleBlockingPasswordDelegate*
1115 ChromeContentBrowserClient::GetCryptoPasswordDelegate( 1146 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1116 const GURL& url) { 1147 const GURL& url) {
1117 return browser::NewCryptoModuleBlockingDialogDelegate( 1148 return browser::NewCryptoModuleBlockingDialogDelegate(
1118 browser::kCryptoModulePasswordKeygen, url.host()); 1149 browser::kCryptoModulePasswordKeygen, url.host());
1119 } 1150 }
1120 #endif 1151 #endif
1121 1152
1122 } // namespace chrome 1153 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_info_map.cc » ('j') | chrome/browser/extensions/extension_info_map.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698