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

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: Fixing remaining nits. 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 GURL guest_url(partition_id);
sky 2012/11/07 22:21:05 What's with the white space here? How about: retu
495
496 return guest_url.is_valid();
497 }
498
499 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
500 content::BrowserContext* browser_context,
501 const GURL& site,
502 std::string* partition_domain,
503 std::string* partition_name,
504 bool* in_memory) {
505 // For the webview tag, we create special guest processes, which host the
506 // tag content separately from the main application that embeds the tag.
507 // A webview tag can specify both the partition name and whether the storage
508 // for that partition should be persisted. Each tag gets a SiteInstance with
509 // a specially formatted URL, based on the application it is hosted by and
510 // the partition requested by it. The format for that URL is:
511 // chrome-guest://partition_domain/persist?partition_name
512 if (site.SchemeIs(chrome::kGuestScheme)) {
513 // Since guest URLs are only used for packaged apps, there must be an app
514 // id in the URL.
515 CHECK(site.has_host());
516 *partition_domain = site.host();
517 // Since persistence is optional, the path must either be empty or the
518 // literal string.
519 *in_memory = (site.path() != "/persist");
520 // The partition name is user supplied value, which we have encoded when the
521 // URL was created, so it needs to be decoded.
522 *partition_name = net::UnescapeURLComponent(site.query(),
523 net::UnescapeRule::NORMAL);
524 return;
525 }
526
495 const Extension* extension = NULL; 527 const Extension* extension = NULL;
496 Profile* profile = Profile::FromBrowserContext(browser_context); 528 Profile* profile = Profile::FromBrowserContext(browser_context);
497 ExtensionService* extension_service = 529 ExtensionService* extension_service =
498 extensions::ExtensionSystem::Get(profile)->extension_service(); 530 extensions::ExtensionSystem::Get(profile)->extension_service();
499 if (extension_service) { 531 if (extension_service) {
500 extension = extension_service->extensions()-> 532 extension = extension_service->extensions()->
501 GetExtensionOrAppByURL(ExtensionURLInfo(site)); 533 GetExtensionOrAppByURL(ExtensionURLInfo(site));
534 if (extension && extension->is_storage_isolated()) {
535 // Extensions which have storage isolation enabled (e.g., apps), use
536 // the extension id as the |partition_domain|.
537 *partition_domain = extension->id();
538 partition_name->clear();
539 *in_memory = false;
540 return;
541 }
502 } 542 }
503 543
504 return GetStoragePartitionIdForExtension(browser_context, extension); 544 // All other cases use the default, browser-wide, storage partition.
505 } 545 partition_domain->clear();
506 546 partition_name->clear();
507 bool ChromeContentBrowserClient::IsValidStoragePartitionId( 547 *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 } 548 }
528 549
529 content::WebContentsViewDelegate* 550 content::WebContentsViewDelegate*
530 ChromeContentBrowserClient::GetWebContentsViewDelegate( 551 ChromeContentBrowserClient::GetWebContentsViewDelegate(
531 content::WebContents* web_contents) { 552 content::WebContents* web_contents) {
532 return chrome::CreateWebContentsViewDelegate(web_contents); 553 return chrome::CreateWebContentsViewDelegate(web_contents);
533 } 554 }
534 555
535 void ChromeContentBrowserClient::RenderViewHostCreated( 556 void ChromeContentBrowserClient::RenderViewHostCreated(
536 RenderViewHost* render_view_host) { 557 RenderViewHost* render_view_host) {
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 if (web_prefs->default_encoding.empty()) { 1622 if (web_prefs->default_encoding.empty()) {
1602 prefs->ClearPref(prefs::kDefaultCharset); 1623 prefs->ClearPref(prefs::kDefaultCharset);
1603 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 1624 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
1604 } 1625 }
1605 DCHECK(!web_prefs->default_encoding.empty()); 1626 DCHECK(!web_prefs->default_encoding.empty());
1606 1627
1607 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); 1628 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1608 chrome::ViewType view_type = chrome::GetViewType(web_contents); 1629 chrome::ViewType view_type = chrome::GetViewType(web_contents);
1609 ExtensionService* service = profile->GetExtensionService(); 1630 ExtensionService* service = profile->GetExtensionService();
1610 if (service) { 1631 if (service) {
1611 const Extension* extension = service->extensions()->GetByID( 1632 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1612 rvh->GetSiteInstance()->GetSiteURL().host()); 1633 const Extension* extension = service->extensions()->GetByID(url.host());
1613 extension_webkit_preferences::SetPreferences( 1634 // Ensure that we are only granting extension preferences to URLs with
1614 extension, view_type, web_prefs); 1635 // the correct scheme. Without this check, chrome-guest:// schemes used by
1636 // webview tags as well as hosts that happen to match the id of an
1637 // installed extension would get the wrong preferences.
1638 if (url.SchemeIs(chrome::kExtensionScheme)) {
1639 extension_webkit_preferences::SetPreferences(
1640 extension, view_type, web_prefs);
1641 }
1615 } 1642 }
1616 1643
1617 if (content::IsForceCompositingModeEnabled()) 1644 if (content::IsForceCompositingModeEnabled())
1618 web_prefs->force_compositing_mode = true; 1645 web_prefs->force_compositing_mode = true;
1619 1646
1620 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { 1647 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
1621 web_prefs->allow_scripts_to_close_windows = true; 1648 web_prefs->allow_scripts_to_close_windows = true;
1622 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { 1649 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1623 // Disable all kinds of acceleration for background pages. 1650 // Disable all kinds of acceleration for background pages.
1624 // See http://crbug.com/96005 and http://crbug.com/96006 1651 // 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))) 1893 base::Unretained(this), locale)))
1867 io_thread_application_locale_ = locale; 1894 io_thread_application_locale_ = locale;
1868 } 1895 }
1869 1896
1870 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( 1897 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1871 const std::string& locale) { 1898 const std::string& locale) {
1872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1873 io_thread_application_locale_ = locale; 1900 io_thread_application_locale_ = locale;
1874 } 1901 }
1875 1902
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 1903 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698