OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 content::WebContentsView* | 400 content::WebContentsView* |
401 ChromeContentBrowserClient::OverrideCreateWebContentsView( | 401 ChromeContentBrowserClient::OverrideCreateWebContentsView( |
402 WebContents* web_contents, | 402 WebContents* web_contents, |
403 content::RenderViewHostDelegateView** render_view_host_delegate_view) { | 403 content::RenderViewHostDelegateView** render_view_host_delegate_view) { |
404 return NULL; | 404 return NULL; |
405 } | 405 } |
406 | 406 |
407 std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess( | 407 std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess( |
408 content::BrowserContext* browser_context, | 408 content::BrowserContext* browser_context, |
409 int child_process_id) { | 409 int child_process_id) { |
410 // In chrome, we use the extension ID as the partition ID. This works well | 410 const Extension* extension = NULL; |
411 // because the extension ID fits the partition ID pattern and currently only | |
412 // apps can designate that storage should be isolated. | |
413 Profile* profile = Profile::FromBrowserContext(browser_context); | 411 Profile* profile = Profile::FromBrowserContext(browser_context); |
414 ExtensionService* extension_service = | 412 ExtensionService* extension_service = |
415 extensions::ExtensionSystem::Get(profile)->extension_service(); | 413 extensions::ExtensionSystem::Get(profile)->extension_service(); |
416 if (extension_service) { | 414 if (extension_service) { |
417 const extensions::Extension* installed_app = extension_service-> | 415 extension = extension_service->GetInstalledAppForRenderer( |
418 GetInstalledAppForRenderer(child_process_id); | 416 child_process_id); |
419 if (installed_app && installed_app->is_storage_isolated()) { | |
420 return installed_app->id(); | |
421 } | |
422 } | 417 } |
423 return std::string(); | 418 |
| 419 return GetStoragePartitionIdForExtension(browser_context, extension); |
| 420 } |
| 421 |
| 422 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSiteInstance( |
| 423 content::BrowserContext* browser_context, |
| 424 SiteInstance* instance) { |
| 425 const Extension* extension = NULL; |
| 426 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 427 ExtensionService* extension_service = |
| 428 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 429 if (extension_service) { |
| 430 extension = extension_service->extensions()-> |
| 431 GetExtensionOrAppByURL(ExtensionURLInfo(instance->GetSite())); |
| 432 } |
| 433 |
| 434 return GetStoragePartitionIdForExtension(browser_context, extension); |
| 435 } |
| 436 |
| 437 bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 438 content::BrowserContext* browser_context, |
| 439 const std::string& partition_id) { |
| 440 // The default ID is empty which is always allowed. |
| 441 if (partition_id.empty()) |
| 442 return true; |
| 443 |
| 444 // If it isn't empty, then it must belong to an extension of some sort. Parse |
| 445 // out the extension ID and make sure it is still installed. |
| 446 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 447 ExtensionService* extension_service = |
| 448 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 449 if (!extension_service) { |
| 450 // No extension service means no storage partitions in Chrome. |
| 451 return false; |
| 452 } |
| 453 |
| 454 // See if we can find an extension. The |partition_id| is the extension ID so |
| 455 // no parsing needed to be done. |
| 456 return extension_service->GetExtensionById(partition_id, false) != NULL; |
424 } | 457 } |
425 | 458 |
426 content::WebContentsViewDelegate* | 459 content::WebContentsViewDelegate* |
427 ChromeContentBrowserClient::GetWebContentsViewDelegate( | 460 ChromeContentBrowserClient::GetWebContentsViewDelegate( |
428 content::WebContents* web_contents) { | 461 content::WebContents* web_contents) { |
429 return chrome::CreateWebContentsViewDelegate(web_contents); | 462 return chrome::CreateWebContentsViewDelegate(web_contents); |
430 } | 463 } |
431 | 464 |
432 void ChromeContentBrowserClient::RenderViewHostCreated( | 465 void ChromeContentBrowserClient::RenderViewHostCreated( |
433 RenderViewHost* render_view_host) { | 466 RenderViewHost* render_view_host) { |
(...skipping 1247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 base::Unretained(this), locale))) | 1714 base::Unretained(this), locale))) |
1682 io_thread_application_locale_ = locale; | 1715 io_thread_application_locale_ = locale; |
1683 } | 1716 } |
1684 | 1717 |
1685 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1718 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
1686 const std::string& locale) { | 1719 const std::string& locale) { |
1687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1720 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1688 io_thread_application_locale_ = locale; | 1721 io_thread_application_locale_ = locale; |
1689 } | 1722 } |
1690 | 1723 |
| 1724 std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension( |
| 1725 content::BrowserContext* browser_context, const Extension* extension) { |
| 1726 // In chrome, we use the extension ID as the partition ID. This works well |
| 1727 // because the extension ID fits the partition ID pattern and currently only |
| 1728 // apps can designate that storage should be isolated. |
| 1729 // |
| 1730 // If |extension| is NULL, then the default, empty string, partition id is |
| 1731 // used. |
| 1732 std::string partition_id; |
| 1733 if (extension && extension->is_storage_isolated()) { |
| 1734 partition_id = extension->id(); |
| 1735 } |
| 1736 |
| 1737 // Enforce that IsValidStoragePartitionId() implementation stays in sync. |
| 1738 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
| 1739 return partition_id; |
| 1740 } |
| 1741 |
| 1742 |
1691 } // namespace chrome | 1743 } // namespace chrome |
OLD | NEW |