OLD | NEW |
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions | 157 // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
158 // below. Extension, and isolated apps require different privileges to be | 158 // below. Extension, and isolated apps require different privileges to be |
159 // granted to their RenderProcessHosts. This classification allows us to make | 159 // granted to their RenderProcessHosts. This classification allows us to make |
160 // sure URLs are served by hosts with the right set of privileges. | 160 // sure URLs are served by hosts with the right set of privileges. |
161 enum RenderProcessHostPrivilege { | 161 enum RenderProcessHostPrivilege { |
162 PRIV_NORMAL, | 162 PRIV_NORMAL, |
| 163 PRIV_HOSTED, |
| 164 PRIV_ISOLATED, |
163 PRIV_EXTENSION, | 165 PRIV_EXTENSION, |
164 PRIV_ISOLATED, | |
165 }; | 166 }; |
166 | 167 |
167 RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( | 168 RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
168 const GURL& url, | 169 const GURL& url, |
169 ExtensionService* service) { | 170 ExtensionService* service) { |
170 // Default to a normal renderer cause it is lower privileged. This should only | 171 // Default to a normal renderer cause it is lower privileged. This should only |
171 // occur if the URL on a site instance is either malformed, or uninitialized. | 172 // occur if the URL on a site instance is either malformed, or uninitialized. |
172 // If it is malformed, then there is no need for better privileges anyways. | 173 // If it is malformed, then there is no need for better privileges anyways. |
173 // If it is uninitialized, but eventually settles on being an a scheme other | 174 // If it is uninitialized, but eventually settles on being an a scheme other |
174 // than normal webrenderer, the navigation logic will correct us out of band | 175 // than normal webrenderer, the navigation logic will correct us out of band |
175 // anyways. | 176 // anyways. |
176 if (!url.is_valid()) | 177 if (!url.is_valid()) |
177 return PRIV_NORMAL; | 178 return PRIV_NORMAL; |
178 | 179 |
179 if (url.SchemeIs(chrome::kExtensionScheme)) { | 180 if (url.SchemeIs(chrome::kExtensionScheme)) { |
180 const Extension* extension = service->GetExtensionByURL(url); | 181 const Extension* extension = service->GetExtensionByURL(url); |
181 if (extension && extension->is_storage_isolated()) { | 182 if (extension && extension->is_storage_isolated()) |
182 return PRIV_ISOLATED; | 183 return PRIV_ISOLATED; |
183 } | 184 if (extension && extension->is_hosted_app()) |
| 185 return PRIV_HOSTED; |
184 | 186 |
185 return PRIV_EXTENSION; | 187 return PRIV_EXTENSION; |
186 } | 188 } |
187 | 189 |
188 return PRIV_NORMAL; | 190 return PRIV_NORMAL; |
189 } | 191 } |
190 | 192 |
191 RenderProcessHostPrivilege GetProcessPrivilege( | 193 RenderProcessHostPrivilege GetProcessPrivilege( |
192 content::RenderProcessHost* process_host, | 194 content::RenderProcessHost* process_host, |
193 extensions::ProcessMap* process_map, | 195 extensions::ProcessMap* process_map, |
194 ExtensionService* service) { | 196 ExtensionService* service) { |
195 // TODO(aa): It seems like hosted apps should be grouped separately from | |
196 // extensions: crbug.com/102533. | |
197 std::set<std::string> extension_ids = | 197 std::set<std::string> extension_ids = |
198 process_map->GetExtensionsInProcess(process_host->GetID()); | 198 process_map->GetExtensionsInProcess(process_host->GetID()); |
199 if (extension_ids.empty()) | 199 if (extension_ids.empty()) |
200 return PRIV_NORMAL; | 200 return PRIV_NORMAL; |
201 | 201 |
202 for (std::set<std::string>::iterator iter = extension_ids.begin(); | 202 for (std::set<std::string>::iterator iter = extension_ids.begin(); |
203 iter != extension_ids.end(); ++iter) { | 203 iter != extension_ids.end(); ++iter) { |
204 const Extension* extension = service->GetExtensionById(*iter, false); | 204 const Extension* extension = service->GetExtensionById(*iter, false); |
205 if (extension && extension->is_storage_isolated()) | 205 if (extension && extension->is_storage_isolated()) |
206 return PRIV_ISOLATED; | 206 return PRIV_ISOLATED; |
| 207 if (extension && extension->is_hosted_app()) |
| 208 return PRIV_HOSTED; |
207 } | 209 } |
208 | 210 |
209 return PRIV_EXTENSION; | 211 return PRIV_EXTENSION; |
210 } | 212 } |
211 | 213 |
| 214 bool IsIsolatedAppInProcess(const GURL& site_url, |
| 215 content::RenderProcessHost* process_host, |
| 216 extensions::ProcessMap* process_map, |
| 217 ExtensionService* service) { |
| 218 std::set<std::string> extension_ids = |
| 219 process_map->GetExtensionsInProcess(process_host->GetID()); |
| 220 if (extension_ids.empty()) |
| 221 return false; |
| 222 |
| 223 for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 224 iter != extension_ids.end(); ++iter) { |
| 225 const Extension* extension = service->GetExtensionById(*iter, false); |
| 226 if (extension && |
| 227 extension->is_storage_isolated() && |
| 228 extension->url() == site_url) |
| 229 return true; |
| 230 } |
| 231 |
| 232 return false; |
| 233 } |
| 234 |
212 bool CertMatchesFilter(const net::X509Certificate& cert, | 235 bool CertMatchesFilter(const net::X509Certificate& cert, |
213 const base::DictionaryValue& filter) { | 236 const base::DictionaryValue& filter) { |
214 // TODO(markusheintz): This is the minimal required filter implementation. | 237 // TODO(markusheintz): This is the minimal required filter implementation. |
215 // Implement a better matcher. | 238 // Implement a better matcher. |
216 | 239 |
217 // An empty filter matches any client certificate since no requirements are | 240 // An empty filter matches any client certificate since no requirements are |
218 // specified at all. | 241 // specified at all. |
219 if (filter.empty()) | 242 if (filter.empty()) |
220 return true; | 243 return true; |
221 | 244 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 // Experimental: | 452 // Experimental: |
430 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages | 453 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages |
431 // to share a renderer process. (We could allow pages from the same site or | 454 // to share a renderer process. (We could allow pages from the same site or |
432 // extensions of the same type to share, if we knew what the given process | 455 // extensions of the same type to share, if we knew what the given process |
433 // was dedicated to. Allowing no sharing is simpler for now.) This may | 456 // was dedicated to. Allowing no sharing is simpler for now.) This may |
434 // cause resource exhaustion issues if too many sites are open at once. | 457 // cause resource exhaustion issues if too many sites are open at once. |
435 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 458 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
436 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) | 459 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) |
437 return false; | 460 return false; |
438 | 461 |
| 462 // An isolated app is only allowed to share with the exact same app in order |
| 463 // to provide complete renderer process isolation. This also works around |
| 464 // issue http://crbug.com/85588, where different isolated apps in the same |
| 465 // process would end up using the first app's storage contexts. |
| 466 RenderProcessHostPrivilege privilege_required = |
| 467 GetPrivilegeRequiredByUrl(site_url, service); |
| 468 if (privilege_required == PRIV_ISOLATED) |
| 469 return IsIsolatedAppInProcess(site_url, process_host, process_map, service); |
| 470 |
| 471 // Otherwise, just make sure the process privilege matches the privilege |
| 472 // required by the site. |
439 return GetProcessPrivilege(process_host, process_map, service) == | 473 return GetProcessPrivilege(process_host, process_map, service) == |
440 GetPrivilegeRequiredByUrl(site_url, service); | 474 privilege_required; |
441 } | 475 } |
442 | 476 |
443 void ChromeContentBrowserClient::SiteInstanceGotProcess( | 477 void ChromeContentBrowserClient::SiteInstanceGotProcess( |
444 SiteInstance* site_instance) { | 478 SiteInstance* site_instance) { |
445 CHECK(site_instance->HasProcess()); | 479 CHECK(site_instance->HasProcess()); |
446 | 480 |
447 Profile* profile = Profile::FromBrowserContext( | 481 Profile* profile = Profile::FromBrowserContext( |
448 site_instance->browsing_instance()->browser_context()); | 482 site_instance->browsing_instance()->browser_context()); |
449 ExtensionService* service = profile->GetExtensionService(); | 483 ExtensionService* service = profile->GetExtensionService(); |
450 if (!service) | 484 if (!service) |
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 #if defined(USE_NSS) | 1211 #if defined(USE_NSS) |
1178 crypto::CryptoModuleBlockingPasswordDelegate* | 1212 crypto::CryptoModuleBlockingPasswordDelegate* |
1179 ChromeContentBrowserClient::GetCryptoPasswordDelegate( | 1213 ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
1180 const GURL& url) { | 1214 const GURL& url) { |
1181 return browser::NewCryptoModuleBlockingDialogDelegate( | 1215 return browser::NewCryptoModuleBlockingDialogDelegate( |
1182 browser::kCryptoModulePasswordKeygen, url.host()); | 1216 browser::kCryptoModulePasswordKeygen, url.host()); |
1183 } | 1217 } |
1184 #endif | 1218 #endif |
1185 | 1219 |
1186 } // namespace chrome | 1220 } // namespace chrome |
OLD | NEW |