| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // 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 |
| 172 // 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. |
| 173 // 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. |
| 174 // 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 |
| 175 // 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 |
| 176 // anyways. | 176 // anyways. |
| 177 if (!url.is_valid()) | 177 if (!url.is_valid()) |
| 178 return PRIV_NORMAL; | 178 return PRIV_NORMAL; |
| 179 | 179 |
| 180 if (url.SchemeIs(chrome::kExtensionScheme)) { | 180 if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 181 const Extension* extension = service->GetExtensionByURL(url); | 181 const Extension* extension = |
| 182 service->extensions()->GetByURL(ExtensionURLInfo(url)); |
| 182 if (extension && extension->is_storage_isolated()) | 183 if (extension && extension->is_storage_isolated()) |
| 183 return PRIV_ISOLATED; | 184 return PRIV_ISOLATED; |
| 184 if (extension && extension->is_hosted_app()) | 185 if (extension && extension->is_hosted_app()) |
| 185 return PRIV_HOSTED; | 186 return PRIV_HOSTED; |
| 186 | 187 |
| 187 return PRIV_EXTENSION; | 188 return PRIV_EXTENSION; |
| 188 } | 189 } |
| 189 | 190 |
| 190 return PRIV_NORMAL; | 191 return PRIV_NORMAL; |
| 191 } | 192 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 content::BrowserContext* browser_context, const GURL& url) { | 371 content::BrowserContext* browser_context, const GURL& url) { |
| 371 Profile* profile = Profile::FromBrowserContext(browser_context); | 372 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 372 // Get the effective URL for the given actual URL. If the URL is part of an | 373 // Get the effective URL for the given actual URL. If the URL is part of an |
| 373 // installed app, the effective URL is an extension URL with the ID of that | 374 // installed app, the effective URL is an extension URL with the ID of that |
| 374 // extension as the host. This has the effect of grouping apps together in | 375 // extension as the host. This has the effect of grouping apps together in |
| 375 // a common SiteInstance. | 376 // a common SiteInstance. |
| 376 if (!profile || !profile->GetExtensionService()) | 377 if (!profile || !profile->GetExtensionService()) |
| 377 return url; | 378 return url; |
| 378 | 379 |
| 379 const Extension* extension = | 380 const Extension* extension = |
| 380 profile->GetExtensionService()->GetExtensionByWebExtent(url); | 381 profile->GetExtensionService()->extensions()->GetByWebExtent(url); |
| 381 if (!extension) | 382 if (!extension) |
| 382 return url; | 383 return url; |
| 383 | 384 |
| 384 // Bookmark apps do not use the hosted app process model, and should be | 385 // Bookmark apps do not use the hosted app process model, and should be |
| 385 // treated as normal URLs. | 386 // treated as normal URLs. |
| 386 if (extension->from_bookmark()) | 387 if (extension->from_bookmark()) |
| 387 return url; | 388 return url; |
| 388 | 389 |
| 389 // If the URL is part of an extension's web extent, convert it to an | 390 // If the URL is part of an extension's web extent, convert it to an |
| 390 // extension URL. | 391 // extension URL. |
| 391 return extension->GetResourceURL(url.path()); | 392 return extension->GetResourceURL(url.path()); |
| 392 } | 393 } |
| 393 | 394 |
| 394 bool ChromeContentBrowserClient::ShouldUseProcessPerSite( | 395 bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
| 395 content::BrowserContext* browser_context, const GURL& effective_url) { | 396 content::BrowserContext* browser_context, const GURL& effective_url) { |
| 396 // Non-extension URLs should generally use process-per-site-instance. | 397 // Non-extension URLs should generally use process-per-site-instance. |
| 397 // Because we expect to use the effective URL, URLs for hosted apps (apart | 398 // Because we expect to use the effective URL, URLs for hosted apps (apart |
| 398 // from bookmark apps) should have an extension scheme by now. | 399 // from bookmark apps) should have an extension scheme by now. |
| 399 if (!effective_url.SchemeIs(chrome::kExtensionScheme)) | 400 if (!effective_url.SchemeIs(chrome::kExtensionScheme)) |
| 400 return false; | 401 return false; |
| 401 | 402 |
| 402 Profile* profile = Profile::FromBrowserContext(browser_context); | 403 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 403 if (!profile || !profile->GetExtensionService()) | 404 if (!profile || !profile->GetExtensionService()) |
| 404 return false; | 405 return false; |
| 405 | 406 |
| 406 const Extension* extension = | 407 const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 407 profile->GetExtensionService()->GetExtensionByURL(effective_url); | 408 GetByURL(ExtensionURLInfo(effective_url)); |
| 408 if (!extension) | 409 if (!extension) |
| 409 return false; | 410 return false; |
| 410 | 411 |
| 411 // If the URL is part of a hosted app that does not have the background | 412 // If the URL is part of a hosted app that does not have the background |
| 412 // permission, we want to give each instance its own process to improve | 413 // permission, we want to give each instance its own process to improve |
| 413 // responsiveness. | 414 // responsiveness. |
| 414 if (extension->GetType() == Extension::TYPE_HOSTED_APP && | 415 if (extension->GetType() == Extension::TYPE_HOSTED_APP && |
| 415 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) | 416 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) |
| 416 return false; | 417 return false; |
| 417 | 418 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 SiteInstance* site_instance) { | 479 SiteInstance* site_instance) { |
| 479 CHECK(site_instance->HasProcess()); | 480 CHECK(site_instance->HasProcess()); |
| 480 | 481 |
| 481 Profile* profile = Profile::FromBrowserContext( | 482 Profile* profile = Profile::FromBrowserContext( |
| 482 site_instance->browsing_instance()->browser_context()); | 483 site_instance->browsing_instance()->browser_context()); |
| 483 ExtensionService* service = profile->GetExtensionService(); | 484 ExtensionService* service = profile->GetExtensionService(); |
| 484 if (!service) | 485 if (!service) |
| 485 return; | 486 return; |
| 486 | 487 |
| 487 const Extension* extension = | 488 const Extension* extension = |
| 488 service->GetExtensionByURL(site_instance->site()); | 489 service->extensions()->GetByURL(ExtensionURLInfo(site_instance->site())); |
| 489 if (!extension) | |
| 490 extension = service->GetExtensionByWebExtent(site_instance->site()); | |
| 491 if (!extension) | 490 if (!extension) |
| 492 return; | 491 return; |
| 493 | 492 |
| 494 service->process_map()->Insert(extension->id(), | 493 service->process_map()->Insert(extension->id(), |
| 495 site_instance->GetProcess()->GetID(), | 494 site_instance->GetProcess()->GetID(), |
| 496 site_instance->id()); | 495 site_instance->id()); |
| 497 BrowserThread::PostTask( | 496 BrowserThread::PostTask( |
| 498 BrowserThread::IO, FROM_HERE, | 497 BrowserThread::IO, FROM_HERE, |
| 499 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, | 498 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, |
| 500 profile->GetExtensionInfoMap(), | 499 profile->GetExtensionInfoMap(), |
| 501 extension->id(), | 500 extension->id(), |
| 502 site_instance->GetProcess()->GetID(), | 501 site_instance->GetProcess()->GetID(), |
| 503 site_instance->id())); | 502 site_instance->id())); |
| 504 } | 503 } |
| 505 | 504 |
| 506 void ChromeContentBrowserClient::SiteInstanceDeleting( | 505 void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 507 SiteInstance* site_instance) { | 506 SiteInstance* site_instance) { |
| 508 if (!site_instance->HasProcess()) | 507 if (!site_instance->HasProcess()) |
| 509 return; | 508 return; |
| 510 | 509 |
| 511 Profile* profile = Profile::FromBrowserContext( | 510 Profile* profile = Profile::FromBrowserContext( |
| 512 site_instance->browsing_instance()->browser_context()); | 511 site_instance->browsing_instance()->browser_context()); |
| 513 ExtensionService* service = profile->GetExtensionService(); | 512 ExtensionService* service = profile->GetExtensionService(); |
| 514 if (!service) | 513 if (!service) |
| 515 return; | 514 return; |
| 516 | 515 |
| 517 const Extension* extension = | 516 const Extension* extension = |
| 518 service->GetExtensionByURL(site_instance->site()); | 517 service->extensions()->GetByURL(ExtensionURLInfo(site_instance->site())); |
| 519 if (!extension) | |
| 520 extension = service->GetExtensionByWebExtent(site_instance->site()); | |
| 521 if (!extension) | 518 if (!extension) |
| 522 return; | 519 return; |
| 523 | 520 |
| 524 service->process_map()->Remove(extension->id(), | 521 service->process_map()->Remove(extension->id(), |
| 525 site_instance->GetProcess()->GetID(), | 522 site_instance->GetProcess()->GetID(), |
| 526 site_instance->id()); | 523 site_instance->id()); |
| 527 BrowserThread::PostTask( | 524 BrowserThread::PostTask( |
| 528 BrowserThread::IO, FROM_HERE, | 525 BrowserThread::IO, FROM_HERE, |
| 529 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, | 526 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, |
| 530 profile->GetExtensionInfoMap(), | 527 profile->GetExtensionInfoMap(), |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 #if defined(USE_NSS) | 1208 #if defined(USE_NSS) |
| 1212 crypto::CryptoModuleBlockingPasswordDelegate* | 1209 crypto::CryptoModuleBlockingPasswordDelegate* |
| 1213 ChromeContentBrowserClient::GetCryptoPasswordDelegate( | 1210 ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 1214 const GURL& url) { | 1211 const GURL& url) { |
| 1215 return browser::NewCryptoModuleBlockingDialogDelegate( | 1212 return browser::NewCryptoModuleBlockingDialogDelegate( |
| 1216 browser::kCryptoModulePasswordKeygen, url.host()); | 1213 browser::kCryptoModulePasswordKeygen, url.host()); |
| 1217 } | 1214 } |
| 1218 #endif | 1215 #endif |
| 1219 | 1216 |
| 1220 } // namespace chrome | 1217 } // namespace chrome |
| OLD | NEW |