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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/string_tokenizer.h" | 14 #include "base/string_tokenizer.h" |
15 #include "base/string_util.h" | |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "chrome/app/breakpad_mac.h" | 17 #include "chrome/app/breakpad_mac.h" |
17 #include "chrome/browser/browser_about_handler.h" | 18 #include "chrome/browser/browser_about_handler.h" |
18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
20 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
21 #include "chrome/browser/character_encoding.h" | 22 #include "chrome/browser/character_encoding.h" |
22 #include "chrome/browser/chrome_benchmarking_message_filter.h" | 23 #include "chrome/browser/chrome_benchmarking_message_filter.h" |
23 #include "chrome/browser/chrome_quota_permission_context.h" | 24 #include "chrome/browser/chrome_quota_permission_context.h" |
24 #include "chrome/browser/content_settings/content_settings_utils.h" | 25 #include "chrome/browser/content_settings/content_settings_utils.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 #include "content/public/browser/render_process_host.h" | 94 #include "content/public/browser/render_process_host.h" |
94 #include "content/public/browser/render_view_host.h" | 95 #include "content/public/browser/render_view_host.h" |
95 #include "content/public/browser/resource_context.h" | 96 #include "content/public/browser/resource_context.h" |
96 #include "content/public/browser/site_instance.h" | 97 #include "content/public/browser/site_instance.h" |
97 #include "content/public/browser/web_contents.h" | 98 #include "content/public/browser/web_contents.h" |
98 #include "content/public/browser/web_contents_view.h" | 99 #include "content/public/browser/web_contents_view.h" |
99 #include "content/public/common/child_process_host.h" | 100 #include "content/public/common/child_process_host.h" |
100 #include "content/public/common/content_descriptors.h" | 101 #include "content/public/common/content_descriptors.h" |
101 #include "grit/generated_resources.h" | 102 #include "grit/generated_resources.h" |
102 #include "grit/ui_resources.h" | 103 #include "grit/ui_resources.h" |
104 #include "net/base/escape.h" | |
103 #include "net/base/ssl_cert_request_info.h" | 105 #include "net/base/ssl_cert_request_info.h" |
104 #include "net/cookies/canonical_cookie.h" | 106 #include "net/cookies/canonical_cookie.h" |
105 #include "net/cookies/cookie_options.h" | 107 #include "net/cookies/cookie_options.h" |
106 #include "ppapi/host/ppapi_host.h" | 108 #include "ppapi/host/ppapi_host.h" |
107 #include "ui/base/l10n/l10n_util.h" | 109 #include "ui/base/l10n/l10n_util.h" |
108 #include "ui/base/resource/resource_bundle.h" | 110 #include "ui/base/resource/resource_bundle.h" |
109 #include "webkit/glue/webpreferences.h" | 111 #include "webkit/glue/webpreferences.h" |
110 #include "webkit/plugins/plugin_switches.h" | 112 #include "webkit/plugins/plugin_switches.h" |
111 | 113 |
112 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 return main_parts; | 463 return main_parts; |
462 } | 464 } |
463 | 465 |
464 content::WebContentsView* | 466 content::WebContentsView* |
465 ChromeContentBrowserClient::OverrideCreateWebContentsView( | 467 ChromeContentBrowserClient::OverrideCreateWebContentsView( |
466 WebContents* web_contents, | 468 WebContents* web_contents, |
467 content::RenderViewHostDelegateView** render_view_host_delegate_view) { | 469 content::RenderViewHostDelegateView** render_view_host_delegate_view) { |
468 return NULL; | 470 return NULL; |
469 } | 471 } |
470 | 472 |
471 std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess( | 473 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
474 content::BrowserContext* browser_context, | |
475 const GURL& site) { | |
476 std::string app_id; | |
477 std::string partition_name; | |
478 bool in_memory; | |
Charlie Reis
2012/11/05 18:15:37
Should probably initialize this, in case a bug lat
nasko
2012/11/05 19:20:26
Done.
| |
479 | |
480 // We need to get all the pieces that will go into the storage partition | |
481 // identifier first, before we compose it. | |
482 GetStoragePartitionConfigForSite(browser_context, site, &app_id, | |
483 &partition_name, &in_memory); | |
484 | |
485 // If there is no app, we are in the default browser partition, so return | |
486 // an empty string. | |
487 if (app_id.empty()) | |
488 return std::string(); | |
489 | |
490 // A non-empty storage partition id string is of the form | |
491 // "app_id:in_memory:partition_name", where each of the three parts is | |
Charlie Reis
2012/11/05 18:15:37
I'm not entirely clear on why we need this format.
nasko
2012/11/05 19:20:26
I've had the same discussion with Albert. He feels
awong
2012/11/05 20:11:18
My objection was that GURL had too much validation
| |
492 // optional and the ':' separators are mandatory. Since "in_memory" is fixed | |
493 // string and the app_id cannot contain the separator, it is safe to parse | |
Charlie Reis
2012/11/05 18:15:37
What are the restrictions on the partition_name?
nasko
2012/11/05 19:20:26
I do have a bug here, the user supplied partition
| |
494 // the string based on the two separators. | |
495 std::string partition_id = base::StringPrintf("%s:%s:%s", | |
496 app_id.c_str(), | |
497 in_memory ? "in-memory" : "", | |
498 partition_name.c_str()); | |
499 | |
500 DCHECK(IsValidStoragePartitionId(browser_context,partition_id)); | |
501 return partition_id; | |
502 } | |
503 | |
504 bool ChromeContentBrowserClient::IsValidStoragePartitionId( | |
472 content::BrowserContext* browser_context, | 505 content::BrowserContext* browser_context, |
473 int child_process_id) { | 506 const std::string& partition_id) { |
474 const Extension* extension = NULL; | 507 // The default ID is empty and is always valid. |
508 if (partition_id.empty()) | |
509 return true; | |
510 | |
475 Profile* profile = Profile::FromBrowserContext(browser_context); | 511 Profile* profile = Profile::FromBrowserContext(browser_context); |
476 ExtensionService* extension_service = | 512 ExtensionService* extension_service = |
477 extensions::ExtensionSystem::Get(profile)->extension_service(); | 513 extensions::ExtensionSystem::Get(profile)->extension_service(); |
478 if (extension_service) { | 514 |
479 std::set<std::string> extension_ids = | 515 // Now, parse the three parts of the partition ID, so we can verify them. |
480 extension_service->process_map()-> | 516 // Set the tokenizer to return delimiters, otherwise we won't get the correct |
481 GetExtensionsInProcess(child_process_id); | 517 // count of delimiters and will fail validation. |
482 if (!extension_ids.empty()) | 518 int token = 0; |
483 // Since All the apps in a process share the same storage partition, | 519 StringTokenizer t(partition_id, ":"); |
484 // we can pick any of them to retrieve the storage partition id. | 520 t.set_options(StringTokenizer::RETURN_DELIMS); |
485 extension = | 521 |
486 extension_service->extensions()->GetByID(*(extension_ids.begin())); | 522 while (t.GetNext()) { |
523 if (t.token_is_delim()) { | |
524 token++; | |
525 continue; | |
526 } | |
527 switch (token) { | |
528 // Starting off with the app id, verify it exists. | |
529 case 0: | |
530 if (!t.token().empty()) { | |
531 // No extension service means no storage partitions in Chrome. | |
532 if (!extension_service) | |
533 return false; | |
534 if (extension_service->GetExtensionById(t.token(), false) == NULL) | |
535 return false; | |
536 } | |
537 break; | |
538 // The second token is either empty or the "in-memory" string. | |
539 case 1: | |
540 if (!t.token().empty() && t.token() != "in-memory") | |
541 return false; | |
542 break; | |
543 // We don't verify the partition_name, as it is user supplied and there is | |
544 // no format constraints to it. | |
545 case 2: | |
546 break; | |
547 // We only expect three parts in the partition_id string, fail otherwise. | |
548 default: | |
549 NOTREACHED(); | |
550 return false; | |
551 } | |
487 } | 552 } |
488 return GetStoragePartitionIdForExtension(browser_context, extension); | 553 |
554 // If there weren't three tokens, even if empty, then it is not a valid | |
555 // partition id. | |
556 return (token == 2); | |
489 } | 557 } |
490 | 558 |
491 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( | 559 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
492 content::BrowserContext* browser_context, | 560 content::BrowserContext* browser_context, |
493 const GURL& site) { | 561 const GURL& site, |
562 std::string* app_id, | |
563 std::string* partition_name, | |
564 bool* in_memory) { | |
565 if (site.SchemeIs(chrome::kGuestScheme)) { | |
Charlie Reis
2012/11/05 18:15:37
Please add some comments for each of these blocks,
nasko
2012/11/05 19:20:26
Done.
| |
566 CHECK(site.has_host()); | |
567 *app_id = site.host(); | |
568 *partition_name = net::UnescapeURLComponent(site.query(), | |
569 net::UnescapeRule::NORMAL); | |
570 *in_memory = ((site.path() == "/persist") ? false : true); | |
571 return; | |
572 } | |
573 | |
494 const Extension* extension = NULL; | 574 const Extension* extension = NULL; |
495 Profile* profile = Profile::FromBrowserContext(browser_context); | 575 Profile* profile = Profile::FromBrowserContext(browser_context); |
496 ExtensionService* extension_service = | 576 ExtensionService* extension_service = |
497 extensions::ExtensionSystem::Get(profile)->extension_service(); | 577 extensions::ExtensionSystem::Get(profile)->extension_service(); |
498 if (extension_service) { | 578 if (extension_service) { |
499 extension = extension_service->extensions()-> | 579 extension = extension_service->extensions()-> |
500 GetExtensionOrAppByURL(ExtensionURLInfo(site)); | 580 GetExtensionOrAppByURL(ExtensionURLInfo(site)); |
581 if (extension && extension->is_storage_isolated()) { | |
582 *app_id = extension->id(); | |
583 *partition_name = std::string(); | |
584 *in_memory = false; | |
585 return; | |
586 } | |
501 } | 587 } |
502 | 588 |
503 return GetStoragePartitionIdForExtension(browser_context, extension); | 589 *app_id = std::string(); |
504 } | 590 *partition_name = std::string(); |
505 | 591 *in_memory = false; |
506 bool ChromeContentBrowserClient::IsValidStoragePartitionId( | |
507 content::BrowserContext* browser_context, | |
508 const std::string& partition_id) { | |
509 // The default ID is empty which is always allowed. | |
510 if (partition_id.empty()) | |
511 return true; | |
512 | |
513 // If it isn't empty, then it must belong to an extension of some sort. Parse | |
514 // out the extension ID and make sure it is still installed. | |
515 Profile* profile = Profile::FromBrowserContext(browser_context); | |
516 ExtensionService* extension_service = | |
517 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
518 if (!extension_service) { | |
519 // No extension service means no storage partitions in Chrome. | |
520 return false; | |
521 } | |
522 | |
523 // See if we can find an extension. The |partition_id| is the extension ID so | |
524 // no parsing needed to be done. | |
525 return extension_service->GetExtensionById(partition_id, false) != NULL; | |
526 } | 592 } |
527 | 593 |
528 content::WebContentsViewDelegate* | 594 content::WebContentsViewDelegate* |
529 ChromeContentBrowserClient::GetWebContentsViewDelegate( | 595 ChromeContentBrowserClient::GetWebContentsViewDelegate( |
530 content::WebContents* web_contents) { | 596 content::WebContents* web_contents) { |
531 return chrome::CreateWebContentsViewDelegate(web_contents); | 597 return chrome::CreateWebContentsViewDelegate(web_contents); |
532 } | 598 } |
533 | 599 |
534 void ChromeContentBrowserClient::RenderViewHostCreated( | 600 void ChromeContentBrowserClient::RenderViewHostCreated( |
535 RenderViewHost* render_view_host) { | 601 RenderViewHost* render_view_host) { |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1601 if (web_prefs->default_encoding.empty()) { | 1667 if (web_prefs->default_encoding.empty()) { |
1602 prefs->ClearPref(prefs::kDefaultCharset); | 1668 prefs->ClearPref(prefs::kDefaultCharset); |
1603 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); | 1669 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
1604 } | 1670 } |
1605 DCHECK(!web_prefs->default_encoding.empty()); | 1671 DCHECK(!web_prefs->default_encoding.empty()); |
1606 | 1672 |
1607 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 1673 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
1608 chrome::ViewType view_type = chrome::GetViewType(web_contents); | 1674 chrome::ViewType view_type = chrome::GetViewType(web_contents); |
1609 ExtensionService* service = profile->GetExtensionService(); | 1675 ExtensionService* service = profile->GetExtensionService(); |
1610 if (service) { | 1676 if (service) { |
1611 const Extension* extension = service->extensions()->GetByID( | 1677 const GURL& url = rvh->GetSiteInstance()->GetSiteURL(); |
1612 rvh->GetSiteInstance()->GetSiteURL().host()); | 1678 const Extension* extension = service->extensions()->GetByID(url.host()); |
1613 extension_webkit_preferences::SetPreferences( | 1679 // Ensure that we are only granting extension preferences to URLs with |
1614 extension, view_type, web_prefs); | 1680 // the correct scheme. Without this check, guest:// schemes used by |
1681 // webview tags as well as hosts that happen to match the id of an | |
1682 // installed extension would get the wrong preferences. | |
1683 if (url.SchemeIs(chrome::kExtensionScheme)) { | |
1684 extension_webkit_preferences::SetPreferences( | |
1685 extension, view_type, web_prefs); | |
1686 } | |
1615 } | 1687 } |
1616 | 1688 |
1617 if (content::IsForceCompositingModeEnabled()) | 1689 if (content::IsForceCompositingModeEnabled()) |
1618 web_prefs->force_compositing_mode = true; | 1690 web_prefs->force_compositing_mode = true; |
1619 | 1691 |
1620 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { | 1692 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { |
1621 web_prefs->allow_scripts_to_close_windows = true; | 1693 web_prefs->allow_scripts_to_close_windows = true; |
1622 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { | 1694 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { |
1623 // Disable all kinds of acceleration for background pages. | 1695 // Disable all kinds of acceleration for background pages. |
1624 // See http://crbug.com/96005 and http://crbug.com/96006 | 1696 // See http://crbug.com/96005 and http://crbug.com/96006 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1861 base::Unretained(this), locale))) | 1933 base::Unretained(this), locale))) |
1862 io_thread_application_locale_ = locale; | 1934 io_thread_application_locale_ = locale; |
1863 } | 1935 } |
1864 | 1936 |
1865 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1937 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
1866 const std::string& locale) { | 1938 const std::string& locale) { |
1867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1868 io_thread_application_locale_ = locale; | 1940 io_thread_application_locale_ = locale; |
1869 } | 1941 } |
1870 | 1942 |
1871 std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension( | |
1872 content::BrowserContext* browser_context, const Extension* extension) { | |
1873 // In chrome, we use the extension ID as the partition ID. This works well | |
1874 // because the extension ID fits the partition ID pattern and currently only | |
1875 // apps can designate that storage should be isolated. | |
1876 // | |
1877 // If |extension| is NULL, then the default, empty string, partition id is | |
1878 // used. | |
1879 std::string partition_id; | |
1880 if (extension && extension->is_storage_isolated()) { | |
1881 partition_id = extension->id(); | |
1882 } | |
1883 | |
1884 // Enforce that IsValidStoragePartitionId() implementation stays in sync. | |
1885 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); | |
1886 return partition_id; | |
1887 } | |
1888 | |
1889 | |
1890 } // namespace chrome | 1943 } // namespace chrome |
OLD | NEW |