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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 // The default ID is empty and is always valid. | 494 // The default ID is empty and is always valid. |
495 if (partition_id.empty()) | 495 if (partition_id.empty()) |
496 return true; | 496 return true; |
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 bool can_be_default, |
504 std::string* partition_domain, | 505 std::string* partition_domain, |
505 std::string* partition_name, | 506 std::string* partition_name, |
506 bool* in_memory) { | 507 bool* in_memory) { |
| 508 // Default to the browser-wide storage partition and override based on |site| |
| 509 // below. |
| 510 partition_domain->clear(); |
| 511 partition_name->clear(); |
| 512 *in_memory = false; |
| 513 |
507 // For the webview tag, we create special guest processes, which host the | 514 // For the webview tag, we create special guest processes, which host the |
508 // tag content separately from the main application that embeds the tag. | 515 // 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 | 516 // 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 | 517 // 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 | 518 // 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: | 519 // the partition requested by it. The format for that URL is: |
513 // chrome-guest://partition_domain/persist?partition_name | 520 // chrome-guest://partition_domain/persist?partition_name |
514 if (site.SchemeIs(chrome::kGuestScheme)) { | 521 if (site.SchemeIs(chrome::kGuestScheme)) { |
515 // Since guest URLs are only used for packaged apps, there must be an app | 522 // Since guest URLs are only used for packaged apps, there must be an app |
516 // id in the URL. | 523 // id in the URL. |
517 CHECK(site.has_host()); | 524 CHECK(site.has_host()); |
518 *partition_domain = site.host(); | 525 *partition_domain = site.host(); |
519 // Since persistence is optional, the path must either be empty or the | 526 // Since persistence is optional, the path must either be empty or the |
520 // literal string. | 527 // literal string. |
521 *in_memory = (site.path() != "/persist"); | 528 *in_memory = (site.path() != "/persist"); |
522 // The partition name is user supplied value, which we have encoded when the | 529 // The partition name is user supplied value, which we have encoded when the |
523 // URL was created, so it needs to be decoded. | 530 // URL was created, so it needs to be decoded. |
524 *partition_name = net::UnescapeURLComponent(site.query(), | 531 *partition_name = net::UnescapeURLComponent(site.query(), |
525 net::UnescapeRule::NORMAL); | 532 net::UnescapeRule::NORMAL); |
526 return; | 533 } else if (site.SchemeIs(extensions::kExtensionScheme)) { |
527 } | 534 // If |can_be_default| is false, the caller is stating that the |site| |
| 535 // should be parsed as if it had isolated storage. In particular it is |
| 536 // important to NOT check ExtensionService for the is_storage_isolated() |
| 537 // attribute because this code path is run during Extension uninstall |
| 538 // to do cleanup after the Extension has already been unloaded from the |
| 539 // ExtensionService. |
| 540 bool is_isolated = !can_be_default; |
| 541 if (can_be_default) { |
| 542 const Extension* extension = NULL; |
| 543 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 544 ExtensionService* extension_service = |
| 545 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 546 if (extension_service) { |
| 547 extension = extension_service->extensions()-> |
| 548 GetExtensionOrAppByURL(ExtensionURLInfo(site)); |
| 549 if (extension && extension->is_storage_isolated()) { |
| 550 is_isolated = true; |
| 551 } |
| 552 } |
| 553 } |
528 | 554 |
529 const Extension* extension = NULL; | 555 if (is_isolated) { |
530 Profile* profile = Profile::FromBrowserContext(browser_context); | 556 CHECK(site.has_host()); |
531 ExtensionService* extension_service = | 557 // For extensions with isolated storage, the the host of the |site| is |
532 extensions::ExtensionSystem::Get(profile)->extension_service(); | 558 // the |partition_domain|. The |in_memory| and |partition_name| are only |
533 if (extension_service) { | 559 // used in guest schemes so they are cleared here. |
534 extension = extension_service->extensions()-> | 560 *partition_domain = site.host(); |
535 GetExtensionOrAppByURL(ExtensionURLInfo(site)); | 561 *in_memory = false; |
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(); | 562 partition_name->clear(); |
541 *in_memory = false; | |
542 return; | |
543 } | 563 } |
544 } | 564 } |
545 | 565 |
546 // All other cases use the default, browser-wide, storage partition. | 566 // Assert that if |can_be_default| is false, the code above must have found a |
547 partition_domain->clear(); | 567 // non-default partition. If this fails, the caller has a serious logic |
548 partition_name->clear(); | 568 // error about which StoragePartition they expect to be in and it is not |
549 *in_memory = false; | 569 // safe to continue. |
| 570 CHECK(can_be_default || !partition_domain->empty()); |
550 } | 571 } |
551 | 572 |
552 content::WebContentsViewDelegate* | 573 content::WebContentsViewDelegate* |
553 ChromeContentBrowserClient::GetWebContentsViewDelegate( | 574 ChromeContentBrowserClient::GetWebContentsViewDelegate( |
554 content::WebContents* web_contents) { | 575 content::WebContents* web_contents) { |
555 return chrome::CreateWebContentsViewDelegate(web_contents); | 576 return chrome::CreateWebContentsViewDelegate(web_contents); |
556 } | 577 } |
557 | 578 |
558 void ChromeContentBrowserClient::RenderViewHostCreated( | 579 void ChromeContentBrowserClient::RenderViewHostCreated( |
559 RenderViewHost* render_view_host) { | 580 RenderViewHost* render_view_host) { |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 io_thread_application_locale_ = locale; | 1934 io_thread_application_locale_ = locale; |
1914 } | 1935 } |
1915 | 1936 |
1916 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1937 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
1917 const std::string& locale) { | 1938 const std::string& locale) { |
1918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1919 io_thread_application_locale_ = locale; | 1940 io_thread_application_locale_ = locale; |
1920 } | 1941 } |
1921 | 1942 |
1922 } // namespace chrome | 1943 } // namespace chrome |
OLD | NEW |