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_split.h" | |
Charlie Reis
2012/11/07 18:38:36
Do we still need this?
nasko
2012/11/07 18:48:05
Done.
| |
14 #include "base/string_tokenizer.h" | 15 #include "base/string_tokenizer.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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 #include "content/public/browser/render_process_host.h" | 95 #include "content/public/browser/render_process_host.h" |
95 #include "content/public/browser/render_view_host.h" | 96 #include "content/public/browser/render_view_host.h" |
96 #include "content/public/browser/resource_context.h" | 97 #include "content/public/browser/resource_context.h" |
97 #include "content/public/browser/site_instance.h" | 98 #include "content/public/browser/site_instance.h" |
98 #include "content/public/browser/web_contents.h" | 99 #include "content/public/browser/web_contents.h" |
99 #include "content/public/browser/web_contents_view.h" | 100 #include "content/public/browser/web_contents_view.h" |
100 #include "content/public/common/child_process_host.h" | 101 #include "content/public/common/child_process_host.h" |
101 #include "content/public/common/content_descriptors.h" | 102 #include "content/public/common/content_descriptors.h" |
102 #include "grit/generated_resources.h" | 103 #include "grit/generated_resources.h" |
103 #include "grit/ui_resources.h" | 104 #include "grit/ui_resources.h" |
105 #include "net/base/escape.h" | |
104 #include "net/base/ssl_cert_request_info.h" | 106 #include "net/base/ssl_cert_request_info.h" |
105 #include "net/cookies/canonical_cookie.h" | 107 #include "net/cookies/canonical_cookie.h" |
106 #include "net/cookies/cookie_options.h" | 108 #include "net/cookies/cookie_options.h" |
107 #include "ppapi/host/ppapi_host.h" | 109 #include "ppapi/host/ppapi_host.h" |
108 #include "ui/base/l10n/l10n_util.h" | 110 #include "ui/base/l10n/l10n_util.h" |
109 #include "ui/base/resource/resource_bundle.h" | 111 #include "ui/base/resource/resource_bundle.h" |
110 #include "webkit/glue/webpreferences.h" | 112 #include "webkit/glue/webpreferences.h" |
111 #include "webkit/plugins/plugin_switches.h" | 113 #include "webkit/plugins/plugin_switches.h" |
112 | 114 |
113 #if defined(OS_WIN) | 115 #if defined(OS_WIN) |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 return main_parts; | 464 return main_parts; |
463 } | 465 } |
464 | 466 |
465 content::WebContentsView* | 467 content::WebContentsView* |
466 ChromeContentBrowserClient::OverrideCreateWebContentsView( | 468 ChromeContentBrowserClient::OverrideCreateWebContentsView( |
467 WebContents* web_contents, | 469 WebContents* web_contents, |
468 content::RenderViewHostDelegateView** render_view_host_delegate_view) { | 470 content::RenderViewHostDelegateView** render_view_host_delegate_view) { |
469 return NULL; | 471 return NULL; |
470 } | 472 } |
471 | 473 |
472 std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess( | |
473 content::BrowserContext* browser_context, | |
474 int child_process_id) { | |
475 const Extension* extension = NULL; | |
476 Profile* profile = Profile::FromBrowserContext(browser_context); | |
477 ExtensionService* extension_service = | |
478 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
479 if (extension_service) { | |
480 std::set<std::string> extension_ids = | |
481 extension_service->process_map()-> | |
482 GetExtensionsInProcess(child_process_id); | |
483 if (!extension_ids.empty()) | |
484 // Since All the apps in a process share the same storage partition, | |
485 // we can pick any of them to retrieve the storage partition id. | |
486 extension = | |
487 extension_service->extensions()->GetByID(*(extension_ids.begin())); | |
488 } | |
489 return GetStoragePartitionIdForExtension(browser_context, extension); | |
490 } | |
491 | |
492 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( | 474 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
493 content::BrowserContext* browser_context, | 475 content::BrowserContext* browser_context, |
494 const GURL& site) { | 476 const GURL& site) { |
477 std::string partition_id; | |
478 | |
479 // The partition ID for webview guest processes is the string value of its | |
480 // SiteInstance URL - "chrome-guest://app_id/persist?partition". | |
481 if (site.SchemeIs(chrome::kGuestScheme)) { | |
Charlie Reis
2012/11/07 18:38:36
nit: No braces.
nasko
2012/11/07 18:48:05
Done.
| |
482 partition_id = site.spec(); | |
483 } | |
484 | |
485 DCHECK(IsValidStoragePartitionId(browser_context,partition_id)); | |
486 return partition_id; | |
487 } | |
488 | |
489 bool ChromeContentBrowserClient::IsValidStoragePartitionId( | |
490 content::BrowserContext* browser_context, | |
491 const std::string& partition_id) { | |
492 // The default ID is empty and is always valid. | |
493 if (partition_id.empty()) | |
494 return true; | |
495 | |
496 GURL guest_url(partition_id); | |
497 | |
498 return guest_url.is_valid(); | |
499 } | |
500 | |
501 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( | |
502 content::BrowserContext* browser_context, | |
503 const GURL& site, | |
504 std::string* partition_domain, | |
505 std::string* partition_name, | |
506 bool* in_memory) { | |
507 // For the webview tag, we create special guest processes, which host the | |
508 // 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 | |
510 // 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 | |
512 // the partition requested by it. The format for that URL is: | |
513 // chrome-guest://partition_domain/persist?partition_name | |
514 if (site.SchemeIs(chrome::kGuestScheme)) { | |
515 // Since guest URLs are only used for packaged apps, there must be an app | |
516 // id in the URL. | |
517 CHECK(site.has_host()); | |
518 *partition_domain = site.host(); | |
519 // Since persistence is optional, the path must either be empty or the | |
520 // literal string. | |
521 *in_memory = (site.path() != "/persist"); | |
522 // The partition name is user supplied value, which we have encoded when the | |
523 // URL was created, so it needs to be decoded. | |
524 *partition_name = net::UnescapeURLComponent(site.query(), | |
525 net::UnescapeRule::NORMAL); | |
526 return; | |
527 } | |
528 | |
495 const Extension* extension = NULL; | 529 const Extension* extension = NULL; |
496 Profile* profile = Profile::FromBrowserContext(browser_context); | 530 Profile* profile = Profile::FromBrowserContext(browser_context); |
497 ExtensionService* extension_service = | 531 ExtensionService* extension_service = |
498 extensions::ExtensionSystem::Get(profile)->extension_service(); | 532 extensions::ExtensionSystem::Get(profile)->extension_service(); |
499 if (extension_service) { | 533 if (extension_service) { |
500 extension = extension_service->extensions()-> | 534 extension = extension_service->extensions()-> |
501 GetExtensionOrAppByURL(ExtensionURLInfo(site)); | 535 GetExtensionOrAppByURL(ExtensionURLInfo(site)); |
536 if (extension && extension->is_storage_isolated()) { | |
537 // Extensions, which have storage isolation enabled (e.g., apps), use | |
Charlie Reis
2012/11/07 18:38:36
nit: Extensions which have
(Saying "extensions, w
nasko
2012/11/07 18:48:05
Done.
| |
538 // the extension id as the |partition_domain|. | |
539 *partition_domain = extension->id(); | |
540 partition_name->clear(); | |
541 *in_memory = false; | |
542 return; | |
543 } | |
502 } | 544 } |
503 | 545 |
504 return GetStoragePartitionIdForExtension(browser_context, extension); | 546 // All other cases use the default, browser-wide, storage partition. |
505 } | 547 partition_domain->clear(); |
506 | 548 partition_name->clear(); |
507 bool ChromeContentBrowserClient::IsValidStoragePartitionId( | 549 *in_memory = false; |
508 content::BrowserContext* browser_context, | |
509 const std::string& partition_id) { | |
510 // The default ID is empty which is always allowed. | |
511 if (partition_id.empty()) | |
512 return true; | |
513 | |
514 // If it isn't empty, then it must belong to an extension of some sort. Parse | |
515 // out the extension ID and make sure it is still installed. | |
516 Profile* profile = Profile::FromBrowserContext(browser_context); | |
517 ExtensionService* extension_service = | |
518 extensions::ExtensionSystem::Get(profile)->extension_service(); | |
519 if (!extension_service) { | |
520 // No extension service means no storage partitions in Chrome. | |
521 return false; | |
522 } | |
523 | |
524 // See if we can find an extension. The |partition_id| is the extension ID so | |
525 // no parsing needed to be done. | |
526 return extension_service->GetExtensionById(partition_id, false) != NULL; | |
527 } | 550 } |
528 | 551 |
529 content::WebContentsViewDelegate* | 552 content::WebContentsViewDelegate* |
530 ChromeContentBrowserClient::GetWebContentsViewDelegate( | 553 ChromeContentBrowserClient::GetWebContentsViewDelegate( |
531 content::WebContents* web_contents) { | 554 content::WebContents* web_contents) { |
532 return chrome::CreateWebContentsViewDelegate(web_contents); | 555 return chrome::CreateWebContentsViewDelegate(web_contents); |
533 } | 556 } |
534 | 557 |
535 void ChromeContentBrowserClient::RenderViewHostCreated( | 558 void ChromeContentBrowserClient::RenderViewHostCreated( |
536 RenderViewHost* render_view_host) { | 559 RenderViewHost* render_view_host) { |
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1601 if (web_prefs->default_encoding.empty()) { | 1624 if (web_prefs->default_encoding.empty()) { |
1602 prefs->ClearPref(prefs::kDefaultCharset); | 1625 prefs->ClearPref(prefs::kDefaultCharset); |
1603 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); | 1626 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
1604 } | 1627 } |
1605 DCHECK(!web_prefs->default_encoding.empty()); | 1628 DCHECK(!web_prefs->default_encoding.empty()); |
1606 | 1629 |
1607 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 1630 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
1608 chrome::ViewType view_type = chrome::GetViewType(web_contents); | 1631 chrome::ViewType view_type = chrome::GetViewType(web_contents); |
1609 ExtensionService* service = profile->GetExtensionService(); | 1632 ExtensionService* service = profile->GetExtensionService(); |
1610 if (service) { | 1633 if (service) { |
1611 const Extension* extension = service->extensions()->GetByID( | 1634 const GURL& url = rvh->GetSiteInstance()->GetSiteURL(); |
1612 rvh->GetSiteInstance()->GetSiteURL().host()); | 1635 const Extension* extension = service->extensions()->GetByID(url.host()); |
1613 extension_webkit_preferences::SetPreferences( | 1636 // Ensure that we are only granting extension preferences to URLs with |
1614 extension, view_type, web_prefs); | 1637 // the correct scheme. Without this check, chrome-guest:// schemes used by |
1638 // webview tags as well as hosts that happen to match the id of an | |
1639 // installed extension would get the wrong preferences. | |
1640 if (url.SchemeIs(chrome::kExtensionScheme)) { | |
1641 extension_webkit_preferences::SetPreferences( | |
1642 extension, view_type, web_prefs); | |
1643 } | |
1615 } | 1644 } |
1616 | 1645 |
1617 if (content::IsForceCompositingModeEnabled()) | 1646 if (content::IsForceCompositingModeEnabled()) |
1618 web_prefs->force_compositing_mode = true; | 1647 web_prefs->force_compositing_mode = true; |
1619 | 1648 |
1620 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { | 1649 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { |
1621 web_prefs->allow_scripts_to_close_windows = true; | 1650 web_prefs->allow_scripts_to_close_windows = true; |
1622 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { | 1651 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { |
1623 // Disable all kinds of acceleration for background pages. | 1652 // Disable all kinds of acceleration for background pages. |
1624 // See http://crbug.com/96005 and http://crbug.com/96006 | 1653 // See http://crbug.com/96005 and http://crbug.com/96006 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1866 base::Unretained(this), locale))) | 1895 base::Unretained(this), locale))) |
1867 io_thread_application_locale_ = locale; | 1896 io_thread_application_locale_ = locale; |
1868 } | 1897 } |
1869 | 1898 |
1870 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( | 1899 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( |
1871 const std::string& locale) { | 1900 const std::string& locale) { |
1872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1873 io_thread_application_locale_ = locale; | 1902 io_thread_application_locale_ = locale; |
1874 } | 1903 } |
1875 | 1904 |
1876 std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension( | |
1877 content::BrowserContext* browser_context, const Extension* extension) { | |
1878 // In chrome, we use the extension ID as the partition ID. This works well | |
1879 // because the extension ID fits the partition ID pattern and currently only | |
1880 // apps can designate that storage should be isolated. | |
1881 // | |
1882 // If |extension| is NULL, then the default, empty string, partition id is | |
1883 // used. | |
1884 std::string partition_id; | |
1885 if (extension && extension->is_storage_isolated()) { | |
1886 partition_id = extension->id(); | |
1887 } | |
1888 | |
1889 // Enforce that IsValidStoragePartitionId() implementation stays in sync. | |
1890 DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); | |
1891 return partition_id; | |
1892 } | |
1893 | |
1894 | |
1895 } // namespace chrome | 1905 } // namespace chrome |
OLD | NEW |