| Index: chrome/browser/chrome_content_browser_client.cc
|
| diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
|
| index 6d6248dc00e0d0d9755a92fed21855274ab44620..ad1cd1b7f54a6200f43dbd23842545a10951d46e 100644
|
| --- a/chrome/browser/chrome_content_browser_client.cc
|
| +++ b/chrome/browser/chrome_content_browser_client.cc
|
| @@ -407,20 +407,53 @@ content::WebContentsView*
|
| std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
|
| content::BrowserContext* browser_context,
|
| int child_process_id) {
|
| - // In chrome, we use the extension ID as the partition ID. This works well
|
| - // because the extension ID fits the partition ID pattern and currently only
|
| - // apps can designate that storage should be isolated.
|
| + const Extension* extension = NULL;
|
| Profile* profile = Profile::FromBrowserContext(browser_context);
|
| ExtensionService* extension_service =
|
| extensions::ExtensionSystem::Get(profile)->extension_service();
|
| if (extension_service) {
|
| - const extensions::Extension* installed_app = extension_service->
|
| - GetInstalledAppForRenderer(child_process_id);
|
| - if (installed_app && installed_app->is_storage_isolated()) {
|
| - return installed_app->id();
|
| - }
|
| + extension = extension_service->GetInstalledAppForRenderer(
|
| + child_process_id);
|
| + }
|
| +
|
| + return GetStoragePartitionIdForExtension(browser_context, extension);
|
| +}
|
| +
|
| +std::string ChromeContentBrowserClient::GetStoragePartitionIdForSiteInstance(
|
| + content::BrowserContext* browser_context,
|
| + SiteInstance* instance) {
|
| + const Extension* extension = NULL;
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + ExtensionService* extension_service =
|
| + extensions::ExtensionSystem::Get(profile)->extension_service();
|
| + if (extension_service) {
|
| + extension = extension_service->extensions()->
|
| + GetExtensionOrAppByURL(ExtensionURLInfo(instance->GetSite()));
|
| + }
|
| +
|
| + return GetStoragePartitionIdForExtension(browser_context, extension);
|
| +}
|
| +
|
| +bool ChromeContentBrowserClient::IsValidStoragePartitionId(
|
| + content::BrowserContext* browser_context,
|
| + const std::string& partition_id) {
|
| + // The default ID is empty which is always allowed.
|
| + if (partition_id.empty())
|
| + return true;
|
| +
|
| + // If it isn't empty, then it must belong to an extension of some sort. Parse
|
| + // out the extension ID and make sure it is still installed.
|
| + Profile* profile = Profile::FromBrowserContext(browser_context);
|
| + ExtensionService* extension_service =
|
| + extensions::ExtensionSystem::Get(profile)->extension_service();
|
| + if (!extension_service) {
|
| + // No extension service means no storage partitions in Chrome.
|
| + return false;
|
| }
|
| - return std::string();
|
| +
|
| + // See if we can find an extension. The |partition_id| is the extension ID so
|
| + // no parsing needed to be done.
|
| + return extension_service->GetExtensionById(partition_id, false) != NULL;
|
| }
|
|
|
| content::WebContentsViewDelegate*
|
| @@ -1688,4 +1721,23 @@ void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
|
| io_thread_application_locale_ = locale;
|
| }
|
|
|
| +std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension(
|
| + content::BrowserContext* browser_context, const Extension* extension) {
|
| + // In chrome, we use the extension ID as the partition ID. This works well
|
| + // because the extension ID fits the partition ID pattern and currently only
|
| + // apps can designate that storage should be isolated.
|
| + //
|
| + // If |extension| is NULL, then the default, empty string, partition id is
|
| + // used.
|
| + std::string partition_id;
|
| + if (extension && extension->is_storage_isolated()) {
|
| + partition_id = extension->id();
|
| + }
|
| +
|
| + // Enforce that IsValidStoragePartitionId() implementation stays in sync.
|
| + DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
|
| + return partition_id;
|
| +}
|
| +
|
| +
|
| } // namespace chrome
|
|
|