Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 11234032: Webview tag creation should be using storage partitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disabling session storage test for isolated apps. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 #include "content/public/browser/render_process_host.h" 94 #include "content/public/browser/render_process_host.h"
95 #include "content/public/browser/render_view_host.h" 95 #include "content/public/browser/render_view_host.h"
96 #include "content/public/browser/resource_context.h" 96 #include "content/public/browser/resource_context.h"
97 #include "content/public/browser/site_instance.h" 97 #include "content/public/browser/site_instance.h"
98 #include "content/public/browser/web_contents.h" 98 #include "content/public/browser/web_contents.h"
99 #include "content/public/browser/web_contents_view.h" 99 #include "content/public/browser/web_contents_view.h"
100 #include "content/public/common/child_process_host.h" 100 #include "content/public/common/child_process_host.h"
101 #include "content/public/common/content_descriptors.h" 101 #include "content/public/common/content_descriptors.h"
102 #include "grit/generated_resources.h" 102 #include "grit/generated_resources.h"
103 #include "grit/ui_resources.h" 103 #include "grit/ui_resources.h"
104 #include "net/base/escape.h"
104 #include "net/base/ssl_cert_request_info.h" 105 #include "net/base/ssl_cert_request_info.h"
105 #include "net/cookies/canonical_cookie.h" 106 #include "net/cookies/canonical_cookie.h"
106 #include "net/cookies/cookie_options.h" 107 #include "net/cookies/cookie_options.h"
107 #include "ppapi/host/ppapi_host.h" 108 #include "ppapi/host/ppapi_host.h"
108 #include "ui/base/l10n/l10n_util.h" 109 #include "ui/base/l10n/l10n_util.h"
109 #include "ui/base/resource/resource_bundle.h" 110 #include "ui/base/resource/resource_bundle.h"
110 #include "webkit/glue/webpreferences.h" 111 #include "webkit/glue/webpreferences.h"
111 #include "webkit/plugins/plugin_switches.h" 112 #include "webkit/plugins/plugin_switches.h"
112 113
113 #if defined(OS_WIN) 114 #if defined(OS_WIN)
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return main_parts; 463 return main_parts;
463 } 464 }
464 465
465 content::WebContentsView* 466 content::WebContentsView*
466 ChromeContentBrowserClient::OverrideCreateWebContentsView( 467 ChromeContentBrowserClient::OverrideCreateWebContentsView(
467 WebContents* web_contents, 468 WebContents* web_contents,
468 content::RenderViewHostDelegateView** render_view_host_delegate_view) { 469 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
469 return NULL; 470 return NULL;
470 } 471 }
471 472
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( 473 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
493 content::BrowserContext* browser_context, 474 content::BrowserContext* browser_context,
494 const GURL& site) { 475 const GURL& site) {
476 std::string partition_id;
477
478 // The partition ID for webview guest processes is the string value of its
479 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
480 if (site.SchemeIs(chrome::kGuestScheme))
481 partition_id = site.spec();
482
483 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
484 return partition_id;
485 }
486
487 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
488 content::BrowserContext* browser_context,
489 const std::string& partition_id) {
490 // The default ID is empty and is always valid.
491 if (partition_id.empty())
492 return true;
493
494 return GURL(partition_id).is_valid();
495 }
496
497 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
498 content::BrowserContext* browser_context,
499 const GURL& site,
500 std::string* partition_domain,
501 std::string* partition_name,
502 bool* in_memory) {
503 // For the webview tag, we create special guest processes, which host the
504 // tag content separately from the main application that embeds the tag.
505 // A webview tag can specify both the partition name and whether the storage
506 // for that partition should be persisted. Each tag gets a SiteInstance with
507 // a specially formatted URL, based on the application it is hosted by and
508 // the partition requested by it. The format for that URL is:
509 // chrome-guest://partition_domain/persist?partition_name
510 if (site.SchemeIs(chrome::kGuestScheme)) {
511 // Since guest URLs are only used for packaged apps, there must be an app
512 // id in the URL.
513 CHECK(site.has_host());
514 *partition_domain = site.host();
515 // Since persistence is optional, the path must either be empty or the
516 // literal string.
517 *in_memory = (site.path() != "/persist");
518 // The partition name is user supplied value, which we have encoded when the
519 // URL was created, so it needs to be decoded.
520 *partition_name = net::UnescapeURLComponent(site.query(),
521 net::UnescapeRule::NORMAL);
522 return;
523 }
524
495 const Extension* extension = NULL; 525 const Extension* extension = NULL;
496 Profile* profile = Profile::FromBrowserContext(browser_context); 526 Profile* profile = Profile::FromBrowserContext(browser_context);
497 ExtensionService* extension_service = 527 ExtensionService* extension_service =
498 extensions::ExtensionSystem::Get(profile)->extension_service(); 528 extensions::ExtensionSystem::Get(profile)->extension_service();
499 if (extension_service) { 529 if (extension_service) {
500 extension = extension_service->extensions()-> 530 extension = extension_service->extensions()->
501 GetExtensionOrAppByURL(ExtensionURLInfo(site)); 531 GetExtensionOrAppByURL(ExtensionURLInfo(site));
532 if (extension && extension->is_storage_isolated()) {
533 // Extensions which have storage isolation enabled (e.g., apps), use
534 // the extension id as the |partition_domain|.
535 *partition_domain = extension->id();
536 partition_name->clear();
537 *in_memory = false;
538 return;
539 }
502 } 540 }
503 541
504 return GetStoragePartitionIdForExtension(browser_context, extension); 542 // All other cases use the default, browser-wide, storage partition.
505 } 543 partition_domain->clear();
506 544 partition_name->clear();
507 bool ChromeContentBrowserClient::IsValidStoragePartitionId( 545 *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 } 546 }
528 547
529 content::WebContentsViewDelegate* 548 content::WebContentsViewDelegate*
530 ChromeContentBrowserClient::GetWebContentsViewDelegate( 549 ChromeContentBrowserClient::GetWebContentsViewDelegate(
531 content::WebContents* web_contents) { 550 content::WebContents* web_contents) {
532 return chrome::CreateWebContentsViewDelegate(web_contents); 551 return chrome::CreateWebContentsViewDelegate(web_contents);
533 } 552 }
534 553
535 void ChromeContentBrowserClient::RenderViewHostCreated( 554 void ChromeContentBrowserClient::RenderViewHostCreated(
536 RenderViewHost* render_view_host) { 555 RenderViewHost* render_view_host) {
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 if (web_prefs->default_encoding.empty()) { 1620 if (web_prefs->default_encoding.empty()) {
1602 prefs->ClearPref(prefs::kDefaultCharset); 1621 prefs->ClearPref(prefs::kDefaultCharset);
1603 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 1622 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
1604 } 1623 }
1605 DCHECK(!web_prefs->default_encoding.empty()); 1624 DCHECK(!web_prefs->default_encoding.empty());
1606 1625
1607 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); 1626 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1608 chrome::ViewType view_type = chrome::GetViewType(web_contents); 1627 chrome::ViewType view_type = chrome::GetViewType(web_contents);
1609 ExtensionService* service = profile->GetExtensionService(); 1628 ExtensionService* service = profile->GetExtensionService();
1610 if (service) { 1629 if (service) {
1611 const Extension* extension = service->extensions()->GetByID( 1630 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1612 rvh->GetSiteInstance()->GetSiteURL().host()); 1631 const Extension* extension = service->extensions()->GetByID(url.host());
1613 extension_webkit_preferences::SetPreferences( 1632 // Ensure that we are only granting extension preferences to URLs with
1614 extension, view_type, web_prefs); 1633 // the correct scheme. Without this check, chrome-guest:// schemes used by
1634 // webview tags as well as hosts that happen to match the id of an
1635 // installed extension would get the wrong preferences.
1636 if (url.SchemeIs(chrome::kExtensionScheme)) {
1637 extension_webkit_preferences::SetPreferences(
1638 extension, view_type, web_prefs);
1639 }
1615 } 1640 }
1616 1641
1617 if (content::IsForceCompositingModeEnabled()) 1642 if (content::IsForceCompositingModeEnabled())
1618 web_prefs->force_compositing_mode = true; 1643 web_prefs->force_compositing_mode = true;
1619 1644
1620 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { 1645 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
1621 web_prefs->allow_scripts_to_close_windows = true; 1646 web_prefs->allow_scripts_to_close_windows = true;
1622 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { 1647 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1623 // Disable all kinds of acceleration for background pages. 1648 // Disable all kinds of acceleration for background pages.
1624 // See http://crbug.com/96005 and http://crbug.com/96006 1649 // See http://crbug.com/96005 and http://crbug.com/96006
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1866 base::Unretained(this), locale))) 1891 base::Unretained(this), locale)))
1867 io_thread_application_locale_ = locale; 1892 io_thread_application_locale_ = locale;
1868 } 1893 }
1869 1894
1870 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( 1895 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1871 const std::string& locale) { 1896 const std::string& locale) {
1872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1873 io_thread_application_locale_ = locale; 1898 io_thread_application_locale_ = locale;
1874 } 1899 }
1875 1900
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 1901 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | chrome/browser/extensions/isolated_app_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698