Chromium Code Reviews| 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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 | 497 |
| 498 return GURL(partition_id).is_valid(); | 498 return GURL(partition_id).is_valid(); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( | 501 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
| 502 content::BrowserContext* browser_context, | 502 content::BrowserContext* browser_context, |
| 503 const GURL& site, | 503 const GURL& site, |
| 504 std::string* partition_domain, | 504 std::string* partition_domain, |
| 505 std::string* partition_name, | 505 std::string* partition_name, |
| 506 bool* in_memory) { | 506 bool* in_memory) { |
| 507 // Handle sites that may not use the default storage partition. | |
| 508 if (site.SchemeIs(chrome::kGuestScheme)) { | |
| 509 ParseNonDefaultStoragePartitionConfig(site, partition_domain, | |
| 510 partition_name, in_memory); | |
|
Charlie Reis
2012/11/16 01:45:10
nit: Wrong indent.
| |
| 511 return; | |
| 512 } | |
| 513 | |
| 514 const Extension* extension = NULL; | |
| 515 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 516 ExtensionService* extension_service = | |
| 517 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 518 if (extension_service) { | |
| 519 extension = extension_service->extensions()-> | |
| 520 GetExtensionOrAppByURL(ExtensionURLInfo(site)); | |
| 521 if (extension && extension->is_storage_isolated()) { | |
| 522 ParseNonDefaultStoragePartitionConfig(site, partition_domain, | |
| 523 partition_name, in_memory); | |
| 524 return; | |
| 525 } | |
| 526 } | |
| 527 | |
| 528 // All other cases use the default, browser-wide, storage partition. | |
| 529 partition_domain->clear(); | |
| 530 partition_name->clear(); | |
| 531 *in_memory = false; | |
| 532 } | |
| 533 | |
| 534 void ChromeContentBrowserClient::ParseNonDefaultStoragePartitionConfig( | |
| 535 const GURL& site, | |
| 536 std::string* partition_domain, | |
| 537 std::string* partition_name, | |
| 538 bool* in_memory) { | |
| 507 // For the webview tag, we create special guest processes, which host the | 539 // For the webview tag, we create special guest processes, which host the |
| 508 // tag content separately from the main application that embeds the tag. | 540 // tag content separately from the main application that embeds the tag. |
| 509 // A webview tag can specify both the partition name and whether the storage | 541 // A webview tag can specify both the partition name and whether the storage |
| 510 // for that partition should be persisted. Each tag gets a SiteInstance with | 542 // for that partition should be persisted. Each tag gets a SiteInstance with |
| 511 // a specially formatted URL, based on the application it is hosted by and | 543 // a specially formatted URL, based on the application it is hosted by and |
| 512 // the partition requested by it. The format for that URL is: | 544 // the partition requested by it. The format for that URL is: |
| 513 // chrome-guest://partition_domain/persist?partition_name | 545 // chrome-guest://partition_domain/persist?partition_name |
| 514 if (site.SchemeIs(chrome::kGuestScheme)) { | 546 if (site.SchemeIs(chrome::kGuestScheme)) { |
| 515 // Since guest URLs are only used for packaged apps, there must be an app | 547 // Since guest URLs are only used for packaged apps, there must be an app |
| 516 // id in the URL. | 548 // id in the URL. |
| 517 CHECK(site.has_host()); | 549 CHECK(site.has_host()); |
| 518 *partition_domain = site.host(); | 550 *partition_domain = site.host(); |
| 519 // Since persistence is optional, the path must either be empty or the | 551 // Since persistence is optional, the path must either be empty or the |
| 520 // literal string. | 552 // literal string. |
| 521 *in_memory = (site.path() != "/persist"); | 553 *in_memory = (site.path() != "/persist"); |
| 522 // The partition name is user supplied value, which we have encoded when the | 554 // The partition name is user supplied value, which we have encoded when the |
| 523 // URL was created, so it needs to be decoded. | 555 // URL was created, so it needs to be decoded. |
| 524 *partition_name = net::UnescapeURLComponent(site.query(), | 556 *partition_name = net::UnescapeURLComponent(site.query(), |
| 525 net::UnescapeRule::NORMAL); | 557 net::UnescapeRule::NORMAL); |
| 558 } else if (site.SchemeIs(extensions::kExtensionScheme)) { | |
| 559 CHECK(site.has_host()); | |
| 560 // This function assumes the extension has isolated storage. For such sites, | |
| 561 // the host of the |site| is the |partition_domain|. The |in_memory| and | |
| 562 // |partition_name| are only used in guest schemes so they are cleared | |
| 563 // here. | |
| 564 *partition_domain = site.host(); | |
| 565 *in_memory = false; | |
| 566 partition_name->clear(); | |
| 567 } else { | |
| 568 // Serious logic error if this is being called on a |site| with an | |
| 569 // unexpected format. | |
| 570 LOG(FATAL) << "site has unexpected format: " << site; | |
| 526 return; | 571 return; |
| 527 } | 572 } |
| 528 | |
| 529 const Extension* extension = NULL; | |
| 530 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 531 ExtensionService* extension_service = | |
| 532 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
| 533 if (extension_service) { | |
| 534 extension = extension_service->extensions()-> | |
| 535 GetExtensionOrAppByURL(ExtensionURLInfo(site)); | |
| 536 if (extension && extension->is_storage_isolated()) { | |
| 537 // Extensions which have storage isolation enabled (e.g., apps), use | |
| 538 // the extension id as the |partition_domain|. | |
| 539 *partition_domain = extension->id(); | |
| 540 partition_name->clear(); | |
| 541 *in_memory = false; | |
| 542 return; | |
| 543 } | |
| 544 } | |
| 545 | |
| 546 // All other cases use the default, browser-wide, storage partition. | |
| 547 partition_domain->clear(); | |
| 548 partition_name->clear(); | |
| 549 *in_memory = false; | |
| 550 } | 573 } |
| 551 | 574 |
| 552 content::WebContentsViewDelegate* | 575 content::WebContentsViewDelegate* |
| 553 ChromeContentBrowserClient::GetWebContentsViewDelegate( | 576 ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 554 content::WebContents* web_contents) { | 577 content::WebContents* web_contents) { |
| 555 return chrome::CreateWebContentsViewDelegate(web_contents); | 578 return chrome::CreateWebContentsViewDelegate(web_contents); |
| 556 } | 579 } |
| 557 | 580 |
| 558 void ChromeContentBrowserClient::RenderViewHostCreated( | 581 void ChromeContentBrowserClient::RenderViewHostCreated( |
| 559 RenderViewHost* render_view_host) { | 582 RenderViewHost* render_view_host) { |
| (...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 io_thread_application_locale_ = locale; | 1936 io_thread_application_locale_ = locale; |
| 1914 } | 1937 } |
| 1915 | 1938 |
| 1916 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1939 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
| 1917 const std::string& locale) { | 1940 const std::string& locale) { |
| 1918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1919 io_thread_application_locale_ = locale; | 1942 io_thread_application_locale_ = locale; |
| 1920 } | 1943 } |
| 1921 | 1944 |
| 1922 } // namespace chrome | 1945 } // namespace chrome |
| OLD | NEW |